|
|
@@ -4,6 +4,7 @@ use std::fmt::Formatter;
|
|
|
use std::io::{Error};
|
|
|
use async_trait::async_trait;
|
|
|
use rust_decimal::Decimal;
|
|
|
+use serde_json::Value;
|
|
|
use tokio::time::Instant;
|
|
|
use global::trace_stack::TraceStack;
|
|
|
|
|
|
@@ -427,7 +428,7 @@ impl Position {
|
|
|
/// let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
/// ```
|
|
|
/// 获取当前交易所交易模式
|
|
|
/// - fn get_self_exchange(&self) -> ExchangeEnum;
|
|
|
@@ -437,9 +438,9 @@ impl Position {
|
|
|
/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// # params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
///
|
|
|
-/// exchange.get_self_exchange();
|
|
|
+/// // exchange.get_self_exchange();
|
|
|
/// ```
|
|
|
/// 获取当前是否使用高速模式
|
|
|
/// - fn get_self_is_colo(&self) -> bool;
|
|
|
@@ -449,9 +450,9 @@ impl Position {
|
|
|
/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// # params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
///
|
|
|
-/// exchange.get_self_is_colo();
|
|
|
+/// // exchange.get_self_is_colo();
|
|
|
/// ```
|
|
|
/// 获取当前是否使用登录
|
|
|
/// - fn get_self_is_login(&self) -> bool;
|
|
|
@@ -461,9 +462,9 @@ impl Position {
|
|
|
/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// # params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
///
|
|
|
-/// exchange.get_self_is_login();
|
|
|
+/// // exchange.get_self_is_login();
|
|
|
/// ```
|
|
|
/// 获取登录params信息
|
|
|
/// - fn get_self_params(&self) -> BTreeMap<String, String>;
|
|
|
@@ -473,9 +474,9 @@ impl Position {
|
|
|
/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// # params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
///
|
|
|
-/// exchange.get_self_params();
|
|
|
+/// // exchange.get_self_params();
|
|
|
/// ```
|
|
|
/// 获取账号信息
|
|
|
/// - async fn get_account(&self, symbol: &str) -> Result<Account, Error>;
|
|
|
@@ -485,9 +486,9 @@ impl Position {
|
|
|
/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// # params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
///
|
|
|
-/// exchange.get_account()
|
|
|
+/// // exchange.get_account()
|
|
|
/// ```
|
|
|
/// 订阅账号信息
|
|
|
/// ```rust
|
|
|
@@ -496,9 +497,9 @@ impl Position {
|
|
|
/// # let mut params:BTreeMap<String,String> = BTreeMap::new();
|
|
|
/// # params.insert("access_key".to_string(), "your_access_key".to_string());
|
|
|
/// # params.insert("access_key".to_string(), "your_secret_key".to_string());
|
|
|
-/// # let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
+/// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
|
|
|
///
|
|
|
-/// exchange.subscribe_account();
|
|
|
+/// // exchange.subscribe_account();
|
|
|
/// ```
|
|
|
#[async_trait]
|
|
|
pub trait Platform {
|
|
|
@@ -551,6 +552,14 @@ pub trait Platform {
|
|
|
async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error>;
|
|
|
// 撤销所有订单
|
|
|
async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error>;
|
|
|
+ /// 下一个止损单
|
|
|
+ /// - stop_price: 触发价
|
|
|
+ /// - price: 委托价,0就市价委托
|
|
|
+ /// - side: 止损哪个方向[long多单,short空单]
|
|
|
+ async fn take_stop_loss_order(&mut self, stop_price: Decimal, price: Decimal, side: &str) -> Result<Value, Error>;
|
|
|
+ /// 撤销止损订单
|
|
|
+ /// - order_id: 需要撤销的id
|
|
|
+ async fn cancel_stop_loss_order(&mut self, order_id: &str) -> Result<Value, Error>;
|
|
|
// 设置持仓模式
|
|
|
async fn set_dual_mode(&mut self, coin: &str, is_dual_mode: bool) -> Result<String, Error>;
|
|
|
// 更新双持仓模式下杠杆
|