class CollectPriceData(ConfigHandler): def __init__(self): ConfigHandler.__init__(self) self.sub_client = SubscriptionClient() def callback(self, candlestick_event: 'CandlestickEvent'): content = f"{str(candlestick_event.timestamp)},{str(candlestick_event.data.close)}" FileReadAndWrite.write( f"{self.get_config_value('strategy', 'price_file_locate')}{candlestick_event.symbol}.txt", content) def run(self, currency_pairs): self.sub_client.subscribe_candlestick_event(currency_pairs, CandlestickInterval.MIN1, self.callback)
import logging from huobi import SubscriptionClient from huobi.model import * from huobi.exception.huobiapiexception import HuobiApiException logger = logging.getLogger("huobi-client") logger.setLevel(level=logging.INFO) handler = logging.StreamHandler() handler.setFormatter( logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')) logger.addHandler(handler) sub_client = SubscriptionClient() def callback(candlestick_event: 'CandlestickEvent'): print("Symbol: ", candlestick_event.symbol) print("Subscribe Receive Time: ", candlestick_event.timestamp) print("Interval: ", candlestick_event.interval) candlestick_event.data.print_object() print() def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) sub_client.subscribe_candlestick_event("btcusdt", CandlestickInterval.MIN1, callback, error)