lib.rs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. use std::collections::{BTreeMap};
  2. use std::io::{Error};
  3. use async_trait::async_trait;
  4. use rust_decimal::Decimal;
  5. use serde_json::Value;
  6. use serde::{Serialize, Deserialize};
  7. use crate::exchange::ExchangeEnum;
  8. // 引入工具模块
  9. pub mod utils;
  10. // 引入exchange模块
  11. pub mod exchange;
  12. pub mod exchange_struct_handler;
  13. // 引入gate模块
  14. mod gate_swap;
  15. pub mod gate_swap_handle;
  16. pub mod coinex_swap;
  17. pub mod coinex_swap_handle;
  18. pub mod binance_swap;
  19. pub mod binance_swap_handle;
  20. pub mod phemex_swap;
  21. pub mod phemex_swap_handle;
  22. pub mod mexc_swap;
  23. pub mod mexc_swap_handle;
  24. pub mod bybit_swap;
  25. pub mod bybit_swap_handle;
  26. pub mod bitget_swap;
  27. pub mod bitget_swap_handle;
  28. pub mod gate_spot;
  29. pub mod gate_spot_handle;
  30. /// 持仓模式枚举
  31. /// - `Both`:单持仓方向
  32. /// - `LONG`:多仓
  33. /// - `SHORT`:空仓
  34. #[derive(Debug, Clone, PartialEq, Eq)]
  35. pub enum PositionModeEnum {
  36. Both,
  37. Long,
  38. Short,
  39. }
  40. /// Account结构体(账户信息)
  41. /// - `coin(String)`: 货币;
  42. /// - `balance(Decimal)`: 总计计价币数量;
  43. /// - `available_balance(Decimal)`: 可用计价币数量;
  44. /// - `frozen_balance(Decimal)`: balance挂单的冻结数量
  45. /// - `stocks(Decimal)`: 总计交易币数量
  46. /// - `available_stocks(Decimal)`: 可用交易币数量
  47. /// - `frozen_stocks(Decimal)`: stocks挂单的冻结数量
  48. #[derive(Debug, Clone, PartialEq, Eq)]
  49. pub struct Account {
  50. pub coin: String,
  51. pub balance: Decimal,
  52. pub available_balance: Decimal,
  53. pub frozen_balance: Decimal,
  54. pub stocks: Decimal,
  55. pub available_stocks: Decimal,
  56. pub frozen_stocks: Decimal,
  57. }
  58. impl Account {
  59. pub fn new() -> Account {
  60. Account {
  61. coin: "".to_string(),
  62. balance: Default::default(),
  63. available_balance: Default::default(),
  64. frozen_balance: Default::default(),
  65. stocks: Default::default(),
  66. available_stocks: Default::default(),
  67. frozen_stocks: Default::default(),
  68. }
  69. }
  70. }
  71. /// 交易结构体(订单流)
  72. /// - `id(String)`: id
  73. /// - `time(Decimal)`: 交易更新时间戳(ms)
  74. /// - `size(Decimal)`: 交易量,负数是卖方
  75. /// - `price(Decimal)`: 成交价格
  76. /// - `symbol(String)`: 成交符号
  77. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  78. pub struct Trade {
  79. pub id: String,
  80. pub time: Decimal,
  81. pub size: Decimal,
  82. pub price: Decimal,
  83. pub symbol: String
  84. }
  85. /// 特殊压缩结构体(订单流)
  86. /// - `0(Decimal)`: id
  87. /// - `1(Decimal)`: 交易更新时间戳(ms)
  88. /// - `2(Decimal)`: 交易量,负数是卖方
  89. /// - `3(Decimal)`: 成交价格
  90. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  91. pub struct SpecialTrade(pub Vec<String>);
  92. impl SpecialTrade {
  93. // 获取内部 Vec<Decimal> 的引用
  94. pub fn inner(&self) -> &Vec<String> {
  95. &self.0
  96. }
  97. // 获取内部 Vec<Decimal> 的可变引用
  98. pub fn inner_mut(&mut self) -> &mut Vec<String> {
  99. &mut self.0
  100. }
  101. // 索引访问特定元素
  102. pub fn get(&self, index: usize) -> Option<&String> {
  103. self.0.get(index)
  104. }
  105. pub fn new(trade: &Trade) -> SpecialTrade {
  106. SpecialTrade(vec![trade.id.clone(), trade.time.to_string(), trade.size.to_string(), trade.price.to_string()])
  107. }
  108. }
  109. /// Depth结构体(市场深度)
  110. /// - `time(Decimal)`: 深度更新时间戳(ms);
  111. /// - `symbol(String)`: 币对符号;
  112. /// - `asks(Vec<MarketOrder>)`: 卖方深度列表;
  113. /// - `bids(Vec<MarketOrder>)`: 买方深度列表;
  114. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  115. pub struct Depth {
  116. pub time: Decimal,
  117. pub symbol: String,
  118. pub asks: Vec<OrderBook>,
  119. pub bids: Vec<OrderBook>,
  120. }
  121. impl Depth {
  122. pub fn new() -> Depth {
  123. Depth {
  124. time: Decimal::ZERO,
  125. symbol: String::new(),
  126. asks: vec![],
  127. bids: vec![],
  128. }
  129. }
  130. }
  131. /// 特殊Depth结构体(市场深度),用于存放到本地数据库中
  132. /// - `a(Vec<Vec<Decimal>>)`: asks;
  133. /// - `b(Vec<Vec<Decimal>>)`: bids;
  134. /// - `t(Decimal)`: 数据生成时间
  135. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  136. pub struct SpecialDepth {
  137. pub b: Vec<Vec<Decimal>>,
  138. pub a: Vec<Vec<Decimal>>,
  139. pub t: Decimal,
  140. }
  141. impl SpecialDepth {
  142. pub fn new(depth: &Depth) -> SpecialDepth {
  143. let bids = depth.bids.iter().map(|ob| vec![ob.price, ob.amount]).collect::<Vec<_>>();
  144. let asks = depth.asks.iter().map(|ob| vec![ob.price, ob.amount]).collect::<Vec<_>>();
  145. SpecialDepth {
  146. b: bids,
  147. a: asks,
  148. t: depth.time,
  149. }
  150. }
  151. }
  152. // 简易深度信息
  153. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  154. pub struct SimpleDepth {
  155. pub time: Decimal,
  156. pub size: Decimal,
  157. pub b1: Decimal,
  158. pub a1: Decimal,
  159. pub symbol: String,
  160. }
  161. impl SimpleDepth {
  162. pub fn new(depth: &Depth) -> SimpleDepth {
  163. let mut total_size = Decimal::ZERO;
  164. for ask in &depth.asks {
  165. total_size += ask.price * ask.amount;
  166. }
  167. for bid in &depth.bids {
  168. total_size += bid.price * bid.amount;
  169. }
  170. total_size.rescale(2);
  171. SimpleDepth {
  172. time: depth.time,
  173. size: total_size,
  174. b1: depth.bids[0].price,
  175. a1: depth.asks[0].price,
  176. symbol: depth.symbol.clone(),
  177. }
  178. }
  179. }
  180. /// 特殊Ticker结构体(市场行情)
  181. /// - `sell(Decimal)`: 卖一价
  182. /// - `buy(Decimal)`: 买一价
  183. /// - `mid_price(Decimal)`: 平均价
  184. /// - `t(Decimal)`: 数据更新id
  185. /// - `create_at(i64)`: 数据生成时间
  186. #[derive(Debug, Clone, PartialEq, Eq, Default)]
  187. pub struct SpecialTicker {
  188. pub sell: Decimal,
  189. pub buy: Decimal,
  190. pub mid_price: Decimal,
  191. pub t: Decimal,
  192. pub create_at: i64
  193. }
  194. impl SpecialTicker {
  195. pub fn new() -> SpecialTicker {
  196. SpecialTicker {
  197. sell: Default::default(),
  198. buy: Default::default(),
  199. mid_price: Default::default(),
  200. t: Default::default(),
  201. create_at: 0,
  202. }
  203. }
  204. }
  205. /// OrderBook结构体(市场深度单)
  206. /// - `price(Decimal)`: 价格
  207. /// - `amount(Decimal)`: 数量
  208. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  209. pub struct OrderBook {
  210. pub price: Decimal,
  211. pub amount: Decimal,
  212. }
  213. impl OrderBook {
  214. pub fn new() -> OrderBook {
  215. OrderBook {
  216. price: Default::default(),
  217. amount: Default::default(),
  218. }
  219. }
  220. }
  221. /// Record结构体(标准的OHLC结构)
  222. /// - `time(i64)`: 时间戳;
  223. /// - `open(Decimal)`: 开盘价;
  224. /// - `high(Decimal)`: 最高价;
  225. /// - `low(Decimal):` 最低价;
  226. /// - `close(Decimal)`: 收盘价;
  227. /// - `volume(Decimal)`: 交易量;
  228. /// - `symbol(String)`: 交易对;
  229. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
  230. pub struct Record {
  231. pub time: Decimal,
  232. pub open: Decimal,
  233. pub high: Decimal,
  234. pub low: Decimal,
  235. pub close: Decimal,
  236. pub volume: Decimal,
  237. pub symbol: String
  238. }
  239. impl Record {
  240. pub fn new() -> Record {
  241. Record {
  242. time: Default::default(),
  243. open: Default::default(),
  244. high: Default::default(),
  245. low: Default::default(),
  246. close: Default::default(),
  247. volume: Default::default(),
  248. symbol: "".to_string(),
  249. }
  250. }
  251. }
  252. /// 特殊Order结构体(订单)
  253. /// - `name<String>`: 平台信息;
  254. /// - `order<Vec<Order>>`: 订单信息数组;
  255. #[derive(Debug, Clone, PartialEq, Eq)]
  256. pub struct SpecialOrder {
  257. pub name: String,
  258. pub order: Vec<Order>,
  259. }
  260. impl SpecialOrder {
  261. pub fn new() -> SpecialOrder {
  262. SpecialOrder {
  263. name: "".to_string(),
  264. order: vec![],
  265. }
  266. }
  267. }
  268. /// Order结构体(订单)
  269. /// - `id(String)`: 交易单唯一标识
  270. /// - `custom_id(String)`: 自定义Id
  271. /// - `price(Decimal)`: 下单价格
  272. /// - `amount(Decimal)`: 下单数量
  273. /// - `deal_amount(Decimal)`: 成交数量
  274. /// - `avg_price(Decimal)`: 成交均价
  275. /// - `status(String)`: 订单状态
  276. /// - `order_type(String)`: 订单类型
  277. #[derive(Debug, Clone, PartialEq, Eq)]
  278. pub struct Order {
  279. pub id: String,
  280. pub custom_id: String,
  281. pub price: Decimal,
  282. pub amount: Decimal,
  283. pub deal_amount: Decimal,
  284. pub avg_price: Decimal,
  285. pub status: String,
  286. pub order_type: String,
  287. }
  288. impl Order {
  289. pub fn new() -> Order {
  290. Order {
  291. id: "".to_string(),
  292. custom_id: "".to_string(),
  293. price: Default::default(),
  294. amount: Default::default(),
  295. deal_amount: Default::default(),
  296. avg_price: Default::default(),
  297. status: "".to_string(),
  298. order_type: "".to_string()
  299. }
  300. }
  301. }
  302. /// Ticker结构体(市场行情)
  303. /// - `time(i64)`: 毫秒级别时间戳
  304. /// - `high(Decimal)`: 最高价
  305. /// - `low(Decimal)`: 最低价
  306. /// - `sell(Decimal)`: 卖一价
  307. /// - `buy(Decimal)`: 买一价
  308. /// - `last(Decimal)`: 最后成交价
  309. /// - `volume(Decimal)`: 最近成交量
  310. #[derive(Debug, Clone, PartialEq, Eq)]
  311. pub struct Ticker {
  312. pub time: i64,
  313. pub high: Decimal,
  314. pub low: Decimal,
  315. pub sell: Decimal,
  316. pub buy: Decimal,
  317. pub last: Decimal,
  318. pub volume: Decimal,
  319. }
  320. impl Ticker {
  321. pub fn new() -> Ticker {
  322. Ticker {
  323. time: 0,
  324. high: Default::default(),
  325. low: Default::default(),
  326. sell: Default::default(),
  327. buy: Default::default(),
  328. last: Default::default(),
  329. volume: Default::default(),
  330. }
  331. }
  332. }
  333. /// Market结构体(交易品种的市场信息)
  334. /// - `symbol(String)`: 交易对
  335. /// - `base_asset(String)`: 交易币
  336. /// - `quote_asset(String)`: 计价币
  337. /// - `tick_size(Decimal)`: 价格最小变动数值
  338. /// - `amount_size(Decimal)`: 下单量最小变动数值
  339. /// - `price_precision(Decimal)`: 价格精度
  340. /// - `amount_precision(Decimal)`: 下单量精度
  341. /// - `min_qty(Decimal)`: 最小下单量
  342. /// - `max_qty(Decimal)`: 最大下单量
  343. /// - `min_notional(Decimal)`: 最小下单金额
  344. /// - `max_notional(Decimal)`: 最大下单金额
  345. /// - `ct_val(Decimal)`: 合约价值
  346. #[derive(Debug, Clone, PartialEq, Eq)]
  347. pub struct Market {
  348. pub symbol: String,
  349. pub base_asset: String,
  350. pub quote_asset: String,
  351. pub tick_size: Decimal,
  352. pub amount_size: Decimal,
  353. pub price_precision: Decimal,
  354. pub amount_precision: Decimal,
  355. pub min_qty: Decimal,
  356. pub max_qty: Decimal,
  357. pub min_notional: Decimal,
  358. pub max_notional: Decimal,
  359. pub ct_val: Decimal,
  360. }
  361. impl Market {
  362. pub fn new() -> Market {
  363. Market {
  364. symbol: "".to_string(),
  365. base_asset: "".to_string(),
  366. quote_asset: "".to_string(),
  367. tick_size: Default::default(),
  368. amount_size: Default::default(),
  369. price_precision: Default::default(),
  370. amount_precision: Default::default(),
  371. min_qty: Default::default(),
  372. max_qty: Default::default(),
  373. min_notional: Default::default(),
  374. max_notional: Default::default(),
  375. ct_val: Default::default(),
  376. }
  377. }
  378. }
  379. /// Position结构体(仓位信息)
  380. /// - `symbol(String)`: 币对
  381. /// - `margin_level(Decimal)`: 持仓杆杠大小
  382. /// - `amount(Decimal)`: 持仓量
  383. /// - `frozen_amount(Decimal)`: 仓位冻结量
  384. /// - `price(Decimal)`: 持仓均价
  385. /// - `profit(Decimal)`: 持仓浮动盈亏
  386. /// - `position_mode(PositionModeEnum)`: 持仓模式
  387. /// - `margin(Decimal)`: 仓位占用的保证金
  388. #[derive(Debug, Clone, PartialEq, Eq)]
  389. pub struct Position {
  390. pub symbol: String,
  391. pub margin_level: Decimal,
  392. pub amount: Decimal,
  393. pub frozen_amount: Decimal,
  394. pub price: Decimal,
  395. pub profit: Decimal,
  396. pub position_mode: PositionModeEnum,
  397. pub margin: Decimal,
  398. }
  399. impl Position {
  400. pub fn new() -> Position {
  401. Position {
  402. symbol: "".to_string(),
  403. margin_level: Default::default(),
  404. amount: Default::default(),
  405. frozen_amount: Default::default(),
  406. price: Default::default(),
  407. profit: Default::default(),
  408. position_mode: PositionModeEnum::Both,
  409. margin: Default::default(),
  410. }
  411. }
  412. }
  413. /// 交易所统一方法接口
  414. ///
  415. /// 使用方法前需实例化
  416. /// ```rust
  417. /// use std::collections::BTreeMap;
  418. /// use standard::exchange::{Exchange, ExchangeEnum};
  419. ///
  420. /// let mut params:BTreeMap<String,String> = BTreeMap::new();
  421. /// params.insert("access_key".to_string(), "your_access_key".to_string());
  422. /// params.insert("access_key".to_string(), "your_secret_key".to_string());
  423. /// // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  424. /// ```
  425. /// 获取当前交易所交易模式
  426. /// - fn get_self_exchange(&self) -> ExchangeEnum;
  427. /// ```rust
  428. /// # use std::collections::BTreeMap;
  429. /// # use standard::exchange::{Exchange, ExchangeEnum};
  430. /// # let mut params:BTreeMap<String,String> = BTreeMap::new();
  431. /// # params.insert("access_key".to_string(), "your_access_key".to_string());
  432. /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
  433. /// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  434. ///
  435. /// // exchange.get_self_exchange();
  436. /// ```
  437. /// 获取当前是否使用高速模式
  438. /// - fn get_self_is_colo(&self) -> bool;
  439. /// ```rust
  440. /// # use std::collections::BTreeMap;
  441. /// # use standard::exchange::{Exchange, ExchangeEnum};
  442. /// # let mut params:BTreeMap<String,String> = BTreeMap::new();
  443. /// # params.insert("access_key".to_string(), "your_access_key".to_string());
  444. /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
  445. /// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  446. ///
  447. /// // exchange.get_self_is_colo();
  448. /// ```
  449. /// 获取当前是否使用登录
  450. /// - fn get_self_is_login(&self) -> bool;
  451. /// ```rust
  452. /// # use std::collections::BTreeMap;
  453. /// # use standard::exchange::{Exchange, ExchangeEnum};
  454. /// # let mut params:BTreeMap<String,String> = BTreeMap::new();
  455. /// # params.insert("access_key".to_string(), "your_access_key".to_string());
  456. /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
  457. /// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  458. ///
  459. /// // exchange.get_self_is_login();
  460. /// ```
  461. /// 获取登录params信息
  462. /// - fn get_self_params(&self) -> BTreeMap<String, String>;
  463. /// ```rust
  464. /// # use std::collections::BTreeMap;
  465. /// # use standard::exchange::{Exchange, ExchangeEnum};
  466. /// # let mut params:BTreeMap<String,String> = BTreeMap::new();
  467. /// # params.insert("access_key".to_string(), "your_access_key".to_string());
  468. /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
  469. /// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  470. ///
  471. /// // exchange.get_self_params();
  472. /// ```
  473. /// 获取账号信息
  474. /// - async fn get_account(&self, symbol: &str) -> Result<Account, Error>;
  475. /// ```rust
  476. /// # use std::collections::BTreeMap;
  477. /// # use standard::exchange::{Exchange, ExchangeEnum};
  478. /// # let mut params:BTreeMap<String,String> = BTreeMap::new();
  479. /// # params.insert("access_key".to_string(), "your_access_key".to_string());
  480. /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
  481. /// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  482. ///
  483. /// // exchange.get_account()
  484. /// ```
  485. /// 订阅账号信息
  486. /// ```rust
  487. /// # use std::collections::BTreeMap;
  488. /// # use standard::exchange::{Exchange, ExchangeEnum};
  489. /// # let mut params:BTreeMap<String,String> = BTreeMap::new();
  490. /// # params.insert("access_key".to_string(), "your_access_key".to_string());
  491. /// # params.insert("access_key".to_string(), "your_secret_key".to_string());
  492. /// # // let exchange = Exchange::new(ExchangeEnum::BinanceSwap, "BTC_USDT".to_string(), true, params);
  493. ///
  494. /// // exchange.subscribe_account();
  495. /// ```
  496. #[async_trait]
  497. pub trait Platform {
  498. fn clone_box(&self) -> Box<dyn Platform + Send + Sync>;
  499. // 获取当前交易所交易模式
  500. fn get_self_exchange(&self) -> ExchangeEnum;
  501. // 获取交易对
  502. fn get_self_symbol(&self) -> String;
  503. // 获取当前是否使用高速模式
  504. fn get_self_is_colo(&self) -> bool;
  505. // 获取登录params信息
  506. fn get_self_params(&self) -> BTreeMap<String, String>;
  507. // 获取market信息
  508. fn get_self_market(&self) -> Market;
  509. // 获取请求时间
  510. fn get_request_delays(&self) -> Vec<i64>;
  511. // 获取请求平均时间
  512. fn get_request_avg_delay(&self) -> Decimal;
  513. // 获取请求最大时间
  514. fn get_request_max_delay(&self) -> i64;
  515. // 获取服务器时间
  516. async fn get_server_time(&mut self) -> Result<String, Error>;
  517. // 获取账号信息
  518. async fn get_account(&mut self) -> Result<Account, Error>;
  519. // 获取现货账号信息
  520. async fn get_spot_account(&mut self) -> Result<Vec<Account>, Error>;
  521. // 获取持仓信息
  522. async fn get_position(&mut self) -> Result<Vec<Position>, Error>;
  523. // 获取所有持仓
  524. async fn get_positions(&mut self) -> Result<Vec<Position>, Error>;
  525. // 获取市场行情
  526. async fn get_ticker(&mut self) -> Result<Ticker, Error>;
  527. // 获取市场行情自定义交易对
  528. async fn get_ticker_symbol(&mut self, symbol: String) -> Result<Ticker, Error>;
  529. // 查询所有的市场信息
  530. async fn get_market(&mut self) -> Result<Market, Error>;
  531. // 查询所有的市场信息自定义交易对
  532. async fn get_market_symbol(&mut self, symbol: String) -> Result<Market, Error>;
  533. // 查询订单详情
  534. async fn get_order_detail(&mut self, order_id: &str, custom_id: &str) -> Result<Order, Error>;
  535. // 获取订单列表
  536. async fn get_orders_list(&mut self, status: &str) -> Result<Vec<Order>, Error>;
  537. // 下单接口
  538. async fn take_order(&mut self, custom_id: &str, origin_side: &str, price: Decimal, amount: Decimal) -> Result<Order, Error>;
  539. // 下单接口自定义交易对
  540. async fn take_order_symbol(&mut self, symbol: String, ct_val: Decimal, custom_id: &str, origin_side: &str, price: Decimal, amount: Decimal) -> Result<Order, Error>;
  541. // 撤销订单
  542. async fn cancel_order(&mut self, order_id: &str, custom_id: &str) -> Result<Order, Error>;
  543. // 批量撤销订单
  544. async fn cancel_orders(&mut self) -> Result<Vec<Order>, Error>;
  545. // 撤销所有订单
  546. async fn cancel_orders_all(&mut self) -> Result<Vec<Order>, Error>;
  547. /// 下一个止损单
  548. /// - stop_price: 触发价
  549. /// - price: 委托价,0就市价委托
  550. /// - side: 止损哪个方向[long多单,short空单]
  551. async fn take_stop_loss_order(&mut self, stop_price: Decimal, price: Decimal, side: &str) -> Result<Value, Error>;
  552. /// 撤销止损订单
  553. /// - order_id: 需要撤销的id
  554. async fn cancel_stop_loss_order(&mut self, order_id: &str) -> Result<Value, Error>;
  555. // 设置持仓模式
  556. async fn set_dual_mode(&mut self, coin: &str, is_dual_mode: bool) -> Result<String, Error>;
  557. // 更新双持仓模式下杠杆
  558. async fn set_dual_leverage(&mut self, leverage: &str) -> Result<String, Error>;
  559. // 设置自动追加保证金
  560. async fn set_auto_deposit_status(&mut self, status: bool) -> Result<String, Error>;
  561. // 交易账户互转
  562. async fn wallet_transfers(&mut self, coin: &str, from: &str, to: &str, amount: Decimal) -> Result<String, Error>;
  563. }