changes
This commit is contained in:
21
src/main.rs
21
src/main.rs
@@ -149,7 +149,7 @@ impl Market {
|
||||
while buy_qty>FiNum::new(0) && self.offers.contains_key(&ap) && self.offers.get(&ap).unwrap().v.len()>0 {
|
||||
let elt=&mut self.offers.get_mut(&ap).unwrap().v[0];
|
||||
if sell_qty_initial/buy_qty_initial>=elt.buy_qty/elt.sell_qty { // Transact at ask_rate
|
||||
println!("Transacting at {}/{}, not at {}/{}",elt.buy_qty,elt.sell_qty,sell_qty_initial,buy_qty_initial);
|
||||
// println!("Transacting at {}/{}, not at {}/{}",elt.buy_qty,elt.sell_qty,sell_qty_initial,buy_qty_initial);
|
||||
let qty=std::cmp::min(elt.sell_remain,buy_qty);
|
||||
elt.sell_remain-=qty;
|
||||
buy_qty-=qty;
|
||||
@@ -254,8 +254,8 @@ impl<T: Dumpable + std::cmp::PartialOrd + std::fmt::Debug> PQueue<T> {
|
||||
|
||||
|
||||
fn main() {
|
||||
let mut rng: StdRng=StdRng::seed_from_u64(10u64);
|
||||
let debug_index=1000000;
|
||||
let mut rng: StdRng=StdRng::seed_from_u64(13u64);
|
||||
let debug_index=100000000;
|
||||
let mut m=Market::new(); // USD type is 1, EUR type is 2, BTC type is 10, ETH type is 11, SOL type is 12
|
||||
let teppy=m.register_trader("Teppy");
|
||||
let luni =m.register_trader("Luni");
|
||||
@@ -263,30 +263,21 @@ fn main() {
|
||||
let btc =m.register_asset("BTC");
|
||||
m.add_trader_balance(teppy,btc,100.into());
|
||||
m.add_trader_balance(luni ,usd,1000000.into());
|
||||
for i in 1..=1000 {
|
||||
for i in 1..=1000000 {
|
||||
let seller=if rng.gen_bool(0.5) { teppy } else { luni };
|
||||
let (buy_type,sell_type,buy_qty,sell_qty):(i32,i32,FiNum,FiNum);
|
||||
if rng.gen_bool(0.5) {
|
||||
sell_type=btc;
|
||||
buy_type=usd;
|
||||
sell_qty=1.into(); //rng.gen_range(2..=5).into();
|
||||
sell_qty=rng.gen_range(1..=5).into();
|
||||
buy_qty=sell_qty*rng.gen_range(60000..=70000).into();
|
||||
} else {
|
||||
sell_type=usd;
|
||||
buy_type=btc;
|
||||
buy_qty=1.into(); //rng.gen_range(2..=5).into();
|
||||
buy_qty=rng.gen_range(1..=5).into();
|
||||
sell_qty=buy_qty*rng.gen_range(60000..=70000).into();
|
||||
}
|
||||
println!("Index {} Sell {} {} to buy {} {} ({})",i,sell_qty,m.number_to_name(sell_type),buy_qty,m.number_to_name(buy_type),m.traders[seller as usize].name);
|
||||
if i==debug_index {
|
||||
println!("Fifty-two!");
|
||||
m.dump();
|
||||
}
|
||||
m.make_offer(seller,sell_type,buy_type,sell_qty,buy_qty);
|
||||
if i==debug_index {
|
||||
println!("Fifty-two!");
|
||||
m.dump();
|
||||
}
|
||||
}
|
||||
m.dump();
|
||||
m.sanity_check();
|
||||
|
||||
Reference in New Issue
Block a user