Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl Display for OrderType {
}
}

#[derive(Debug, Clone)]
pub enum OrderSide {
Buy,
Sell,
Expand Down
38 changes: 38 additions & 0 deletions src/futures/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl From<ContractType> for String {
}
}

#[derive(Debug, Clone)]
pub enum PositionSide {
Both,
Long,
Expand All @@ -56,6 +57,7 @@ impl Display for PositionSide {
}
}

#[derive(Debug, Clone)]
pub enum OrderType {
Limit,
Market,
Expand Down Expand Up @@ -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 {
Expand All @@ -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"),
}
}
}
Expand All @@ -129,24 +138,41 @@ struct OrderRequest {
pub working_type: Option<WorkingType>,
pub price_protect: Option<f64>,
pub new_client_order_id: Option<String>,
pub good_till_date: Option<u64>,
}

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<PositionSide>,
pub order_type: OrderType,
pub time_in_force: Option<TimeInForce>,
/// Cannot be sent with `closePosition`=true(Close-All)
pub qty: Option<f64>,
pub reduce_only: Option<bool>,
pub price: Option<f64>,
/// Used with `STOP`/`STOP_MARKET` or `TAKE_PROFIT`/`TAKE_PROFIT_MARKET` orders.
pub stop_price: Option<f64>,
/// Close-All,used with `STOP_MARKET` or `TAKE_PROFIT_MARKET`.
pub close_position: Option<bool>,
/// Used with `TRAILING_STOP_MARKET` orders, default as the latest price(supporting different `workingType`)
pub activation_price: Option<f64>,
/// Used with `TRAILING_STOP_MARKET` orders, min `0.1`, max `10` where `1` for `1%`
pub callback_rate: Option<f64>,
/// `stopPrice` triggered by: `MARK_PRICE`, `CONTRACT_PRICE`. Default `CONTRACT_PRICE`
pub working_type: Option<WorkingType>,
pub price_protect: Option<f64>,
/// 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<String>,
/// 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<u64>,
}

pub struct IncomeRequest {
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions tests/futures_account_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Loading