Package: asynchuobi
Unofficial asynchronous python client for HuobiOfficial documentationDocumentationInstallpipinstallasynchuobiGeneric APIfromasynchuobi.api.clients.genericimportGenericHuobiClientasyncdefmain():asyncwithGenericHuobiClient()asclient:current_timestamp=awaitclient.get_current_timestamp()trading_symbols=awaitclient.get_all_supported_trading_symbols()system_status=awaitclient.get_system_status()Market APIfromasynchuobi.api.clients.marketimportMarketHuobiClientfromasynchuobi.enumsimportCandleIntervalasyncdefmain():asyncwithMarketHuobiClient()asclient:candles=awaitclient.get_candles('btcusdt',CandleInterval.min_1)orderbook=awaitclient.get_market_depth('btcusdt')recent_trades=awaitclient.get_most_recent_trades('btcusdt')Subuser APIfromasynchuobi.api.clients.subuserimportSubUserHuobiClientfromasynchuobi.enumsimportApiKeyPermissionasyncdefmain():asyncwithSubUserHuobiClient(access_key='access_key',secret_key='secret_key',)asclient:subusers=awaitclient.get_sub_users_list()forsubuserinsubusers['data']:keys=awaitclient.api_key_query(subuser['uid'])status=awaitclient.get_sub_user_status(subuser['uid'])balance=awaitclient.get_account_balance_of_sub_user(subuser['uid'])api_key=awaitclient.sub_user_api_key_creation(sub_uid=subuser['uid'],note='Test api',permissions=[ApiKeyPermission.readOnly,ApiKeyPermission.trade],)Wallet APIfromasynchuobi.api.clients.walletimportWalletHuobiClientasyncdefmain():asyncwithWalletHuobiClient(access_key='access_key',secret_key='secret_key',)asclient:deposit_address=awaitclient.query_deposit_address('usdt')withdraw_address=awaitclient.query_withdraw_address('usdt')withdraw_response=awaitclient.create_withdraw_request(address='address',currency='usdt',amount=10)Account APIfromasynchuobi.api.clients.accountimportAccountHuobiClientfromasynchuobi.enumsimportAccountTypeCode,Sortasyncdefmain():asyncwithAccountHuobiClient(access_key='access_key',secret_key='secret_key',)asclient:accounts=awaitclient.accounts()foraccountinaccounts['data']:balances=awaitclient.account_balance(account_id=account['id'])history=awaitclient.get_account_history(account_id=account['id'],currency='usdt',transact_types=['deposit','withdraw'],sorting=Sort.desc,)foraccount_typein(AccountTypeCode.spot,AccountTypeCode.flat):total_valuation=awaitclient.get_total_valuation_of_platform_assets(account_type_code=account_type,valuation_currency='BTC',)Orders APIfromasynchuobi.api.clients.orderimportOrderHuobiClientfromasynchuobi.enumsimportOrderTypeasyncdefmain():asyncwithOrderHuobiClient(access_key='access_key',secret_key='secret_key')asclient:response=awaitclient.new_order(account_id=account_id,symbol='dogeusdt',order_type=OrderType.buy_limit,amount=20,price=0.0660,)ifresponse['status']=='ok':order_id=response['data']cancelling=awaitclient.cancel_order(order_id=order_id,)active_orders=awaitclient.get_all_open_orders()order_detail=awaitclient.get_order_detail_by_client_order_id(client_order_id=client_order_id,)Margin APIfromasynchuobi.api.clients.marginimportMarginHuobiClientasyncdefmain():asyncwithMarginHuobiClient(access_key='access_key',secret_key='secret_key',)asclient:cross_margin_balance=awaitclient.get_balance_of_cross_margin_account()isolated_margin_balance=awaitclient.get_balance_of_isolated_margin_account(symbol='btcusdt',)WebSocketClient supports retrieving information about market data, such as candles, orderbook, trade details.Usagefromasynchuobi.enumsimportCandleIntervalfromasynchuobi.ws.ws_clientimportWSHuobiMarketasyncdefmain():asyncwithWSHuobiMarket()asws:awaitws.candlestick('btcusdt',CandleInterval.min_1).sub()awaitws.market_stats('btcusdt').sub()awaitws.market_ticker_info('btcusdt').sub()awaitws.orderbook('btcusdt').sub()asyncformessageinws:...You can define callbacks which will called when message was received from websocketfromtypingimportDictfromasynchuobi.exceptionsimportWSHuobiErrorfromasynchuobi.ws.ws_clientimportWSHuobiMarketdefcallback(msg:Dict):print(msg)deferror(e:WSHuobiError):print(e)asyncdeforderbook():asyncwithWSHuobiMarket()asws:awaitws.orderbook('btcusdt').sub(callback=callback)awaitws.run_with_callbacks(error_callback=error)You can also define async callbackRetrieving information about account balance changing and about ordersAuthentication is requiredfromasynchuobi.ws.ws_clientimportWSHuobiAccountasyncdefmain():asyncwithWSHuobiAccount('access_key','secret_key')asws:awaitws.subscribe_account_change()awaitws.subscribe_order_updates('btcusdt')asyncformessageinws:...With callbacksfromasynchuobi.ws.ws_clientimportWSHuobiAccountfromasynchuobi.exceptionsimportWSHuobiErrordefcallback(message:dict):print(message)deferror(e:WSHuobiError):print(e)asyncdefmain():asyncwithWSHuobiAccount('access_key','secret_key')asws:awaitws.subscribe_account_change(callback=callback,)awaitws.run_with_callbacks(error_callback=error)