kucoin_swap_test.rs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // use std::sync::Arc;
  2. // use std::sync::atomic::AtomicBool;
  3. //
  4. // use futures_util::StreamExt;
  5. // use tokio::sync::Mutex;
  6. // use tracing::trace;
  7. //
  8. // use exchanges::kucoin_swap_ws::{KucoinSwapLogin, KucoinSwapSubscribeType, KucoinSwapWs, KucoinSwapWsType};
  9. //
  10. // const ACCESS_KEY: &str = "";
  11. // const SECRET_KEY: &str = "";
  12. // const PASS_KEY: &str = "";
  13. //
  14. // //ws-订阅公共频道信息
  15. // #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
  16. // async fn ws_custom_subscribe_pu() {
  17. // global::log_utils::init_log_with_trace();
  18. //
  19. //
  20. // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  21. // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded();
  22. //
  23. //
  24. //
  25. // let mut ws = get_ws(None, KucoinSwapWsType::Public).await;
  26. // ws.set_symbols(vec!["xbt_usdtM".to_string()]);
  27. // ws.set_subscribe(vec![
  28. // KucoinSwapSubscribeType::PuContractMarketLevel2Depth50,
  29. // KucoinSwapSubscribeType::PuContractMarketExecution,
  30. // KucoinSwapSubscribeType::PuContractMarkettickerV2,
  31. // ]);
  32. //
  33. //
  34. // let write_tx_am = Arc::new(Mutex::new(write_tx));
  35. // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  36. //
  37. // //读取
  38. // let _is_shutdown_arc_clone = Arc::clone(&is_shutdown_arc);
  39. // let _tr = tokio::spawn(async move {
  40. // trace!("线程-数据读取-开启");
  41. // loop {
  42. // if let Some(data) = read_rx.next().await {
  43. // trace!("读取数据data:{:?}",data)
  44. // }
  45. // }
  46. // });
  47. //
  48. // //写数据
  49. // let _bool_v2_clone = Arc::clone(&is_shutdown_arc);
  50. // let _write_tx_clone = Arc::clone(&write_tx_am);
  51. // // let tw = tokio::spawn(async move {
  52. // // trace!("线程-数据写入-开始");
  53. // // loop {
  54. // // tokio::time::sleep(Duration::from_millis(20*1000)).await;
  55. // // let close_frame = CloseFrame {
  56. // // code: CloseCode::Normal,
  57. // // reason: Cow::Borrowed("Bye bye"),
  58. // // };
  59. // // let close_message = Message::Close(Some(close_frame));
  60. // // // AbstractWsMode::send_subscribe(write_tx_clone.clone(), Message::Text("32313221".to_string()));
  61. // // AbstractWsMode::send_subscribe(write_tx_clone.clone(), close_message);
  62. // // trace!("发送指令成功");
  63. // // }
  64. // // trace!("线程-数据写入-结束");
  65. // // });
  66. //
  67. // // loop {
  68. // let t1 = tokio::spawn(async move {
  69. // //链接
  70. // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  71. // ws.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  72. // trace!("test 唯一线程结束--");
  73. // });
  74. // tokio::try_join!(t1).unwrap();
  75. // trace!("当此结束");
  76. // // }
  77. // trace!("重启!");
  78. // trace!("参考交易所关闭");
  79. // return;
  80. // }
  81. //
  82. // //ws-订阅私有频道信息
  83. // #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
  84. // async fn ws_custom_subscribe_pr() {
  85. // global::log_utils::init_log_with_trace();
  86. //
  87. //
  88. // //对象
  89. // let btree_map = KucoinSwapLogin {
  90. // access_key: ACCESS_KEY.to_string(),
  91. // secret_key: SECRET_KEY.to_string(),
  92. // pass_key: PASS_KEY.to_string(),
  93. // };
  94. //
  95. // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  96. // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded();
  97. //
  98. // // let (write_tx, write_rx) = tokio::sync::broadcast::channel::<Message>(10);
  99. // // let (read_tx, mut read_rx) = tokio::sync::broadcast::channel::<ResponseData>(10);
  100. //
  101. //
  102. // let mut ws = get_ws(Option::from(btree_map), KucoinSwapWsType::Private).await;
  103. // ws.set_symbols(vec!["xbt_usdtM".to_string()]);
  104. // ws.set_subscribe(vec![
  105. // // KucoinSwapSubscribeType::PuContractMarketLevel2Depth50,
  106. // // KucoinSwapSubscribeType::PuContractMarketExecution,
  107. // KucoinSwapSubscribeType::PuContractMarkettickerV2,
  108. // KucoinSwapSubscribeType::PrContractAccountWallet,
  109. // KucoinSwapSubscribeType::PrContractPosition,
  110. // KucoinSwapSubscribeType::PrContractMarketTradeOrdersSys,
  111. // KucoinSwapSubscribeType::PrContractMarketTradeOrders,
  112. // ]);
  113. //
  114. //
  115. // let write_tx_am = Arc::new(Mutex::new(write_tx));
  116. // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  117. //
  118. // //读取
  119. // let _is_shutdown_arc_clone = Arc::clone(&is_shutdown_arc);
  120. // let _tr = tokio::spawn(async move {
  121. // trace!("线程-数据读取-开启");
  122. // loop {
  123. // if let Some(data) = read_rx.next().await {
  124. // trace!("读取数据data:{:?}",data)
  125. // }
  126. // }
  127. // });
  128. //
  129. // //写数据
  130. // let _bool_v2_clone = Arc::clone(&is_shutdown_arc);
  131. // let _write_tx_clone = Arc::clone(&write_tx_am);
  132. // // let tw = tokio::spawn(async move {
  133. // // trace!("线程-数据写入-开始");
  134. // // loop {
  135. // // tokio::time::sleep(Duration::from_millis(20*1000)).await;
  136. // // let close_frame = CloseFrame {
  137. // // code: CloseCode::Normal,
  138. // // reason: Cow::Borrowed("Bye bye"),
  139. // // };
  140. // // let close_message = Message::Close(Some(close_frame));
  141. // // // AbstractWsMode::send_subscribe(write_tx_clone.clone(), Message::Text("32313221".to_string()));
  142. // // AbstractWsMode::send_subscribe(write_tx_clone.clone(), close_message);
  143. // // trace!("发送指令成功");
  144. // // }
  145. // // trace!("线程-数据写入-结束");
  146. // // });
  147. //
  148. // // loop {
  149. // let t1 = tokio::spawn(async move {
  150. // //链接
  151. // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  152. // ws.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  153. // trace!("test 唯一线程结束--");
  154. // });
  155. // tokio::try_join!(t1).unwrap();
  156. // trace!("当此结束");
  157. // // }
  158. // trace!("重启!");
  159. // trace!("参考交易所关闭");
  160. // return;
  161. // }
  162. //
  163. //
  164. // async fn get_ws(btree_map: Option<KucoinSwapLogin>, type_v: KucoinSwapWsType) -> KucoinSwapWs {
  165. // let ku_ws = KucoinSwapWs::new(false, btree_map,
  166. // type_v).await;
  167. // ku_ws
  168. // }