Kaynağa Gözat

kucoin私有频道订阅可行

skyfffire 2 yıl önce
ebeveyn
işleme
04894f4134

+ 1 - 1
exchange/kucoin_usdt_swap_rest.py

@@ -189,7 +189,7 @@ class KucoinUsdtSwapRest:
                 'tradeType':'TRADE',
             }
             response, error = await self._request('GET', '/api/v1/orders', params=params, auth=1)
-            if response is not None:
+            if response is not None and response['data']['items'] is not None:
                 for i in response['data']['items']:
                     res = await self.cancel_order(order_id=i["id"])
                     self.logger.info(res)

+ 7 - 1
exchange/kucoin_usdt_swap_ws.py

@@ -349,8 +349,12 @@ class KucoinUsdtSwapWs:
                             f"/contract/position:{self.symbol}",
                             f"/contractMarket/tradeOrders:{self.symbol}",
                         ]
+
                     for i in channels:
-                        sub_str = ujson.dumps({"topic": i, "type":"subscribe"})
+                        sub_str = ujson.dumps({"topic": i, "type": "subscribe"})
+                        if "/contractMarket/level2Depth50" not in i and "/contractMarket/execution" not in i:
+                            print(i)
+                            sub_str = ujson.dumps({"topic": i, "type": "subscribe", "privateChannel": True, "response": True})
                         await _ws.send_str(sub_str)
                     while True:
                         # 接受消息
@@ -364,6 +368,8 @@ class KucoinUsdtSwapWs:
                         # print(msg)
                         # 处理消息
                         if 'data' in msg:
+                            if 'level2' not in msg['subject']:print(msg)
+
                             if 'level2' in msg['subject']:self._update_depth(msg)
                             elif "tickerV2" in msg["subject"]:self._update_ticker(msg)
                             elif 'match' in msg['subject']:self._update_trade(msg)

+ 5 - 1
quant.py

@@ -52,7 +52,7 @@ class Quant:
             r = psutil.cpu_times_percent(percpu=True)
             for i in range(cpu_count):
                 cpu_used_pct[i] += int(r[i].user)
-            time.sleep(1)
+            time.sleep(0.1)
             print(cpu_used_pct)
         cpu_id = cpu_used_pct.index(min(cpu_used_pct))
         print(f"当前负载最低的cpu为:{cpu_id}")
@@ -438,6 +438,8 @@ class Quant:
                             # 更新策略时间
                             self.strategy.local_time = time.time()
                             orders = self.strategy.onTime(self.tradeMsg)
+                            self.logger.info("update_local_order订单指令")
+                            self.logger.info(orders)
                             ### 记录指令触发信息
                             if self._not_empty(orders):
                                 self.logger.debug("触发onOrder")
@@ -630,6 +632,8 @@ class Quant:
                 self.strategy.local_time = time.time()
                 # 产生交易信号
                 orders = self.strategy.onTime(self.tradeMsg)
+                self.logger.info("_update_depth订单指令")
+                self.logger.info(orders)
                 ### 记录指令触发信息
                 if self._not_empty(orders):
                     self.logger.debug("触发onTick")

+ 1 - 1
strategy.py

@@ -48,7 +48,7 @@ class Strategy:
         self.total_amount = 0.0
         self.ready = 0
         self._is_print = is_print
-        self._min_amount_value = 30.0  # 最小下单额 防止下单失败
+        self._min_amount_value = 5.0  # 最小下单额 防止下单失败
         self._max_amount_value = 10000.0  # 最大下单额 防止下单过重 平不掉就很悲剧
         self.local_time = time.time()
         self.local_start_time = time.time()