浏览代码

修改coinex获取币对逻辑

DESKTOP-NE65RNK\Citrus_limon 1 年之前
父节点
当前提交
832d2e2b70
共有 1 个文件被更改,包括 11 次插入8 次删除
  1. 11 8
      src/coinex_usdt_swap_data_listener.rs

+ 11 - 8
src/coinex_usdt_swap_data_listener.rs

@@ -30,16 +30,19 @@ pub async fn run_listener(is_shutdown_arc: Arc<AtomicBool>) {
     // 订阅所有币种
     let login = BTreeMap::new();
     let mut coinex_rest = CoinexSwapRest::new(login);
-    let response = coinex_rest.get_market_details("usdt".to_string()).await;
     let mut symbols = vec![];
-    if response.code == 200 {
-        let data = response.data.as_array().unwrap();
-        for info in data {
-            let s = info["market"].as_str().unwrap();
-            if !s.ends_with("USDT") { continue; }
-            let symbol = s.to_string().replace("USDT", "_USDT");
-            symbols.push(symbol)
+    loop {
+        let response = coinex_rest.get_market_details("usdt".to_string()).await;
+        if response.code == 200 {
+            let data = response.data.as_array().unwrap();
+            for info in data {
+                let s = info["market"].as_str().unwrap();
+                if !s.ends_with("USDT") { continue; }
+                let symbol = s.to_string().replace("USDT", "_USDT");
+                symbols.push(symbol)
+            }
         }
+        if symbols.len() > 0 { break; } else { tokio::time::sleep(Duration::from_secs(2)).await; }
     }
 
     for chunk in symbols.chunks(20) {