def test_trade_order(self): trade_client = TradeClient(api_key=g_api_key, secret_key=g_secret_key, performance_test=True) client_order_id = "test_" + str(round(time.time())) + "_id" print("client order id : ", client_order_id) # case create_order tc = TimeCost(function_name=trade_client.create_order.__name__) result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.create_order( symbol=trade_symbol, account_id=g_account_id, order_type=OrderType.BUY_LIMIT, source=OrderSource.API, amount=55, price=0.1, client_order_id=client_order_id, stop_price=0.08, operator="gte") order_id_tmp = result tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED tc.add_record() # case get_order tc = TimeCost(function_name=trade_client.get_order.__name__) result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_order( order_id=order_id_tmp) tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED tc.add_record() # case get_order_by_client_order_id tc = TimeCost( function_name=trade_client.get_order_by_client_order_id.__name__) result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_order_by_client_order_id( client_order_id=client_order_id) tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED tc.add_record() # case get_open_orders tc = TimeCost(function_name=trade_client.get_open_orders.__name__) result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_open_orders( symbol=trade_symbol, account_id=g_account_id) tc.run_status = RunStatus.SUCCESS if result and len( result) else RunStatus.FAILED tc.add_record() # case get_orders tc = TimeCost(function_name=trade_client.get_orders.__name__) result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.get_orders( symbol=trade_symbol, order_type=OrderType.BUY_LIMIT, order_state=OrderState.SUBMITTED) tc.run_status = RunStatus.SUCCESS if result and len( result) else RunStatus.FAILED tc.add_record() # case cancel_order tc = TimeCost(function_name=trade_client.cancel_order.__name__) result, tc.server_req_cost, tc.server_api_cost = trade_client.order_id = trade_client.cancel_order( symbol=trade_symbol, order_id=order_id_tmp) tc.run_status = RunStatus.SUCCESS if result else RunStatus.FAILED tc.add_record()
source=OrderSource.API, amount=20, price=0.26, client_order_id=client_order_id_test, stop_price=0.11, operator="gte") LogInfo.output( "======= create new order id : {order_id} with client id {client_id} =======" .format(order_id=(order_id), client_id=client_order_id_test)) orderObj = trade_client.get_order(order_id=order_id) LogInfo.output("======= get order by order id : {order_id} =======".format( order_id=order_id)) orderObj.print_object() orderObj = trade_client.get_order_by_client_order_id( client_order_id=client_order_id_test) LogInfo.output( "======= get order by client order id : {client_id} =======".format( client_id=client_order_id_test)) orderObj.print_object() trade_client.cancel_client_order(client_order_id=client_order_id_test) LogInfo.output( "======= cancel order by client order id : {client_id} =======".format( client_id=client_order_id_test)) orderObj = trade_client.get_order_by_client_order_id( client_order_id=client_order_id_test) LogInfo.output( "======= get order by client order id : {client_id} after cancel =======". format(client_id=client_order_id_test))