Esempio n. 1
0
 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}
     from huobi.service.account.get_balance import GetBalanceService
     return GetBalanceService(params).request(**self.__kwargs)
Esempio n. 2
0
    def get_account_balance(self) -> list:
        from huobi.service.account.get_balance import GetBalanceService
        """
        Get the balance of a all accounts.

        :return: The information of all account balance.
        """
        server_url = get_default_server_url(self.__kwargs.get("url"))
        tasks = []
        account_obj_map = {}
        accounts = self.get_accounts()
        account_balance_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_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)))

        loop = asyncio.get_event_loop()
        try:
            loop.run_until_complete(asyncio.wait(tasks))
        except Exception as ee:
            print(ee)
        finally:
            # loop.close()  #for thread safe, the event loop can't be closed
            pass

        for account_id, account_balance_json in account_balance_json_map.items(
        ):
            account_balance = AccountBalance.json_parse(
                account_balance_json.get("data", {}))
            account_obj_tmp = account_obj_map.get(account_id, None)
            account_balance.subtype = None if account_obj_tmp is None else account_obj_tmp.subtype
            account_balance_list.append(account_balance)

        del account_balance_json_map
        del tasks
        return account_balance_list
    def get_account_balance(self) -> list:
        from huobi.service.account.get_balance import GetBalanceService
        """
        Get the balance of a all accounts.

        :return: The information of all account balance.
        """
        server_url = get_default_server_url(self.__kwargs.get("url"))
        tasks = []
        accounts, req_cost_1, cost_manual_1  = super(AccountClientPerformance, self).get_accounts()
        start_time = time.time()
        account_balance_list = []
        account_balance_json_map = {}
        for account_item in accounts:
            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(
                super(AccountClientPerformance, self).async_get_account_balance(balance_url, account_item.id, account_balance_json_map)))

        loop = asyncio.get_event_loop()
        try:
            loop.run_until_complete(asyncio.wait(tasks))
        except Exception as ee:
            print(ee)
        finally:
            # loop.close()  #for thread safe, the event loop can't be closed
            pass

        for account_id, account_balance_json in account_balance_json_map.items():
            account_balance = AccountBalance.json_parse(account_balance_json.get("data", {}))
            account_balance_list.append(account_balance)

        del account_balance_json_map
        del tasks
        end_time = time.time()
        async_balane_cost = round(end_time - start_time, 6)
        return account_balance_list, req_cost_1 + async_balane_cost, cost_manual_1 + async_balane_cost