火币API的Python版
- websocket封装成
HBWebsocket类,用run开启连接线程 HBWebsocket通过注册Handler的方式来处理数据,消息通过pub_msg来分发到个各topic下的Handler线程来处理- 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进程
# --------------------------------------------
hb.sub_kline('ethbtc', '1min') # 订阅数据
@hb.register_handle_func('market.ethbtc.kline.1min') # 注册一个处理函数,最好的处理方法应该是实现一个handler
def handle(msg):
print('handle:', msg)
hb.unregister_handle_func(handle, 'market.ethbtc.kline.1min') # 释放处理函数
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
- handler是用来处理websocket的原始返回消息的,通过继承basehandler实现handle函数以及注册进HBWebsocket相关的topic来使用
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
- 内置实现了一个mongodb的
DBHandler
from huobitrade.handler import DBHandler
handler = DBHandler()
hb.register_handler(handler, 'market.ethbtc.kline.1min')
Metadata
Release files for huobitrade 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| huobitrade-0.1.2.tar.gz | 8.7 kB | Without provenance | Details for huobitrade-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| huobitrade-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for huobitrade-0.1.2-py3-none-any.whl |
Total release size: 19.0 kB
Release files / huobitrade-0.1.2.tar.gz
| Download URL | huobitrade-0.1.2.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2635fa37fdcbeefdc72343b6e36ec5680a68817ffcba8f9f17c618cfafc57caa
|
|
BLAKE2b-256 checksum How to use checksums |
d2bdadda7adfa5b8bbaa297c3383a790d6bd7fa187277246a33b8dd2525a63f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / huobitrade-0.1.2-py3-none-any.whl
| Download URL | huobitrade-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38177ad11dca1509defa839efecf4d05742b59928f0e680ba9bee86709d50704
|
|
BLAKE2b-256 checksum How to use checksums |
693197553fff5d3527a3cfb06809f7e41820b6e3cf2b731f70ce8395d3ec9dec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for huobitrade 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.