Ejemplo n.º 1
0
 async def found_kline(self, symbol, period, size, callback, **kwargs):
     """
         data:{
             huobi_usdt_spot_btc_usdt_1min :deque[{...},...]
         }
     """
     tag = "{}_{}_{}".format(callback.platform, symbol, period)
     setattr(self, "{}_f".format(tag), open("{}.txt".format(tag), "w"))
     # import pdb
     # pdb.set_trace()
     ok, error = await callback.get_klines(symbol, period, **{"size": size})
     if ok:
         kline = callback.history.get(tag)
     else:
         return
     if kline and len(kline) > 0:
         if self._check_kline_ts_continuous(kline):
             logger.info("Kline datetime continuous!", caller=self)
             self.data[tag] = deque(maxlen=self.data_lenght)
             self.data[tag].extend(kline)
             for data in kline[:-1]:
                 self.write_f(tag, data)
             task_id = kwargs.get("task_id")
             self.task.unregister(task_id)
         else:
             logger.error("Kline datetime discontinuous!", caller=self)
Ejemplo n.º 2
0
 async def found_kline(self, symbol, period, size, callback, **kwargs):
     """
         data:{
             huobi_usdt_spot_btc_usdt_1min :deque[{...},...]
         }
     """
     tag = "{}_{}_{}".format(callback.platform, symbol, period)
     await callback.get_klines(symbol, period, **{"size": size})
     kline = callback.history.get(tag)
     if kline and len(kline) > 0:
         if self._check_kline_ts_continuous(kline):
             logger.info("Kline datetime continuous!", caller=self)
             self.data[tag] = deque(maxlen=self.data_lenght)
             self.data[tag].extend(kline)
             task_id = kwargs.get("task_id")
             self.task.unregister(task_id)
         else:
             logger.error("Kline datetime discontinuous!", caller=self)
Ejemplo n.º 3
0
    async def update_kline(self, symbol, period, callback, **kwargs):
        """
            {'period': '1min', 'size': 2, 'symbol': 'btc_usdt',
             'task_id': '47ae4272-7ee6-11eb-a2d8-4bea7b2049e6', 'heart_beat_count': 200}

         """
        tag = "{}_{}_{}".format(callback.platform, symbol, period)
        if not self.data.get(tag):
            return
        if not self.conts_data.get(tag):
            self.conts_data[tag] = deque(maxlen=self.conts_max)
        ok, error = await callback.get_klines(symbol, period, size=2)
        if ok:
            _new_data = callback.history.get(tag)
            self.conts_data[tag].append(_new_data[-1])
            # import pdb
            # pdb.set_trace()
            data = self.data[tag][-3], self.data[tag][-2], self.data[tag][-1]
            if self.cur_ts - data[-1]["id"] > 3 * 60:
                task_id = kwargs.get("task_id")
                logger.error("updating kline but time out!", caller=self)
                getattr(self, "{}_f".format(tag)).close()
                self.task.unregister(task_id)
            if self._check_update_ts_continuous(data):
                if data[-1]["id"] == _new_data[-1]["id"]:
                    self.data[tag].pop()
                    self.data[tag].append(_new_data[-1])
                if data[-1]["id"] == _new_data[0]["id"]:
                    self.data[tag].pop()
                    self.write_f(tag, _new_data[0])
                    self.data[tag].extend(_new_data)
                logger.info(self.data, caller=self)
            else:
                task_id = kwargs.get("task_id")
                getattr(self, "{}_f".format(tag)).close()
                logger.error("updating kline  but datetime discontinuous!",
                             caller=self)
                import pdb
                pdb.set_trace()
                self.task.unregister(task_id)