changes
This commit is contained in:
25
src/main.rs
25
src/main.rs
@@ -454,9 +454,11 @@ impl Market {
|
||||
}
|
||||
fn dump(&mut self) {
|
||||
println!("Dumping Market:");
|
||||
println!("Money Supply:");
|
||||
println!("Asset MoneySupply Royalty% Commission%");
|
||||
for index in 0..self.assets.len() {
|
||||
println!(" {}: {}",self.number_to_asset(index).name,self.money_supply[&index]);
|
||||
let ass=self.number_to_asset(index);
|
||||
let aname=self.money_supply[&index].to_string();
|
||||
println!(" {:<3}{:>16} {}/{} {}/{}",ass.name,aname,ass.royalty0_rate.fmt_pct2(),ass.royalty1_rate.fmt_pct2(),ass.commission0_rate.fmt_pct2(),ass.commission1_rate.fmt_pct2());
|
||||
}
|
||||
for (ap,pq) in &self.orders {
|
||||
println!("Orders selling {} to buy {}:",self.number_to_name(ap.0),self.number_to_name(ap.1));
|
||||
@@ -474,12 +476,14 @@ impl Market {
|
||||
royalty_amt);
|
||||
}
|
||||
}
|
||||
println!("Royalties accumulated but not captured:");
|
||||
println!("Royalty Accum SpareChange");
|
||||
for index in 0..self.assets.len() {
|
||||
self.royalties.entry(index).or_insert(RoyaltyTree::new());
|
||||
let tot=self.royalties.get(&index).unwrap().acc_total();
|
||||
println!(" For {}: {}",self.number_to_asset(index).name,tot);
|
||||
let name=self.number_to_asset(index).name;
|
||||
let rt=self.royalties.get_mut(&index).unwrap();
|
||||
let sc=rt.spare_change;
|
||||
let tot=rt.acc_total();
|
||||
println!(" {:<3} {} {}",name,tot,sc);
|
||||
for indexr in 0..rt.tree.len() {
|
||||
let royalty_amt=rt.get_royalty(indexr);
|
||||
let r=&rt.tree[indexr];
|
||||
@@ -492,7 +496,7 @@ impl Market {
|
||||
println!(" Index {} Weight {} Royalty {} OrderID {}",indexr,r.weight,royalty_amt,r.order_id);
|
||||
}
|
||||
}
|
||||
for (k,v) in &rt.order_finder { println!(" Order ID {} at position {}",k,v); }
|
||||
// Heavy Debug for (k,v) in &rt.order_finder { println!(" Order ID {} at position {}",k,v); }
|
||||
}
|
||||
println!("Trader Balances:");
|
||||
for t in &self.traders {
|
||||
@@ -545,7 +549,7 @@ impl Market {
|
||||
Result::ExecutedBatch(log)
|
||||
}
|
||||
*/
|
||||
fn retract_order(&mut self, order_id:usize) -> Result {
|
||||
fn retract_order(&mut self, order_id:usize) -> Result { // Still need to credit back funds! But first fix the bug where we are creating commission0 from thin air in make_order (not charging seller)
|
||||
let pair=self.order_finder.get(&order_id).unwrap();
|
||||
let queue=self.orders.get_mut(pair).unwrap();
|
||||
let queue_index=*queue.order_finder.get(&order_id).unwrap();
|
||||
@@ -633,7 +637,8 @@ impl Market {
|
||||
self.next_order_id+=1;
|
||||
|
||||
// Pay royalties to existing orders on the sell size
|
||||
self.royalties.entry(sell_type).or_insert(RoyaltyTree::new()).add_royalty(royalty0_qty);
|
||||
self.royalties.entry(sell_type).or_insert(RoyaltyTree::new()).add_royalty(royalty0_qty+royalty1_qty);
|
||||
royalty_acc+=royalty0_qty+royalty1_qty;
|
||||
|
||||
// Create a new entry in the RoyaltyTree to accumulate for this Order
|
||||
let rt=self.royalties.entry(buy_type).or_insert(RoyaltyTree::new());
|
||||
@@ -647,7 +652,7 @@ impl Market {
|
||||
self.order_count+=1;
|
||||
self.order_finder.insert(id,(sell_type,buy_type));
|
||||
self.traders[owner].sub_balance(sell_type,sell_qty_remain);
|
||||
self.traders[0].add_balance(sell_type,commission0_qty);
|
||||
commission_acc+=commission0_qty+commission1_qty;
|
||||
self.traders[owner].order_finder.insert(id,(sell_type,buy_type));
|
||||
log.push(format!("Moved {} {} ({}) to market",sell_qty_remain,self.number_to_name(sell_type),self.traders[owner].name));
|
||||
}
|
||||
@@ -1156,7 +1161,7 @@ fn interactive(m: &mut Market, mut out: Option<File>) {
|
||||
Ok(input) => {
|
||||
let tokens: Vec<&str> = input.split_whitespace().collect();
|
||||
let cmd:Command=match tokens.as_slice() {
|
||||
["dump"] => { m.dump(); Command::None },
|
||||
["dump"] => { m.dump(); m.sanity_check(); Command::None },
|
||||
["randomorder"] => { println!("Random OrderID: {:?}",m.random_order_id()); Command::None }
|
||||
["login", username] => {
|
||||
if let Some(t)=m.trader_name2num.get_mut(*username) { trader=*t; println!("Logged in as {}",m.traders[trader].name) } else { println!("Trader {} not found.",username) }
|
||||
|
||||
Reference in New Issue
Block a user