exchange_test.rs 32 KB

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