exchange_test.rs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. // use std::collections::{BTreeMap};
  2. // use std::io::{Error};
  3. // use std::sync::Arc;
  4. // use std::sync::atomic::AtomicBool;
  5. // use futures::StreamExt;
  6. // use rust_decimal_macros::dec;
  7. // use tokio::sync::mpsc::{channel, Receiver, Sender};
  8. // use tokio::sync::Mutex;
  9. // use tokio::try_join;
  10. // use tracing::{error, trace};
  11. // // use exchanges::binance_spot_ws::{BinanceSpotLogin, BinanceSpotSubscribeType, BinanceSpotWs, BinanceSpotWsType};
  12. // // use exchanges::binance_swap_ws::{BinanceSwapLogin, BinanceSwapSubscribeType, BinanceSwapWs, BinanceSwapWsType};
  13. // // use exchanges::kucoin_swap_ws::{KucoinSwapLogin, KucoinSwapSubscribeType, KucoinSwapWs, KucoinSwapWsType};
  14. // // use exchanges::kucoin_spot_ws::{KucoinSpotLogin, KucoinSpotSubscribeType, KucoinSpotWs, KucoinSpotWsType};
  15. // // use exchanges::gate_swap_ws::{GateSwapLogin, GateSwapSubscribeType, GateSwapWs, GateSwapWsType};
  16. // // use exchanges::bitget_spot_ws::{BitgetSpotLogin, BitgetSpotSubscribeType, BitgetSpotWs, BitgetSpotWsType};
  17. // use exchanges::okx_swap_ws::{OkxSwapLogin, OkxSwapSubscribeType, OkxSwapWs, OkxSwapWsType};
  18. // use exchanges::response_base::ResponseData;
  19. // use standard::exchange::{Exchange, ExchangeEnum};
  20. // // use standard::{binance_spot_handle, Order, Platform, utils};
  21. // // use standard::{binance_handle, Order, Platform, utils};
  22. // // use standard::{kucoin_handle, Order, Platform, utils};
  23. // // use standard::{kucoin_spot_handle, Order, Platform, utils};
  24. // // use standard::{gate_handle, Order, Platform, utils};
  25. // // use standard::{bitget_spot_handle, Order, Platform, utils};
  26. // use standard::{okx_handle, Order, Platform, utils};
  27. //
  28. // // 创建实体
  29. // #[allow(dead_code)]
  30. // pub async fn test_new_exchange(exchange: ExchangeEnum, symbol: &str) -> Box<dyn Platform> {
  31. // utils::proxy_handle();
  32. // let (order_sender, _order_receiver): (Sender<Order>, Receiver<Order>) = channel(1024);
  33. // let (error_sender, _error_receiver): (Sender<Error>, Receiver<Error>) = channel(1024);
  34. //
  35. // let account_info = global::account_info::get_account_info("../test_account.toml");
  36. // match exchange {
  37. // ExchangeEnum::BinanceSwap => {
  38. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  39. // let access_key = account_info.binance_access_key;
  40. // let secret_key = account_info.binance_secret_key;
  41. // params.insert("access_key".to_string(), access_key);
  42. // params.insert("secret_key".to_string(), secret_key);
  43. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  44. // }
  45. // ExchangeEnum::BinanceSpot => {
  46. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  47. // let access_key = account_info.binance_access_key;
  48. // let secret_key = account_info.binance_secret_key;
  49. // params.insert("access_key".to_string(), access_key);
  50. // params.insert("secret_key".to_string(), secret_key);
  51. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  52. // }
  53. // ExchangeEnum::GateSwap => {
  54. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  55. // let access_key = account_info.gate_access_key;
  56. // let secret_key = account_info.gate_secret_key;
  57. // params.insert("access_key".to_string(), access_key);
  58. // params.insert("secret_key".to_string(), secret_key);
  59. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  60. // }
  61. // ExchangeEnum::GateSpot => {
  62. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  63. // let access_key = account_info.gate_access_key;
  64. // let secret_key = account_info.gate_secret_key;
  65. // params.insert("access_key".to_string(), access_key);
  66. // params.insert("secret_key".to_string(), secret_key);
  67. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  68. // }
  69. // ExchangeEnum::KucoinSwap => {
  70. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  71. // let access_key = account_info.kucoin_access_key;
  72. // let secret_key = account_info.kucoin_secret_key;
  73. // let pass_key = account_info.kucoin_pass;
  74. // params.insert("access_key".to_string(), access_key);
  75. // params.insert("secret_key".to_string(), secret_key);
  76. // params.insert("pass_key".to_string(), pass_key);
  77. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  78. // }
  79. // ExchangeEnum::KucoinSpot => {
  80. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  81. // let access_key = account_info.kucoin_access_key;
  82. // let secret_key = account_info.kucoin_secret_key;
  83. // let pass_key = account_info.kucoin_pass;
  84. // params.insert("access_key".to_string(), access_key);
  85. // params.insert("secret_key".to_string(), secret_key);
  86. // params.insert("pass_key".to_string(), pass_key);
  87. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  88. // }
  89. // ExchangeEnum::OkxSwap => {
  90. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  91. // let access_key = account_info.okx_access_key;
  92. // let secret_key = account_info.okx_secret_key;
  93. // let pass_key = account_info.okx_pass;
  94. // params.insert("access_key".to_string(), access_key);
  95. // params.insert("secret_key".to_string(), secret_key);
  96. // params.insert("pass_key".to_string(), pass_key);
  97. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  98. // }
  99. // ExchangeEnum::BitgetSpot => {
  100. // let mut params: BTreeMap<String, String> = BTreeMap::new();
  101. // let access_key = account_info.bitget_access_key;
  102. // let secret_key = account_info.bitget_secret_key;
  103. // let pass_key = account_info.bitget_pass;
  104. // params.insert("access_key".to_string(), access_key);
  105. // params.insert("secret_key".to_string(), secret_key);
  106. // params.insert("pass_key".to_string(), pass_key);
  107. // Exchange::new(exchange, symbol.to_string(), false, params, order_sender, error_sender).await
  108. // }
  109. // }
  110. // }
  111. //
  112. // #[allow(dead_code)]
  113. // pub async fn test_new_exchange_wss<T>(exchange: ExchangeEnum, symbol: &str, subscriber_type: T, mold: &str) where Vec<OkxSwapSubscribeType>: From<T> {
  114. // utils::proxy_handle();
  115. // let account_info = global::account_info::get_account_info("../test_account.toml");
  116. // match exchange {
  117. // ExchangeEnum::BinanceSpot => {
  118. // // let symbol_format = utils::format_symbol(symbol.to_string(), "").to_uppercase();
  119. // // trace!(symbol_format);
  120. // // let name = format!("binance_spot@{}", symbol.to_string().to_lowercase());
  121. // // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  122. // // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  123. // // let write_tx_am = Arc::new(Mutex::new(write_tx));
  124. // // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  125. // //
  126. // // let params = BinanceSpotLogin {
  127. // // api_key: account_info.binance_access_key,
  128. // // api_secret: account_info.binance_secret_key,
  129. // // };
  130. // // let mut exchange_wss;
  131. // // exchange_wss = BinanceSpotWs::new_with_tag(name, false, Option::from(params), BinanceSpotWsType::PublicAndPrivate);
  132. // // exchange_wss.set_symbols(vec![symbol_format]);
  133. // // exchange_wss.set_subscribe(subscriber_type.into());
  134. // //
  135. // //
  136. // // let mold_arc = Arc::new(mold.to_string());
  137. // // //读取
  138. // // tokio::spawn(async move {
  139. // // let mold_clone = Arc::clone(&mold_arc);
  140. // // loop {
  141. // // if let Some(data) = read_rx.next().await {
  142. // // trace!("原始数据 data:{:?}",data);
  143. // // match mold_clone.as_str() {
  144. // // "depth" => {
  145. // // if data.data != "" {
  146. // // let result = binance_spot_handle::handle_special_depth(data);
  147. // // trace!(?result)
  148. // // }
  149. // // }
  150. // // "ticker" => {
  151. // // if data.data != "" {
  152. // // let result = binance_spot_handle::handle_special_ticker(data);
  153. // // trace!(?result)
  154. // // }
  155. // // }
  156. // // _ => {
  157. // // error!("没有该命令!mode={}", mold_clone);
  158. // // panic!("没有该命令!mode={}", mold_clone)
  159. // // }
  160. // // }
  161. // // }
  162. // // };
  163. // // });
  164. // //
  165. // // let t1 = tokio::spawn(async move {
  166. // // //链接
  167. // // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  168. // // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  169. // // });
  170. // // try_join!(t1).unwrap();
  171. // }
  172. // ExchangeEnum::BinanceSwap => {
  173. // // let symbol_format = utils::format_symbol(symbol.to_string(), "").to_uppercase();
  174. // // trace!(symbol_format);
  175. // // let name = format!("binance_swap@{}", symbol.to_string().to_lowercase());
  176. // // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  177. // // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  178. // // let write_tx_am = Arc::new(Mutex::new(write_tx));
  179. // // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  180. // //
  181. // // let params = BinanceSwapLogin {
  182. // // api_key: account_info.binance_access_key,
  183. // // api_secret: account_info.binance_secret_key,
  184. // // };
  185. // // let mut exchange_wss;
  186. // // exchange_wss = BinanceSwapWs::new_with_tag(name, false, Option::from(params), BinanceSwapWsType::PublicAndPrivate);
  187. // // exchange_wss.set_symbols(vec![symbol_format]);
  188. // // exchange_wss.set_subscribe(subscriber_type.into());
  189. // //
  190. // //
  191. // // let mold_arc = Arc::new(mold.to_string());
  192. // // //读取
  193. // // tokio::spawn(async move {
  194. // // let mold_clone = Arc::clone(&mold_arc);
  195. // // loop {
  196. // // if let Some(data) = read_rx.next().await {
  197. // // trace!("原始数据 data:{:?}",data);
  198. // // match mold_clone.as_str() {
  199. // // "depth" => {
  200. // // if data.data != "" {
  201. // // let result = binance_handle::handle_special_depth(data);
  202. // // trace!(?result)
  203. // // }
  204. // // }
  205. // // "ticker" => {
  206. // // if data.data != "" {
  207. // // let result = binance_handle::handle_special_ticker(data);
  208. // // trace!(?result)
  209. // // }
  210. // // }
  211. // // _ => {
  212. // // error!("没有该命令!mode={}", mold_clone);
  213. // // panic!("没有该命令!mode={}", mold_clone)
  214. // // }
  215. // // }
  216. // // }
  217. // // };
  218. // // });
  219. // //
  220. // // let t1 = tokio::spawn(async move {
  221. // // //链接
  222. // // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  223. // // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  224. // // });
  225. // // try_join!(t1).unwrap();
  226. // }
  227. // ExchangeEnum::KucoinSwap => {
  228. // // let symbol_format = format!("{}M", utils::format_symbol(symbol.to_string(), ""));
  229. // // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
  230. // //
  231. // // let name = format!("kucoin_swap@{}", symbol.to_string().to_lowercase());
  232. // // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  233. // // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  234. // // let write_tx_am = Arc::new(Mutex::new(write_tx));
  235. // // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  236. // //
  237. // // let params = KucoinSwapLogin {
  238. // // access_key: account_info.kucoin_access_key,
  239. // // secret_key: account_info.kucoin_secret_key,
  240. // // pass_key: account_info.kucoin_pass,
  241. // // };
  242. // // let mut exchange_wss;
  243. // // if ["depth", "ticker"].contains(&mold) {
  244. // // exchange_wss = KucoinSwapWs::new_with_tag(name, false, Option::from(params), KucoinSwapWsType::Public).await;
  245. // // } else {
  246. // // exchange_wss = KucoinSwapWs::new_with_tag(name, false, Option::from(params), KucoinSwapWsType::Private).await;
  247. // // }
  248. // // exchange_wss.set_symbols(vec![symbol_format]);
  249. // // exchange_wss.set_subscribe(subscriber_type.into());
  250. // //
  251. // // let mold_arc = Arc::new(mold.to_string());
  252. // // tokio::spawn(async move {
  253. // // let mold_clone = Arc::clone(&mold_arc);
  254. // // loop {
  255. // // if let Some(data) = read_rx.next().await {
  256. // // trace!("原始数据 data:{:?}",data);
  257. // // match mold_clone.as_str() {
  258. // // "depth" => {
  259. // // let result = kucoin_handle::handle_special_depth(data);
  260. // // trace!(?result)
  261. // // }
  262. // // "ticker" => {
  263. // // let result = kucoin_handle::handle_special_ticker(data);
  264. // // trace!(?result)
  265. // // }
  266. // // "account" => {
  267. // // let result = kucoin_handle::handle_account_info(data, symbol_back.clone());
  268. // // trace!(?result)
  269. // // }
  270. // // "position" => {
  271. // // let result = kucoin_handle::handle_position(data, dec!(1));
  272. // // trace!(?result)
  273. // // }
  274. // // "orders" => {
  275. // // let result = kucoin_handle::handle_order(data, dec!(0.001));
  276. // // trace!(?result)
  277. // // }
  278. // // _ => {
  279. // // error!("没有该命令!mode={}", mold_clone);
  280. // // panic!("没有该命令!mode={}", mold_clone)
  281. // // }
  282. // // }
  283. // // }
  284. // // }
  285. // // });
  286. // //
  287. // // let t1 = tokio::spawn(async move {
  288. // // //链接
  289. // // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  290. // // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  291. // // });
  292. // // try_join!(t1).unwrap();
  293. // }
  294. // ExchangeEnum::KucoinSpot => {
  295. // // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
  296. // // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
  297. // // trace!(symbol_format);
  298. // // let name = format!("kucoin_spot@{}", symbol.to_string().to_lowercase());
  299. // // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  300. // // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  301. // // let write_tx_am = Arc::new(Mutex::new(write_tx));
  302. // // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  303. // //
  304. // // let params = KucoinSpotLogin {
  305. // // access_key: account_info.kucoin_access_key,
  306. // // secret_key: account_info.kucoin_secret_key,
  307. // // pass_key: account_info.kucoin_pass,
  308. // // };
  309. // // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
  310. // // KucoinSpotWs::new_with_tag(name, false, Option::from(params), KucoinSpotWsType::Public).await
  311. // // } else {
  312. // // KucoinSpotWs::new_with_tag(name, false, Option::from(params), KucoinSpotWsType::Private).await
  313. // // };
  314. // // exchange_wss.set_symbols(vec![symbol_format]);
  315. // // exchange_wss.set_subscribe(subscriber_type.into());
  316. // //
  317. // // let mold_arc = Arc::new(mold.to_string());
  318. // // tokio::spawn(async move {
  319. // // let mold_clone = Arc::clone(&mold_arc);
  320. // // loop {
  321. // // if let Some(data) = read_rx.next().await {
  322. // // trace!("原始数据 data:{:?}",data);
  323. // // match mold_clone.as_str() {
  324. // // "depth" => {
  325. // // if data.data != "" {
  326. // // let result = kucoin_spot_handle::handle_special_depth(data);
  327. // // trace!(?result)
  328. // // }
  329. // // }
  330. // // "ticker" => {
  331. // // if data.data != "" {
  332. // // let result = kucoin_spot_handle::handle_special_ticker(data);
  333. // // trace!(?result)
  334. // // }
  335. // // }
  336. // // "account" => {
  337. // // if data.data != "" {
  338. // // let result = kucoin_spot_handle::handle_account_info(data, symbol_back.clone());
  339. // // trace!(?result)
  340. // // }
  341. // // }
  342. // // "orders" => {
  343. // // if data.data != "" {
  344. // // let result = kucoin_spot_handle::handle_order(data, dec!(1));
  345. // // trace!(?result)
  346. // // }
  347. // // }
  348. // // _ => {
  349. // // error!("没有该命令!mode={}", mold_clone);
  350. // // panic!("没有该命令!mode={}", mold_clone)
  351. // // }
  352. // // }
  353. // // }
  354. // // }
  355. // // });
  356. // // let t1 = tokio::spawn(async move {
  357. // // //链接
  358. // // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  359. // // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  360. // // });
  361. // // try_join!(t1).unwrap();
  362. // }
  363. // ExchangeEnum::GateSwap => {
  364. // // let symbol_format = utils::format_symbol(symbol.to_string(), "_").to_uppercase();
  365. // // trace!(symbol_format);
  366. // // let name = format!("gate_swap@{}", symbol.to_string().to_lowercase());
  367. // // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  368. // // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  369. // // let write_tx_am = Arc::new(Mutex::new(write_tx));
  370. // // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  371. // //
  372. // // let params = GateSwapLogin {
  373. // // api_key: account_info.gate_access_key,
  374. // // secret: account_info.gate_secret_key,
  375. // // };
  376. // // let mut exchange_wss = GateSwapWs::new_with_tag(name, false, Option::from(params), GateSwapWsType::PublicAndPrivate("usdt".to_string()));
  377. // // exchange_wss.set_symbols(vec![symbol_format.clone()]);
  378. // // exchange_wss.set_subscribe(subscriber_type.into());
  379. // //
  380. // // let mold_arc = Arc::new(mold.to_string());
  381. // // tokio::spawn(async move {
  382. // // let mold_clone = Arc::clone(&mold_arc);
  383. // // loop {
  384. // // if let Some(data) = read_rx.next().await {
  385. // // trace!("原始数据 data:{:?}",data);
  386. // // match mold_clone.as_str() {
  387. // // "depth" => {
  388. // // if data.data != "" {
  389. // // let result = gate_handle::handle_special_depth(data);
  390. // // trace!(?result)
  391. // // }
  392. // // }
  393. // // "ticker" => {
  394. // // if data.data != "" {
  395. // // let result = gate_handle::handle_special_ticker(data);
  396. // // trace!(?result)
  397. // // }
  398. // // }
  399. // // "account" => {
  400. // // if data.data != "" {
  401. // // let result = gate_handle::handle_account_info(data, symbol_format.clone());
  402. // // trace!(?result)
  403. // // }
  404. // // }
  405. // // "orders" => {
  406. // // if data.data != "" {
  407. // // let result = gate_handle::handle_order(data, dec!(1));
  408. // // trace!(?result)
  409. // // }
  410. // // }
  411. // // _ => {
  412. // // error!("没有该命令!mode={}", mold_clone);
  413. // // panic!("没有该命令!mode={}", mold_clone)
  414. // // }
  415. // // }
  416. // // }
  417. // // }
  418. // // });
  419. // // let t1 = tokio::spawn(async move {
  420. // // //链接
  421. // // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  422. // // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  423. // // });
  424. // // try_join!(t1).unwrap();
  425. // }
  426. // ExchangeEnum::BitgetSpot => {
  427. // // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
  428. // // let symbol_back = utils::format_symbol(symbol.to_string(), "_");
  429. // // trace!(symbol_format);
  430. // // let name = format!("bitget_spot@{}", symbol.to_string().to_lowercase());
  431. // // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  432. // // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  433. // // let write_tx_am = Arc::new(Mutex::new(write_tx));
  434. // // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  435. // //
  436. // // let params = BitgetSpotLogin {
  437. // // api_key: account_info.bitget_access_key,
  438. // // secret_key: account_info.bitget_secret_key,
  439. // // passphrase_key: account_info.bitget_pass,
  440. // // };
  441. // //
  442. // // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
  443. // // BitgetSpotWs::new_with_tag(name, false, Option::from(params), BitgetSpotWsType::Public)
  444. // // } else {
  445. // // BitgetSpotWs::new_with_tag(name, false, Option::from(params), BitgetSpotWsType::Private)
  446. // // };
  447. // // exchange_wss.set_symbols(vec![symbol_format]);
  448. // // exchange_wss.set_subscribe(subscriber_type.into());
  449. // //
  450. // // let mold_arc = Arc::new(mold.to_string());
  451. // // //读取
  452. // // tokio::spawn(async move {
  453. // // loop {
  454. // // let mold_clone = Arc::clone(&mold_arc);
  455. // // if let Some(data) = read_rx.next().await {
  456. // // trace!("原始数据 data:{:?}",data);
  457. // // match mold_clone.as_str() {
  458. // // "depth" => {
  459. // // if data.data != "" {
  460. // // let result = bitget_spot_handle::handle_special_depth(data);
  461. // // trace!(?result)
  462. // // }
  463. // // }
  464. // // "ticker" => {
  465. // // if data.data != "" {
  466. // // let result = bitget_spot_handle::handle_special_ticker(data);
  467. // // trace!(?result)
  468. // // }
  469. // // }
  470. // // "account" => {
  471. // // if data.data != "" {
  472. // // let result = bitget_spot_handle::handle_account_info(data, symbol_back.clone());
  473. // // trace!(?result)
  474. // // }
  475. // // }
  476. // // "orders" => {
  477. // // if data.data != "" {
  478. // // let result = bitget_spot_handle::handle_order(data, dec!(1));
  479. // // trace!(?result)
  480. // // }
  481. // // }
  482. // // _ => {
  483. // // error!("没有该命令!mode={}", mold_clone);
  484. // // panic!("没有该命令!mode={}", mold_clone)
  485. // // }
  486. // // }
  487. // // }
  488. // // }
  489. // // });
  490. // // let t1 = tokio::spawn(async move {
  491. // // //链接
  492. // // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  493. // // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  494. // // });
  495. // // try_join!(t1).unwrap();
  496. // }
  497. // ExchangeEnum::OkxSwap => {
  498. // let symbol_format = utils::format_symbol(symbol.to_string(), "-").to_uppercase();
  499. // trace!(symbol_format);
  500. // let name = format!("okx_swap@{}", symbol.to_string().to_lowercase());
  501. // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  502. // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded::<ResponseData>();
  503. // let write_tx_am = Arc::new(Mutex::new(write_tx));
  504. // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  505. //
  506. // let params = OkxSwapLogin {
  507. // api_key: account_info.okx_access_key,
  508. // secret_key: account_info.okx_secret_key,
  509. // passphrase: account_info.okx_pass,
  510. // };
  511. //
  512. // let mut exchange_wss = if ["depth", "ticker"].contains(&mold) {
  513. // OkxSwapWs::new_with_tag(name, false, Option::from(params), OkxSwapWsType::Public)
  514. // } else if ["account", "orders", "position"].contains(&mold) {
  515. // OkxSwapWs::new_with_tag(name, false, Option::from(params), OkxSwapWsType::Private)
  516. // } else {
  517. // OkxSwapWs::new_with_tag(name, false, Option::from(params), OkxSwapWsType::Business)
  518. // };
  519. //
  520. // exchange_wss.set_symbols(vec![symbol_format.clone()]);
  521. // exchange_wss.set_subscribe(subscriber_type.into());
  522. //
  523. // let mold_arc = Arc::new(mold.to_string());
  524. // tokio::spawn(async move {
  525. // let mold_clone = Arc::clone(&mold_arc);
  526. // loop {
  527. // if let Some(data) = read_rx.next().await {
  528. // trace!("原始数据 data:{:?}",data);
  529. // match mold_clone.as_str() {
  530. // "depth" => {
  531. // if data.data != "" {
  532. // let result = okx_handle::handle_special_depth(data);
  533. // trace!(?result)
  534. // }
  535. // }
  536. // "ticker" => {
  537. // if data.data != "" {
  538. // let result = okx_handle::handle_special_ticker(data);
  539. // trace!(?result)
  540. // }
  541. // }
  542. // "account" => {
  543. // if data.data != "" {
  544. // let result = okx_handle::handle_account_info(data, symbol_format.clone());
  545. // trace!(?result)
  546. // }
  547. // }
  548. // "position" => {
  549. // if data.data != "" {
  550. // let result = okx_handle::handle_position(data, dec!(10));
  551. // trace!(?result)
  552. // }
  553. // }
  554. // "orders" => {
  555. // if data.data != "" {
  556. // let result = okx_handle::handle_order(data, dec!(10));
  557. // trace!(?result)
  558. // }
  559. // }
  560. // _ => {
  561. // error!("没有该命令!mode={}", mold_clone);
  562. // panic!("没有该命令!mode={}", mold_clone)
  563. // }
  564. // }
  565. // }
  566. // }
  567. // });
  568. //
  569. // let t1 = tokio::spawn(async move {
  570. // //链接
  571. // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  572. // exchange_wss.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  573. // });
  574. // try_join!(t1).unwrap();
  575. // }
  576. // _ => {
  577. // error!("该交易所不支持!test_new_exchange_wss:{:?}",exchange);
  578. // panic!("该交易所不支持!test_new_exchange_wss:{:?}", exchange)
  579. // }
  580. // }
  581. // }