def post_create_withdraw(self, address: 'str', amount: 'float', currency: 'str', fee: 'float', chain:'str' =None, address_tag: 'str' = None) -> int: """ Submit a request to withdraw some asset from an account. :param address: The destination address of this withdraw. (mandatory) :param amount: The amount of currency to withdraw. (mandatory) :param currency: The crypto currency to withdraw. (mandatory) :param fee: The fee to pay with this withdraw. (mandatory) :param address_tag: A tag specified for this address. (optional) :param chain: set as "usdt" to withdraw USDT to OMNI, set as "trc20usdt" to withdraw USDT to TRX. (optional) :return: Withdraw id """ return call_sync(self.request_impl.post_create_withdraw(address, amount, currency, fee, chain, address_tag))
def get_etf_candlestick(self, etf_symbol: 'str', interval: 'CandlestickInterval', size: 'int' = None) -> list: """ Get the latest candlestick/kline for the etf. :param etf_symbol: The symbol, currently only support hb10. (mandatory) :param interval: The candlestick/kline interval, MIN1, MIN5, DAY1 etc. (mandatory) :param size: The maximum number of candlestick/kline requested. Range [1 - 2000] (optional) :return: The list of candlestick/kline data. """ return call_sync( self.request_impl.get_etf_candlestick(etf_symbol, interval, size))
def get_open_orders(self, symbol: 'str', account_type: 'AccountType', side: 'OrderSide' = None, size: 'int' = 100, from_id=None, direct=None) -> list: """ The request of get open orders. :param symbol: The symbol, like "btcusdt". (mandatory) :param account_type: The order side, buy or sell. If no side defined, will return all open orders of the account. (mandatory) :param side: The order side, buy or sell. If no side defined, will return all open orders of the account. (optional) :param size: The number of orders to return. Range is [1, 500]. Default is 100. (optional) :param direct: 1:prev order by ID asc from from_id, 2:next order by ID desc from from_id :param from_id: start ID for search :return: The orders information. """ return call_sync(self.request_impl.get_open_orders(symbol, account_type, size, side, from_id, direct))
def get_reference_currencies(self, currency: 'str' = None, is_authorized_user: '******' = None) -> list: """ Get all the trading assets and currencies supported in huobi. The information of trading instrument, including base currency, quote precision, etc. :param currency: btc, ltc, bch, eth, etc ...(available currencies in Huobi Global) :param is_authorized_user: is Authorized user? True or False :return: The information of trading instrument and currencies. """ return call_sync( self.request_impl.get_reference_currencies(currency, is_authorized_user))
def transfer_between_parent_and_sub(self, sub_uid: 'int', currency: 'str', amount: 'float', transfer_type: 'TransferMasterType'): """ Transfer Asset between Parent and Sub Account. :param sub_uid: The target sub account uid to transfer to or from. (mandatory) :param currency: The crypto currency to transfer. (mandatory) :param amount: The amount of asset to transfer. (mandatory) :param transfer_type: The type of transfer, see {@link TransferMasterType} (mandatory) :return: The order id. """ return call_sync( self.request_impl.transfer_between_parent_and_sub( sub_uid, currency, amount, transfer_type))
def get_latest_candlestick(self, symbol: 'str', interval: 'CandlestickInterval', size: 'int' = 150) -> list: """ Get the latest candlestick/kline for the specified symbol. :param symbol: The symbol, like "btcusdt". To query hb10, put "hb10" at here. (mandatory) :param interval: The candlestick/kline interval, MIN1, MIN5, DAY1 etc. (mandatory) :param size: The maximum number of candlestick/kline requested. Range [1 - 2000] (mandatory) :return: The list of candlestick/kline data. """ return call_sync( self.request_impl.get_candlestick(symbol, interval, size, None, None))
def get_account_balance_by_account_type( self, account_type: "AccountType") -> Account: """ Get the balance of a all accounts or specified account. :param account_type: The specified account type. if it is not filled, this method will return all accounts (mandatory) :return: The information of the account that is specified type. """ check_should_not_none(account_type, "account_type") accounts = call_sync(self.request_impl.get_accounts()) for item in accounts: if account_type == item.account_type: balances = self.request_impl.get_balance(item) item.balances = balances return item
def transfer_between_futures_and_pro( self, currency: 'str', amount: 'float', transfer_type: 'TransferFuturesPro') -> int: """ Transfer Asset between Futures and Contract. :param sub_uid: The target sub account uid to transfer to or from. (mandatory) :param currency: The crypto currency to transfer. (mandatory) :param amount: The amount of asset to transfer. (mandatory) :param transfer_type: The type of transfer, need be "futures-to-pro" or "pro-to-futures" (mandatory) :return: The order id. """ return call_sync( self.request_impl.transfer_between_futures_and_pro( currency, amount, transfer_type))
def get_loan_history(self, symbol: 'str', start_date: 'str' = None, end_date: 'str' = None, status: 'LoanOrderState' = None, from_id: 'int' = None, size: 'int' = None, direction: 'QueryDirection' = None) -> list: """ Get the margin loan records. :param symbol: The symbol, like "btcusdt" (mandatory). :param start_date: The search starts date in format yyyy-mm-dd. (optional). :param end_date: The search end date in format yyyy-mm-dd.(optional, can be null). :param status: The loan order states, it could be created, accrual, cleared or invalid. (optional) :param from_id: Search order id to begin with. (optional) :param size: The number of orders to return.. (optional) :param direction: The query direction, prev or next. (optional) :return: The list of the margin loan records. """ return call_sync(self.request_impl.get_loan(symbol, start_date, end_date, status, from_id, size, direction))
def batch_create_order(self, order_config_list) -> int: """ Make an order in huobi. :param order_config_list: order config list, it can batch create orders, and each order config check as below : items as below :param symbol: The symbol, like "btcusdt". (mandatory) :param account_type: Account type. (mandatory) :param order_type: The order type. (mandatory) :param amount: The amount to buy (quote currency) or to sell (base currency). (mandatory) :param price: The limit price of limit order, only needed for limit order. (mandatory for buy-limit, sell-limit, buy-limit-maker and sell-limit-maker) :param client_order_id: unique Id which is user defined and must be unique in recent 24 hours :param stop_price: Price for auto sell to get the max benefit :param operator: the condition for stop_price, value can be "gte" or "lte", gte – greater than and equal (>=), lte – less than and equal (<=) :return: The order id. """ return call_sync(self.request_impl.batch_create_order(order_config_list))
def create_order(self, symbol: 'str', account_type: 'AccountType', order_type: 'OrderType', amount: 'float', price: 'float', client_order_id=None, stop_price=None, operator=None) -> int: """ Make an order in huobi. :param symbol: The symbol, like "btcusdt". (mandatory) :param account_type: Account type. (mandatory) :param order_type: The order type. (mandatory) :param amount: The amount to buy (quote currency) or to sell (base currency). (mandatory) :param price: The limit price of limit order, only needed for limit order. (mandatory for buy-limit, sell-limit, buy-limit-maker and sell-limit-maker) :param client_order_id: unique Id which is user defined and must be unique in recent 24 hours :param stop_price: Price for auto sell to get the max benefit :param operator: the condition for stop_price, value can be "gte" or "lte", gte – greater than and equal (>=), lte – less than and equal (<=) :return: The order id. """ return call_sync(self.request_impl.create_order(symbol, account_type, order_type, amount, price, client_order_id, stop_price, operator))
def get_cross_margin_loan_orders(self, currency: 'str' = None, state: 'str' = None, start_date: 'str' = None, end_date: 'str' = None, from_id: 'int' = None, size: 'int' = None, direct: 'str' = None) -> list: """ get cross margin loan orders :return: return list. """ return call_sync( self.request_impl.get_cross_margin_loan_orders( currency, state, start_date, end_date, from_id, size, direct))
def transfer(self, symbol: 'str', from_account: 'AccountType', to_account: 'AccountType', currency: 'str', amount: 'float') -> int: """ Transfer asset from specified account to another account. :param symbol: The symbol, like "btcusdt". (mandatory) :param from_account: The type, transfer from which account, could be SPOT or MARGIN. (mandatory) :param to_account: The type, transfer to which account, could be SPOT or MARGIN. (mandatory) :param currency: The currency of transfer. (mandatory) :param amount: The amount of transfer. (mandatory) :return: """ return call_sync( self.request_impl.transfer(symbol, from_account, to_account, currency, amount))
def create_order(self, symbol: 'str', account_type: 'AccountType', order_type: 'OrderType', amount: 'float', price: 'float') -> int: """ Make an order in huobi. :param symbol: The symbol, like "btcusdt". (mandatory) :param account_type: Account type. (mandatory) :param order_type: The order type. (mandatory) :param amount: The amount to buy (quote currency) or to sell (base currency). (mandatory) :param price: The limit price of limit order, only needed for limit order. (mandatory for buy-limit, sell-limit, buy-limit-maker and sell-limit-maker) :return: The order id. """ return call_sync( self.request_impl.create_order(symbol, account_type, order_type, amount, price))
def get_match_result(self, symbol: 'str', order_type: 'OrderSide' = None, start_date: 'str' = None, end_date: 'str' = None, size: 'int' = None, from_id: 'int' = None): """ Search for the trade records of an account. :param symbol: The symbol, like "btcusdt" (mandatory). :param order_type: The types of order to include in the search (optional). :param start_date: Search starts date in format yyyy-mm-dd. (optional). :param end_date: Search ends date in format yyyy-mm-dd. (optional). :param size: The number of orders to return, range [1-100] default is 100. (optional). :param from_id: Search order id to begin with. (optional). :return: """ return call_sync(self.request_impl.get_match_results(symbol, order_type, start_date, end_date, size, from_id))
def get_open_orders(self, symbol: 'str', account_type: 'AccountType', side: 'OrderSide' = None, size: 'int' = 10) -> list: """ The request of get open orders. :param symbol: The symbol, like "btcusdt". (mandatory) :param account_type: The order side, buy or sell. If no side defined, will return all open orders of the account. (mandatory) :param side: The order side, buy or sell. If no side defined, will return all open orders of the account. (optional) :param size: The number of orders to return. Range is [1, 500]. Default is 10. (optional) :return: The orders information. """ return call_sync( self.request_impl.get_open_orders(symbol, account_type, size, side))
def get_deposit_history(self, currency: 'str', from_id: 'int', size: 'int', direct=None) -> list: """ Get the deposit records of an account. :param currency: The currency, like "btc". (mandatory) :param from_id: The beginning deposit record id. (mandatory) :param size: The size of record. (mandatory) :param direct: "prev" is order by asc, "next" is order by desc, default as "prev" :return: The list of deposit records. """ return call_sync( self.request_impl.get_deposit_history(currency, from_id, size, direct))
def get_account_history(self, account_id: 'int', currency: 'str' = None, transact_types: 'str' = None, start_time: 'int' = None, end_time: 'int' = None, sort: 'str' = None, size: 'int' = None): """ get account change record :return: account change record list. """ return call_sync( self.request_impl.get_account_history(account_id, currency, transact_types, start_time, end_time, sort, size))
def cancel_open_orders(self, symbol: 'str', account_type: 'AccountType', side: 'OrderSide' = None, size: 'int' = None) -> BatchCancelResult: """ Request to cancel open orders. :param symbol: The symbol, like "btcusdt". (mandatory) :param account_type: Account type. (mandatory) :param side: The order side, buy or sell. If no side defined, will cancel all open orders of the account. (optional) :param size: The number of orders to cancel. Range is [1, 100]. Default is 100. (optional) :return: Status of batch cancel result. """ return call_sync( self.request_impl.cancel_open_orders(symbol, account_type, side, size))
def get_last_trade_and_best_quote(self, symbol: 'str') -> LastTradeAndBestQuote: """ Get last trade, best bid and best ask of a symbol. :param symbol: The symbol, like "btcusdt". (mandatory) :return: The data includes last trade, best bid and best ask. """ best_quote = call_sync(self.request_impl.get_best_quote(symbol)) last_trade = self.get_last_trade(symbol) last_trade_and_best_quote = LastTradeAndBestQuote() last_trade_and_best_quote.bid_amount = best_quote.bid_amount last_trade_and_best_quote.bid_price = best_quote.bid_price last_trade_and_best_quote.ask_amount = best_quote.ask_amount last_trade_and_best_quote.ask_price = best_quote.ask_price last_trade_and_best_quote.last_trade_price = last_trade.price last_trade_and_best_quote.last_trade_amount = last_trade.amount return last_trade_and_best_quote
def get_historical_orders(self, symbol: 'str', order_state: 'OrderState', order_type: 'OrderType' = None, start_date: 'str' = None, end_date: 'str' = None, start_id: 'int' = None, size: 'int' = None) -> list: """ Get historical orders. :param symbol: The symbol, like "btcusdt". (mandatory) :param order_state: Order state , SUBMITTED etc. (mandatory) :param order_type: Order type. (optional) :param start_date: Start date in format yyyy-mm-dd. (optional) :param end_date: End date in format yyyy-mm-dd. (optional) :param start_id: Start id. (optional) :param size: The size of orders. (optional) :return: """ return call_sync( self.request_impl.get_historical_orders(symbol, order_state, order_type, start_date, end_date, start_id, size))
def get_order_recent_48hour(self, symbol=None, start_time=None, end_time=None, size=None, direct=None) -> list: """ Transfer Asset between Futures and Contract. :param direct: :param symbol: The target sub account uid to transfer to or from. (mandatory) :param start_time: The crypto currency to transfer. (mandatory) :param end_time: The amount of asset to transfer. (mandatory) :param size: The type of transfer, need be "futures-to-pro" or "pro-to-futures" (mandatory) :return: The Order list. """ return call_sync( self.request_impl.get_order_recent_48hour(symbol, start_time, end_time, size, direct))
def get_account_ledger(self, account_id: 'int', currency: 'str' = None, transact_types: 'str' = None, start_time: 'int' = None, end_time: 'int' = None, sort: 'str' = None, limit: 'int' = None, from_id: 'int' = None) -> list: """ get account ledger :return: account ledger list. """ return call_sync( self.request_impl.get_account_ledger(account_id, currency, transact_types, start_time, end_time, sort, limit, from_id))
def get_deposit_withdraw(self, op_type: 'str', currency: 'str' = None, from_id: 'int' = None, size: 'int' = None, direct: 'str' = None) -> list: """ Get the withdraw records of an account. :param currency: The currency, like "btc". (optional) :param from_id: The beginning withdraw record id. (optional) :param op_type: deposit or withdraw, see defination DepositWithdraw (mandatory) :param size: The size of record. (optional) :param direct: "prev" is order by asc, "next" is order by desc, default as "prev"(optional) :return: The list of withdraw records. """ return call_sync( self.request_impl.get_deposit_withdraw(op_type, currency, from_id, size, direct))
def get_candlestick(self, symbol: 'str', interval: 'CandlestickInterval', size: 'int' = 150, start_time: 'int' = 0, end_time: 'int' = 0) -> list: """ Get the candlestick/kline for the specified symbol. The data number is 150 as default. :param symbol: The symbol, like "btcusdt". To query hb10, put "hb10" at here. (mandatory) :param interval: The candlestick/kline interval, MIN1, MIN5, DAY1 etc. (mandatory) :param size: The start time of of requested candlestick/kline data. (optional) :param start_time: The start time of of requested candlestick/kline data. (optional) :param end_time: The end time of of requested candlestick/kline data. (optional) :return: The list of candlestick/kline data. """ return call_sync( self.request_impl.get_candlestick(symbol, interval, size, start_time, end_time))
def get_sub_user_deposit_history(self, sub_uid: 'int', currency: 'str' = None, start_time: 'int' = None, end_time: 'int' = None, sort: 'str' = None, limit: 'int' = None, from_id: 'int' = None) -> DepositHistory: """ Parent get sub user depoist history. :param sub_uid: Sub user id. (mandatory) :param currency: Cryptocurrency. :param start_time: Farthest time :param end_time: Nearest time :param sort: Sorting order :param limit: Maximum number of items in one page :param from_id: First record Id in this query """ return call_sync( self.request_impl.get_sub_user_deposit_history( sub_uid, currency, start_time, end_time, sort, limit, from_id))
def get_my_symbol_map(self): my_symbol_map = call_sync( self.request_impl.get_symbols_by_usdt_btc_eth()) return my_symbol_map
def update_user_info(self, api_key, request_impl): accounts = call_sync(request_impl.get_accounts()) user = User() user.accounts = accounts self.user_map[api_key] = user