### Subuser Client Initialization Example Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Example of how to initialize the SubuserClient with API credentials. ```python from huobi.client import SubuserClient from huobi.constant import SubuserTradePrivilegeType, SubUserTradeStatus # Initialize subuser_client = SubuserClient(api_key="key", secret_key="secret") ``` -------------------------------- ### Install Huobi Python SDK Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Demonstrates how to include the Huobi Python SDK clients in your project. ```python # Clone or include the SDK in your project from huobi.client import GenericClient, MarketClient, TradeClient ``` -------------------------------- ### Get User Information Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md Retrieves general information about the user. ```python def get_user_info(self) -> UserInfo ``` -------------------------------- ### Get User Account Overview Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md Fetches an overview of the user's account information. ```python def get_overview_info(self) ``` -------------------------------- ### Get Records by ID and Size Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieve records starting from a specific ID with a defined size, allowing for previous (ascending) or next (descending) ordering. ```python method(from_id=100, size=50, direct="prev") ``` -------------------------------- ### ETF Client Example Workflow Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Demonstrates a typical workflow using the ETF client, including checking configuration, creating, listing history, and redeeming ETFs. ```python from huobi.client import EtfClient # Initialize client etf_client = EtfClient(api_key="key", secret_key="secret") # 1. Check ETF configuration config = etf_client.get_etf_swap_config("hb10") print(f"Unit price: {config.unit_price}") print(f"Min creation: {config.min_amount_creation}") # 2. Create ETF (if you have all constituents) result = etf_client.post_etf_swap_in("hb10", 5) # 3. Check history history = etf_client.get_etf_swap_list("hb10", 0, 10) for swap in history: print(f"{swap.operation_type}: {swap.quantity} units @ {swap.timestamp}") # 4. Redeem ETF result = etf_client.post_etf_swap_out("hb10", 2) ``` -------------------------------- ### Get All Account Balances Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md A convenience method to get balance information for all accounts. It returns a list of AccountBalance objects. ```python all_balances = account_client.get_account_balance() for account_balance in all_balances: print(f"Account ID: {account_balance.id}, Type: {account_balance.type}") ``` -------------------------------- ### Get ETF Swap Configuration Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the swap configuration details for a specific ETF. ```python config = etf_client.get_etf_swap_config(etf_name='BTC3X') ``` -------------------------------- ### Get Reference Currencies Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Retrieves a list of reference currencies. Requires initialization of the GenericClient. ```python generic_client = GenericClient() list_symbol = generic_client.get_exchange_symbols() list_currency = generic_client.get_reference_currencies() ``` -------------------------------- ### Subscribe to Real-Time Data Example Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Placeholder for a code snippet demonstrating subscription to real-time data. This typically involves MarketClient and CandlestickInterval. ```python from huobi.client import MarketClient, TradeClient from huobi.constant import CandlestickInterval ``` -------------------------------- ### Get Order Information Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Retrieves detailed information about a specific order. Requires authentication and TradeClient initialization. ```python trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key) orderObj = trade_client.get_order(order_id=order_id) ``` -------------------------------- ### Check and Use Available Balance Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/errors.md Retrieve account balance to ensure sufficient funds before placing an order. This example checks for BTC balance and proceeds if it's adequate. ```python from huobi.client import AccountClient, TradeClient account_client = AccountClient(api_key=key, secret_key=secret) trade_client = TradeClient(api_key=key, secret_key=secret) balance = account_client.get_balance(account_id=12345) for b in balance.list: if b.currency == "btc": print(f"Available BTC: {b.balance}") if b.balance >= 0.1: # Safe to place order order_id = trade_client.create_order(...) ``` -------------------------------- ### Set Environment Variables for Huobi API Keys Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Example commands to set environment variables for API keys on Linux/macOS and Windows. ```bash # Linux/macOS export HUOBI_API_KEY="your_api_key" export HUOBI_SECRET_KEY="your_secret_key" # Windows set HUOBI_API_KEY=your_api_key set HUOBI_SECRET_KEY=your_secret_key ``` -------------------------------- ### Get ETF Swap Configuration Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Retrieve the creation and redemption configuration for a specific ETF. This includes min/max amounts, fee rates, and constituent assets. ```python config = etf_client.get_etf_swap_config(etf_name="hb10") print(f"Min creation: {config.min_amount_creation}") print(f"Max redemption: {config.max_amount_redemption}") print(f"Creation fee: {config.creation_fee_rate}%") print(f"Unit price: {config.unit_price}") for constituent in config.constituents: print(f" {constituent.symbol}: {constituent.amount}") ``` -------------------------------- ### Create Generic and Market Client Instances Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Demonstrates how to create client instances for generic and market data queries. Requires importing the necessary clients and constants. ```python # Create generic client instance and get the timestamp generic_client = GenericClient() ts = generic_client.get_exchange_timestamp() print(timestamp) # Create the market client instance and get the latest btcusdt‘s candlestick market_client = MarketClient() list_obj = market_client.get_candlestick("btcusdt", CandlestickInterval.MIN5, 10) LogInfo.output_list(list_obj) ``` -------------------------------- ### get_subuser_user_list Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Get list of all sub-users for the parent account. This method retrieves a list of all sub-user accounts associated with the parent account, optionally starting from a specific sub-user ID. ```APIDOC ## get_subuser_user_list ### Description Get list of all sub-users for the parent account. This method retrieves a list of all sub-user accounts associated with the parent account, optionally starting from a specific sub-user ID. ### Method GET ### Endpoint `/subuser/user/list` ### Parameters #### Path Parameters None #### Query Parameters - **from_id** (int) - Optional - Start from sub-user ID ### Request Example (No request body needed for this GET request) ### Response #### Success Response (200) - **sub-user objects** (list) - List of sub-user objects #### Response Example (Example response not provided in source, but would be a list of sub-user objects) ``` -------------------------------- ### Get Account Withdrawal Addresses Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/wallet-client.md Retrieves a list of saved withdrawal addresses for a specified currency. Supports filtering by blockchain network and address note, with configurable limits and starting ID. ```python def get_account_withdraw_address(self, currency: str, chain: str = None, note: str = None, limit: int = 100, fromid: int = None) ``` ```python addresses = wallet_client.get_account_withdraw_address(currency="usdt", limit=20) ``` -------------------------------- ### Get ETF Swap List Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves a list of ETF swap records for a given ETF name, with pagination support. ```python swaps = etf_client.get_etf_swap_list(etf_name='BTC3X', offset=0, size=10) ``` -------------------------------- ### Get Account Information and Balances Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Retrieves a list of user accounts and their respective balances using the AccountClient. Requires API authentication. ```python from huobi.client import AccountClient account_client = AccountClient(api_key="your_key", secret_key="your_secret") # Get accounts accounts = account_client.get_accounts() for account in accounts: print(f"Account {account.id}: {account.type}") # Get balance balance = account_client.get_balance(account_id=accounts[0].id) for item in balance.list: print(f"{item.currency}: {item.balance}") ``` -------------------------------- ### Get ETF Swap Configuration Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Retrieves the current configuration details for a specified ETF, including unit price and minimum creation amount. ```APIDOC ## GET /etf/swap/config ### Description Retrieves the current configuration details for a specified ETF, including unit price and minimum creation amount. ### Method GET ### Endpoint `/etf/swap/config` ### Parameters #### Query Parameters - **etfName** (string) - Required - The name of the ETF to retrieve configuration for. ### Response #### Success Response (200) - **unit_price** (string) - The current unit price of the ETF. - **min_amount_creation** (string) - The minimum amount required for ETF creation. ### Request Example ```python etf_client.get_etf_swap_config("hb10") ``` ### Response Example ```json { "unit_price": "10.50", "min_amount_creation": "1.0" } ``` ``` -------------------------------- ### Initialize WalletClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/wallet-client.md Instantiate the WalletClient with your API credentials. Ensure you replace 'your_api_key' and 'secret_key' with your actual Huobi API keys. ```python from huobi.client import WalletClient wallet_client = WalletClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Initializes the MarginClient with API credentials and optional configuration. ```APIDOC ## Constructor ```python def __init__(self, **kwargs) ``` Initializes the MarginClient with API credentials and optional configuration. | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | api_key | str | Yes | — | API key from Huobi | | secret_key | str | Yes | — | Secret key from Huobi | | url | str | No | "http://api.huobi.pro" | Base URL for API requests | | init_log | bool | No | False | Initialize logger | **Example**: ```python from huobi.client import MarginClient margi_client = MarginClient(api_key="your_api_key", secret_key="your_secret_key") ``` ``` -------------------------------- ### get_margin_loan_orders Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Get margin loan history for a symbol. ```APIDOC ## get_margin_loan_orders Get margin loan history for a symbol. ```python def get_margin_loan_orders(self, symbol: str, state: str = None, start_date: str = None, end_date: str = None, from_id: int = None, size: int = None, direct: str = None, sub_uid: int = None) -> list ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | symbol | str | Yes | — | Trading symbol | | state | str | No | None | Loan state filter | | start_date | str | No | None | Start date (yyyy-mm-dd) | | end_date | str | No | None | End date (yyyy-mm-dd) | | from_id | int | No | None | Record ID to start from | | size | int | No | None | Number of records | | direct | str | No | None | Direction ("prev" or "next") | | sub_uid | int | No | None | Sub-account UID | **Return Type**: `list` — List of margin loan order objects **Example**: ```python loans = margin_client.get_margin_loan_orders(symbol="eosusdt") for loan in loans: print(f"Loan {loan.id}: State={loan.state}, Amount={loan.loan_amount}") ``` ``` -------------------------------- ### Initialize MarketClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/market-client.md Instantiate the MarketClient. You can optionally specify a custom API URL. ```python from huobi.client import MarketClient market_client = MarketClient() market_client = MarketClient(url="https://api-aws.huobi.pro") ``` -------------------------------- ### Get User ID Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the user ID for the current account. ```python user_id = subuser_client.get_uid() ``` -------------------------------- ### Initialize AlgoClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/algo-client.md Instantiate the AlgoClient with your API credentials. Ensure you have your API key and secret key from Huobi. ```python from huobi.client import AlgoClient algo_client = AlgoClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### Get Fee Rate Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the fee rate for specified symbols. ```python fee_rates = client.get_feerate(symbols=['XBTUSDT', 'ETHUSDT']) ``` -------------------------------- ### Initialize MarginClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Instantiate the MarginClient with your API credentials. Ensure you have your API key and secret key ready. The base URL can be customized if needed. ```python from huobi.client import MarginClient margin_client = MarginClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### Initialize EtfClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Instantiate the EtfClient with your API credentials. Ensure you have your API key and secret key from Huobi. ```python from huobi.client import EtfClient etf_client = EtfClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### get_margin_account_balance Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Get balance information for margin account (isolated margin). ```APIDOC ## get_margin_account_balance Get balance information for margin account (isolated margin). ```python def get_margin_account_balance(self, symbol: str, sub_uid: int = None) -> list ``` | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | symbol | str | Yes | — | Trading symbol | | sub_uid | int | No | None | Sub-account UID | **Return Type**: `list` — List of margin balance details including collateral and borrowed amounts **Example**: ```python balances = margin_client.get_margin_account_balance(symbol="btcusdt") for balance in balances: print(f"Currency: {balance.currency}, Balance: {balance.balance}, Borrowed: {balance.borrowed}") ``` ``` -------------------------------- ### Get Sub-User State Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the current state or status of a specific sub-user. ```python subuser_state = subuser_client.get_subuser_user_state(sub_uid='123') ``` -------------------------------- ### Initialize AccountClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md Instantiate the AccountClient with your API key and secret key. Optionally, you can specify the API URL and whether to initialize logging. ```python from huobi.client import AccountClient account_client = AccountClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### Create ETF (Swap In) Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Initiate the creation of ETF units by swapping in the required constituent assets. Provide the ETF name and the number of units to create. ```python # Create 10 units of HB10 ETF result = etf_client.post_etf_swap_in(etf_name="hb10", amount=10) print(f"Creation submitted: {result}") ``` -------------------------------- ### Get Subuser List Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Retrieves a list of all subusers associated with the main account. ```APIDOC ## GET /v1/subuser/user/list ### Description Retrieves a list of all subusers associated with the main account. ### Method GET ### Endpoint /v1/subuser/user/list ### Response #### Success Response (200) - **user_id** (string) - The unique identifier for the subuser. - **user_name** (string) - The username of the subuser. - **created_at** (string) - The timestamp when the subuser was created. #### Response Example ```json [ { "user_id": "123456789", "user_name": "trader-001", "created_at": "2023-01-01T10:00:00Z" } ] ``` ``` -------------------------------- ### Create and Get Withdrawal History Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Demonstrates creating a cryptocurrency withdrawal request and retrieving withdrawal history using the WalletClient. Ensure correct currency and address details are provided. ```python from huobi.client import WalletClient wallet_client = WalletClient(api_key=key, secret_key=secret) # Create withdrawal request withdraw_id = wallet_client.post_create_withdraw( address="1A1z7agoat5NUy46LV1uGHLGaLY3995xxxx", amount=0.5, currency="btc", fee=0.001 # Network fee ) print(f"Withdrawal created: {withdraw_id}") # Get withdrawal history history = wallet_client.get_deposit_withdraw( op_type="withdraw", currency="btc", size=10 ) for item in history: print(f"Withdraw {item.id}: {item.amount} BTC, State: {item.state}") ``` -------------------------------- ### Get Account Deposit Address Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the deposit address for a specified currency. ```python addresses = wallet_client.get_account_deposit_address(currency='USDT') ``` -------------------------------- ### Create MarketClient with Customized Host Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Instantiate the MarketClient with a specific host URL for accessing market data. No API key is required. ```python market_client = MarketClient(url="https://api-aws.huobi.pro") ``` -------------------------------- ### Initialize TradeClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/trade-client.md Instantiate the TradeClient with your API credentials. Ensure you have your API key and secret key from Huobi. ```python from huobi.client import TradeClient trade_client = TradeClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### WalletClient Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/wallet-client.md Initializes the WalletClient with API credentials and optional configuration. Requires API key and secret key for authentication. ```APIDOC ## WalletClient Constructor ### Description Initializes the WalletClient with API credentials and optional configuration. Requires API key and secret key for authentication. ### Method ```python def __init__(self, api_key: str, secret_key: str, url: str = "http://api.huobi.pro", init_log: bool = False) ``` ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example ```python from huobi.client import WalletClient wallet_client = WalletClient(api_key="your_api_key", secret_key="your_secret_key") ``` ### Response (None) ``` -------------------------------- ### Get Cross Margin Loan Orders Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the history of loans in the cross-margin account. ```python loan_history = cross_margin_client.get_cross_margin_loan_orders() ``` -------------------------------- ### Initialize SubuserClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Instantiate the SubuserClient with your API credentials. Ensure you have the necessary API key and secret key from your Huobi parent account. ```python from huobi.client import SubuserClient subuser_client = SubuserClient(api_key="your_api_key", secret_key="your_secret_key") ``` -------------------------------- ### Get Account Withdraw Quota Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the withdrawal quota (limits) for a specified currency. ```python quota = wallet_client.get_account_withdraw_quota(currency='USDT') ``` -------------------------------- ### Get Transaction Fee Rate Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves the transaction fee rate for specified symbols. ```python fee_rates = client.get_transact_feerate(symbols=['XBTUSDT', 'ETHUSDT']) ``` -------------------------------- ### Initialize Public Huobi Clients Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Instantiate GenericClient and MarketClient for public API access without authentication. Custom hosts can be specified. ```python from huobi.client import GenericClient, MarketClient # Public APIs - no authentication needed generic_client = GenericClient() market_client = MarketClient() # With custom host market_client = MarketClient(url="https://api-aws.huobi.pro") ``` -------------------------------- ### Get Order by ID Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves details for a specific order using its order ID. ```python order = client.get_order(order_id=12345) ``` -------------------------------- ### Initialize Huobi Client Using Environment Variables Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Load API key and secret key from environment variables to initialize the TradeClient securely. ```python import os from huobi.client import TradeClient api_key = os.getenv('HUOBI_API_KEY') secret_key = os.getenv('HUOBI_SECRET_KEY') trade_client = TradeClient(api_key=api_key, secret_key=secret_key) ``` -------------------------------- ### Get Price Depth Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Retrieves the price depth for a symbol. Requires MarketClient initialization. ```python market_client = MarketClient() depth = market_client.get_pricedepth("btcusdt", DepthStep.STEP0, depth_size) ``` -------------------------------- ### AccountClient Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md Initializes the AccountClient with API credentials and optional configuration. Requires API key and secret key for authentication. ```APIDOC ## AccountClient Constructor ### Description Initializes the AccountClient with API credentials and optional configuration. Requires API key and secret key for authentication. ### Method ```python def __init__(self, **kwargs) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | api_key | str | Yes | — | API key from Huobi | | secret_key | str | Yes | — | Secret key from Huobi | | url | str | No | "http://api.huobi.pro" | Base URL for API requests | | init_log | bool | No | False | Initialize logger | ### Request Example ```python from huobi.client import AccountClient account_client = AccountClient(api_key="your_api_key", secret_key="your_secret_key") ``` ``` -------------------------------- ### AlgoClient Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/algo-client.md Initializes the AlgoClient with API credentials and optional configuration. ```APIDOC ## AlgoClient Constructor Initializes the AlgoClient with API credentials and optional configuration. ### Method Signature ```python def __init__(self, api_key: str, secret_key: str, url: str = "http://api.huobi.pro", init_log: bool = False) ``` ### Parameters #### Keyword Arguments - **api_key** (str) - Required - API key from Huobi - **secret_key** (str) - Required - Secret key from Huobi - **url** (str) - Optional - Base URL for API requests. Defaults to "http://api.huobi.pro". - **init_log** (bool) - Optional - Initialize logger. Defaults to False. ### Example ```python from huobi.client import AlgoClient algo_client = AlgoClient(api_key="your_api_key", secret_key="your_secret_key") ``` ``` -------------------------------- ### Huobi Constant LoanOrderState Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Examples of using the LoanOrderState constants to filter or interpret loan statuses. ```python from huobi.constant import LoanOrderState LoanOrderState.CREATED # Loan created LoanOrderState.ACCRUAL # Accruing interest LoanOrderState.CLEARED # Repaid LoanOrderState.FAILED # Failed ``` -------------------------------- ### Import API Keys from a Configuration File Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Load API keys from a separate Python configuration file (e.g., privateconfig.py) and use them to initialize the TradeClient. ```python # privateconfig.py p_api_key = "your_api_key" p_secret_key = "your_secret_key" # Add to .gitignore: # privateconfig.py from privateconfig import p_api_key, p_secret_key from huobi.client import TradeClient trade_client = TradeClient(api_key=p_api_key, secret_key=p_secret_key) ``` -------------------------------- ### Place and Monitor a Limit Order Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Demonstrates placing a limit buy order and then checking its status. If the order is still submitted, it shows how to cancel it. ```python from huobi.client import TradeClient, AccountClient from huobi.constant import OrderType, OrderState, OrderSource trade_client = TradeClient(api_key=key, secret_key=secret) # Create order order_id = trade_client.create_order( symbol="btcusdt", account_id=12345, order_type=OrderType.BUY_LIMIT, amount=0.1, price=45000.0, source=OrderSource.API ) print(f"Order created: {order_id}") # Check order status order = trade_client.get_order(order_id) print(f"Status: {order.state}, Filled: {order.filled_amount}") # Cancel if needed if order.state == OrderState.SUBMITTED: result = trade_client.cancel_order(symbol="btcusdt", order_id=order_id) ``` -------------------------------- ### Get Sub-User List Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves a list of sub-users associated with the main account, with pagination support. ```python subuser_list = subuser_client.get_subuser_user_list(from_id=0) ``` -------------------------------- ### Get Account Points Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md Retrieves loyalty program points for an account. Can be filtered by sub-account UID. ```python def get_account_point(self, sub_uid: str = None) ``` -------------------------------- ### Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/generic-client.md Initializes the GenericClient. API key and secret key are not required for public endpoints. A custom URL can be provided for the API base. ```APIDOC ## Constructor Initializes the GenericClient. API key and secret key are not required for public endpoints. A custom URL can be provided for the API base. ```python def __init__(self, api_key: str = None, secret_key: str = None, url: str = "http://api.huobi.pro", init_log: bool = False) ``` ### Parameters * **api_key** (str) - Optional - API key from Huobi (not required for public endpoints) * **secret_key** (str) - Optional - Secret key from Huobi (not required for public endpoints) * **url** (str) - Optional - Base URL for API requests. Defaults to "http://api.huobi.pro". * **init_log** (bool) - Optional - Whether to initialize logger. Defaults to False. ### Example ```python from huobi.client import GenericClient # Create a client instance generic_client = GenericClient() # Create with custom host generic_client = GenericClient(url="https://api-aws.huobi.pro") ``` ``` -------------------------------- ### Get Historical Trades Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Retrieves historical trade data for a symbol. Requires MarketClient initialization. ```python market_client = MarketClient() list_obj = market_client.get_history_trade("btcusdt", 6) ``` -------------------------------- ### Create TradeClient with API Key and Customized Host Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Instantiate the TradeClient for trading operations using API keys and a custom host URL. ```python trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key, url="https://api-aws.huobi.pro") ``` -------------------------------- ### Get Exchange Symbols Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Retrieves a list of available exchange symbols. Requires initialization of the GenericClient. ```python generic_client = GenericClient() list_obj = generic_client.get_exchange_symbols() ``` -------------------------------- ### Create GenericClient Instance Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Instantiate the GenericClient to access public data. No API key is required. ```python generic_client = GenericClient() ``` -------------------------------- ### Get User API Key Info Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves information about API keys associated with a user or sub-user. ```python api_keys = subuser_client.get_user_apikey_info(uid='123') ``` -------------------------------- ### Create AccountClient with API Key Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Instantiate the AccountClient to access private account data. Requires API key and secret key. ```python account_client = AccountClient(api_key=g_api_key, secret_key=g_secret_key) ``` -------------------------------- ### Initialize MarketClient for Public Endpoints Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Initialize the MarketClient for accessing public market data endpoints that do not require authentication. ```python from huobi.client import MarketClient # Public endpoints (no auth) market_client = MarketClient() ``` -------------------------------- ### Get Deposit/Withdraw History Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Retrieves history for deposits or withdrawals. Requires authentication and wallet client initialization. ```python wallet_client = WalletClient(api_key=g_api_key, secret_key=g_secret_key) list_deposit_history = wallet_client.get_deposit_withdraw(op_type=DepositWithdraw.DEPOSIT, currency=None, from_id=1, size=10, direct=QueryDirection.PREV) list_withdraw_history = wallet_client.get_deposit_withdraw(op_type=DepositWithdraw.WITHDRAW, currency=None, from_id=1, size=10, direct=QueryDirection.NEXT) ``` -------------------------------- ### Account Client Exception Handling Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/account-client.md Demonstrates how to handle potential API exceptions when using the Account Client. ```python from huobi.exception import HuobiApiException try: accounts = account_client.get_accounts() except HuobiApiException as e: print(f"Error {e.error_code}: {e.error_message}") ``` -------------------------------- ### TradeClient Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/trade-client.md Initializes the TradeClient with API credentials and optional configuration. ```APIDOC ## TradeClient Constructor ### Description Initializes the TradeClient with API credentials and optional configuration. ### Parameters #### Keyword Arguments - **api_key** (str) - Required - API key from Huobi - **secret_key** (str) - Required - Secret key from Huobi - **url** (str) - Optional - Base URL for API requests (default: "http://api.huobi.pro") - **init_log** (bool) - Optional - Initialize logger (default: False) ### Request Example ```python from huobi.client import TradeClient trade_client = TradeClient(api_key="your_api_key", secret_key="your_secret_key") ``` ``` -------------------------------- ### Get Account Balance Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Fetches the account balance. Requires authentication with API key and secret key. ```python account_client = AccountClient(api_key=g_api_key, secret_key=g_secret_key) account_balance_list = account_client.get_account_balance() ``` -------------------------------- ### Get Market Tickers Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/market-client.md Retrieves the latest tickers for all available trading pairs. This function does not require any parameters. ```python tickers = market_client.get_market_tickers() ``` -------------------------------- ### Get Latest Market Trades Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Fetches the latest trade data for a symbol. Requires MarketClient initialization. ```python market_client = MarketClient() list_obj = market_client.get_market_trade(symbol="btcusdt") ``` -------------------------------- ### Create GenericClient Instance Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/generic-client.md Instantiate the GenericClient to interact with public exchange APIs. You can use the default URL or specify a custom host. ```python from huobi.client import GenericClient # Create a client instance generic_client = GenericClient() # Create with custom host generic_client = GenericClient(url="https://api-aws.huobi.pro") ``` -------------------------------- ### EtfClient Constructor Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Initializes the EtfClient with API credentials and optional configuration for connecting to the Huobi API. ```APIDOC ## EtfClient Constructor ### Description Initializes the EtfClient with API credentials and optional configuration for connecting to the Huobi API. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```python def __init__(self, **kwargs) ``` ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | api_key | str | Yes | — | API key from Huobi | | secret_key | str | Yes | — | Secret key from Huobi | | url | str | No | "http://api.huobi.pro" | Base URL for API requests | | init_log | bool | No | False | Initialize logger | ### Example ```python from huobi.client import EtfClient etf_client = EtfClient(api_key="your_api_key", secret_key="your_secret_key") ``` ``` -------------------------------- ### Get Candlestick Data Source: https://github.com/huobirdcenter/huobi_python/blob/master/README.md Fetches candlestick data for a given symbol and interval. Requires MarketClient initialization. ```python market_client = MarketClient() list_obj = market_client.get_candlestick("btcusdt", CandlestickInterval.MIN5, 10) ``` -------------------------------- ### Get Exchange Timestamp Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/generic-client.md Retrieve the current server timestamp in milliseconds. This is useful for time synchronization or logging. ```python generic_client = GenericClient() timestamp_ms = generic_client.get_exchange_timestamp() print(f"Server timestamp: {timestamp_ms}") # e.g., 1546300800000 ``` -------------------------------- ### Huobi API Exception Handling Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Example of how to handle potential Huobi API exceptions when performing margin operations. ```python from huobi.exception import HuobiApiException try: loan_id = margin_client.post_create_margin_order( symbol="eosusdt", currency="usdt", amount=100.0 ) except HuobiApiException as e: print(f"Error {e.error_code}: {e.error_message}") ``` -------------------------------- ### Initialize Private Huobi Clients Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Instantiate private clients like AccountClient and TradeClient, which require API keys and secret keys for authenticated access. ```python from huobi.client import ( AccountClient, TradeClient, WalletClient, MarginClient, SubuserClient, AlgoClient, EtfClient ) account_client = AccountClient(api_key="your_key", secret_key="your_secret") trade_client = TradeClient(api_key="your_key", secret_key="your_secret") ``` -------------------------------- ### Get Account Withdraw by Client Order ID Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves withdrawal information using a client-defined order ID. ```python wallet_client.get_account_withdraw_client_order_id(client_order_id='my_withdraw_id') ``` -------------------------------- ### Get Account Withdraw Address Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves a list of withdrawal addresses for a specified currency, with optional filtering and pagination. ```python addresses = wallet_client.get_account_withdraw_address(currency='USDT') ``` -------------------------------- ### Create Subuser Accounts Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Create new sub-user accounts by providing a list of user objects, each with a 'userName' field. The result will contain the user ID and account information for each newly created sub-user. ```python users = [ {"userName": "subuser-001"}, {"userName": "subuser-002"} ] result = subuser_client.post_create_subuser(users) for user in result: print(f"Created: {user.user_id}") ``` -------------------------------- ### Create ETF Swap (In) Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Initiates the creation (swap in) of an ETF, provided all constituent assets are available. ```APIDOC ## POST /etf/swap/in ### Description Initiates the creation (swap in) of an ETF, provided all constituent assets are available. ### Method POST ### Endpoint `/etf/swap/in` ### Parameters #### Query Parameters - **etfName** (string) - Required - The name of the ETF to create. - **quantity** (integer) - Required - The number of ETF units to create. ### Request Example ```python etf_client.post_etf_swap_in("hb10", 5) ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. ### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Get Deposit/Withdraw History Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves a list of deposit and withdrawal records. Supports filtering by operation type and pagination. ```python records = wallet_client.get_deposit_withdraw(op_type='deposit') ``` -------------------------------- ### Get Match Results by Order ID Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves trade match results associated with a specific order ID. ```python order_matches = client.get_match_results_by_order_id(order_id=12345) ``` -------------------------------- ### Apply for Margin Loan Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Use `post_create_margin_order` to borrow funds for margin trading. You must specify the trading symbol, the currency you wish to borrow, and the amount. ```python loan_id = margin_client.post_create_margin_order( symbol="eosusdt", currency="usdt", amount=100.0 ) ``` -------------------------------- ### post_etf_swap_in Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Initiates the creation of a specified amount of ETF units by swapping in constituent assets. ```APIDOC ## post_etf_swap_in ### Description Initiates the creation of a specified amount of ETF units by swapping in constituent assets. ### Method POST (Implied by SDK method) ### Endpoint (Not explicitly defined, SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Signature ```python def post_etf_swap_in(self, etf_name: str, amount: int) -> None ``` ### Parameters Table | Parameter | Type | Required | Default | Description | |-----------|------|----------|---------|-------------| | etf_name | str | Yes | — | ETF name (e.g., "hb10") | | amount | int | Yes | — | Number of ETF units to create | ### Example ```python # Create 10 units of HB10 ETF result = etf_client.post_etf_swap_in(etf_name="hb10", amount=10) print(f"Creation submitted: {result}") ``` ``` -------------------------------- ### Get Match Results Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves trade match results for a symbol. Supports filtering by date range and pagination. ```python match_results = client.get_match_result(symbol='XBTUSDT', start_date=20210101, end_date=20210102) ``` -------------------------------- ### Get Order History Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves historical orders for a given symbol. Supports filtering by time range and pagination. ```python history = client.get_history_orders(symbol='XBTUSDT', start_time=1609459200, end_time=1609545600) ``` -------------------------------- ### ETF Client Exception Handling Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/etf-client.md Illustrates how to handle potential API exceptions when interacting with the ETF client. ```python from huobi.exception import HuobiApiException try: config = etf_client.get_etf_swap_config("hb10") except HuobiApiException as e: print(f"Error {e.error_code}: {e.error_message}") ``` -------------------------------- ### Initialize TradeClient with API Keys Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/README.md Initialize the TradeClient for authenticated REST and WebSocket operations using your API key and secret key. Optional parameters include custom endpoints and logging. ```python from huobi.client import TradeClient # With API key trade_client = TradeClient( api_key="your_api_key", secret_key="your_secret_key", url="http://api.huobi.pro", # Optional: custom endpoint init_log=True # Optional: enable logging ) ``` -------------------------------- ### get_uid Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Get user UID for the authenticated account. This method retrieves the unique identifier for the currently logged-in user. ```APIDOC ## get_uid ### Description Get user UID for the authenticated account. This method retrieves the unique identifier for the currently logged-in user. ### Method GET ### Endpoint `/uid` ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example (No request body needed for this GET request) ### Response #### Success Response (200) - **uid** (dict) - Dictionary containing user information including `uid` #### Response Example ```json { "uid": "123456" } ``` ``` -------------------------------- ### Configure Huobi Client with Custom Host Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Set a custom base URL for the MarketClient to target different regional or backup API endpoints. ```python from huobi.client import MarketClient # Global endpoint market_client = MarketClient(url="http://api.huobi.pro") # AWS endpoint market_client = MarketClient(url="https://api-aws.huobi.pro") # Vietnam endpoint (if available) market_client = MarketClient(url="https://api.huobi.vn") # For testnet or staging market_client = MarketClient(url="https://api-staging.huobi.pro") ``` -------------------------------- ### Get Multiple Orders Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves a list of orders based on specified criteria such as symbol and state. Supports pagination. ```python orders = client.get_orders(symbol='XBTUSDT', state='submitted') ``` -------------------------------- ### Enable Logging for Huobi TradeClient Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/configuration.md Initialize the TradeClient with init_log set to True to enable debug logging for API requests and responses. ```python from huobi.client import TradeClient # With logging enabled trade_client = TradeClient( api_key="your_key", secret_key="your_secret", init_log=True ) ``` -------------------------------- ### Get Order by Client Order ID Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Retrieves details for a specific order using its client-defined order ID. ```python order = client.get_order_by_client_order_id(client_order_id='my_custom_id') ``` -------------------------------- ### Get Cross-Margin Account Balance Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/margin-client.md Retrieve the balance details for your cross-margin account. An optional sub-account UID can be provided. ```python def get_cross_margin_account_balance(self, sub_uid: int = None) -> list ``` -------------------------------- ### Create Spot Order Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/quick-reference.md Convenience method to create a spot trading order. ```python client.create_spot_order(symbol='XBTUSDT', order_type='limit', order_price=10000, order_size=1, order_side='buy') ``` -------------------------------- ### Place Auto-Execute Order with Margin Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/trade-client.md Place an order that will auto-execute with margin. Requires symbol, account ID, amount, source, type, and trade purpose. Optional parameters include market amount, borrow amount, price, stop price, and operator. ```python def post_order_auto_place(self, symbol: str, account_id: str, amount: str, source: str, type_: str, trade_purpose: str, market_amount: str = None, borrow_amount: str = None, price: str = None, stop_price: str = None, operator: str = None) ``` -------------------------------- ### Get Trading Fee Rates Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/trade-client.md Retrieve the trading fee rates for specified symbols. This is useful for understanding the cost of trades. ```python fee_rates = trade_client.get_feerate("btcusdt,ethusdt") for rate in fee_rates: print(f"Symbol: {rate.symbol}, Maker: {rate.maker_rate}, Taker: {rate.taker_rate}") ``` -------------------------------- ### Handling Authentication Errors Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/errors.md Demonstrates catching 'invalid-apikey' and 'invalid-signature' errors when authentication fails. ```python from huobi.client import AccountClient try: # Missing or invalid API key account_client = AccountClient(api_key="invalid", secret_key="wrong") accounts = account_client.get_accounts() except HuobiApiException as e: if e.error_code == "invalid-apikey": print("API key is invalid - please check credentials") elif e.error_code == "invalid-signature": print("Request signature is invalid") ``` -------------------------------- ### get_subuser_user_state Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Get status of a specific sub-user account. This method retrieves the current state and lock status of a given sub-user. ```APIDOC ## get_subuser_user_state ### Description Get status of a specific sub-user account. This method retrieves the current state and lock status of a given sub-user. ### Method GET ### Endpoint `/subuser/user/state` ### Parameters #### Path Parameters None #### Query Parameters - **sub_uid** (int) - Required - Sub-user UID ### Request Example (No request body needed for this GET request) ### Response #### Success Response (200) - **sub-user state object** (object) - Sub-user state object with status information (e.g., `state`, `lock`) #### Response Example ```json { "state": "normal", "lock": "unlocked" } ``` ``` -------------------------------- ### Get Specific Sub-user State Source: https://github.com/huobirdcenter/huobi_python/blob/master/_autodocs/api-reference/subuser-client.md Retrieve the current status and lock state of a specific sub-user account using their UID. ```python state = subuser_client.get_subuser_user_state(sub_uid=100001) print(f"State: {state.state}, Lock: {state.lock}") ```