This commit is contained in:
2025-01-13 21:52:33 -05:00
parent 4250598a5f
commit de03fa8741
3 changed files with 24 additions and 15 deletions

1
1.log Normal file
View File

@@ -0,0 +1 @@
NOP Error:

View File

@@ -1,13 +1,15 @@
AT Teppy AT Teppy ; addtrader Teppy
AT Luni AT Luni ; addtrader Luni
AT Hamza AT Hamza ; addtrader Hamza
AA USD AA USD ; addasset USD
AA BTC AA BTC ; addasset BTC
SR 1 51EB851 28F5C28 33333333 28F5C28 SR 0 51EB851 28F5C28 7AE147A 28F5C28 ; setroyalty USD 0.02 0.01 0.03 0.01
AF 1 1 500000000 SR 1 51EB851 28F5C28 7AE147A 28F5C28 ; setroyalty BTC 0.02 0.01 0.03 0.01
AF 2 0 3D09000000000 AF 1 1 500000000 ; addfunds Teppy 5 BTC
AF 3 0 3D09000000000 AF 2 0 186A000000000 ; addfunds Luni 100000 USD
SR 0 28F5C28 0 19999999 28F5C28 AF 3 0 186A000000000 ; addfunds Hamza 100000 USD
OR 1 1 100000000 0 C35000000000 OR 1 1 200000000 0 186A000000000 ; [login Teppy] order 2 BTC 100000 USD
OR 2 0 9C4000000000 1 100000000 OR 2 0 753000000000 1 80000000 ; [login Luni] order 30000 USD 0.5 BTC
OR 3 0 753000000000 1 80000000 OR 2 0 4E2000000000 1 80000000 ; [login Luni] order 20000 USD 0.5 BTC
OR 2 0 55F000000000 1 80000000
OR 2 1 40000000 0 35B600000000

View File

@@ -483,12 +483,12 @@ impl Market {
for (ap,pq) in &self.orders { for (ap,pq) in &self.orders {
println!("Orders selling {} to buy {}:",self.number_to_name(ap.0),self.number_to_name(ap.1)); println!("Orders selling {} to buy {}:",self.number_to_name(ap.0),self.number_to_name(ap.1));
let mut sorted=pq.v.clone(); let mut sorted=pq.v.clone();
sorted.sort_by(|a,b| { (a.sell_qty/a.buy_qty).cmp(&(b.sell_qty/b.buy_qty)) }); sorted.sort_by(|a,b| { (b.sell_qty/b.buy_qty).cmp(&(a.sell_qty/a.buy_qty)) });
for off in sorted.iter() { for off in sorted.iter() {
let rt=self.royalties.get_mut(&ap.1).unwrap(); let rt=self.royalties.get_mut(&ap.1).unwrap();
let indexr=rt.order_finder.get(&off.order_id).unwrap(); let indexr=rt.order_finder.get(&off.order_id).unwrap();
let royalty_amt=rt.get_royalty(*indexr); let royalty_amt=rt.get_royalty(*indexr);
println!(" {} @ {} ({}) OrderID: {} Royalties Accumulated: {} Royalties Offered {} Commissions Offered: {}", println!(" {} @ {} ({}) OrderID: {} Accumulated: {} Royalties {} Commissions: {}",
off.sell_remain, // off.buy_qty*off.sell_remain/off.sell_qty, off.sell_remain, // off.buy_qty*off.sell_remain/off.sell_qty,
(off.buy_qty/off.sell_qty).fmt_recip(), (off.buy_qty/off.sell_qty).fmt_recip(),
self.traders[off.owner as usize].name, self.traders[off.owner as usize].name,
@@ -532,6 +532,7 @@ impl Market {
let reader=io::BufReader::new(f.unwrap()); let reader=io::BufReader::new(f.unwrap());
for line in reader.lines() { for line in reader.lines() {
if let Ok(line) = line { if let Ok(line) = line {
let line=clean_replay(&line);
let cmd=Command::deserialize(line); let cmd=Command::deserialize(line);
if let Command::NOP(comment)=cmd { println!("{}",comment); } if let Command::NOP(comment)=cmd { println!("{}",comment); }
else { else {
@@ -957,6 +958,11 @@ enum Command {
fn clean(s: &str) -> String { s.to_string() } fn clean(s: &str) -> String { s.to_string() }
fn clean_replay(input: &str) -> String {
let before_semicolon = input.split(';').next().unwrap_or(""); // Split on semicolon; take first chunk (before semicolon), or "" if none
before_semicolon.trim_end().to_string() // Trim trailing whitespace, then convert to owned String
}
impl Command { impl Command {
fn serialize(&self) -> String { fn serialize(&self) -> String {
match self { match self {