Package: huobipy
Huobi Python SDKThis is Huobi Python SDK, requires python >= 3.5.The SDK API supports both RESTful and websocket to get/sub the market, account and order infomation.It supports Spot trading, Coin-M Futures, Coin-M Swaps and USDT-M.Table of ContentsQuick StartUsageConfigurationFolder structureClientRequestResponseQuick StartThe projecthuobiis a dll project as SDK API.
The projecttestsis a unit test project and you can find usage of each API interface.If you want to create your own application, you can follow below steps:Create a client instance.Call the method of client instance.//RESTfulfromhuobi.linear_swap.rest.accountimportAccountclient=Account(ACCESS_KEY,SECRET_KEY)result=client.get_balance_valuation({"valuation_asset":"usdt"})//websocketfromhuobi.linear_swap.ws.accountimportAccountclient=Account(ACCESS_KEY,SECRET_KEY)client.sub({"op":"sub","topic":"orders.btc-usdt"},lambdax:logger.info(x))time.sleep(10)UsageConfigurationThe client constructor must set AccessKey/SecretKey two value when you access private data. And it not need to set AccessKey/SecretKey value when you access public data such as market data.You can create config.py in your project for config AccessKey/SecretKey and other input data.ACCESS_KEY="x-x-x-x"SECRET_KEY="x-x-x-x"And use it as follow:fromconfigimportACCESS_KEY,SECRET_KEY# to do somethingFolder StructureThis is the folder and namespace structure of SDK source code and the descriptionhuobi: The SDK API projectspot: the Spot trading api src inclue RESTful and Websocketfutures: the Coin-M Futures api src inclue RESTful and Websocketcoin_swap: the Coin-M Swaps api src inclue RESTful and Websocketlinear_swap: the USDT-M api src inclue RESTful and Websocketutils: http.get/post lib, websocket api lib and log settinghost.py: the host name of spot and futures(Coin-M Futures, Coin-M Swaps and USDT-M are using the same host name)tests: The unit test projectconfig.py: config of accessKey and secretKeyxxx: The Python unit test folderYou can find all demo in test_xxx.py to get/sub private/public dataClientIn this SDK, the client is the object to access the Huobi API. All the client are listed in below table. Each client is very small and simple.Access TypeClientPrivacyData CategoryRESTfulAccountPrivateaccount infoMarketPublicmarket infoOrderPrivateabout orderTransferPrivatetransfer assetsTriggerOrderPrivateabout trigger orderWebsocketIndexPublicindex inforMarketPublicmarket infoNotifyPublic/Privatemarket info/ account infoPublic vs. PrivateThere are two types of privacy that is correspondent with privacy of API:Public client: It invokes public API to get public data (Common data and Market data), therefore you can create a new instance without applying an API Key.fromhuobi.linear_swap.rest.marketimportMarketclient=Market()result=client.get_contract_info({"contract_code":"btc-usdt","support_margin_mode":"all"})Private client: It invokes private API to access private data, you need to follow the API document to apply an API Key first, and pass the API Key to the constructor.fromhuobi.linear_swap.rest.accountimportAccountclient=Account(ACCESS_KEY,SECRET_KEY)result=client.get_balance_valuation({"valuation_asset":"usdt"})The API key is used for authentication. If the authentication cannot pass, the invoking of private interface will fail.Rest vs. WebSocketRest Client: It invokes Rest API and get once-off response.fromhuobi.linear_swap.rest.accountimportAccountclient=Account(ACCESS_KEY,SECRET_KEY)result=client.get_balance_valuation({"valuation_asset":"usdt"})WebSocket Client: It establishes WebSocket connection with server and data will be pushed from server actively. There are two types of method for WebSocket client:Request method: The method name starts with "req", it will receive the once-off data after sending the request.Subscription: The method name starts with "sub", it will receive update after sending the subscription.fromhuobi.linear_swap.ws.marketimportMarketclient=Market()client.sub({"sub":"market.BTC-USDT.kline.1min"},lambdax:logger.info(x))whileTrue:time.sleep(1)Custom hostEach client constructor support an optional host parameter, by default it is in host.py file. If you need to use different host, you can specify the custom host.fromhuobi.linear_swap.rest.accountimportAccountclient=Account(ACCESS_KEY,SECRET_KEY,"your_host")# to do somethingRequestIn this SDK, the response is the dict type or None. More detail to see:https://docs.huobigroup.com/docs/spot/v1/en/ResponseIn this SDK, the response is the json data. More detail to see:https://docs.huobigroup.com/docs/spot/v1/en/