from huobi.connection.restapi_sync_client import RestApiSyncClient from huobi.constant.system import HttpMethod from huobi.model.account import * from huobi.utils import * ''' https://huobiapi.github.io/docs/spot/v1/cn/#bd9157656f 账户余额 API Key 权限:读取 限频值(NEW):100次/2s 查询指定账户的余额,支持以下账户: spot:现货账户, margin:逐仓杠杆账户,otc:OTC 账户,point:点卡账户,super-margin:全仓杠杆账户, investment: C2C杠杆借出账户, borrow: C2C杠杆借入账户 响应数据 { "data": { "id": 100009, 账户 ID "type": "spot", 账户类型 pot:现货账户, margin:逐仓杠杆账户, otc:OTC 账户, point:点卡账户, super-margin:全仓杠杆账户, investment: C2C杠杆借出账户, borrow: C2C杠杆借入账户,矿池账户: minepool, ETF账户: etf, 抵押借贷账户: crypto-loans "state": "working", 账户状态 working:正常 lock:账户被锁定 "list": [ { "currency": "usdt", 币种 "type": "trade", 类型 trade: 交易余额,frozen: 冻结余额, loan: 待还借贷本金, interest: 待还借贷利息, lock: 锁仓, bank: 储蓄 "balance": "5007.4362872650" 余额 }, { "currency": "usdt", "type": "frozen", "balance": "348.1199920000" } ] } } ''' class GetBalanceService: def __init__(self, params): self.params = params def request(self, **kwargs): account_id = self.params["account-id"] def get_channel(): path = "/v1/account/accounts/{}/balance" return path.format(account_id) def parse(dict_data): data = dict_data.get("data", {}) balance_list = data.get("list", []) return default_parse_list_dict(balance_list, Balance, []) return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET_SIGN, get_channel(), self.params, parse) def get_request(self, **kwargs): account_id = self.params["account-id"] def get_channel(): path = "/v1/account/accounts/{}/balance" return path.format(account_id) def parse(dict_data): data = dict_data.get("data", {}) balance_list = data.get("list", []) return default_parse_list_dict(balance_list, Balance, []) return RestApiSyncClient(**kwargs).create_request(HttpMethod.GET_SIGN, get_channel(), self.params, parse)