From 57d6bb0ac572c367992162ce05aa523379fd11cd Mon Sep 17 00:00:00 2001 From: eynzhang <2427928+eynzhang@users.noreply.github.com> Date: Fri, 18 Sep 2020 10:26:32 +0800 Subject: [PATCH] Update according to API update in May and June --- example/account/post_account_transfer.py | 6 + example/algo/get_open_orders.py | 10 ++ example/algo/get_order.py | 10 ++ example/algo/get_order_history.py | 10 ++ example/algo/post_cancel_algo_orders.py | 17 +++ example/algo/post_create_algo_order.py | 12 ++ example/generic/get_market_status.py | 8 ++ example/market/req_mbp.py | 5 +- example/market/sub_mbp_full.py | 6 +- example/market/sub_mbp_increase.py | 5 +- example/subuser/get_user_apikey_info.py | 7 + example/subuser/post_create_subuser.py | 17 +++ .../post_set_subuser_transferability.py | 9 ++ .../subuser/post_subuser_apikey_deletion.py | 10 ++ .../subuser/post_subuser_apikey_generation.py | 13 ++ .../post_subuser_apikey_modification.py | 12 ++ example/subuser/post_trade_market.py | 12 ++ .../wallet/get_account_withdraw_address.py | 14 ++ huobi/client/account.py | 73 ++++++---- huobi/client/algo.py | 128 ++++++++++++++++++ huobi/client/generic.py | 14 +- huobi/client/market.py | 46 +++---- huobi/client/subuser.py | 109 +++++++++++++++ huobi/client/wallet.py | 28 +++- huobi/connection/impl/websocket_manage.py | 6 + huobi/connection/impl/websocket_request.py | 1 + huobi/connection/subscribe_client.py | 20 ++- huobi/connection/websocket_req_client.py | 12 +- huobi/constant/definition.py | 59 +++++++- huobi/model/account/__init__.py | 1 + .../model/account/account_transfer_result.py | 23 ++++ huobi/model/algo/__init__.py | 3 + huobi/model/algo/cancel_order_result.py | 17 +++ huobi/model/algo/order_history_item.py | 51 +++++++ huobi/model/algo/order_list_item.py | 71 ++++++++++ huobi/model/generic/__init__.py | 3 +- huobi/model/generic/market_status.py | 20 +++ huobi/model/market/mbp_increase_event.py | 4 +- huobi/model/subuser/__init__.py | 5 + .../subuser/subuser_apikey_generation.py | 26 ++++ .../subuser/subuser_apikey_modification.py | 20 +++ huobi/model/subuser/subuser_creation.py | 27 ++++ .../model/subuser/subuser_transferability.py | 20 +++ huobi/model/subuser/trade_market.py | 21 +++ huobi/model/subuser/user_apikey_info.py | 37 +++++ huobi/model/trade/matchresult.py | 5 +- huobi/model/wallet/__init__.py | 1 + huobi/model/wallet/chain_withdraw_address.py | 25 ++++ huobi/model/wallet/deposit.py | 3 +- .../service/account/post_account_transfer.py | 19 +++ huobi/service/algo/__init__.py | 0 huobi/service/algo/get_open_orders.py | 40 ++++++ huobi/service/algo/get_order_by_cid.py | 19 +++ huobi/service/algo/get_order_history.py | 19 +++ huobi/service/algo/post_cancel_orders.py | 20 +++ huobi/service/algo/post_create_order.py | 18 +++ huobi/service/generic/get_market_status.py | 18 +++ huobi/service/market/req_mbp.py | 11 +- huobi/service/market/sub_mbp_full.py | 9 +- huobi/service/market/sub_mbp_increase.py | 2 +- huobi/service/subuser/__init__.py | 0 huobi/service/subuser/get_user_apikey_info.py | 18 +++ huobi/service/subuser/post_create_subuser.py | 18 +++ .../subuser/post_set_transferability.py | 18 +++ .../subuser/post_subuser_apikey_deletion.py | 17 +++ .../subuser/post_subuser_apikey_generation.py | 18 +++ .../post_subuser_apikey_modification.py | 18 +++ huobi/service/subuser/post_tradable_market.py | 17 +++ .../wallet/get_account_withdraw_address.py | 25 ++++ huobi/utils/channels.py | 10 +- huobi/utils/input_checker.py | 14 +- huobi/utils/json_parser.py | 56 ++++---- setup.py | 2 +- 73 files changed, 1335 insertions(+), 133 deletions(-) create mode 100644 example/account/post_account_transfer.py create mode 100644 example/algo/get_open_orders.py create mode 100644 example/algo/get_order.py create mode 100644 example/algo/get_order_history.py create mode 100644 example/algo/post_cancel_algo_orders.py create mode 100644 example/algo/post_create_algo_order.py create mode 100644 example/generic/get_market_status.py create mode 100644 example/subuser/get_user_apikey_info.py create mode 100644 example/subuser/post_create_subuser.py create mode 100644 example/subuser/post_set_subuser_transferability.py create mode 100644 example/subuser/post_subuser_apikey_deletion.py create mode 100644 example/subuser/post_subuser_apikey_generation.py create mode 100644 example/subuser/post_subuser_apikey_modification.py create mode 100644 example/subuser/post_trade_market.py create mode 100644 example/wallet/get_account_withdraw_address.py create mode 100644 huobi/client/algo.py create mode 100644 huobi/client/subuser.py create mode 100644 huobi/model/account/account_transfer_result.py create mode 100644 huobi/model/algo/__init__.py create mode 100644 huobi/model/algo/cancel_order_result.py create mode 100644 huobi/model/algo/order_history_item.py create mode 100644 huobi/model/algo/order_list_item.py create mode 100644 huobi/model/generic/market_status.py create mode 100644 huobi/model/subuser/__init__.py create mode 100644 huobi/model/subuser/subuser_apikey_generation.py create mode 100644 huobi/model/subuser/subuser_apikey_modification.py create mode 100644 huobi/model/subuser/subuser_creation.py create mode 100644 huobi/model/subuser/subuser_transferability.py create mode 100644 huobi/model/subuser/trade_market.py create mode 100644 huobi/model/subuser/user_apikey_info.py create mode 100644 huobi/model/wallet/chain_withdraw_address.py create mode 100644 huobi/service/account/post_account_transfer.py create mode 100644 huobi/service/algo/__init__.py create mode 100644 huobi/service/algo/get_open_orders.py create mode 100644 huobi/service/algo/get_order_by_cid.py create mode 100644 huobi/service/algo/get_order_history.py create mode 100644 huobi/service/algo/post_cancel_orders.py create mode 100644 huobi/service/algo/post_create_order.py create mode 100644 huobi/service/generic/get_market_status.py create mode 100644 huobi/service/subuser/__init__.py create mode 100644 huobi/service/subuser/get_user_apikey_info.py create mode 100644 huobi/service/subuser/post_create_subuser.py create mode 100644 huobi/service/subuser/post_set_transferability.py create mode 100644 huobi/service/subuser/post_subuser_apikey_deletion.py create mode 100644 huobi/service/subuser/post_subuser_apikey_generation.py create mode 100644 huobi/service/subuser/post_subuser_apikey_modification.py create mode 100644 huobi/service/subuser/post_tradable_market.py create mode 100644 huobi/service/wallet/get_account_withdraw_address.py diff --git a/example/account/post_account_transfer.py b/example/account/post_account_transfer.py new file mode 100644 index 0000000..59c4f50 --- /dev/null +++ b/example/account/post_account_transfer.py @@ -0,0 +1,6 @@ +from huobi.client.account import AccountClient +from huobi.constant import * + +account_client = AccountClient(api_key=g_api_key, secret_key=g_secret_key) +transfer_result = account_client.post_account_transfer(36979737, 'spot', 3684354, 122946475, 'spot', 11907558, 'usdt', 1) +transfer_result.print_object() diff --git a/example/algo/get_open_orders.py b/example/algo/get_open_orders.py new file mode 100644 index 0000000..17161c1 --- /dev/null +++ b/example/algo/get_open_orders.py @@ -0,0 +1,10 @@ +from huobi.client.algo import AlgoClient +from huobi.constant import * +from huobi.utils import * + +symbol_test = "adausdt" +account_id = g_account_id + +algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key) +result = algo_client.get_open_orders() +LogInfo.output_list(result) diff --git a/example/algo/get_order.py b/example/algo/get_order.py new file mode 100644 index 0000000..d606d92 --- /dev/null +++ b/example/algo/get_order.py @@ -0,0 +1,10 @@ +from huobi.client.algo import AlgoClient +from huobi.constant import * + +account_id = g_account_id +client_order_id = "test002" + +# get specific order by clientOrderId +algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key) +result = algo_client.get_order(client_order_id) +result.print_object() diff --git a/example/algo/get_order_history.py b/example/algo/get_order_history.py new file mode 100644 index 0000000..896d5f9 --- /dev/null +++ b/example/algo/get_order_history.py @@ -0,0 +1,10 @@ +from huobi.client.algo import AlgoClient +from huobi.constant import * +from huobi.utils import * + +symbol_test = "adausdt" +account_id = g_account_id + +algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key) +result = algo_client.get_order_history(symbol_test, AlgoOrderStatus.TRIGGERED) +LogInfo.output_list(result) diff --git a/example/algo/post_cancel_algo_orders.py b/example/algo/post_cancel_algo_orders.py new file mode 100644 index 0000000..272ba81 --- /dev/null +++ b/example/algo/post_cancel_algo_orders.py @@ -0,0 +1,17 @@ +from huobi.client.algo import AlgoClient +from huobi.constant import * +from huobi.utils import * + +symbol_test = "adausdt" +account_id = g_account_id + +orders_to_cancel = ["test003", "test001"] +algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key) +result = algo_client.cancel_orders(orders_to_cancel) +result.print_object() + +# order_id = algo_client.create_order(symbol=symbol_test, account_id=account_id, order_type=OrderType.BUY_MARKET, source=OrderSource.API, amount=5.0, price=1.292) +# LogInfo.output("created order id : {id}".format(id=order_id)) +# +# order_id = algo_client.create_order(symbol=symbol_test, account_id=account_id, order_type=OrderType.SELL_MARKET, source=OrderSource.API, amount=1.77, price=None) +# LogInfo.output("created order id : {id}".format(id=order_id)) diff --git a/example/algo/post_create_algo_order.py b/example/algo/post_create_algo_order.py new file mode 100644 index 0000000..c14670a --- /dev/null +++ b/example/algo/post_create_algo_order.py @@ -0,0 +1,12 @@ +from huobi.client.algo import AlgoClient +from huobi.constant import * +from huobi.utils import * + +symbol_test = "adausdt" +account_id = g_account_id + +algo_client = AlgoClient(api_key=g_api_key, secret_key=g_secret_key) +order_id = algo_client.create_order(symbol=symbol_test, account_id=account_id, order_side=OrderSide.BUY, + order_type=AlgoOrderType.LIMIT, order_size=65, order_price=0.08, stop_price=0.085, + client_order_id="test004") +LogInfo.output("created order id : {id}".format(id=order_id)) diff --git a/example/generic/get_market_status.py b/example/generic/get_market_status.py new file mode 100644 index 0000000..2b8c2ff --- /dev/null +++ b/example/generic/get_market_status.py @@ -0,0 +1,8 @@ +from huobi.client.generic import GenericClient + +generic_client = GenericClient() +market_status = generic_client.get_market_status() +print(market_status) + + + diff --git a/example/market/req_mbp.py b/example/market/req_mbp.py index a1d9fd6..b2c3232 100644 --- a/example/market/req_mbp.py +++ b/example/market/req_mbp.py @@ -5,9 +5,10 @@ def callback(mbp_event: 'MbpIncreaseEvent'): mbp_event.print_object() + def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) -market_client = MarketClient(init_log=True) -market_client.req_mbp("btcusdt,eosusdt", MbpLevel.MBP150, callback, error) +market_client = MarketClient(init_log=True) +market_client.req_mbp("btcusdt", MbpLevel.MBP5, callback, error) diff --git a/example/market/sub_mbp_full.py b/example/market/sub_mbp_full.py index bc5da76..e1cd3cb 100644 --- a/example/market/sub_mbp_full.py +++ b/example/market/sub_mbp_full.py @@ -1,12 +1,14 @@ from huobi.client.market import MarketClient from huobi.constant import * + def callback(mbp_event: 'MbpFullEvent'): mbp_event.print_object() + def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) -market_client = MarketClient(init_log=True) -market_client.sub_mbp_full("btcusdt,eosusdt", MbpLevel.MBP20, callback, error) +market_client = MarketClient(init_log=True) +market_client.sub_mbp_full("btcusdt,eosusdt", MbpLevel.MBP5, callback, error) diff --git a/example/market/sub_mbp_increase.py b/example/market/sub_mbp_increase.py index c7bbe7d..044781e 100644 --- a/example/market/sub_mbp_increase.py +++ b/example/market/sub_mbp_increase.py @@ -5,9 +5,10 @@ def callback(mbp_event: 'MbpIncreaseEvent'): mbp_event.print_object() + def error(e: 'HuobiApiException'): print(e.error_code + e.error_message) -market_client = MarketClient(init_log=True) -market_client.sub_mbp_increase("btcusdt,eosusdt", MbpLevel.MBP150, callback, error) +market_client = MarketClient(init_log=True) +market_client.sub_mbp_increase("btcusdt,eosusdt", MbpLevel.MBP5, callback, error) diff --git a/example/subuser/get_user_apikey_info.py b/example/subuser/get_user_apikey_info.py new file mode 100644 index 0000000..870dd67 --- /dev/null +++ b/example/subuser/get_user_apikey_info.py @@ -0,0 +1,7 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * +from huobi.utils import * + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) +apikey_info = subuser_client.get_user_apikey_info(122946475) +LogInfo.output_list(apikey_info) diff --git a/example/subuser/post_create_subuser.py b/example/subuser/post_create_subuser.py new file mode 100644 index 0000000..49b3909 --- /dev/null +++ b/example/subuser/post_create_subuser.py @@ -0,0 +1,17 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * +from huobi.utils import * +import string +import random + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) +userName = ''.join(random.choices(string.ascii_uppercase + string.digits, k=7)) +params = {"userList": [ + { + "userName": userName, + "note": "huobi" + } +]} + +userList = subuser_client.post_create_subuser(params) +LogInfo.output_list(userList) diff --git a/example/subuser/post_set_subuser_transferability.py b/example/subuser/post_set_subuser_transferability.py new file mode 100644 index 0000000..39f6f7b --- /dev/null +++ b/example/subuser/post_set_subuser_transferability.py @@ -0,0 +1,9 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * +from huobi.utils import * + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) +sub_uids = '122946475' + +transferability_result = subuser_client.post_set_subuser_transferability(sub_uids, False) +LogInfo.output_list(transferability_result) diff --git a/example/subuser/post_subuser_apikey_deletion.py b/example/subuser/post_subuser_apikey_deletion.py new file mode 100644 index 0000000..b493619 --- /dev/null +++ b/example/subuser/post_subuser_apikey_deletion.py @@ -0,0 +1,10 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * +from huobi.utils import * + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) +sub_uid = '122946475' +access_key = '7ab679d7-b9fee8ed-9cd4cd8a-bgbfh5tv3f' + +result = subuser_client.post_subuser_apikey_deletion(sub_uid, access_key) +LogInfo.output(result) diff --git a/example/subuser/post_subuser_apikey_generation.py b/example/subuser/post_subuser_apikey_generation.py new file mode 100644 index 0000000..f2d65b2 --- /dev/null +++ b/example/subuser/post_subuser_apikey_generation.py @@ -0,0 +1,13 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) + +otp_token = '746316' +sub_uid = 122946475 +note = "huobi_subuser" +permission = 'readOnly' +# ip_addresses = '' + +result = subuser_client.post_subuser_apikey_generate(otp_token, sub_uid, note, permission) +result.print_object() diff --git a/example/subuser/post_subuser_apikey_modification.py b/example/subuser/post_subuser_apikey_modification.py new file mode 100644 index 0000000..63a1c51 --- /dev/null +++ b/example/subuser/post_subuser_apikey_modification.py @@ -0,0 +1,12 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) + +subUid = 122946475 +access_key = "abc" +note = "test" +permission = 'readOnly,trade' + +result = subuser_client.post_subuser_apikey_modification(subUid, access_key, permission=permission, note=note) +result.print_object() diff --git a/example/subuser/post_trade_market.py b/example/subuser/post_trade_market.py new file mode 100644 index 0000000..dd0df19 --- /dev/null +++ b/example/subuser/post_trade_market.py @@ -0,0 +1,12 @@ +from huobi.client.subuser import SubuserClient +from huobi.constant import * +from huobi.utils import * + +subuser_client = SubuserClient(api_key=g_api_key, secret_key=g_secret_key) + +subUids = '159284259' +accountType = SubuserTradePrivilegeType.MARGIN +activation = SubUserTradeStatus.DEACTIVATED + +subUserList = subuser_client.post_set_tradable_market(subUids, accountType, activation) +LogInfo.output_list(subUserList) diff --git a/example/wallet/get_account_withdraw_address.py b/example/wallet/get_account_withdraw_address.py new file mode 100644 index 0000000..4d43068 --- /dev/null +++ b/example/wallet/get_account_withdraw_address.py @@ -0,0 +1,14 @@ + +from huobi.client.wallet import WalletClient +from huobi.constant import * +from huobi.utils import * + + +wallet_client = WalletClient(api_key=g_api_key, secret_key=g_secret_key) +list_obj = wallet_client.get_account_withdraw_address(currency="usdt") +LogInfo.output_list(list_obj) + + + + + diff --git a/huobi/client/account.py b/huobi/client/account.py index 3c38dd5..8a0ef05 100644 --- a/huobi/client/account.py +++ b/huobi/client/account.py @@ -3,6 +3,8 @@ from huobi.utils import * import aiohttp import asyncio +from huobi.utils.input_checker import check_in_list + class AccountClient(object): @@ -26,14 +28,14 @@ def get_accounts(self): from huobi.service.account.get_accounts import GetAccountsService return GetAccountsService({}).request(**self.__kwargs) - def get_balance(self, account_id:'int'): + def get_balance(self, account_id: 'int'): """ Get the account list. :return: The list of accounts data. """ check_should_not_none(account_id, "account-id") params = { - "account-id" : account_id + "account-id": account_id } from huobi.service.account.get_balance import GetBalanceService return GetBalanceService(params).request(**self.__kwargs) @@ -61,6 +63,7 @@ async def async_get_account_balance(self, balance_full_url, account_id, ret_map) """ (SDK encapsulated api) to easily use but not recommend for low performance and frequence limitation """ + def get_account_balance(self) -> list: from huobi.service.account.get_balance import GetBalanceService """ @@ -76,10 +79,11 @@ def get_account_balance(self) -> list: account_balance_json_map = {} for account_item in accounts: account_obj_map[account_item.id] = account_item - balance_params = {"account-id" : account_item.id} + balance_params = {"account-id": account_item.id} balance_request = GetBalanceService(balance_params).get_request(**self.__kwargs) balance_url = server_url + balance_request.url - tasks.append(asyncio.ensure_future(self.async_get_account_balance(balance_url, account_item.id, account_balance_json_map))) + tasks.append(asyncio.ensure_future( + self.async_get_account_balance(balance_url, account_item.id, account_balance_json_map))) loop = asyncio.get_event_loop() try: @@ -109,7 +113,7 @@ def get_account_balance_by_subuid(self, sub_uid): """ check_should_not_none(sub_uid, "sub-uid") params = { - "sub-uid" : sub_uid + "sub-uid": sub_uid } from huobi.service.account.get_account_balance_by_subuid import GetAccountBalanceBySubUidService return GetAccountBalanceBySubUidService(params).request(**self.__kwargs) @@ -120,12 +124,12 @@ def get_aggregated_subuser_balance(self): :return: The balance of all the sub-account aggregated. """ - params={} + params = {} from huobi.service.account.get_aggregate_subuser_balance import GetAggregateSubUserBalanceService return GetAggregateSubUserBalanceService(params).request(**self.__kwargs) def transfer_between_parent_and_subuser(self, sub_uid: 'int', currency: 'str', amount: 'float', - transfer_type: 'TransferMasterType'): + transfer_type: 'TransferMasterType'): """ Transfer Asset between Parent and Sub Account. @@ -141,16 +145,14 @@ def transfer_between_parent_and_subuser(self, sub_uid: 'int', currency: 'str', a check_should_not_none(transfer_type, "type") params = { - "sub-uid" : sub_uid, - "currency" : currency, - "amount" : amount, - "type" : transfer_type + "sub-uid": sub_uid, + "currency": currency, + "amount": amount, + "type": transfer_type } from huobi.service.account.post_subaccount_transfer import PostSubaccountTransferService return PostSubaccountTransferService(params).request(**self.__kwargs) - - def sub_account_update(self, mode: 'AccountBalanceMode', callback, error_handler=None): """ Subscribe accounts update @@ -175,7 +177,7 @@ def sub_account_update(self, mode: 'AccountBalanceMode', callback, error_handler mode = AccountBalanceMode.BALANCE params = { - "mode" : mode, + "mode": mode, } from huobi.service.account.sub_account_update_v2 import SubAccountUpdateV2Service @@ -197,14 +199,14 @@ def req_account_balance(self, callback, client_req_id=None, error_handler=None): check_should_not_none(callback, "callback") params = { - "client_req_id" : client_req_id + "client_req_id": client_req_id } from huobi.service.account.req_account_balance import ReqAccountBalanceService ReqAccountBalanceService(params).subscribe(callback, error_handler, **self.__kwargs) def transfer_between_futures_and_pro(self, currency: 'str', amount: 'float', - transfer_type: 'TransferFuturesPro')-> int: + transfer_type: 'TransferFuturesPro') -> int: """ Transfer Asset between Futures and Contract. @@ -219,15 +221,14 @@ def transfer_between_futures_and_pro(self, currency: 'str', amount: 'float', check_should_not_none(amount, "amount") check_should_not_none(transfer_type, "transfer_type") params = { - "currency" : currency, - "amount" : amount, - "type" : transfer_type + "currency": currency, + "amount": amount, + "type": transfer_type } from huobi.service.account.post_futures_and_pro_transfer import PostTransferBetweenFuturesAndProService return PostTransferBetweenFuturesAndProService(params).request(**self.__kwargs) - def get_account_balance_by_subuid(self, sub_uid): """ Get account balance of a sub-account. @@ -237,7 +238,7 @@ def get_account_balance_by_subuid(self, sub_uid): """ check_should_not_none(sub_uid, "sub-uid") params = { - "sub-uid" : sub_uid + "sub-uid": sub_uid } from huobi.service.account.get_account_balance_by_subuid import GetAccountBalanceBySubUidService return GetAccountBalanceBySubUidService(params).request(**self.__kwargs) @@ -269,7 +270,7 @@ def get_account_history(self, account_id: 'int', currency: 'str' = None, from huobi.service.account.get_account_history import GetAccountHistoryService return GetAccountHistoryService(params).request(**self.__kwargs) - def post_sub_uid_management(self, sub_uid:'int', action:'str'): + def post_sub_uid_management(self, sub_uid: 'int', action: 'str'): """ use to freeze or unfreeze the sub uid @@ -313,4 +314,30 @@ def get_account_ledger(self, account_id: 'int', currency: 'str' = None, transact "fromId": from_id } from huobi.service.account.get_account_ledger import GetAccountLedgerService - return GetAccountLedgerService(params).request(**self.__kwargs) \ No newline at end of file + return GetAccountLedgerService(params).request(**self.__kwargs) + + def post_account_transfer(self, from_user: 'int', from_account_type: 'str', from_account: 'int', to_user: 'int', + to_account_type: 'str', to_account: 'int', currency: 'str', amount: 'str'): + check_should_not_none(from_user, "from-user") + check_should_not_none(from_account_type, "from-account-type") + check_should_not_none(from_account, "from_account") + check_should_not_none(to_user, "to-user") + check_should_not_none(to_account, "to-account") + check_should_not_none(to_account_type, "to-account") + check_should_not_none(currency, "currency") + + check_in_list(from_account_type, [AccountType.SPOT], "from_account_type") + check_in_list(to_account_type, [AccountType.SPOT], "to_account_type") + + params = { + "from-user": from_user, + "from-account-type": from_account_type, + "from-account": from_account, + "to-user": to_user, + "to-account-type": to_account_type, + "to-account": to_account, + "currency": currency, + "amount": amount + } + from huobi.service.account.post_account_transfer import PostAccountTransferService + return PostAccountTransferService(params).request(**self.__kwargs) diff --git a/huobi/client/algo.py b/huobi/client/algo.py new file mode 100644 index 0000000..d5d8151 --- /dev/null +++ b/huobi/client/algo.py @@ -0,0 +1,128 @@ +from huobi.model.algo import * +from huobi.utils.input_checker import * + + +class AlgoClient(object): + + def __init__(self, **kwargs): + """ + Create the request client instance. + :param kwargs: The option of request connection. + api_key: The public key applied from Huobi. + secret_key: The private key applied from Huobi. + url: The URL name like "https://api.huobi.pro". + init_log: to init logger + """ + self.__kwargs = kwargs + + def create_order(self, account_id: 'int', symbol: 'str', order_side: 'OrderSide', order_type: 'OrderType', + client_order_id: 'str', stop_price: 'str', order_price: 'str' = None, order_size: 'str' = None, + order_value: 'str' = None, time_in_force: 'str' = None, trailing_rate: 'str' = None) -> int: + """ + Make an algo order in huobi. + :param account_id: Account id. (mandatory) + :param symbol: The symbol, like "btcusdt". (mandatory) + :param order_side: the Order side, possible values: buy,sell. (mandatory) + :param order_type: The order type, possible values: limit, market. (mandatory) + :param stop_price: The stop price. (mandatory) + :param order_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 order_size: The amount of market order only + :param order_value: for market buy order only + :param stop_price: Price for auto sell to get the max benefit + :param time_in_force: gtc(invalid for orderType=market), boc(invalid orderType=market),ioc,fok(invalid for orderType=market) + :param trailing_rate: for trailing orders only + :param client_order_id: unique Id which is user defined and must be unique in recent 24 hours + """ + + params = self.create_order_param_check(symbol, account_id, order_side, order_type, stop_price, order_price, + order_size, order_value, time_in_force, trailing_rate, client_order_id) + from huobi.service.algo.post_create_order import PostCreateOrderService + return PostCreateOrderService(params).request(**self.__kwargs) + + def cancel_orders(self, client_order_ids) -> CancelOrderResult: + check_should_not_none(client_order_ids, "clientOrderIds") + + params = { + "clientOrderIds": client_order_ids + } + from huobi.service.algo.post_cancel_orders import PostCancelOrderService + return PostCancelOrderService(params).request(**self.__kwargs) + + def get_open_orders(self, account_id: 'str' = None, symbol: 'str' = None, order_side: 'OrderSide' = None, + order_type: 'AlgoOrderType' = None, sort: 'SortDesc' = None, limit: 'int' = 100, + from_id: 'int' = None): + + params = { + "accountId": account_id, + "symbol": symbol, + "orderSide": order_side, + "orderType": order_type, + "sort": sort, + "limit": limit, + "fromId": from_id + } + from huobi.service.algo.get_open_orders import GetOpenOrdersService + return GetOpenOrdersService(params).request(**self.__kwargs) + + def get_order_history(self, symbol: 'str', order_status: 'AlgoOrderStatus', account_id: 'str' = None, + order_side: 'OrderSide' = None, order_type: 'AlgoOrderType' = None, start_time: 'int' = None, + end_time: 'int' = None, sort: 'SortDesc' = SortDesc.DESC, limit: 'int' = 100, + from_id: 'int' = None): + + params = { + "symbol": symbol, + "accountId": account_id, + "orderSide": order_side, + "orderType": order_type, + "orderStatus": order_status, + "startTime": start_time, + "endTime": end_time, + "sort": sort, + "limit": limit, + "fromId": from_id + } + from huobi.service.algo.get_order_history import GetOrderHistoryService + return GetOrderHistoryService(params).request(**self.__kwargs) + + def get_order(self, client_order_id: 'str'): + params = { + "clientOrderId": client_order_id + } + from huobi.service.algo.get_order_by_cid import GetOrderByClientOrderIdService + return GetOrderByClientOrderIdService(params).request(**self.__kwargs) + + + def create_order_param_check(self, symbol, account_id, order_side, order_type, stop_price, order_price, + order_size, order_value, time_in_force, trailing_rate, client_order_id): + check_symbol(symbol) + check_should_not_none(account_id, "accountId") + check_should_not_none(order_type, "orderType") + check_should_not_none(order_side, "orderSide") + + if order_type == OrderType.SELL_LIMIT \ + or order_type == OrderType.BUY_LIMIT \ + or order_type == OrderType.BUY_LIMIT_MAKER \ + or order_type == OrderType.SELL_LIMIT_MAKER: + check_should_not_none(order_price, "orderPrice") + + if time_in_force is not None: + check_time_in_force(time_in_force) + + if order_type in [OrderType.SELL_MARKET, OrderType.BUY_MARKET]: + order_price = None + + params = { + "accountId": account_id, + "symbol": symbol, + "orderPrice": order_price, + "orderSide": order_side, + "orderSize": order_size, + "orderValue": order_value, + "timeInForce": time_in_force, + "orderType": order_type, + "clientOrderId": client_order_id, + "stopPrice": stop_price, + "trailingRate": trailing_rate + } + + return params diff --git a/huobi/client/generic.py b/huobi/client/generic.py index ffc138c..ddc0ce1 100644 --- a/huobi/client/generic.py +++ b/huobi/client/generic.py @@ -3,7 +3,6 @@ from huobi.model.generic import * - class GenericClient(object): def __init__(self, **kwargs): @@ -70,7 +69,7 @@ def get_exchange_info(self) -> ExchangeInfo: ret.currencies = self.get_exchange_currencies() return ret - def get_reference_currencies(self, currency:'str'=None, is_authorized_user:'bool' =None) ->list: + def get_reference_currencies(self, currency: 'str' = None, is_authorized_user: 'bool' = None) -> list: """ Get all the trading assets and currencies supported in huobi. The information of trading instrument, including base currency, quote precision, etc. @@ -81,14 +80,13 @@ def get_reference_currencies(self, currency:'str'=None, is_authorized_user:'bool """ params = { - "currency" : currency, - "authorizedUser" : is_authorized_user + "currency": currency, + "authorizedUser": is_authorized_user } from huobi.service.generic.get_reference_currencies import GetReferenceCurrenciesService return GetReferenceCurrenciesService(params).request(**self.__kwargs) - def get_system_status(self) -> str: """ get system status @@ -97,4 +95,8 @@ def get_system_status(self) -> str: """ from huobi.service.generic.get_system_status import GetSystemStatusService - return GetSystemStatusService({}).request(**self.__kwargs) \ No newline at end of file + return GetSystemStatusService({}).request(**self.__kwargs) + + def get_market_status(self): + from huobi.service.generic.get_market_status import GetMarketStatusService + return GetMarketStatusService({}).request(**self.__kwargs) diff --git a/huobi/client/market.py b/huobi/client/market.py index b398275..7d281be 100644 --- a/huobi/client/market.py +++ b/huobi/client/market.py @@ -1,4 +1,3 @@ - from huobi.constant import * from huobi.model.market import * from huobi.utils import * @@ -61,15 +60,15 @@ def sub_candlestick(self, symbols: 'str', interval: 'CandlestickInterval', callb check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, - "interval" : interval, + "symbol_list": symbol_list, + "interval": interval, } from huobi.service.market.sub_candlestick import SubCandleStickService SubCandleStickService(params).subscribe(callback, error_handler, **self.__kwargs) def req_candlestick(self, symbols: 'str', interval: 'CandlestickInterval', callback, - from_ts_second = None, end_ts_second = None, error_handler=None): + from_ts_second=None, end_ts_second=None, error_handler=None): """ Subscribe candlestick/kline event. If the candlestick/kline is updated, server will send the data to client and onReceive in callback will be called. @@ -92,10 +91,10 @@ def req_candlestick(self, symbols: 'str', interval: 'CandlestickInterval', callb check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, - "interval" : interval, - "from_ts_second" : from_ts_second, - "end_ts_second" : end_ts_second + "symbol_list": symbol_list, + "interval": interval, + "from_ts_second": from_ts_second, + "end_ts_second": end_ts_second } from huobi.service.market.req_candlestick import ReqCandleStickService @@ -113,7 +112,8 @@ def get_pricedepth(self, symbol: 'str', depth_type: 'str', depth_size: 'int' = N """ check_symbol(symbol) - check_in_list(depth_type, [DepthStep.STEP0, DepthStep.STEP1, DepthStep.STEP2, DepthStep.STEP3, DepthStep.STEP4, DepthStep.STEP5], "depth_type") + check_in_list(depth_type, [DepthStep.STEP0, DepthStep.STEP1, DepthStep.STEP2, DepthStep.STEP3, DepthStep.STEP4, + DepthStep.STEP5], "depth_type") params = { "symbol": symbol, "type": depth_type, @@ -170,8 +170,8 @@ def sub_pricedepth(self, symbols: 'str', depth_step: 'str', callback, error_hand check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, - "step" : new_step, + "symbol_list": symbol_list, + "step": new_step, } from huobi.service.market.sub_pricedepth import SubPriceDepthService @@ -196,7 +196,7 @@ def sub_pricedepth_bbo(self, symbols: 'str', callback, error_handler=None): check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, + "symbol_list": symbol_list, } from huobi.service.market.sub_pricedepth_bbo import SubPriceDepthBboService @@ -265,7 +265,7 @@ def sub_market_detail(self, symbols: 'str', callback, error_handler=None): check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, + "symbol_list": symbol_list, } from huobi.service.market.sub_market_detail import SubMarketDetailService @@ -326,7 +326,7 @@ def get_history_trade(self, symbol: 'str', size: 'int' = None) -> list: params = { "symbol": symbol, - "size" : size + "size": size } from huobi.service.market.get_history_trade import GetHistoryTradeService @@ -349,9 +349,8 @@ def sub_trade_detail(self, symbols: 'str', callback, error_handler=None): check_symbol_list(symbol_list) check_should_not_none(callback, "callback") - params = { - "symbol_list" : symbol_list, + "symbol_list": symbol_list, } from huobi.service.market.sub_trade_detail import SubTradeDetailService @@ -375,7 +374,7 @@ def req_trade_detail(self, symbols: 'str', callback, error_handler=None): check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, + "symbol_list": symbol_list, } from huobi.service.market.req_trade_detail import ReqTradeDetailService @@ -401,10 +400,10 @@ def get_market_tickers(self) -> list: from huobi.service.market.get_market_tickers import GetMarketTickersService return GetMarketTickersService(params).request(**self.__kwargs) - """ increase mbp(market by price) """ + def sub_mbp_increase(self, symbols: 'str', levels: 'int', callback, error_handler=None): """ Subscribe mbp event. If the mbp is updated, server will send the data to client and onReceive in callback will be called. @@ -427,17 +426,17 @@ def sub_mbp_increase(self, symbols: 'str', levels: 'int', callback, error_handle check_should_not_none(callback, "callback") params = { - "symbol_list" : symbol_list, - "levels" : levels + "symbol_list": symbol_list, + "levels": levels } from huobi.service.market.sub_mbp_increase import SubMbpIncreaseService SubMbpIncreaseService(params).subscribe(callback, error_handler, **self.__kwargs) - """ subscribe full mbp(market by price) """ + def sub_mbp_full(self, symbols: 'str', levels: 'int', callback, error_handler=None): """ Subscribe full mbp event. If the mbp is updated, server will send the data to client and onReceive in callback will be called. @@ -457,6 +456,7 @@ def sub_mbp_full(self, symbols: 'str', levels: 'int', callback, error_handler=No symbol_list = symbols.split(",") check_symbol_list(symbol_list) check_should_not_none(levels, "levels") + check_in_list(levels, [MbpLevel.MBP5, MbpLevel.MBP10, MbpLevel.MBP20], "levels") check_should_not_none(callback, "callback") params = { @@ -467,7 +467,7 @@ def sub_mbp_full(self, symbols: 'str', levels: 'int', callback, error_handler=No from huobi.service.market.sub_mbp_full import SubMbpFullService SubMbpFullService(params).subscribe(callback, error_handler, **self.__kwargs) - def req_mbp(self, symbols: 'str', levels: 'int', callback, auto_close = True, error_handler=None): + def req_mbp(self, symbols: 'str', levels: 'int', callback, auto_close=True, error_handler=None): """ Subscribe mbp event. If the mbp is updated, server will send the data to client and onReceive in callback will be called. @@ -493,4 +493,4 @@ def req_mbp(self, symbols: 'str', levels: 'int', callback, auto_close = True, er "levels": levels } from huobi.service.market.req_mbp import ReqMbpService - ReqMbpService(params).subscribe(callback, error_handler, **self.__kwargs) \ No newline at end of file + ReqMbpService(params).subscribe(callback, error_handler, **self.__kwargs) diff --git a/huobi/client/subuser.py b/huobi/client/subuser.py new file mode 100644 index 0000000..87b26a8 --- /dev/null +++ b/huobi/client/subuser.py @@ -0,0 +1,109 @@ +from huobi.utils import * +from huobi.constant import * +from huobi.utils.input_checker import check_in_list + + +class SubuserClient(object): + def __init__(self, **kwargs): + """ + Create the request client instance. + :param kwargs: The option of request connection. + api_key: The public key applied from Huobi. + secret_key: The private key applied from Huobi. + url: The URL name like "https://api.huobi.pro". + init_log: Init logger, default is False, True will init logger handler + """ + self.__kwargs = kwargs + + def post_create_subuser(self, user_list): + check_should_not_none(user_list, 'userList') + + params = user_list + from huobi.service.subuser.post_create_subuser import PostSubuserCreationService + return PostSubuserCreationService(params).request(**self.__kwargs) + + def post_set_tradable_market(self, sub_uids, account_type: 'SubuserTradePrivilegeType', + activation: 'SubUserTradeStatus'): + check_should_not_none(sub_uids, 'subUids') + check_should_not_none(account_type, 'accountType') + check_should_not_none(activation, 'activation') + + check_in_list(account_type, + [SubuserTradePrivilegeType.MARGIN, SubuserTradePrivilegeType.SUPER_MARGIN], "accountType") + check_in_list(activation, [SubUserTradeStatus.ACTIVATED, SubUserTradeStatus.DEACTIVATED], "activation") + + params = { + 'subUids': sub_uids, + 'accountType': account_type, + 'activation': activation + } + from huobi.service.subuser.post_tradable_market import PostTradableMarketService + return PostTradableMarketService(params).request(**self.__kwargs) + + def post_set_subuser_transferability(self, sub_uids: 'str', transferrable: 'bool', + account_type: 'AccountType' = AccountType.SPOT): + check_should_not_none(sub_uids, 'subUids') + check_should_not_none(transferrable, 'transferrable') + check_in_list(account_type, [AccountType.SPOT], 'accountType') + + params = { + "subUids": sub_uids, + "accountType": account_type, + "transferrable": transferrable + } + from huobi.service.subuser.post_set_transferability import PostSetSubuserTransferability + return PostSetSubuserTransferability(params).request(**self.__kwargs) + + def post_subuser_apikey_generate(self, otp_token: 'str', sub_uid: 'int', note: 'str', permission: 'bool', + ip_addresses: 'str' = None): + check_should_not_none(otp_token, 'otpToken') + check_should_not_none(sub_uid, 'subUid') + check_should_not_none(note, 'note') + check_should_not_none(permission, 'permission') + # check_in_list(permission, [AccountType.SPOT], 'accountType') + + params = { + "otpToken": otp_token, + "subUid": sub_uid, + "note": note, + "permission": permission, + "ipAddresses": ip_addresses + } + from huobi.service.subuser.post_subuser_apikey_generation import PostSubuserApikeyGenerationService + return PostSubuserApikeyGenerationService(params).request(**self.__kwargs) + + def get_user_apikey_info(self, uid: 'str', access_key: 'str' = None): + check_should_not_none(uid, 'uid') + + params = { + "uid": uid, + "accessKey": access_key + } + from huobi.service.subuser.get_user_apikey_info import GetUserApikeyInfoService + return GetUserApikeyInfoService(params).request(**self.__kwargs) + + def post_subuser_apikey_modification(self, sub_uid: 'str', access_key: 'str', note: 'str' = None, + permission: 'str' = None, ip_addresses: 'str' = None): + check_should_not_none(sub_uid, 'subUid') + check_should_not_none(access_key, 'accessKey') + + params = { + "subUid": sub_uid, + "accessKey": access_key, + "note": note, + "permission": permission, + "ipAddresses": ip_addresses + } + from huobi.service.subuser.post_subuser_apikey_modification import PostSubuserApikeyModificationService + return PostSubuserApikeyModificationService(params).request(**self.__kwargs) + + def post_subuser_apikey_deletion(self, sub_uid: 'str', access_key: 'str'): + check_should_not_none(sub_uid, 'subUid') + check_should_not_none(access_key, 'accessKey') + + params = { + "subUid": sub_uid, + "accessKey": access_key + } + from huobi.service.subuser.post_subuser_apikey_deletion import PostSubuserApikeyDeletionService + return PostSubuserApikeyDeletionService(params).request(**self.__kwargs) diff --git a/huobi/client/wallet.py b/huobi/client/wallet.py index 75d6608..519b822 100644 --- a/huobi/client/wallet.py +++ b/huobi/client/wallet.py @@ -1,4 +1,3 @@ - from huobi.utils.input_checker import * from huobi.model.wallet import * @@ -16,7 +15,8 @@ def __init__(self, **kwargs): """ self.__kwargs = kwargs - def get_deposit_withdraw(self, op_type:'str', currency: 'str'=None, from_id: 'int'=None, size: 'int'=None, direct:'str'=None) -> list: + 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. @@ -41,7 +41,7 @@ def get_deposit_withdraw(self, op_type:'str', currency: 'str'=None, from_id: 'in return GetDepositWithdrawService(params).request(**self.__kwargs) def post_create_withdraw(self, address: 'str', amount: 'float', currency: 'str', fee: 'float', - chain:'str' =None, address_tag: 'str' = None) -> int: + chain: 'str' = None, address_tag: 'str' = None) -> int: """ Submit a request to withdraw some asset from an account. @@ -64,7 +64,7 @@ def post_create_withdraw(self, address: 'str', amount: 'float', currency: 'str', "amount": amount, "fee": fee, "chain": chain, - "addr-tag" : address_tag + "addr-tag": address_tag } from huobi.service.wallet.post_create_withdraw import PostCreateWithdrawService @@ -84,7 +84,7 @@ def post_cancel_withdraw(self, withdraw_id: 'int') -> int: from huobi.service.wallet.post_cancel_withdraw import PostCancelWithdrawService return PostCancelWithdrawService(params).request(**self.__kwargs) - def get_account_deposit_address(self, currency: 'str') ->list: + def get_account_deposit_address(self, currency: 'str') -> list: """ Get deposit address of corresponding chain, for a specific crypto currency (except IOTA) @@ -100,7 +100,7 @@ def get_account_deposit_address(self, currency: 'str') ->list: from huobi.service.wallet.get_account_deposit_address import GetAccountDepositAddressService return GetAccountDepositAddressService(params).request(**self.__kwargs) - def get_account_withdraw_quota(self, currency: 'str')->list: + def get_account_withdraw_quota(self, currency: 'str') -> list: """ Get the withdraw quota for currencies @@ -162,4 +162,18 @@ def get_sub_user_deposit_address(self, sub_uid: 'int', currency: 'str') -> list: } from huobi.service.wallet.get_sub_user_deposit_address import GetSubUserDepositAddressService - return GetSubUserDepositAddressService(params).request(**self.__kwargs) \ No newline at end of file + return GetSubUserDepositAddressService(params).request(**self.__kwargs) + + def get_account_withdraw_address(self, currency: 'str', chain: 'str'=None, note: 'str'=None, limit: 'int' = 100, + fromid: 'int' = None): + check_should_not_none(currency, "currency") + params = { + "currency": currency, + "chain": chain, + "note": note, + "limit": limit, + "fromid": fromid + } + from huobi.service.wallet.get_account_withdraw_address import GetAccountWithdrawAddressService + return GetAccountWithdrawAddressService(params).request(**self.__kwargs) + diff --git a/huobi/connection/impl/websocket_manage.py b/huobi/connection/impl/websocket_manage.py index 542f8db..f590601 100644 --- a/huobi/connection/impl/websocket_manage.py +++ b/huobi/connection/impl/websocket_manage.py @@ -62,6 +62,7 @@ def __init__(self, api_key, secret_key, uri, request): self.__thread = None self.__market_url = HUOBI_WEBSOCKET_URI_PRO + "/ws" self.__trading_url = HUOBI_WEBSOCKET_URI_PRO + "/ws/" + request.api_version + self.__mbp_feed_url = HUOBI_WEBSOCKET_URI_PRO + "/feed" self.__api_key = api_key self.__secret_key = secret_key self.request = request @@ -76,12 +77,17 @@ def __init__(self, api_key, secret_key, uri, request): host = urllib.parse.urlparse(uri).hostname if host.find("api") == 0: self.__market_url = "wss://" + host + "/ws" + self.__mbp_feed_url = "wss://" + host + "/feed" self.__trading_url = "wss://" + host + "/ws/" + request.api_version else: self.__market_url = "wss://" + host + "/api/ws" + self.__mbp_feed_url = "wss://" + host + "/feed" self.__trading_url = "wss://" + host + "/ws/" + request.api_version + if request.is_trading: self.url = self.__trading_url + elif request.is_mbp_feed: + self.url = self.__mbp_feed_url else: self.url = self.__market_url diff --git a/huobi/connection/impl/websocket_request.py b/huobi/connection/impl/websocket_request.py index 6eaf37d..9efd1de 100644 --- a/huobi/connection/impl/websocket_request.py +++ b/huobi/connection/impl/websocket_request.py @@ -7,6 +7,7 @@ def __init__(self): self.subscription_handler = None self.auto_close = False # close connection after receive data, for subscribe set False, for request set True self.is_trading = False + self.is_mbp_feed = False self.error_handler = None self.json_parser = None self.update_callback = None diff --git a/huobi/connection/subscribe_client.py b/huobi/connection/subscribe_client.py index 650e55b..3a46845 100644 --- a/huobi/connection/subscribe_client.py +++ b/huobi/connection/subscribe_client.py @@ -7,8 +7,7 @@ class SubscribeClient(object): - - #static property + # static property subscribe_watch_dog = WebSocketWatchDog() def __init__(self, **kwargs): @@ -40,10 +39,11 @@ def __create_websocket_manage(self, request): manager.connect() SubscribeClient.subscribe_watch_dog.on_connection_created(manager) - def create_request(self, subscription_handler, parse, callback, error_handler, is_trade): + def create_request(self, subscription_handler, parse, callback, error_handler, is_trade, is_mbp_feed=False): request = WebsocketRequest() request.subscription_handler = subscription_handler request.is_trading = is_trade + request.is_mbp_feed = is_mbp_feed request.auto_close = False # subscribe need connection. websocket request need close request. request.json_parser = parse request.update_callback = callback @@ -51,16 +51,18 @@ def create_request(self, subscription_handler, parse, callback, error_handler, i return request def create_request_v1(self, subscription_handler, parse, callback, error_handler, is_trade=False): - request = self.create_request(subscription_handler=subscription_handler, parse=parse, callback=callback, error_handler=error_handler, is_trade=is_trade) + request = self.create_request(subscription_handler=subscription_handler, parse=parse, callback=callback, + error_handler=error_handler, is_trade=is_trade) request.api_version = ApiVersion.VERSION_V1 return request def create_request_v2(self, subscription_handler, parse, callback, error_handler, is_trade=False): - request = self.create_request(subscription_handler=subscription_handler, parse=parse, callback=callback, error_handler=error_handler, is_trade=is_trade) + request = self.create_request(subscription_handler=subscription_handler, parse=parse, callback=callback, + error_handler=error_handler, is_trade=is_trade) request.api_version = ApiVersion.VERSION_V2 return request - def execute_subscribe_v1(self, subscription_handler, parse, callback, error_handler, is_trade = False): + def execute_subscribe_v1(self, subscription_handler, parse, callback, error_handler, is_trade=False): request = self.create_request_v1(subscription_handler, parse, callback, error_handler, is_trade) self.__create_websocket_manage(request) @@ -68,9 +70,13 @@ def execute_subscribe_v2(self, subscription_handler, parse, callback, error_hand request = self.create_request_v2(subscription_handler, parse, callback, error_handler, is_trade) self.__create_websocket_manage(request) + def execute_subscribe_mbp(self, subscription_handler, parse, callback, error_handler, is_trade=False, + is_mbp_feed=True): + request = self.create_request(subscription_handler, parse, callback, error_handler, is_trade, is_mbp_feed) + self.__create_websocket_manage(request) + def unsubscribe_all(self): for websocket_manage in self.__websocket_manage_list: SubscribeClient.subscribe_watch_dog.on_connection_closed(websocket_manage) websocket_manage.close() self.__websocket_manage_list.clear() - diff --git a/huobi/connection/websocket_req_client.py b/huobi/connection/websocket_req_client.py index ad22f9c..e74af07 100644 --- a/huobi/connection/websocket_req_client.py +++ b/huobi/connection/websocket_req_client.py @@ -33,18 +33,22 @@ def __create_websocket_manage(self, request): manager = WebsocketManage(self.__api_key, self.__secret_key, self.__uri, request) manager.connect() - def create_request(self, subscription_handler, parse, callback, error_handler, is_trade = False): + def create_request(self, subscription_handler, parse, callback, error_handler, is_trade=False, is_mbp_feed=False): request = WebsocketRequest() request.subscription_handler = subscription_handler request.is_trading = is_trade - request.auto_close = True # for websocket request, auto close the connection after request. + request.is_mbp_feed = is_mbp_feed + request.auto_close = True # for websocket request, auto close the connection after request. request.json_parser = parse request.update_callback = callback request.error_handler = error_handler return request - def execute_subscribe_v1(self, subscription_handler, parse, callback, error_handler, is_trade = False): + def execute_subscribe_v1(self, subscription_handler, parse, callback, error_handler, is_trade=False): request = self.create_request(subscription_handler, parse, callback, error_handler, is_trade) self.__create_websocket_manage(request) - + def execute_subscribe_mbp(self, subscription_handler, parse, callback, error_handler, is_trade=False, + is_mbp_feed=True): + request = self.create_request(subscription_handler, parse, callback, error_handler, is_trade, is_mbp_feed) + self.__create_websocket_manage(request) diff --git a/huobi/constant/definition.py b/huobi/constant/definition.py index 2e0bf52..99981b9 100644 --- a/huobi/constant/definition.py +++ b/huobi/constant/definition.py @@ -42,6 +42,17 @@ class OrderType: INVALID = None +class AlgoOrderType: + LIMIT = "limit" + MARKET = "market" + + +class AlgoOrderStatus: + CANCELED = "canceled" + REJECTED = "rejected" + TRIGGERED = "triggered" + + class AccountType: SPOT = "spot" MARGIN = "margin" @@ -82,6 +93,8 @@ class WithdrawState: CONFIRMED = "confirmed" CONFIRMERROR = "confirm-error" REPEALED = "repealed" + VERIFYING = "verifying" + FAILED = "failed" INVALID = None @@ -128,7 +141,7 @@ class OrderSource: class OrderState: - CREATED = "created" #for stop loss order + CREATED = "created" # for stop loss order PRE_SUBMITTED = "pre-submitted" SUBMITTING = "submitting" SUBMITTED = "submitted" @@ -142,6 +155,13 @@ class OrderState: INVALID = None +class TimeInForceType: + IOC = "ioc" + FOK = "fok" + BOC = "boc" + GTC = "gtc" + + class TransferMasterType: IN = "master-transfer-in" OUT = "master-transfer-out" @@ -196,19 +216,23 @@ class OperateMode: PONG = "pong" INVALID = None + class QueryDirection: PREV = "prev" NEXT = "next" INVALID = None + class TransferFuturesPro: TO_PRO = "futures-to-pro" TO_FUTURES = "pro-to-futures" + class MatchRole: MAKER = "maker" TAKER = "taker" + class DepthStep: STEP0 = "step0" STEP1 = "step1" @@ -217,27 +241,32 @@ class DepthStep: STEP4 = "step4" STEP5 = "step5" + class DepthSize: SIZE5 = 5 SIZE10 = 10 SIZE20 = 20 + class MbpLevel: MBP5 = 5 MBP10 = 10 MBP20 = 20 MBP150 = 150 - + + class ChainDepositStatus: ALLOWED = "allowed" PROHIBITED = "prohibited" INVALID = None + class ChainWithdrawStatus: ALLOWED = "allowed" PROHIBITED = "prohibited" INVALID = None + class InstrumentStatus: NORMAL = "normal" DELISTED = "delisted" @@ -263,11 +292,13 @@ class FeeDeductType: DEDUCT_BY_POINT = "point" INVALID = None + class SubUidAction: UNLOCK = "unlock" LOCK = "lock" INVALID = None + class SubUidState: NORMAL = "normal" LOCK = "lock" @@ -296,6 +327,28 @@ class AccountTransactType: EXCHANGE = "exchange" OTHER = "other-types" + class SortDesc: ASC = "asc" - DESC = "desc" \ No newline at end of file + DESC = "desc" + + +class SubuserTradePrivilegeType: + MARGIN = "isolated-margin" + SUPER_MARGIN = "cross-margin" + + +class SubUserTradeStatus: + ACTIVATED = "activated" + DEACTIVATED = "deactivated" + + +class MarketStatus: + NORMAL: 1 + HALTED: 2 + CANCEL_ONLY: 3 + + +class HaltReason: + EMERGENCY_MAINTENANCE: 2 + SCHEDULED_MAINTENANCE: 3 diff --git a/huobi/model/account/__init__.py b/huobi/model/account/__init__.py index 3e4eb2d..cf344cc 100644 --- a/huobi/model/account/__init__.py +++ b/huobi/model/account/__init__.py @@ -9,5 +9,6 @@ from huobi.model.account.account_history import AccountHistory from huobi.model.account.sub_uid_management import SubUidManagement from huobi.model.account.account_ledger import AccountLedger +from huobi.model.account.account_transfer_result import AccountTransferResult diff --git a/huobi/model/account/account_transfer_result.py b/huobi/model/account/account_transfer_result.py new file mode 100644 index 0000000..114497d --- /dev/null +++ b/huobi/model/account/account_transfer_result.py @@ -0,0 +1,23 @@ +from huobi.constant import * + + +class AccountTransferResult: + """ + The account information for spot account, margin account etc. + + :member + id: The unique account id. + account_type: The type of this account, possible value: spot, margin, otc, point. + account_state: The account state, possible value: working, lock. + balances: The balance list of the specified currency. The content is Balance class + + """ + + def __init__(self): + self.transact_id = 0 + self.transact_time = 0 + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.transact_id, format_data + "TransactionId") + PrintBasic.print_basic(self.transact_time, format_data + "TransactionTime") diff --git a/huobi/model/algo/__init__.py b/huobi/model/algo/__init__.py new file mode 100644 index 0000000..a7279a2 --- /dev/null +++ b/huobi/model/algo/__init__.py @@ -0,0 +1,3 @@ +from huobi.model.algo.cancel_order_result import CancelOrderResult +from huobi.model.algo.order_list_item import OrderListItem +from huobi.model.algo.order_history_item import OrderHistoryItem diff --git a/huobi/model/algo/cancel_order_result.py b/huobi/model/algo/cancel_order_result.py new file mode 100644 index 0000000..1ab3faa --- /dev/null +++ b/huobi/model/algo/cancel_order_result.py @@ -0,0 +1,17 @@ +class CancelOrderResult: + """ + The result of batch cancel operation. + + :member + accepted: The clientOrderIds accepted. + rejected: The clientOrderIds rejected . + + """ + + def __init__(self): + self.accepted = [] + self.rejected = [] + + def print_object(self, format_data=""): + print("Success Order Counts", len(self.accepted), " accepted Order Ids : ", self.accepted) + print("Fail Order Counts", len(self.rejected), " Rejected Order Ids : ", self.rejected) \ No newline at end of file diff --git a/huobi/model/algo/order_history_item.py b/huobi/model/algo/order_history_item.py new file mode 100644 index 0000000..f9b9020 --- /dev/null +++ b/huobi/model/algo/order_history_item.py @@ -0,0 +1,51 @@ +class OrderHistoryItem: + """ + The result of batch cancel operation. + + :member + orderOrigTime + lastActTime + symbol + source + orderSide + orderType + timeInForce + clientOrderId + accountId + orderPrice + orderSize + stopPrice + orderStatus + + """ + + def __init__(self): + self.orderOrigTime = "" + self.lastActTime = "" + self.symbol = "" + self.source = "" + self.orderSide = "" + self.orderType = "" + self.timeInForce = "" + self.clientOrderId = "" + self.accountId = "" + self.orderPrice = "" + self.orderSize = "" + self.stopPrice = "" + self.orderStatus = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.orderOrigTime, format_data + "") + PrintBasic.print_basic(self.lastActTime, format_data + "") + PrintBasic.print_basic(self.symbol, format_data + "") + PrintBasic.print_basic(self.source, format_data + "") + PrintBasic.print_basic(self.orderSide, format_data + "") + PrintBasic.print_basic(self.orderType, format_data + "") + PrintBasic.print_basic(self.timeInForce, format_data + "") + PrintBasic.print_basic(self.clientOrderId, format_data + "") + PrintBasic.print_basic(self.accountId, format_data + "") + PrintBasic.print_basic(self.orderPrice, format_data + "") + PrintBasic.print_basic(self.orderSize, format_data + "") + PrintBasic.print_basic(self.stopPrice, format_data + "") + PrintBasic.print_basic(self.orderStatus, format_data + "") diff --git a/huobi/model/algo/order_list_item.py b/huobi/model/algo/order_list_item.py new file mode 100644 index 0000000..6a0b229 --- /dev/null +++ b/huobi/model/algo/order_list_item.py @@ -0,0 +1,71 @@ +class OrderListItem: + """ + The result of batch cancel operation. + + :member + event_type: + symbol: + order_id: + trade_price: + trade_volume: + order_side: + aggressor: + trade_id: + trade_time: + transact_fee: + fee_deduct: + fee_deduct_type: + fee_currency: + account_id: + source: + order_price: + order_size: + client_order_id: + order_create_time: + order_status: + """ + + def __init__(self): + self.eventType = "" + self.symbol = "" + self.orderId = "" + self.tradePrice = "" + self.tradeVolume = "" + self.orderSide = "" + self.aggressor = "" + self.tradeId = "" + self.tradeTime = "" + self.transactFee = "" + self.feeDeduct = "" + self.feeDeductType = "" + self.feeCurrency = "" + self.accountId = "" + self.source = "" + self.orderPrice = "" + self.orderSize = "" + self.clientOrderId = "" + self.orderCreateTime = "" + self.orderStatus = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.eventType, format_data + "Event Type") + PrintBasic.print_basic(self.symbol, format_data + "Symbol") + PrintBasic.print_basic(self.orderId, format_data + "OrderId") + PrintBasic.print_basic(self.tradePrice, format_data + "Trade Price") + PrintBasic.print_basic(self.tradeVolume, format_data + "Trade Volume") + PrintBasic.print_basic(self.orderSide, format_data + "Order Side") + PrintBasic.print_basic(self.aggressor, format_data + "Aggressor") + PrintBasic.print_basic(self.tradeId, format_data + "TradeId") + PrintBasic.print_basic(self.tradeTime, format_data + "Trade Time") + PrintBasic.print_basic(self.transactFee, format_data + "Transact Fee") + PrintBasic.print_basic(self.feeDeduct, format_data + "Fee Deduct") + PrintBasic.print_basic(self.feeDeductType, format_data + "Fee Deduct Type") + PrintBasic.print_basic(self.feeCurrency, format_data + "Fee Currency") + PrintBasic.print_basic(self.accountId, format_data + "Account Id") + PrintBasic.print_basic(self.source, format_data + "Source") + PrintBasic.print_basic(self.orderPrice, format_data + "Order Price") + PrintBasic.print_basic(self.orderSize, format_data + "Order Size") + PrintBasic.print_basic(self.clientOrderId, format_data + "Client Order Id") + PrintBasic.print_basic(self.orderCreateTime, format_data + "Order Create Time") + PrintBasic.print_basic(self.orderStatus, format_data + "Order Status") diff --git a/huobi/model/generic/__init__.py b/huobi/model/generic/__init__.py index 8f142a6..08d45b4 100644 --- a/huobi/model/generic/__init__.py +++ b/huobi/model/generic/__init__.py @@ -1,4 +1,5 @@ from huobi.model.generic.symbol import Symbol from huobi.model.generic.exchange_info import ExchangeInfo from huobi.model.generic.chain import Chain -from huobi.model.generic.reference_currency import ReferenceCurrency \ No newline at end of file +from huobi.model.generic.reference_currency import ReferenceCurrency +from huobi.model.generic.market_status import MarketStatus diff --git a/huobi/model/generic/market_status.py b/huobi/model/generic/market_status.py new file mode 100644 index 0000000..4a5ac5c --- /dev/null +++ b/huobi/model/generic/market_status.py @@ -0,0 +1,20 @@ +from huobi.constant import * + + +class MarketStatus: + """ + The Huobi market status info. + + :member + marketStatus: . + haltStartTime: . + haltEndTime: . + haltReason: + affectedSymbols: + """ + + def __init__(self): + self.marketStatus = MarketStatus.NORMAL + self.haltStartTime = -1 + self.haltEndTime = -1 + self.affectedSymbols = "" diff --git a/huobi/model/market/mbp_increase_event.py b/huobi/model/market/mbp_increase_event.py index f2f2d88..c60da0b 100644 --- a/huobi/model/market/mbp_increase_event.py +++ b/huobi/model/market/mbp_increase_event.py @@ -26,11 +26,9 @@ def json_parse(json_data): mbp_event.data = mbp return mbp_event - - def print_object(self, format_data=""): from huobi.utils.print_mix_object import PrintBasic PrintBasic.print_basic(self.ch, format_data + "Topic") PrintBasic.print_basic(self.ts, format_data + "Timestamp") - self.data.print_object(format_data + "\t") \ No newline at end of file + self.data.print_object(format_data + "\t") diff --git a/huobi/model/subuser/__init__.py b/huobi/model/subuser/__init__.py new file mode 100644 index 0000000..41bd908 --- /dev/null +++ b/huobi/model/subuser/__init__.py @@ -0,0 +1,5 @@ +from huobi.model.subuser.subuser_creation import SubuserCreation +from huobi.model.subuser.subuser_transferability import SubuserTransferability +from huobi.model.subuser.subuser_apikey_generation import SubuserApikeyGeneration +from huobi.model.subuser.user_apikey_info import UserApikeyInfo +from huobi.model.subuser.subuser_apikey_modification import SubuserApikeyModification diff --git a/huobi/model/subuser/subuser_apikey_generation.py b/huobi/model/subuser/subuser_apikey_generation.py new file mode 100644 index 0000000..aad98a3 --- /dev/null +++ b/huobi/model/subuser/subuser_apikey_generation.py @@ -0,0 +1,26 @@ +class SubuserApikeyGeneration: + """ + The trade information with price and amount etc. + + :member + accessKey: + secretKey: + note: + permission: "trade,readOnly", + ipAddresses": + """ + + def __init__(self): + self.accessKey = "" + self.secretKey = "" + self.note = "" + self.permission = "" + self.ipAddresses = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.accessKey, format_data + "accessKey") + PrintBasic.print_basic(self.secretKey, format_data + "secretKey") + PrintBasic.print_basic(self.note, format_data + "note") + PrintBasic.print_basic(self.permission, format_data + "permission") + PrintBasic.print_basic(self.ipAddresses, format_data + "ipAddresses") diff --git a/huobi/model/subuser/subuser_apikey_modification.py b/huobi/model/subuser/subuser_apikey_modification.py new file mode 100644 index 0000000..6265e7d --- /dev/null +++ b/huobi/model/subuser/subuser_apikey_modification.py @@ -0,0 +1,20 @@ +class SubuserApikeyModification: + """ + The trade information with price and amount etc. + + :member + note: + permission: "trade,readOnly", + ipAddresses": + """ + + def __init__(self): + self.note = "" + self.permission = "" + self.ipAddresses = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.note, format_data + "note") + PrintBasic.print_basic(self.permission, format_data + "permission") + PrintBasic.print_basic(self.ipAddresses, format_data + "ipAddresses") diff --git a/huobi/model/subuser/subuser_creation.py b/huobi/model/subuser/subuser_creation.py new file mode 100644 index 0000000..b8f6b88 --- /dev/null +++ b/huobi/model/subuser/subuser_creation.py @@ -0,0 +1,27 @@ + +class SubuserCreation: + """ + The trade information with price and amount etc. + + :member + subUid: sub user ID. + userState: sub user account state, states see SubUidState. + """ + + def __init__(self): + self.user_name = "" + self.note = "" + self.uid = 0 + self.err_code = 0 + self.err_message = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.user_name, format_data + "userName") + PrintBasic.print_basic(self.note, format_data + "note") + PrintBasic.print_basic(self.uid, format_data + "uid") + PrintBasic.print_basic(self.err_code, format_data + "errCode") + PrintBasic.print_basic(self.err_message, format_data + "errMessage") + + + diff --git a/huobi/model/subuser/subuser_transferability.py b/huobi/model/subuser/subuser_transferability.py new file mode 100644 index 0000000..a327390 --- /dev/null +++ b/huobi/model/subuser/subuser_transferability.py @@ -0,0 +1,20 @@ + +class SubuserTransferability: + """ + The trade information with price and amount etc. + + :member + subUid: sub user ID. + userState: sub user account state, states see SubUidState. + """ + + def __init__(self): + self.transferrable = "" + self.accountType = "" + self.subUid = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.subUid, format_data + "subUid") + PrintBasic.print_basic(self.accountType, format_data + "accountType") + PrintBasic.print_basic(self.transferrable, format_data + "transferrable") diff --git a/huobi/model/subuser/trade_market.py b/huobi/model/subuser/trade_market.py new file mode 100644 index 0000000..74d22b7 --- /dev/null +++ b/huobi/model/subuser/trade_market.py @@ -0,0 +1,21 @@ + +class TradeMarket: + """ + The trade information with price and amount etc. + + :member + subUid: sub user ID. + accountType: + activation: sub user account state for given accountType. + """ + + def __init__(self): + self.sub_uid = "" + self.account_type = "" + self.activation = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.sub_uid, format_data + "subUid") + PrintBasic.print_basic(self.account_type, format_data + "accountType") + PrintBasic.print_basic(self.activation, format_data + "activation") diff --git a/huobi/model/subuser/user_apikey_info.py b/huobi/model/subuser/user_apikey_info.py new file mode 100644 index 0000000..a55c126 --- /dev/null +++ b/huobi/model/subuser/user_apikey_info.py @@ -0,0 +1,37 @@ +class UserApikeyInfo: + """ + The trade information with price and amount etc. + + :member + accessKey: . + createTime: + ipAddresses: . + note: + permission: + status: + updateTime: + validDays: + + """ + + def __init__(self): + self.accessKey = "" + self.createTime = 0 + self.ipAddresses = "" + self.note = "" + self.permission = "" + self.status = "" + self.updateTime = 0 + self.validDays = -1 + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + + PrintBasic.print_basic(self.accessKey, format_data + "accessKey") + PrintBasic.print_basic(self.createTime, format_data + "createTime") + PrintBasic.print_basic(self.ipAddresses, format_data + "ipAddresses") + PrintBasic.print_basic(self.note, format_data + "note") + PrintBasic.print_basic(self.permission, format_data + "permission") + PrintBasic.print_basic(self.status, format_data + "status") + PrintBasic.print_basic(self.updateTime, format_data + "updateTime") + PrintBasic.print_basic(self.validDays, format_data + "validDays") diff --git a/huobi/model/trade/matchresult.py b/huobi/model/trade/matchresult.py index 3c7f90e..be2e757 100644 --- a/huobi/model/trade/matchresult.py +++ b/huobi/model/trade/matchresult.py @@ -19,6 +19,7 @@ class MatchResult: buy-ioc, sell-ioc, buy-limit-maker, sell-limit-maker, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok. filled_points: deduct points fee_deduct_currency: deduct type, it means deduct from HT/ HT points / or other currency + fee_currency: """ def __init__(self): @@ -35,6 +36,7 @@ def __init__(self): self.role = "" self.filled_points = "" self.fee_deduct_currency = "" + self.fee_currency = "" def print_object(self, format_data=""): from huobi.utils.print_mix_object import PrintBasic @@ -50,4 +52,5 @@ def print_object(self, format_data=""): PrintBasic.print_basic(self.symbol, format_data + "Symbol") PrintBasic.print_basic(self.type, format_data + "Order Type") PrintBasic.print_basic(self.role, format_data + "Role") - PrintBasic.print_basic(self.fee_deduct_currency, format_data + "Fee Deduct Currency") \ No newline at end of file + PrintBasic.print_basic(self.fee_deduct_currency, format_data + "Fee Deduct Currency") + PrintBasic.print_basic(self.fee_currency, format_data + "Fee Currency") diff --git a/huobi/model/wallet/__init__.py b/huobi/model/wallet/__init__.py index 9769244..f351a02 100644 --- a/huobi/model/wallet/__init__.py +++ b/huobi/model/wallet/__init__.py @@ -1,6 +1,7 @@ from huobi.model.wallet.deposit import Deposit from huobi.model.wallet.withdraw import Withdraw from huobi.model.wallet.chain_deposit_address import ChainDepositAddress +from huobi.model.wallet.chain_withdraw_address import ChainWithdrawAddress from huobi.model.wallet.withdraw_quota import WithdrawQuota from huobi.model.wallet.deposit_history import DepositHistory from huobi.model.wallet.deposit_history_item import DepositHistoryItem diff --git a/huobi/model/wallet/chain_withdraw_address.py b/huobi/model/wallet/chain_withdraw_address.py new file mode 100644 index 0000000..ff16357 --- /dev/null +++ b/huobi/model/wallet/chain_withdraw_address.py @@ -0,0 +1,25 @@ +class ChainWithdrawAddress: + """ + The deposit address. + + :member + currency: The crypto currency to deposit. + address: Deposit address + addressTag: Deposit address tag. + chain: Block chain name. + """ + + def __init__(self): + self.currency = "" + self.address = "" + self.addressTag = "" + self.chain = "" + self.note = "" + + def print_object(self, format_data=""): + from huobi.utils.print_mix_object import PrintBasic + PrintBasic.print_basic(self.currency, format_data + "Currency") + PrintBasic.print_basic(self.address, format_data + "Address") + PrintBasic.print_basic(self.addressTag, format_data + "addressTag") + PrintBasic.print_basic(self.chain, format_data + "Chain") + PrintBasic.print_basic(self.note, format_data + "Note") diff --git a/huobi/model/wallet/deposit.py b/huobi/model/wallet/deposit.py index ea0b60a..fc6471a 100644 --- a/huobi/model/wallet/deposit.py +++ b/huobi/model/wallet/deposit.py @@ -32,7 +32,6 @@ def __init__(self): self.updated_at = 0 self.state = DepositState.INVALID - def print_object(self, format_data=""): from huobi.utils.print_mix_object import PrintBasic PrintBasic.print_basic(self.id, format_data + "ID") @@ -46,4 +45,4 @@ def print_object(self, format_data=""): PrintBasic.print_basic(self.fee, format_data + "Fee") PrintBasic.print_basic(self.state, format_data + "Deposit State") PrintBasic.print_basic(self.created_at, format_data + "Create Time") - PrintBasic.print_basic(self.updated_at, format_data + "Update Time") \ No newline at end of file + PrintBasic.print_basic(self.updated_at, format_data + "Update Time") diff --git a/huobi/service/account/post_account_transfer.py b/huobi/service/account/post_account_transfer.py new file mode 100644 index 0000000..36278d0 --- /dev/null +++ b/huobi/service/account/post_account_transfer.py @@ -0,0 +1,19 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.model.account import * +from huobi.utils import * + + +class PostAccountTransferService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v1/account/transfer" + + def parse(dict_data): + data = dict_data.get("data", {}) + return default_parse(data, AccountTransferResult, []) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/algo/__init__.py b/huobi/service/algo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/huobi/service/algo/get_open_orders.py b/huobi/service/algo/get_open_orders.py new file mode 100644 index 0000000..7099876 --- /dev/null +++ b/huobi/service/algo/get_open_orders.py @@ -0,0 +1,40 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant import * +from huobi.utils.json_parser import * +from huobi.model.algo import * + + +class GetOpenOrdersService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/algo-orders/opening" + + # { + # "code": 200, + # "data": [ + # { + # "accountId": 3684354, + # "clientOrderId": "test004", + # "lastActTime": 1600141535221, + # "orderOrigTime": 1600141535137, + # "orderPrice": "0.08", + # "orderSide": "buy", + # "orderSize": "65", + # "orderStatus": "created", + # "orderType": "limit", + # "source": "api", + # "stopPrice": "0.085", + # "symbol": "adausdt", + # "timeInForce": "gtc" + # } + # ] + # } + + def parse(dict_data): + data = dict_data.get("data", {}) + return default_parse_list_dict(data, OrderListItem) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET_SIGN, channel, self.params, parse) diff --git a/huobi/service/algo/get_order_by_cid.py b/huobi/service/algo/get_order_by_cid.py new file mode 100644 index 0000000..c33c285 --- /dev/null +++ b/huobi/service/algo/get_order_by_cid.py @@ -0,0 +1,19 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant import * +from huobi.utils.json_parser import * +from huobi.model.algo import * + + +class GetOrderByClientOrderIdService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/algo-orders/specific" + + def parse(dict_data): + data = dict_data.get("data", {}) + return default_parse(data, OrderHistoryItem) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET_SIGN, channel, self.params, parse) diff --git a/huobi/service/algo/get_order_history.py b/huobi/service/algo/get_order_history.py new file mode 100644 index 0000000..05aee58 --- /dev/null +++ b/huobi/service/algo/get_order_history.py @@ -0,0 +1,19 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant import * +from huobi.utils.json_parser import * +from huobi.model.algo import * + + +class GetOrderHistoryService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/algo-orders/history" + + def parse(dict_data): + data = dict_data.get("data", {}) + return default_parse_list_dict(data, OrderHistoryItem) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET_SIGN, channel, self.params, parse) diff --git a/huobi/service/algo/post_cancel_orders.py b/huobi/service/algo/post_cancel_orders.py new file mode 100644 index 0000000..96caaff --- /dev/null +++ b/huobi/service/algo/post_cancel_orders.py @@ -0,0 +1,20 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant import * +from huobi.utils.json_parser import default_parse_fill_directly +from huobi.model.algo import * + + +class PostCancelOrderService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/algo-orders/cancellation" + + # {'code': 200, 'data': {'accepted': [], 'rejected': ['test001', 'test002']}} + def parse(dict_data): + data = dict_data.get("data", {}) + return default_parse_fill_directly(data, CancelOrderResult) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/algo/post_create_order.py b/huobi/service/algo/post_create_order.py new file mode 100644 index 0000000..9f3ab86 --- /dev/null +++ b/huobi/service/algo/post_create_order.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant import * + + +class PostCreateOrderService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/algo-orders" + + # {'code': 200, 'data': {'clientOrderId': 'test001'}} + def parse(dict_data): + data = dict_data.get('data') + return data.get('clientOrderId') + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/generic/get_market_status.py b/huobi/service/generic/get_market_status.py new file mode 100644 index 0000000..788e55c --- /dev/null +++ b/huobi/service/generic/get_market_status.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.model.generic import * +from huobi.utils import * + + +class GetMarketStatusService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/market-status" + + def parse(dict_data): + return default_parse(dict_data.get("data", {}), MarketStatus) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET, channel, self.params, parse) diff --git a/huobi/service/market/req_mbp.py b/huobi/service/market/req_mbp.py index f0c2a2c..51aa791 100644 --- a/huobi/service/market/req_mbp.py +++ b/huobi/service/market/req_mbp.py @@ -21,10 +21,7 @@ def subscription(connection): def parse(dict_data): return MbpReq.json_parse(dict_data) - WebSocketReqClient(**kwargs).execute_subscribe_v1(subscription, - parse, - callback, - error_handler) - - - + WebSocketReqClient(**kwargs).execute_subscribe_mbp(subscription, + parse, + callback, + error_handler) diff --git a/huobi/service/market/sub_mbp_full.py b/huobi/service/market/sub_mbp_full.py index 63f946e..0e99660 100644 --- a/huobi/service/market/sub_mbp_full.py +++ b/huobi/service/market/sub_mbp_full.py @@ -22,9 +22,6 @@ def parse(dict_data): return MbpFullEvent.json_parse(dict_data) SubscribeClient(**kwargs).execute_subscribe_v1(subscription, - parse, - callback, - error_handler) - - - + parse, + callback, + error_handler) diff --git a/huobi/service/market/sub_mbp_increase.py b/huobi/service/market/sub_mbp_increase.py index 119b495..a185769 100644 --- a/huobi/service/market/sub_mbp_increase.py +++ b/huobi/service/market/sub_mbp_increase.py @@ -21,7 +21,7 @@ def subscription(connection): def parse(dict_data): return MbpIncreaseEvent.json_parse(dict_data) - SubscribeClient(**kwargs).execute_subscribe_v1(subscription, + SubscribeClient(**kwargs).execute_subscribe_mbp(subscription, parse, callback, error_handler) diff --git a/huobi/service/subuser/__init__.py b/huobi/service/subuser/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/huobi/service/subuser/get_user_apikey_info.py b/huobi/service/subuser/get_user_apikey_info.py new file mode 100644 index 0000000..a37c392 --- /dev/null +++ b/huobi/service/subuser/get_user_apikey_info.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.utils import * +from huobi.model.subuser import * + + +class GetUserApikeyInfoService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/user/api-key" + + def parse(dict_data): + return default_parse_list_dict(dict_data.get("data", {}), UserApikeyInfo) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET_SIGN, channel, self.params, parse) diff --git a/huobi/service/subuser/post_create_subuser.py b/huobi/service/subuser/post_create_subuser.py new file mode 100644 index 0000000..45dd123 --- /dev/null +++ b/huobi/service/subuser/post_create_subuser.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.utils import * +from huobi.model.subuser import * + + +class PostSubuserCreationService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/sub-user/creation" + + def parse(dict_data): + return default_parse_list_dict(dict_data.get("data", {}), SubuserCreation) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/subuser/post_set_transferability.py b/huobi/service/subuser/post_set_transferability.py new file mode 100644 index 0000000..47fe674 --- /dev/null +++ b/huobi/service/subuser/post_set_transferability.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.utils import * +from huobi.model.subuser import * + + +class PostSetSubuserTransferability: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/sub-user/transferability" + + def parse(dict_data): + return default_parse_list_dict(dict_data.get("data", {}), SubuserTransferability) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/subuser/post_subuser_apikey_deletion.py b/huobi/service/subuser/post_subuser_apikey_deletion.py new file mode 100644 index 0000000..821fbfa --- /dev/null +++ b/huobi/service/subuser/post_subuser_apikey_deletion.py @@ -0,0 +1,17 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod + + +class PostSubuserApikeyDeletionService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/sub-user/api-key-deletion" + + # {'code': 200, 'data': None, 'ok': True} + def parse(dict_data): + return dict_data + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/subuser/post_subuser_apikey_generation.py b/huobi/service/subuser/post_subuser_apikey_generation.py new file mode 100644 index 0000000..76243a5 --- /dev/null +++ b/huobi/service/subuser/post_subuser_apikey_generation.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.utils import * +from huobi.model.subuser import * + + +class PostSubuserApikeyGenerationService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/sub-user/api-key-generation" + + def parse(dict_data): + return default_parse(dict_data.get("data", {}), SubuserApikeyGeneration) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/subuser/post_subuser_apikey_modification.py b/huobi/service/subuser/post_subuser_apikey_modification.py new file mode 100644 index 0000000..6671abe --- /dev/null +++ b/huobi/service/subuser/post_subuser_apikey_modification.py @@ -0,0 +1,18 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.utils import * +from huobi.model.subuser import * + + +class PostSubuserApikeyModificationService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/sub-user/api-key-modification" + + def parse(dict_data): + return default_parse(dict_data.get("data", {}), SubuserApikeyModification) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/subuser/post_tradable_market.py b/huobi/service/subuser/post_tradable_market.py new file mode 100644 index 0000000..4e644eb --- /dev/null +++ b/huobi/service/subuser/post_tradable_market.py @@ -0,0 +1,17 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant.system import HttpMethod +from huobi.model.subuser.trade_market import TradeMarket +from huobi.utils import * + + +class PostTradableMarketService: + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/sub-user/tradable-market" + + def parse(dict_data): + return default_parse_list_dict(dict_data.get("data", {}), TradeMarket) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.POST_SIGN, channel, self.params, parse) diff --git a/huobi/service/wallet/get_account_withdraw_address.py b/huobi/service/wallet/get_account_withdraw_address.py new file mode 100644 index 0000000..ade6e3a --- /dev/null +++ b/huobi/service/wallet/get_account_withdraw_address.py @@ -0,0 +1,25 @@ +from huobi.connection.restapi_sync_client import RestApiSyncClient +from huobi.constant import * +from huobi.model.wallet import * +from huobi.utils import * + + +class GetAccountWithdrawAddressService: + + def __init__(self, params): + self.params = params + + def request(self, **kwargs): + channel = "/v2/account/withdraw/address" + + def parse(dict_data): + data_list = dict_data.get("data", []) + return default_parse_list_dict(data_list, ChainWithdrawAddress) + + return RestApiSyncClient(**kwargs).request_process(HttpMethod.GET_SIGN, channel, self.params, parse) + + + + + + diff --git a/huobi/utils/channels.py b/huobi/utils/channels.py index 314d990..96dfac1 100644 --- a/huobi/utils/channels.py +++ b/huobi/utils/channels.py @@ -3,9 +3,6 @@ from huobi.constant import DepthStep - - - def kline_channel(symbol, interval): channel = dict() channel["sub"] = "market." + symbol + ".kline." + interval @@ -20,12 +17,13 @@ def trade_detail_channel(symbol): return json.dumps(channel) -def price_depth_channel(symbol, step_type = DepthStep.STEP0): +def price_depth_channel(symbol, step_type=DepthStep.STEP0): channel = dict() channel["sub"] = "market." + symbol + ".depth." + step_type channel["id"] = str(get_current_timestamp()) return json.dumps(channel) + def price_depth_bbo_channel(symbol): channel = dict() channel["sub"] = "market." + symbol + ".bbo" @@ -70,14 +68,16 @@ def mbp_full_channel(symbol, levels): channel["id"] = str(get_current_timestamp()) return json.dumps(channel) + def request_mbp_channel(symbol, levels): channel = dict() channel["req"] = "market.{symbol}.mbp.{levels}".format(symbol=symbol, levels=levels) channel["id"] = str(get_current_timestamp()) return json.dumps(channel) + def trade_clearing_channel(symbol="*"): channel = dict() channel["action"] = "sub" channel["ch"] = "trade.clearing#" + symbol - return json.dumps(channel) \ No newline at end of file + return json.dumps(channel) diff --git a/huobi/utils/input_checker.py b/huobi/utils/input_checker.py index 9d80ee2..2de456c 100644 --- a/huobi/utils/input_checker.py +++ b/huobi/utils/input_checker.py @@ -1,6 +1,7 @@ import re import time from huobi.exception.huobi_api_exception import HuobiApiException +from huobi.constant.definition import * reg_ex = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\t" @@ -12,6 +13,15 @@ def check_symbol(symbol): raise HuobiApiException(HuobiApiException.INPUT_ERROR, "[Input] " + symbol + " is invalid symbol") +def check_time_in_force(time_in_force, order_type): + if time_in_force is None: + return + + if order_type in [OrderType.BUY_MARKET, OrderType.SELL_MARKET] \ + and time_in_force in [TimeInForceType.GTC, TimeInForceType.BOC, TimeInForceType.FOK]: + raise HuobiApiException(HuobiApiException.INPUT_ERROR, "[Input] timeInForce not supported for market order") + + def check_symbol_list(symbols): if not isinstance(symbols, list): raise HuobiApiException(HuobiApiException.INPUT_ERROR, "[Input] symbols in subscription is not a list") @@ -44,9 +54,11 @@ def check_should_none(value, name): if value is not None: raise HuobiApiException(HuobiApiException.INPUT_ERROR, "[Input] " + name + " should be null") + def check_in_list(value, list_configed, name): if (value is not None) and (value not in list_configed): - raise HuobiApiException(HuobiApiException.INPUT_ERROR, "[Input] " + name + " should be one in " + (",".join(list_configed))) + raise HuobiApiException(HuobiApiException.INPUT_ERROR, + "[Input] " + name + " should be one in " + (",".join(list_configed))) def check_list(list_value, min_value, max_value, name): diff --git a/huobi/utils/json_parser.py b/huobi/utils/json_parser.py index c01255b..61c38fb 100644 --- a/huobi/utils/json_parser.py +++ b/huobi/utils/json_parser.py @@ -1,23 +1,24 @@ - from huobi.utils.print_mix_object import * def key_trans(key_origin): - if key_origin and len(key_origin) > 1 : + if key_origin and len(key_origin) > 1: return key_origin.replace("-", "_") else: return "" + def fill_obj(dict_data, class_name=object): obj = class_name() for ks, vs in dict_data.items(): obj_key = key_trans(ks) - #print("===== fill_obj =====", ks, obj_key, str(vs)) + # print("===== fill_obj =====", ks, obj_key, str(vs)) if hasattr(obj, obj_key): setattr(obj, obj_key, vs) continue return obj + def fill_obj_list(list_data, class_name): if (TypeCheck.is_list(list_data)): inner_obj_list = list() @@ -28,17 +29,18 @@ def fill_obj_list(list_data, class_name): return list() + def default_parse(dict_data, outer_class_name=object, inner_class_name=object): from huobi.utils.print_mix_object import TypeCheck rsp_obj = outer_class_name() for outer_key, outer_value in dict_data.items(): obj_key = key_trans(outer_key) - #print("===", outer_key, obj_key, str(outer_value)) - #PrintBasic.print_basic_bool(hasattr(rsp_obj, obj_key)) + # print("===", outer_key, obj_key, str(outer_value)) + # PrintBasic.print_basic_bool(hasattr(rsp_obj, obj_key)) if hasattr(rsp_obj, obj_key): new_value = outer_value - #print("==========", type(outer_value), outer_value) + # print("==========", type(outer_value), outer_value) if (TypeCheck.is_list(outer_value)): new_value = fill_obj_list(outer_value, inner_class_name) elif (TypeCheck.is_dict(outer_value)): @@ -49,12 +51,13 @@ def default_parse(dict_data, outer_class_name=object, inner_class_name=object): return rsp_obj -def default_parse_data_as_long(ret_original_json, key_name = None, default_value=0): + +def default_parse_data_as_long(ret_original_json, key_name=None, default_value=0): if ret_original_json: # from data get value by key_name if key_name and len(key_name): data_json = ret_original_json.get("data", {}) - ret_val = data_json.get(key_name, default_value) + ret_val = data_json.get(key_name, default_value) else: # get data value ret_val = ret_original_json.get("data", 0) @@ -62,6 +65,7 @@ def default_parse_data_as_long(ret_original_json, key_name = None, default_value else: return default_value + def default_parse_list_dict(inner_data, inner_class_name=object, default_value=None): from huobi.utils.print_mix_object import TypeCheck @@ -76,6 +80,7 @@ def default_parse_list_dict(inner_data, inner_class_name=object, default_value=N return new_value + def default_parse_fill_directly(dict_data, outer_class_name=object): rsp_obj = outer_class_name() @@ -88,31 +93,30 @@ def default_parse_fill_directly(dict_data, outer_class_name=object): return rsp_obj -if __name__ == "__main__": - #json_str = """{"id":1571037900,"open":8306.850000000000000000,"close":8307.990000000000000000,"low":8305.800000000000000000,"high":8308.000000000000000000,"amount":4.314954363225502510,"vol":35845.853207199999993966820000000000000000,"count":45}""" - #obj = parse(json_str, outer_class_name=Candlestick, inner_class_name=None) - - #obj.print_object() +if __name__ == "__main__": + # json_str = """{"id":1571037900,"open":8306.850000000000000000,"close":8307.990000000000000000,"low":8305.800000000000000000,"high":8308.000000000000000000,"amount":4.314954363225502510,"vol":35845.853207199999993966820000000000000000,"count":45}""" + # obj = parse(json_str, outer_class_name=Candlestick, inner_class_name=None) - #json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":[{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165},{"id":1571038080,"open":8306.060000000000000000,"close":8304.130000000000000000,"low":8304.130000000000000000,"high":8306.060000000000000000,"amount":3.440305012281757977,"vol":28571.704804969999998985000000000000000000,"count":70},{"id":1571038020,"open":8303.890000000000000000,"close":8305.990000000000000000,"low":8303.890000000000000000,"high":8307.000000000000000000,"amount":6.164746957847080072,"vol":51200.094613737306439860000000000000000000,"count":89},{"id":1571037960,"open":8308.000000000000000000,"close":8303.660000000000000000,"low":8303.610000000000000000,"high":8308.430000000000000000,"amount":9.449641840557003640,"vol":78488.394246429999983963200000000000000000,"count":128},{"id":1571037900,"open":8306.850000000000000000,"close":8307.990000000000000000,"low":8305.800000000000000000,"high":8308.000000000000000000,"amount":4.314954363225502510,"vol":35845.853207199999993966820000000000000000,"count":45},{"id":1571037840,"open":8305.290000000000000000,"close":8306.820000000000000000,"low":8305.040000000000000000,"high":8307.300000000000000000,"amount":3.661411574656800047,"vol":30412.286333819999984471300000000000000000,"count":68},{"id":1571037780,"open":8306.500000000000000000,"close":8305.490000000000000000,"low":8305.100000000000000000,"high":8307.690000000000000000,"amount":2.958112866447550895,"vol":24569.573928609999984901150000000000000000,"count":59},{"id":1571037720,"open":8306.300000000000000000,"close":8307.560000000000000000,"low":8305.440000000000000000,"high":8309.000000000000000000,"amount":8.506926000000000000,"vol":70665.848347860000000000000000000000000000,"count":90},{"id":1571037660,"open":8306.920000000000000000,"close":8306.300000000000000000,"low":8306.200000000000000000,"high":8307.000000000000000000,"amount":5.084311000000000000,"vol":42233.572201310000000000000000000000000000,"count":57},{"id":1571037600,"open":8307.200000000000000000,"close":8306.920000000000000000,"low":8306.920000000000000000,"high":8309.160000000000000000,"amount":4.540090141728746275,"vol":37715.585646199999989163880000000000000000,"count":54}]}""" - #obj_event = parse(json_str, outer_class_name=CandlestickRsp, inner_class_name=Candlestick) - #obj_event.print_object() + # obj.print_object() - #json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165}}""" - #obj_event = parse(json_str, outer_class_name=CandlestickEvent, inner_class_name=Candlestick) - #obj_event.print_object() + # json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":[{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165},{"id":1571038080,"open":8306.060000000000000000,"close":8304.130000000000000000,"low":8304.130000000000000000,"high":8306.060000000000000000,"amount":3.440305012281757977,"vol":28571.704804969999998985000000000000000000,"count":70},{"id":1571038020,"open":8303.890000000000000000,"close":8305.990000000000000000,"low":8303.890000000000000000,"high":8307.000000000000000000,"amount":6.164746957847080072,"vol":51200.094613737306439860000000000000000000,"count":89},{"id":1571037960,"open":8308.000000000000000000,"close":8303.660000000000000000,"low":8303.610000000000000000,"high":8308.430000000000000000,"amount":9.449641840557003640,"vol":78488.394246429999983963200000000000000000,"count":128},{"id":1571037900,"open":8306.850000000000000000,"close":8307.990000000000000000,"low":8305.800000000000000000,"high":8308.000000000000000000,"amount":4.314954363225502510,"vol":35845.853207199999993966820000000000000000,"count":45},{"id":1571037840,"open":8305.290000000000000000,"close":8306.820000000000000000,"low":8305.040000000000000000,"high":8307.300000000000000000,"amount":3.661411574656800047,"vol":30412.286333819999984471300000000000000000,"count":68},{"id":1571037780,"open":8306.500000000000000000,"close":8305.490000000000000000,"low":8305.100000000000000000,"high":8307.690000000000000000,"amount":2.958112866447550895,"vol":24569.573928609999984901150000000000000000,"count":59},{"id":1571037720,"open":8306.300000000000000000,"close":8307.560000000000000000,"low":8305.440000000000000000,"high":8309.000000000000000000,"amount":8.506926000000000000,"vol":70665.848347860000000000000000000000000000,"count":90},{"id":1571037660,"open":8306.920000000000000000,"close":8306.300000000000000000,"low":8306.200000000000000000,"high":8307.000000000000000000,"amount":5.084311000000000000,"vol":42233.572201310000000000000000000000000000,"count":57},{"id":1571037600,"open":8307.200000000000000000,"close":8306.920000000000000000,"low":8306.920000000000000000,"high":8309.160000000000000000,"amount":4.540090141728746275,"vol":37715.585646199999989163880000000000000000,"count":54}]}""" + # obj_event = parse(json_str, outer_class_name=CandlestickRsp, inner_class_name=Candlestick) + # obj_event.print_object() + # json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165}}""" + # obj_event = parse(json_str, outer_class_name=CandlestickEvent, inner_class_name=Candlestick) + # obj_event.print_object() - #json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165}}""" - #ret = default_parse_restful(json_str, inner_class_name=Candlestick, default_value=None) - #ret.print_object() + # json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165}}""" + # ret = default_parse_restful(json_str, inner_class_name=Candlestick, default_value=None) + # ret.print_object() - #json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":[{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165},{"id":1571038080,"open":8306.060000000000000000,"close":8304.130000000000000000,"low":8304.130000000000000000,"high":8306.060000000000000000,"amount":3.440305012281757977,"vol":28571.704804969999998985000000000000000000,"count":70},{"id":1571038020,"open":8303.890000000000000000,"close":8305.990000000000000000,"low":8303.890000000000000000,"high":8307.000000000000000000,"amount":6.164746957847080072,"vol":51200.094613737306439860000000000000000000,"count":89},{"id":1571037960,"open":8308.000000000000000000,"close":8303.660000000000000000,"low":8303.610000000000000000,"high":8308.430000000000000000,"amount":9.449641840557003640,"vol":78488.394246429999983963200000000000000000,"count":128},{"id":1571037900,"open":8306.850000000000000000,"close":8307.990000000000000000,"low":8305.800000000000000000,"high":8308.000000000000000000,"amount":4.314954363225502510,"vol":35845.853207199999993966820000000000000000,"count":45},{"id":1571037840,"open":8305.290000000000000000,"close":8306.820000000000000000,"low":8305.040000000000000000,"high":8307.300000000000000000,"amount":3.661411574656800047,"vol":30412.286333819999984471300000000000000000,"count":68},{"id":1571037780,"open":8306.500000000000000000,"close":8305.490000000000000000,"low":8305.100000000000000000,"high":8307.690000000000000000,"amount":2.958112866447550895,"vol":24569.573928609999984901150000000000000000,"count":59},{"id":1571037720,"open":8306.300000000000000000,"close":8307.560000000000000000,"low":8305.440000000000000000,"high":8309.000000000000000000,"amount":8.506926000000000000,"vol":70665.848347860000000000000000000000000000,"count":90},{"id":1571037660,"open":8306.920000000000000000,"close":8306.300000000000000000,"low":8306.200000000000000000,"high":8307.000000000000000000,"amount":5.084311000000000000,"vol":42233.572201310000000000000000000000000000,"count":57},{"id":1571037600,"open":8307.200000000000000000,"close":8306.920000000000000000,"low":8306.920000000000000000,"high":8309.160000000000000000,"amount":4.540090141728746275,"vol":37715.585646199999989163880000000000000000,"count":54}]}""" - #ret = default_parse_restful(json_str, inner_class_name=Candlestick, default_value=None) - #if ret and len(ret): + # json_str = """{"status":"ok","ch":"market.btcusdt.kline.1min","ts":1571038189274,"data":[{"id":1571038140,"open":8304.130000000000000000,"close":8305.000000000000000000,"low":8300.010000000000000000,"high":8305.000000000000000000,"amount":41.791380418639796061,"vol":347038.873910589999990613890000000000000000,"count":165},{"id":1571038080,"open":8306.060000000000000000,"close":8304.130000000000000000,"low":8304.130000000000000000,"high":8306.060000000000000000,"amount":3.440305012281757977,"vol":28571.704804969999998985000000000000000000,"count":70},{"id":1571038020,"open":8303.890000000000000000,"close":8305.990000000000000000,"low":8303.890000000000000000,"high":8307.000000000000000000,"amount":6.164746957847080072,"vol":51200.094613737306439860000000000000000000,"count":89},{"id":1571037960,"open":8308.000000000000000000,"close":8303.660000000000000000,"low":8303.610000000000000000,"high":8308.430000000000000000,"amount":9.449641840557003640,"vol":78488.394246429999983963200000000000000000,"count":128},{"id":1571037900,"open":8306.850000000000000000,"close":8307.990000000000000000,"low":8305.800000000000000000,"high":8308.000000000000000000,"amount":4.314954363225502510,"vol":35845.853207199999993966820000000000000000,"count":45},{"id":1571037840,"open":8305.290000000000000000,"close":8306.820000000000000000,"low":8305.040000000000000000,"high":8307.300000000000000000,"amount":3.661411574656800047,"vol":30412.286333819999984471300000000000000000,"count":68},{"id":1571037780,"open":8306.500000000000000000,"close":8305.490000000000000000,"low":8305.100000000000000000,"high":8307.690000000000000000,"amount":2.958112866447550895,"vol":24569.573928609999984901150000000000000000,"count":59},{"id":1571037720,"open":8306.300000000000000000,"close":8307.560000000000000000,"low":8305.440000000000000000,"high":8309.000000000000000000,"amount":8.506926000000000000,"vol":70665.848347860000000000000000000000000000,"count":90},{"id":1571037660,"open":8306.920000000000000000,"close":8306.300000000000000000,"low":8306.200000000000000000,"high":8307.000000000000000000,"amount":5.084311000000000000,"vol":42233.572201310000000000000000000000000000,"count":57},{"id":1571037600,"open":8307.200000000000000000,"close":8306.920000000000000000,"low":8306.920000000000000000,"high":8309.160000000000000000,"amount":4.540090141728746275,"vol":37715.585646199999989163880000000000000000,"count":54}]}""" + # ret = default_parse_restful(json_str, inner_class_name=Candlestick, default_value=None) + # if ret and len(ret): # for row in ret: # row.print_object() # print("========") - pass \ No newline at end of file + pass diff --git a/setup.py b/setup.py index b5811ea..898489c 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ 'huobi.utils', 'huobi.client', 'huobi.service', 'huobi.service.account', 'huobi.service.margin', 'huobi.service.market', 'huobi.service.trade', 'huobi.service.wallet', 'huobi.service.generic', 'huobi.service.etf', - 'huobi.model', 'huobi.model.account', 'huobi.model.margin', 'huobi.model.market', 'huobi.model.trade', 'huobi.model.wallet', 'huobi.model.generic', 'huobi.model.etf', + 'huobi.model', 'huobi.model.account', 'huobi.model.margin', 'huobi.model.market', 'huobi.model.trade', 'huobi.model.wallet', 'huobi.model.generic', 'huobi.model.etf', 'huobi.model.subuser', 'huobi.connection', 'huobi.connection.impl', "performance", "tests" ], install_requires=['requests', 'apscheduler', 'websocket-client', 'urllib3']