From 00147a5e45a56bdfddf35c76898b03f30c8a2973 Mon Sep 17 00:00:00 2001 From: Teppy Date: Mon, 29 Jul 2024 19:30:36 -0400 Subject: [PATCH] changes --- src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bb87f29..37507a2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,6 +110,7 @@ struct Order { commission_remain: FiNum, // Based on commission1 owner: usize, rt_loc: usize, // Location in the Royalty Tree + id: usize, } struct RoyaltyTree { @@ -268,6 +269,7 @@ struct Market { orders: HashMap<(usize,usize),PQueue>>>, royalties: HashMap, // Active orders that are accepting asset X. They receive royalties when someone makes an order to sell X royalty_rate: HashMap, + next_order_id: usize, } impl Market { @@ -281,6 +283,7 @@ impl Market { orders: HashMap::new(), royalties: HashMap::new(), royalty_rate: HashMap::new(), + next_order_id: 1, }; rval.register_trader("*HOUSE*"); rval @@ -397,6 +400,7 @@ impl Market { let ap=(buy_type,sell_type); let mut royalty_acc=FiNum::zero(); let mut commission_acc=FiNum::zero(); + let new_order_id:usize; while buy_qty>FiNum::new(0) && self.orders.contains_key(&ap) && self.orders.get(&ap).unwrap().v.len()>0 { let mut elt=(*(self.orders.get(&ap).unwrap().v[0].borrow())).clone(); if sell_qty/buy_qty_initial>=elt.buy_qty/elt.sell_qty { // Transact at ask_rate @@ -447,19 +451,21 @@ impl Market { let rt=self.royalties.entry(buy_type).or_insert(RoyaltyTree::new()); rt.add_weight(rt.next_entry,buy_qty); // Weight should really be the quantity you would be able to immediately transact rather than how much you wish for. let neworder=Rc::new(RefCell::new( - Order { owner:owner, sell_qty:sell_qty_remain, sell_remain:sell_qty_remain, buy_qty:buy_qty, rt_loc: rt.next_entry, royalty_remain:royalty1_qty, commission_remain:commission1_qty } )); + Order { owner:owner, sell_qty:sell_qty_remain, sell_remain:sell_qty_remain, buy_qty:buy_qty, rt_loc: rt.next_entry, royalty_remain:royalty1_qty, commission_remain:commission1_qty, id:self.next_order_id } )); + new_order_id=self.next_order_id; + self.next_order_id+=1; rt.next_entry+=1; bids.insert(neworder); self.traders[owner].sub_balance(sell_type,sell_qty_remain); self.traders[0].add_balance(sell_type,commission0_qty); log.push(format!("Moved {} {} ({}) to market",sell_qty_remain,self.number_to_name(sell_type),self.traders[owner].name)); - } - } + } else { new_order_id=0; } + } else { new_order_id=0; } self.traders[0].add_balance(sell_type,commission_acc); self.traders[owner].sub_balance(sell_type,royalty_acc+commission_acc); log.push(format!("Paid {} {} in royalties and {} {} ({}) in commissions",royalty_acc ,self.number_to_name(sell_type), commission_acc,self.number_to_name(sell_type),self.traders[owner].name)); - Result::PlacedOrder(0,log) + Result::PlacedOrder(new_order_id,log) } }