Ejemplo n.º 1
0
    def test_cross_margin(self):
        margin_client = MarginClient(api_key=g_api_key,
                                     secret_key=g_secret_key,
                                     performance_test=True)

        # case post_cross_margin_transfer_in
        tc = TimeCost(
            function_name=margin_client.post_cross_margin_transfer_in.__name__)
        result, tc.server_req_cost, tc.server_api_cost = margin_client.post_cross_margin_transfer_in(
            currency=loan_currency, amount=loan_amount)
        tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
        tc.add_record()

        # case get_cross_margin_account_balance
        tc = TimeCost(function_name=margin_client.
                      get_cross_margin_account_balance.__name__)
        result, tc.server_req_cost, tc.server_api_cost = margin_client.get_cross_margin_account_balance(
        )
        tc.run_status = RunStatus.SUCCESS if result and result.id else RunStatus.FAILED
        tc.add_record()

        # case get_cross_margin_loan_info
        tc = TimeCost(
            function_name=margin_client.get_cross_margin_loan_info.__name__)
        result, tc.server_req_cost, tc.server_api_cost = margin_client.get_cross_margin_loan_info(
        )
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case post_cross_margin_create_loan_orders
        tc = TimeCost(function_name=margin_client.
                      post_cross_margin_create_loan_orders.__name__)
        result, tc.server_req_cost, tc.server_api_cost = margin_client.post_cross_margin_create_loan_orders(
            currency=loan_currency, amount=loan_amount)
        tc.run_status = RunStatus.SUCCESS if result and int(
            result) > 0 else RunStatus.FAILED
        tc.add_record()

        time.sleep(3)  # wait for interest amount
        # case get_cross_margin_loan_orders
        tc = TimeCost(
            function_name=margin_client.get_cross_margin_loan_orders.__name__)
        result, tc.server_req_cost, tc.server_api_cost = margin_client.get_cross_margin_loan_orders(
            currency=loan_currency, state=LoanOrderState.ACCRUAL)
        cross_loan_accrual_order_list = result
        tc.run_status = RunStatus.SUCCESS if result and len(
            result) else RunStatus.FAILED
        tc.add_record()

        # case post_cross_margin_loan_order_repay
        interest_amount = 0.0
        if cross_loan_accrual_order_list and len(
                cross_loan_accrual_order_list):
            for loan_order in cross_loan_accrual_order_list:
                tc = TimeCost(function_name=margin_client.
                              post_cross_margin_loan_order_repay.__name__)
                repay_amount = float(loan_order.loan_balance) + float(
                    loan_order.interest_balance)
                interest_amount = interest_amount + float(
                    loan_order.interest_balance)
                result, tc.server_req_cost, tc.server_api_cost = margin_client.post_cross_margin_loan_order_repay(
                    order_id=loan_order.id, amount=repay_amount)
                tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
                tc.add_record()

        time.sleep(2)  # wait for repay result
        # case post_cross_margin_transfer_out
        tc = TimeCost(function_name=margin_client.
                      post_cross_margin_transfer_out.__name__)
        result, tc.server_req_cost, tc.server_api_cost = margin_client.post_cross_margin_transfer_out(
            currency=loan_currency, amount=loan_amount - interest_amount)
        tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED
        tc.add_record()
from huobi.client.margin import MarginClient
from huobi.constant import *
from huobi.utils import *

margin_client = MarginClient(api_key=g_api_key, secret_key=g_secret_key)
transfer_id = margin_client.post_cross_margin_transfer_in(currency="eos", amount=5)
LogInfo.output(transfer_id)

transfer_id = margin_client.post_cross_margin_transfer_out(currency="eos", amount=5)
LogInfo.output(transfer_id)