This commit is contained in:
2024-10-06 22:02:25 -04:00
parent 26051ccda6
commit 5a70a04af4

View File

@@ -1,4 +1,4 @@
//
//
// When inserting a new Order into the royalties tree, we must make sure the existing
// royalties don't get shared with that new node. To do this, we must "shave" down
// the tree, pushing royalties from the root down to all nodes to the left of the
@@ -275,8 +275,7 @@ impl RoyaltyTree {
self.tree[index].acc-=redist;
let mut index=index;
let ff=self.forefather();
if delta_count>0 { println!("YES ITS > 0"); }
while index!=ff {
loop {
self.tree[index].weight-=weight;
self.tree[index].count-=delta_count;
if index==ff { break; }
@@ -811,14 +810,14 @@ fn royalty_stuff() {
rt.add_weight(5,FiNum::new_i32(1));
rt.dump();
// return;
for i in 1..10000 {
for i in 1..1000000 {
// rt.dump();
let node=rng.gen_range(0..10);
match rng.gen_range(0..10) {
0 => { println!("Add at {}",node); rt.add_weight(node,FiNum::new_i32(rng.gen_range(0..101))) },
1 => { println!("Sub at {}",node); rt.sub_weight(node,FiNum::new_i32(rng.gen_range(0..101))) },
0 => rt.add_weight(node,FiNum::new_i32(rng.gen_range(0..101))),
1 => rt.sub_weight(node,FiNum::new_i32(rng.gen_range(0..101))),
2 => rt.add_royalty(FiNum::new_i32(rng.gen_range(0..10))),
3 => println!("Random Order ID: {:?}",rt.random_order_id(&mut rng)),
// 3 => println!("Random Order ID: {:?}",rt.random_order_id(&mut rng)),
_ => (),
}
}
@@ -894,6 +893,8 @@ impl Command {
["ORB",user_id,sell_type,sell_qty,buy_type,buy_qty] =>
Self::OrderBatch { user_id: user_id.parse::<usize>().unwrap(), sell_type: sell_type.parse::<usize>().unwrap(), sell_qty: FiNum::new_deserialize(sell_qty),
buy_type: buy_type.parse::<usize>().unwrap(), buy_qty: FiNum::new_deserialize(buy_qty) },
["RE",order_id] =>
Self::Retract { order_id: order_id:parse::<usize>().unwrap() },
["EXE",asset_type0,strike0,asset_type1,strike1] =>
Self::ExecuteBatch { asset_type0: asset_type0.parse::<usize>().unwrap(),strike0: FiNum::new_deserialize(strike0), asset_type1: asset_type1.parse::<usize>().unwrap(), strike1: FiNum::new_deserialize(strike1) },
["NOP", many_things @ ..] => Self::NOP(clean(&line)),
@@ -910,6 +911,7 @@ impl Result {
Self::AddedAsset(id,name) => format!("Added Asset Id {}: {}",id,name),
Self::ExecutedBatch(vec) => format!("{}",vec.join("\n")),
Self::FundsRemaining(amt) => format!("Funds Remaining: {}",amt),
Self::RetractedOrder(order_id) => format!("Retracted Order {}",order_id),
Self::Ok => format!("Ok"),
Self::Error(str) => format!("Error: {}",str),
// _ => "Some other result".to_string(),
@@ -960,6 +962,9 @@ impl Market {
Command::OrderBatch { user_id, sell_type, sell_qty, buy_type, buy_qty } => {
self.make_order(*user_id,*sell_type,*buy_type,*sell_qty,*buy_qty,false)
}
Command::RetractOrder { order_id } => {
self.retract_order(*order_id)
}
Command::ExecuteBatch { asset_type0, strike0, asset_type1, strike1 } => {
self.execute_batch(*asset_type0, *strike0, *asset_type1, *strike1)
}
@@ -1026,6 +1031,12 @@ fn tokens_to_command(m: &Market, logged_in: usize, tokens: Vec<&str>,line: &str)
Command::SubFunds { user_id: user, asset_id: cur, amt: qty }
}
}
["retract", order_id ] => {
let order_id=order_id.parse();
if m.order_finder.contains_key(order_id) {
{*}
Command::Retract { order_id: order_id }
}
["order", qty0, cur0, qty1, cur1 ] => {
let qty0=FiNum::new_str(qty0);
let cur0=m.name_to_number(cur0);