Unofficial asynchronous python client for Huobi
Official documentation
Install
pip install asynchuobi
Generic API
from asynchuobi.api.clients.generic import GenericHuobiClient
async def main():
async with GenericHuobiClient() as client:
current_timestamp = await client.get_current_timestamp()
trading_symbols = await client.get_all_supported_trading_symbols()
system_status = await client.get_system_status()
Market API
from asynchuobi.api.clients.market import MarketHuobiClient
from asynchuobi.enums import CandleInterval
async def main():
async with MarketHuobiClient() as client:
candles = await client.get_candles('btcusdt', CandleInterval.min_1)
orderbook = await client.get_market_depth('btcusdt')
recent_trades = await client.get_most_recent_trades('btcusdt')
Subuser API
from asynchuobi.api.clients.subuser import SubUserHuobiClient
from asynchuobi.enums import ApiKeyPermission
async def main():
async with SubUserHuobiClient(
access_key='access_key',
secret_key='secret_key',
) as client:
subusers = await client.get_sub_users_list()
for subuser in subusers['data']:
keys = await client.api_key_query(subuser['uid'])
status = await client.get_sub_user_status(subuser['uid'])
balance = await client.get_account_balance_of_sub_user(subuser['uid'])
api_key = await client.sub_user_api_key_creation(
sub_uid=subuser['uid'],
note='Test api',
permissions=[ApiKeyPermission.readOnly, ApiKeyPermission.trade],
)
Wallet API
from asynchuobi.api.clients.wallet import WalletHuobiClient
async def main():
async with WalletHuobiClient(
access_key='access_key',
secret_key='secret_key',
) as client:
deposit_address = await client.query_deposit_address('usdt')
withdraw_address = await client.query_withdraw_address('usdt')
withdraw_response = await client.create_withdraw_request(
address='address',
currency='usdt',
amount=10
)
Account API
from asynchuobi.api.clients.account import AccountHuobiClient
from asynchuobi.enums import AccountTypeCode, Sort
async def main():
async with AccountHuobiClient(
access_key='access_key',
secret_key='secret_key',
) as client:
accounts = await client.accounts()
for account in accounts['data']:
balances = await client.account_balance(account_id=account['id'])
history = await client.get_account_history(
account_id=account['id'],
currency='usdt',
transact_types=['deposit', 'withdraw'],
sorting=Sort.desc,
)
for account_type in (AccountTypeCode.spot, AccountTypeCode.flat):
total_valuation = await client.get_total_valuation_of_platform_assets(
account_type_code=account_type,
valuation_currency='BTC',
)
Orders API
from asynchuobi.api.clients.order import OrderHuobiClient
from asynchuobi.enums import OrderType
async def main():
async with OrderHuobiClient(
access_key='access_key',
secret_key='secret_key'
) as client:
response = await client.new_order(
account_id=account_id,
symbol='dogeusdt',
order_type=OrderType.buy_limit,
amount=20,
price=0.0660,
)
if response['status'] == 'ok':
order_id = response['data']
cancelling = await client.cancel_order(
order_id=order_id,
)
active_orders = await client.get_all_open_orders()
order_detail = await client.get_order_detail_by_client_order_id(
client_order_id=client_order_id,
)
Margin API
from asynchuobi.api.clients.margin import MarginHuobiClient
async def main():
async with MarginHuobiClient(
access_key='access_key',
secret_key='secret_key',
) as client:
cross_margin_balance = await client.get_balance_of_cross_margin_account()
isolated_margin_balance = await client.get_balance_of_isolated_margin_account(
symbol='btcusdt',
)
WebSocket
Client supports retrieving information about market data, such as candles, orderbook, trade details.
Usage
from asynchuobi.enums import CandleInterval
from asynchuobi.ws.ws_client import WSHuobiMarket
async def main():
async with WSHuobiMarket() as ws:
await ws.candlestick('btcusdt', CandleInterval.min_1).sub()
await ws.market_stats('btcusdt').sub()
await ws.market_ticker_info('btcusdt').sub()
await ws.orderbook('btcusdt').sub()
async for message in ws:
...
You can define callbacks which will called when message was received from websocket
from typing import Dict
from asynchuobi.exceptions import WSHuobiError
from asynchuobi.ws.ws_client import WSHuobiMarket
def callback(msg: Dict):
print(msg)
def error(e: WSHuobiError):
print(e)
async def orderbook():
async with WSHuobiMarket() as ws:
await ws.orderbook('btcusdt').sub(callback=callback)
await ws.run_with_callbacks(error_callback=error)
You can also define async callback
Retrieving information about account balance changing and about orders
Authentication is required
from asynchuobi.ws.ws_client import WSHuobiAccount
async def main():
async with WSHuobiAccount('access_key', 'secret_key') as ws:
await ws.subscribe_account_change()
await ws.subscribe_order_updates('btcusdt')
async for message in ws:
...
With callbacks
from asynchuobi.ws.ws_client import WSHuobiAccount
from asynchuobi.exceptions import WSHuobiError
def callback(message: dict):
print(message)
def error(e: WSHuobiError):
print(e)
async def main():
async with WSHuobiAccount('access_key', 'secret_key') as ws:
await ws.subscribe_account_change(
callback=callback,
)
await ws.run_with_callbacks(error_callback=error)
Metadata
Release files for asynchuobi 0.0.1
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 |
|---|---|---|---|---|
| asynchuobi-0.0.1.tar.gz | 20.1 kB | Without provenance | Details for asynchuobi-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asynchuobi-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for asynchuobi-0.0.1-py3-none-any.whl |
Total release size: 47.4 kB
Release files / asynchuobi-0.0.1.tar.gz
| Download URL | asynchuobi-0.0.1.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
196aff4058ac83e27ac5afa03f0191df737950416b3606b99c9ffa26800cde4a
|
|
BLAKE2b-256 checksum How to use checksums |
50450cc853aec9e1d8ae32d3bf94dc0ace11bb01d8908be498c33186e62e4cf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.2
|
Release files / asynchuobi-0.0.1-py3-none-any.whl
| Download URL | asynchuobi-0.0.1-py3-none-any.whl |
|---|---|
| Size | 27.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
80083f01b459a1282cff498206d9f6cbdbe41d85ea34dc749803da9e5592b8b4
|
|
BLAKE2b-256 checksum How to use checksums |
31db5d49c03b4bfb66f505bc076658c6a23d3455112776de9e407a13a4253947
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.2
|
Security for asynchuobi 0.0.1
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.