Exemple #1
0
 def _init_history_kline_callback(self, success, error):
     if error:
         logger.error("init history_kline error:", error, caller=self)
         return
     history_klines = success.get("data")
     # print("_get_history_kline_callback")
     # print(history_klines)
     ts = int(success.get("ts"))
     for k in history_klines:
         info = {
             "platform": self._platform,
             "id": int(k["id"]),
             "symbol": self._symbol,
             "open": "%.8f" % k["open"],
             "high": "%.8f" % k["high"],
             "low": "%.8f" % k["low"],
             "close": "%.8f" % k["close"],
             "volume": int(k["vol"]),
             "amount": "%.8f" % k["amount"],
             "timestamp": ts,
             "kline_type": MARKET_TYPE_KLINE
         }
         kline = Kline(**info)
         self._klines.append(kline)
     self._klines_init = True
Exemple #2
0
 async def process_kline(self, data):
     """ process kline data
     """
     if not self._klines_init:
         logger.info("klines not init. current:", len(self.klines), caller=self)
         return
     channel = data.get("ch")
     symbol = self._c_to_s[channel]
     d = data.get("tick")
     # print("process_kline", symbol)
     # print(d)
     info = {
         "platform": self._platform,
         "id": int(d["id"]),
         "symbol": symbol,
         "open": "%.8f" % d["open"],
         "high": "%.8f" % d["high"],
         "low": "%.8f" % d["low"],
         "close": "%.8f" % d["close"],
         "volume": int(d["vol"]),
         "amount": "%.8f" % d["amount"],
         "timestamp": int(data.get("ts")),
         "kline_type": MARKET_TYPE_KLINE
     }
     kline = Kline(**info)
     if kline.id == self._klines[-1].id:
         self._klines.pop()
     self._klines.append(kline)
     SingleTask.run(self._kline_update_callback, copy.copy(kline))
Exemple #3
0
 async def on_event_kline_update(self, kline: Kline):
     """ kline更新
         self.market.klines 是最新的kline组成的队列,记录的是历史N次kline的数据。
         本回调所传的kline是最新的单次kline。
     """
     print("on_event_kline_update")
     print(kline.__str__())
    async def process_kline(self, data):
        """ process kline data
        """
        channel = data.get("ch")
        symbol = self._c_to_s[channel]
        d = data.get("tick")
        info = {
            "platform": self._platform,
            "symbol": symbol,
            "open": "%.8f" % d["open"],
            "high": "%.8f" % d["high"],
            "low": "%.8f" % d["low"],
            "close": "%.8f" % d["close"],
            "volume": "%.8f" % d["amount"],
            "timestamp": int(data.get("ts")),
            "kline_type": MARKET_TYPE_KLINE
        }
        kline = Kline(**info)
        self._klines.append(kline)
        SingleTask.run(self._kline_update_callback, copy.copy(kline))

        logger.debug("symbol:", symbol, "kline:", kline, caller=self)