crypto_spot_test.rs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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::crypto_spot_ws::{CryptoSpotLogin, CryptoSpotSubscribeType, CryptoSpotWs, CryptoSpotWsType};
  9. //
  10. // const ACCESS_KEY: &str = "";
  11. // const SECRET_KEY: &str = "";
  12. //
  13. //
  14. // //ws-订阅公共频道信息
  15. // #[tokio::test(flavor = "multi_thread", worker_threads = 5)]
  16. // async fn ws_pu() {
  17. // global::log_utils::init_log_with_trace();
  18. //
  19. // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  20. // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded();
  21. //
  22. // let mut ws = get_ws(None, CryptoSpotWsType::Public);
  23. // ws.set_symbols(vec!["BTC_USD".to_string()]);
  24. // ws.set_subscribe(vec![
  25. // // CryptoSpotSubscribeType::PuBook,
  26. // // CryptoSpotSubscribeType::PuTicker,
  27. // // CryptoSpotSubscribeType::PuTrade,
  28. // CryptoSpotSubscribeType::PuCandlestick,
  29. // ]);
  30. //
  31. // let write_tx_am = Arc::new(Mutex::new(write_tx));
  32. // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  33. //
  34. // //读取
  35. // let _is_shutdown_arc_clone = Arc::clone(&is_shutdown_arc);
  36. // let _tr = tokio::spawn(async move {
  37. // trace!("线程-数据读取-开启");
  38. // loop {
  39. // if let Some(data) = read_rx.next().await {
  40. // trace!("读取数据data:{:?}",data)
  41. // }
  42. // }
  43. // // trace!("线程-数据读取-结束");
  44. // });
  45. //
  46. // //写数据
  47. // // let bool_v2_clone = Arc::clone(&is_shutdown_arc);
  48. // // let write_tx_clone = Arc::clone(&write_tx_am);
  49. // // let su = ws.get_subscription();
  50. // // let tw = tokio::spawn(async move {
  51. // // trace!("线程-数据写入-开始");
  52. // // loop {
  53. // // tokio::time::sleep(Duration::from_millis(20 * 1000)).await;
  54. // // // let close_frame = CloseFrame {
  55. // // // code: CloseCode::Normal,
  56. // // // reason: Cow::Borrowed("Bye bye"),
  57. // // // };
  58. // // // let message = Message::Close(Some(close_frame));
  59. // //
  60. // //
  61. // // let message = Message::Text(su.clone());
  62. // // AbstractWsMode::send_subscribe(write_tx_clone.clone(), message.clone()).await;
  63. // // trace!("发送指令成功");
  64. // // }
  65. // // trace!("线程-数据写入-结束");
  66. // // });
  67. //
  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. // trace!("重启!");
  77. // trace!("参考交易所关闭");
  78. // return;
  79. // }
  80. //
  81. // fn get_ws(btree_map: Option<CryptoSpotLogin>, ws_type: CryptoSpotWsType) -> CryptoSpotWs {
  82. // let binance_ws = CryptoSpotWs::new(false,
  83. // btree_map,
  84. // ws_type);
  85. // binance_ws
  86. // }