hbdmapi / huobi_futures_Python

An Asynchronous Event-driven High-frequency Trading System,huobi future,huobi coin margined swap, huobi usdt margined swap included.
MIT License
267 stars 113 forks source link

调用问题 #31

Closed Lxtluck closed 4 years ago

Lxtluck commented 4 years ago
async def on_ticker(self, *args, **kwargs):
    """ 定时执行任务
    """
    ts_diff = int(time.time()*1000) - self.last_orderbook_timestamp
    if ts_diff > self.orderbook_invalid_seconds * 1000:
        logger.warn("received orderbook timestamp exceed:", self.strategy, self.symbol, ts_diff, caller=self)
        return
    # url = 'https://api.hbdm.com/market/history/kline'
    # data = {"symbol":"eth_CQ","period":"30min","size":"20"}
    # hkilne = requests.get(url,params=data)
    success, error = await self.trader.rest_api.get_klines("eth_CQ","30min","30")
    if success:
        logger.info(success)
    else:
        logger.error("Get swap market index faild:", error, caller=self)
    await self.trader.rest_api.get_klines()
Lxtluck commented 4 years ago

在huobi_future_api.py中添加如下代码 async def get_klines(self, symbol=None,period=None,size=None):

    uri = "market/history/kline"
    body = {}
    if symbol:
        body["symbol"] = symbol
    if period:
        body["period"] = period
    if size:
        body["size"] = size
    success, error = await self.request("get", uri, body=body, auth=True)
    return success, error
Lxtluck commented 4 years ago

报错信息如下: [MyStrategy] Get swap market index faild: {'err-code': 'invalid-method', 'err-msg': 'not supported msg', 'status': 'error', 'ts': 1597132337579}

Lxtluck commented 4 years ago
async def get_klines(self, symbol=None,period=None,size=None):

    uri = "market/history/kline"
    params = {}
    if symbol:
        params["symbol"] = symbol
    if period:
        params["period"] = period
    if size:
        params["size"] = size
    success, error = await self.request("get", uri, params=params)
    return success, error
foonsun commented 4 years ago

@Lxtluck 请参考最新的版本, https://github.com/hbdmapi/hbdm_Python/blob/master/alpha/platforms/huobi_swap_api.py#L100 https://github.com/hbdmapi/hbdm_Python/blob/master/alpha/platforms/huobi_future_api.py#L113 已经添加了klines的method.