• Welcome to forex.pm forex forum binary options trade. Please login or sign up.
 

How can I pull the "Candles" argument from the Huobi websocket data?

Started by Bitcoin, Apr 26, 2022, 06:34 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bitcoin

How can I pull the "Candles" argument from the Huobi websocket data?

I've a problem with Huobi Websocket, I know my ways in REST API but new to asyncio and websockets, and Huobi only gives resonable amount of history through websocket request so I'm stuck with it. I'm using their [sdk](https://github.com/HuobiRDCenter/huobi_Python. I managed to figure this out:


from huobi.client.market import MarketClient
from huobi.client.market import CandlestickInterval
import pandas as pd
from pandas import DataFrame as df

def callback(candlestick_req: "CandlestickReq"):
    Candles = candlestick_req.data

Market_client = MarketClient()
Market_client.req_candlestick("btcusdt", CandlestickInterval.MIN60, callback, from_ts_second = 1611788400, end_ts_second = 1614812400)

History_dataframe_new["Date"] = [Candles[f].id for f in range(len(Candles))]
History_dataframe_new["Open"] = [Candles[f].open for f in range(len(Candles))]
History_dataframe_new["High"] = [Candles[f].high for f in range(len(Candles))]
History_dataframe_new["Low"] = [Candles[f].low for f in range(len(Candles))]
History_dataframe_new["Close"] = [Candles[f].close for f in range(len(Candles))]
History_dataframe_new["Volume"] = [Candles[f].vol for f in range(len(Candles))]

The problem is, how can I get this Candles argument out of the callback to use below? I'm not calling callback directly, only in the req_candlestick so return won't work. And it's a callback so I propably have to wait for the response somehow. And tips how to do that? Or if what I'm trying here is the correct way?


Source: How can I pull the "Candles" argument from the Huobi websocket data?