changes
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -29,6 +29,7 @@
|
|||||||
// whoami # Shows logged in name for this Interactive session
|
// whoami # Shows logged in name for this Interactive session
|
||||||
// wallet # Show all of the logged-in trader's funds (but not what is on the market)
|
// wallet # Show all of the logged-in trader's funds (but not what is on the market)
|
||||||
// order 0.5 BTC 30000 USD # Create an order selling 0.5 BTC to buy 30000 USD. Uses logged in Trader's balance.
|
// order 0.5 BTC 30000 USD # Create an order selling 0.5 BTC to buy 30000 USD. Uses logged in Trader's balance.
|
||||||
|
// orderbatch 0.5 BTC 30000 USD # Enter an order but don't execute it (allow it to contribute to a crossed market)
|
||||||
// quit # Clean exit
|
// quit # Clean exit
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -388,6 +389,9 @@ impl Market {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn execute_batch(&mut self, asset_type0: usize, strike0: FiNum, asset_type1: usize, strike1: FiNum) -> Result {
|
||||||
|
Result::Error("Execute_batch not yet implemented".to_string())
|
||||||
|
}
|
||||||
fn make_order(&mut self, owner:usize, sell_type:usize, buy_type:usize, sell_qty_initial:FiNum, buy_qty_initial:FiNum, execute_if_possible:bool) -> Result {
|
fn make_order(&mut self, owner:usize, sell_type:usize, buy_type:usize, sell_qty_initial:FiNum, buy_qty_initial:FiNum, execute_if_possible:bool) -> Result {
|
||||||
let mut log:Vec<String>=Vec::new();
|
let mut log:Vec<String>=Vec::new();
|
||||||
let initial_balance=self.traders[owner].get_balance(sell_type);
|
let initial_balance=self.traders[owner].get_balance(sell_type);
|
||||||
@@ -662,6 +666,7 @@ enum Result {
|
|||||||
AddedAsset(usize),
|
AddedAsset(usize),
|
||||||
PlacedOrder(usize, Vec<String>),
|
PlacedOrder(usize, Vec<String>),
|
||||||
FundsRemaining(FiNum),
|
FundsRemaining(FiNum),
|
||||||
|
ExecutedBatch(FiNum,FiNum),
|
||||||
Error(String),
|
Error(String),
|
||||||
Ok
|
Ok
|
||||||
}
|
}
|
||||||
@@ -674,6 +679,7 @@ enum Command {
|
|||||||
SubFunds { user_id: usize, asset_id: usize, amt: FiNum },
|
SubFunds { user_id: usize, asset_id: usize, amt: FiNum },
|
||||||
Order { user_id: usize, sell_type: usize, sell_qty: FiNum, buy_type: usize, buy_qty: FiNum },
|
Order { user_id: usize, sell_type: usize, sell_qty: FiNum, buy_type: usize, buy_qty: FiNum },
|
||||||
OrderBatch { user_id: usize, sell_type: usize, sell_qty: FiNum, buy_type: usize, buy_qty: FiNum },
|
OrderBatch { user_id: usize, sell_type: usize, sell_qty: FiNum, buy_type: usize, buy_qty: FiNum },
|
||||||
|
ExecuteBatch { asset_type0: usize, strike0: FiNum, asset_type1: usize, strike1: FiNum },
|
||||||
Retract { order_id: usize },
|
Retract { order_id: usize },
|
||||||
Error(String),
|
Error(String),
|
||||||
NOP(String),
|
NOP(String),
|
||||||
@@ -697,6 +703,8 @@ impl Command {
|
|||||||
=> format!("OR {} {} {} {} {}",user_id,sell_type,sell_qty.serialize(),buy_type,buy_qty.serialize()),
|
=> format!("OR {} {} {} {} {}",user_id,sell_type,sell_qty.serialize(),buy_type,buy_qty.serialize()),
|
||||||
Self::OrderBatch { user_id, sell_type, sell_qty, buy_type, buy_qty }
|
Self::OrderBatch { user_id, sell_type, sell_qty, buy_type, buy_qty }
|
||||||
=> format!("ORB {} {} {} {} {}",user_id,sell_type,sell_qty.serialize(),buy_type,buy_qty.serialize()),
|
=> format!("ORB {} {} {} {} {}",user_id,sell_type,sell_qty.serialize(),buy_type,buy_qty.serialize()),
|
||||||
|
Self::ExecuteBatch { asset_type0, strike0, asset_type1, strike1 }
|
||||||
|
=> format!("EXE {} {} {} {}",asset_type0,strike0.serialize(),asset_type1,strike1.serialize()),
|
||||||
Self::Retract { order_id } => format!("RE {}",order_id),
|
Self::Retract { order_id } => format!("RE {}",order_id),
|
||||||
Self::Error(str) => format!("NOP Error: {}",str),
|
Self::Error(str) => format!("NOP Error: {}",str),
|
||||||
Self::NOP(str) => format!("NOP {}",clean(str)),
|
Self::NOP(str) => format!("NOP {}",clean(str)),
|
||||||
@@ -721,6 +729,8 @@ impl Command {
|
|||||||
["ORB",user_id,sell_type,sell_qty,buy_type,buy_qty] =>
|
["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),
|
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) },
|
buy_type: buy_type.parse::<usize>().unwrap(), buy_qty: FiNum::new_deserialize(buy_qty) },
|
||||||
|
["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)),
|
["NOP", many_things @ ..] => Self::NOP(clean(&line)),
|
||||||
_ => Self::Error("Unimplemented Parse".to_string()),
|
_ => Self::Error("Unimplemented Parse".to_string()),
|
||||||
}
|
}
|
||||||
@@ -733,6 +743,7 @@ impl Result {
|
|||||||
Self::PlacedOrder(order_id,vec) => format!("Placed order {}:\n {}",order_id,vec.join("\n ")),
|
Self::PlacedOrder(order_id,vec) => format!("Placed order {}:\n {}",order_id,vec.join("\n ")),
|
||||||
Self::AddedTrader(id) => format!("Added Trader Id {}",id),
|
Self::AddedTrader(id) => format!("Added Trader Id {}",id),
|
||||||
Self::AddedAsset(id) => format!("Added Asset Id {}",id),
|
Self::AddedAsset(id) => format!("Added Asset Id {}",id),
|
||||||
|
Self::ExecutedBatch(amt0,amt1) => format!("Executed Batch {} / {}",amt0,amt1),
|
||||||
Self::FundsRemaining(amt) => format!("Funds Remaining: {}",amt),
|
Self::FundsRemaining(amt) => format!("Funds Remaining: {}",amt),
|
||||||
Self::Ok => format!("Ok"),
|
Self::Ok => format!("Ok"),
|
||||||
Self::Error(str) => format!("Error: {}",str),
|
Self::Error(str) => format!("Error: {}",str),
|
||||||
@@ -784,6 +795,9 @@ impl Market {
|
|||||||
Command::OrderBatch { user_id, sell_type, sell_qty, buy_type, buy_qty } => {
|
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)
|
self.make_order(*user_id,*sell_type,*buy_type,*sell_qty,*buy_qty,false)
|
||||||
}
|
}
|
||||||
|
Command::ExecuteBatch { asset_type0, strike0, asset_type1, strike1 } => {
|
||||||
|
self.execute_batch(*asset_type0, *strike0, *asset_type1, *strike1)
|
||||||
|
}
|
||||||
Command::Error(str) => Result::Error(format!("Command Error")),
|
Command::Error(str) => Result::Error(format!("Command Error")),
|
||||||
Command::NOP(str) => Result::Ok,
|
Command::NOP(str) => Result::Ok,
|
||||||
_ => Result::Error(format!("Tried to execute an unimplemented Command. This is a bug because all Commands should be implemented, even NOPs and Errors.")),
|
_ => Result::Error(format!("Tried to execute an unimplemented Command. This is a bug because all Commands should be implemented, even NOPs and Errors.")),
|
||||||
@@ -867,7 +881,18 @@ fn tokens_to_command(m: &Market, logged_in: usize, tokens: Vec<&str>,line: &str)
|
|||||||
else if !cur1.is_some() { Command::Error("Count not find currency".to_string()) }
|
else if !cur1.is_some() { Command::Error("Count not find currency".to_string()) }
|
||||||
else if qty0.is_zero() { Command::Error("Qty0 is must be > 0".to_string()) }
|
else if qty0.is_zero() { Command::Error("Qty0 is must be > 0".to_string()) }
|
||||||
else if qty1.is_zero() { Command::Error("Qty1 is must be > 0".to_string()) }
|
else if qty1.is_zero() { Command::Error("Qty1 is must be > 0".to_string()) }
|
||||||
else { Command::Orderbatch { user_id: logged_in, sell_type: *cur0.unwrap(), sell_qty: qty0, buy_type: *cur1.unwrap(), buy_qty: qty1 } }
|
else { Command::OrderBatch { user_id: logged_in, sell_type: *cur0.unwrap(), sell_qty: qty0, buy_type: *cur1.unwrap(), buy_qty: qty1 } }
|
||||||
|
}
|
||||||
|
["execute", strike0, asset_type0, strike1, asset_type1 ] => {
|
||||||
|
let strike0=FiNum::new_str(strike0);
|
||||||
|
let asset_type0=m.name_to_number(asset_type0);
|
||||||
|
let strike1=FiNum::new_str(strike1);
|
||||||
|
let asset_type1=m.name_to_number(asset_type1);
|
||||||
|
if !asset_type0.is_some() { Command::Error("Count not find currency".to_string()) }
|
||||||
|
else if !asset_type1.is_some() { Command::Error("Count not find currency".to_string()) }
|
||||||
|
else if strike0.is_zero() { Command::Error("Strike0 is must be > 0".to_string()) }
|
||||||
|
else if strike1.is_zero() { Command::Error("Strike1 is must be > 0".to_string()) }
|
||||||
|
else { Command::ExecuteBatch { asset_type0: *asset_type0.unwrap(), strike0:strike0, asset_type1: *asset_type1.unwrap(), strike1: strike1 } }
|
||||||
}
|
}
|
||||||
_ => { Command::Error(line.to_string()) },
|
_ => { Command::Error(line.to_string()) },
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user