5

I'm looking for a simple API description to get some basic stats from the huobi.com exchange. Mainly the last trading price, and current orderbook (bids & asks).

They seem to have an API: http://www.huobi.com/help/index.php?a=api_help but this page doesn't help me much (even after translating it with Google, as I can't read Chinese).

Does anyone know how to use this API?

Sheldon Pinkman
  • 151
  • 1
  • 2

4 Answers4

4

I had some trouble finding it there but then I found it in "reference" https://github.com/huobiapi/API_Docs_en/wiki/REST_Reference

You can use normal http queries like on other exchanges so to get an orderbook you use this for example: https://api.huobi.pro/market/depth?symbol=ethbtc&type=step1

Vitas
  • 141
  • 2
0

Huobi API documentation is https://huobiapi.github.io/docs/spot/v1/en/#introduction

import requests
import json

#Get Latest Aggregated Ticker, #retrieves the latest ticker with some important 24h aggregated market data url = 'https://api.huobi.pro/market/detail/merged?symbol=ethusdt' response = requests.request('GET', url) r = json.loads(response.text) r

To get all accounts, use endpoint GET /v1/account/accounts

from datetime import datetime
import requests
import json
import hmac
import hashlib
import base64
from urllib.parse import urlencode

#Get all Accounts of the Current User AccessKeyId = 'xxxxx-xxxxx-xxxxx-xxxxx' SecretKey = 'xxxxx-xxxxx-xxxxx-xxxxx' timestamp = str(datetime.utcnow().isoformat())[0:19] params = urlencode({'AccessKeyId': AccessKeyId, 'SignatureMethod': 'HmacSHA256', 'SignatureVersion': '2', 'Timestamp': timestamp }) method = 'GET' endpoint = '/v1/account/accounts' base_uri = 'api.huobi.pro' pre_signed_text = method + '\n' + base_uri + '\n' + endpoint + '\n' + params hash_code = hmac.new(SecretKey.encode(), pre_signed_text.encode(), hashlib.sha256).digest() signature = urlencode({'Signature': base64.b64encode(hash_code).decode()}) url = 'https://' + base_uri + endpoint + '?' + params + '&' + signature response = requests.request(method, url) accts = json.loads(response.text) print(accts)

blackraven
  • 101
  • 2
0

To get the latest prices, you can use:

https://api.huobi.pro/market/trade?symbol=btcusdt

{"ch":"market.btcusdt.trade.detail","status":"ok","ts":1636430996365,"tick":{"id":141243356294,"ts":1636430996153,"data":[{"id":141243356294406904906517411,"ts":1636430996153,"trade-id":102555243865,"amount":0.005594,"price":68284.01,"direction":"buy"}]}}

To get the depth, you can use:

https://api.huobi.pro/market/depth?symbol=btcusdt&type=step1

{"ch":"market.btcusdt.depth.step1","status":"ok","ts":1636431051579,"tick":{"bids":[[68295.9,0.120818],[68293.2,0.2],[68290.5,0.04992],[68289.7,0.2],[68288.2,0.259111],[68288.1,0.1],[68287.5,0.01],[68287.2,0.120919],[68286.8,0.001464],[68285.0,0.2],[68283.8,0.002419],[68283.7,0.004837],[68281.4,0.2],[68280.2,0.00732],[68280.0,0.008036],[68278.4,0.015],[68277.0,0.004876],[68275.9,0.018194],[68275.8,0.073161],[68274.2,1.500967]],"asks":[[68296.0,0.385628],[68296.1,0.014631],[68297.7,0.100889],[68298.0,0.005074],[68300.0,0.005185],[68300.2,0.4],[68301.5,0.073157],[68302.8,0.19],[68303.6,0.487816],[68305.5,0.1],[68307.7,0.4],[68307.9,1.11],[68308.4,0.0187],[68308.7,0.015],[68309.2,0.194342],[68310.3,1.121419],[68314.5,1.526117],[68315.8,0.11],[68317.8,0.146459],[68318.1,0.5]],"version":141243384400,"ts":1636431051004}}

These APIs don't require API keys, but it has 10 calls / second limit.

-2

I think this is the newest api on github

https://github.com/huobiapi