Jelajahi Sumber

kucoin支持ticker数据订阅,不知道为什么原文没有加上。

skyfffire 1 tahun lalu
induk
melakukan
8326a9f1b9
4 mengubah file dengan 16 tambahan dan 3 penghapusan
  1. 10 1
      exchange/kucoin_usdt_swap_ws.py
  2. 2 0
      predictor.py
  3. 2 1
      quant.py
  4. 2 1
      strategy.py

+ 10 - 1
exchange/kucoin_usdt_swap_ws.py

@@ -168,6 +168,13 @@ class KucoinUsdtSwapWs:
             self.ticker_info['bp'] = float(msg['data']['bestBidPrice'])
             self.ticker_info['ap'] = float(msg['data']['bestAskPrice'])
             self.callback['onTicker'](self.ticker_info)
+
+            bp = float(msg['data']['bestBidPrice'])
+            bv = float(msg['data']['bestBidSize'])
+            ap = float(msg['data']['bestAskPrice'])
+            av = float(msg['data']['bestAskSize'])
+            self.depth = [bp, bv, ap, av]
+            self.callback['onDepth']({'name':self.name,'data':self.depth})
     
     def _update_trade(self, msg):
         price = float(msg["data"]['price'])
@@ -353,7 +360,9 @@ class KucoinUsdtSwapWs:
 
                     for i in channels:
                         sub_str = ujson.dumps({"topic": i, "type": "subscribe"})
-                        if "/contractMarket/level2Depth50" not in i and "/contractMarket/execution" not in i:
+                        if "/contractMarket/level2Depth50" not in i \
+                                and "/contractMarket/execution" not in i \
+                                and "/contractMarket/tickerV2" not in i:
                             # print(i)
                             sub_str = ujson.dumps({"topic": i, "type": "subscribe", "privateChannel": True, "response": True})
                         await _ws.send_str(sub_str)

+ 2 - 0
predictor.py

@@ -1,6 +1,8 @@
 import time
+
 import utils
 import numpy as np
+from loguru import logger
 
 class Predictor:
     '''

+ 2 - 1
quant.py

@@ -587,7 +587,6 @@ class Quant:
 
     # @utils.timeit
     async def _update_depth(self, data):
-        # logger.info(data)
         '''
             update orderbook infomation
         '''
@@ -932,6 +931,8 @@ class Quant:
         for i in self.ref_name:
             ref_tickers.append([self.tickers[i]['bp'], self.tickers[i]['ap']])
         self.tradeMsg.ref_price = self.Predictor.Get_ref(ref_tickers)
+        # logger.info('ref_price={}, market={}, predict={}'.format(
+        #     self.tradeMsg.ref_price, self.tradeMsg.market, self.tradeMsg.predict))
 
     async def server_handle(self, request):
         '''中控数据接口'''

+ 2 - 1
strategy.py

@@ -4,6 +4,7 @@ import model
 import logging, logging.handlers
 from decimal import Decimal
 from decimal import ROUND_HALF_UP, ROUND_FLOOR
+from loguru import logger
 
 class Strategy:
     '''
@@ -900,7 +901,7 @@ class Strategy:
                 self._refresh_request_limit()
                 # 统计请求频率
                 self._update_request_num(signals)
-                ##########################
+
                 return signals
         except:
             traceback.print_exc()