Skip to main content

huobi_api for python

Project description

火币API的Python版

  • websocket封装成HBWebsocket类,用run开启连接线程
  • restful api基本参照火币网的demo封装HBRestAPI
  • 没有test和debug,估计含有巨量的BUG,慎用!

Installation

pip install huobitrade

Usage

WebSocket API

from huobitrade.service import HBWebsocket
hb = HBWebsocket()  # 可以填入url参数,默认是https://api.huobi.br.com
hb.run()  # 开启websocket进程

Restful API

  • restapi需要先用setKey设置密钥
  • 默认交易和行情url都是[https://api.huobi.br.com](调试用),实盘要设置url用from huobitrade import setUrl
from huobitrade.service import HBRestAPI
from huobitrade import setKey
setKey('your acess_key', 'you secret_key')
api = HBRestAPI()
print(api.get_timestamp())

Message Handler

from huobitrade.handler import baseHandler

class MyHandler(baseHandler):
    def __init__(self, *args, **kwargs):
        baseHandler.__init__(self, name='just Thread name')

    def handle(self, msg):  # 实现handle来处理websocket推送的msg
        print(msg)


handler = MyHandler()
hb.register_handler(handler, 'market.ethbtc.kline.1min')  # 通过register来把handler注册到相应的topic

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

huobitrade-0.1.1.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

huobitrade-0.1.1-py3-none-any.whl (9.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page