binance_spot_test.rs 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // use std::sync::Arc;
  2. // use std::sync::atomic::AtomicBool;
  3. // use std::time::Duration;
  4. // use futures_util::StreamExt;
  5. //
  6. // use tokio::sync::Mutex;
  7. // use tokio_tungstenite::tungstenite::Message;
  8. // use tracing::trace;
  9. //
  10. // use exchanges::binance_spot_ws::{BinanceSpotLogin, BinanceSpotSubscribeType, BinanceSpotWs, BinanceSpotWsType};
  11. // use exchanges::socket_tool::AbstractWsMode;
  12. //
  13. // // 账号密码
  14. // const ACCESS_KEY: &str = "";
  15. // const SECRET_KEY: &str = "";
  16. //
  17. //
  18. // //ws-订阅公共频道信息
  19. // #[tokio::test(flavor = "multi_thread", worker_threads = 2)]
  20. // async fn ws_custom_subscribe() {
  21. // global::log_utils::init_log_with_trace();
  22. //
  23. // let (write_tx, write_rx) = futures_channel::mpsc::unbounded();
  24. // let (read_tx, mut read_rx) = futures_channel::mpsc::unbounded();
  25. //
  26. // let login_param = BinanceSpotLogin {
  27. // api_key: ACCESS_KEY.to_string(),
  28. // api_secret: SECRET_KEY.to_string(),
  29. // };
  30. // let mut ws = get_ws(None);
  31. // ws.set_symbols(vec!["BTC_USDT".to_string()]);
  32. // ws.set_subscribe(vec![
  33. // // BinanceSpotSubscribeType::PuBookTicker,
  34. // // BinanceSpotSubscribeType::PuAggTrade,
  35. // BinanceSpotSubscribeType::PuDepth20levels100ms,
  36. // ]);
  37. //
  38. // let write_tx_am = Arc::new(Mutex::new(write_tx));
  39. // let is_shutdown_arc = Arc::new(AtomicBool::new(true));
  40. //
  41. // //读取
  42. // let _is_shutdown_arc_clone = Arc::clone(&is_shutdown_arc);
  43. // let _tr = tokio::spawn(async move {
  44. // trace!("线程-数据读取-开启");
  45. // loop {
  46. // if let Some(data) = read_rx.next().await {
  47. // trace!("读取数据data:{:?}",data)
  48. // }
  49. // }
  50. // // trace!("线程-数据读取-结束");
  51. // });
  52. //
  53. // //写数据
  54. // // let bool_v2_clone = Arc::clone(&is_shutdown_arc);
  55. // // let write_tx_clone = Arc::clone(&write_tx_am);
  56. // // let su = ws.get_subscription();
  57. // // let tw = tokio::spawn(async move {
  58. // // trace!("线程-数据写入-开始");
  59. // // loop {
  60. // // tokio::time::sleep(Duration::from_millis(20 * 1000)).await;
  61. // // // let close_frame = CloseFrame {
  62. // // // code: CloseCode::Normal,
  63. // // // reason: Cow::Borrowed("Bye bye"),
  64. // // // };
  65. // // // let message = Message::Close(Some(close_frame));
  66. // //
  67. // //
  68. // // let message = Message::Text(su.clone());
  69. // // AbstractWsMode::send_subscribe(write_tx_clone.clone(), message.clone()).await;
  70. // // trace!("发送指令成功");
  71. // // }
  72. // // trace!("线程-数据写入-结束");
  73. // // });
  74. //
  75. // let t1 = tokio::spawn(async move {
  76. // //链接
  77. // let bool_v3_clone = Arc::clone(&is_shutdown_arc);
  78. // ws.ws_connect_async(bool_v3_clone, &write_tx_am, write_rx, read_tx).await.expect("链接失败(内部一个心跳线程应该已经关闭了)");
  79. // trace!("test 唯一线程结束--");
  80. // });
  81. // tokio::try_join!(t1).unwrap();
  82. // trace!("当此结束");
  83. // trace!("重启!");
  84. // trace!("参考交易所关闭");
  85. // return;
  86. // }
  87. //
  88. // fn get_ws(login_param: Option<BinanceSpotLogin>) -> BinanceSpotWs {
  89. // let binance_ws = BinanceSpotWs::new(false,
  90. // login_param, BinanceSpotWsType::PublicAndPrivate,
  91. // );
  92. // binance_ws
  93. // }
  94. //