diff --git a/src/account.rs b/src/account.rs index 5c5bd6d2..a56c263d 100644 --- a/src/account.rs +++ b/src/account.rs @@ -65,6 +65,7 @@ impl Display for OrderType { } } +#[derive(Debug, Clone)] pub enum OrderSide { Buy, Sell, diff --git a/src/futures/account.rs b/src/futures/account.rs index 208af8c7..08462e12 100644 --- a/src/futures/account.rs +++ b/src/futures/account.rs @@ -40,6 +40,7 @@ impl From for String { } } +#[derive(Debug, Clone)] pub enum PositionSide { Both, Long, @@ -56,6 +57,7 @@ impl Display for PositionSide { } } +#[derive(Debug, Clone)] pub enum OrderType { Limit, Market, @@ -96,10 +98,16 @@ impl Display for WorkingType { #[allow(clippy::all)] pub enum TimeInForce { + /// Good Till Cancel GTC, + /// Immediate or Cancel IOC, + /// Fill or Kill FOK, + /// Good Till Crossing GTX, + /// Good Till Date + GTD, } impl Display for TimeInForce { @@ -109,6 +117,7 @@ impl Display for TimeInForce { Self::IOC => write!(f, "IOC"), Self::FOK => write!(f, "FOK"), Self::GTX => write!(f, "GTX"), + Self::GTD => write!(f, "GTD"), } } } @@ -129,24 +138,41 @@ struct OrderRequest { pub working_type: Option, pub price_protect: Option, pub new_client_order_id: Option, + pub good_till_date: Option, } pub struct CustomOrderRequest { pub symbol: String, pub side: OrderSide, + /// Default `BOTH` for One-way Mode ; `LONG` or `SHORT` for Hedge Mode. \ + /// It must be sent in Hedge Mode. pub position_side: Option, pub order_type: OrderType, pub time_in_force: Option, + /// Cannot be sent with `closePosition`=true(Close-All) pub qty: Option, pub reduce_only: Option, pub price: Option, + /// Used with `STOP`/`STOP_MARKET` or `TAKE_PROFIT`/`TAKE_PROFIT_MARKET` orders. pub stop_price: Option, + /// Close-All,used with `STOP_MARKET` or `TAKE_PROFIT_MARKET`. pub close_position: Option, + /// Used with `TRAILING_STOP_MARKET` orders, default as the latest price(supporting different `workingType`) pub activation_price: Option, + /// Used with `TRAILING_STOP_MARKET` orders, min `0.1`, max `10` where `1` for `1%` pub callback_rate: Option, + /// `stopPrice` triggered by: `MARK_PRICE`, `CONTRACT_PRICE`. Default `CONTRACT_PRICE` pub working_type: Option, pub price_protect: Option, + /// A unique id among open orders. \ + /// Automatically generated if not sent. \ + /// Can only be string following the rule: `^[\.A-Z\:/a-z0-9_-]{1,32}$` pub new_client_order_id: Option, + /// order cancel time for timeInForce **GTD**, mandatory when [TimeInForce] set to **GTD** \ + /// order the timestamp only retains second-level precision, **ms part will be ignored** \ + /// The goodTillDate timestamp must be greater than the current time **plus 600 seconds** and smaller than **253402300799000**. + /// the timestamp should be in `UTC` timezone + pub good_till_date: Option, } pub struct IncomeRequest { @@ -227,6 +253,7 @@ impl FuturesAccount { working_type: None, price_protect: None, new_client_order_id: None, + good_till_date: None, }; let order = self.build_order(buy, None); let request = build_signed_request(order, self.recv_window)?; @@ -254,6 +281,7 @@ impl FuturesAccount { working_type: None, price_protect: None, new_client_order_id: None, + good_till_date: None, }; let order = self.build_order(sell, None); let request = build_signed_request(order, self.recv_window)?; @@ -283,6 +311,7 @@ impl FuturesAccount { working_type: None, price_protect: None, new_client_order_id: None, + good_till_date: None, }; let order = self.build_order(buy, None); let request = build_signed_request(order, self.recv_window)?; @@ -312,6 +341,7 @@ impl FuturesAccount { working_type: None, price_protect: None, new_client_order_id: None, + good_till_date: None, }; let order = self.build_order(sell, None); let request = build_signed_request(order, self.recv_window)?; @@ -369,6 +399,7 @@ impl FuturesAccount { working_type: None, price_protect: None, new_client_order_id: None, + good_till_date: None, }; let order = self.build_order(sell, None); let request = build_signed_request(order, self.recv_window)?; @@ -398,6 +429,7 @@ impl FuturesAccount { working_type: None, price_protect: None, new_client_order_id: None, + good_till_date: None, }; let order = self.build_order(sell, None); let request = build_signed_request(order, self.recv_window)?; @@ -430,6 +462,7 @@ impl FuturesAccount { working_type: order_request.working_type, price_protect: order_request.price_protect, new_client_order_id: order_request.new_client_order_id, + good_till_date: order_request.good_till_date, }; let order = self.build_order(order, Some(request_params)); let request = build_signed_request(order, self.recv_window)?; @@ -460,6 +493,7 @@ impl FuturesAccount { working_type: order_request.working_type, price_protect: order_request.price_protect, new_client_order_id: order_request.new_client_order_id, + good_till_date: order_request.good_till_date, }; let _order = self.build_order(order, Some(request_params.clone())); // TODO : make a request string for batch orders api @@ -585,6 +619,10 @@ impl FuturesAccount { parameters.insert("newClientOrderId".into(), uuid); } + if let Some(good_till_date) = order.good_till_date { + parameters.insert("goodTillDate".into(), good_till_date.to_string()); + } + if let Some(params) = request_params { for (key, value) in params { parameters.insert(key, value.to_string()); diff --git a/tests/futures_account_tests.rs b/tests/futures_account_tests.rs index 0ab30a24..4dc6ed0d 100644 --- a/tests/futures_account_tests.rs +++ b/tests/futures_account_tests.rs @@ -246,6 +246,7 @@ mod tests { working_type: None, price_protect: None, new_client_order_id: Some("myId".into()), + good_till_date: None, }; let transaction: Transaction = account.custom_order(custom_order).unwrap();