contract_code_list = ['BTCUSDT', 'ETHUSDT'] type_list = [] side = 0 # 0:no limit start_time = 0 end_time = 0 page = 1 limit = 10 list_obj = trade_client.req_history_orders( contract_code_list=contract_code_list, type_list=type_list, side=side, start_time=start_time, end_time=end_time, page=page, limit=limit) LogInfo.output_list(list_obj, '==query history orders all==') # case query history orders by side type time.sleep(1) # api rate limit type_list = [1, 2] list_obj = trade_client.req_history_orders( contract_code_list=contract_code_list, type_list=type_list, side=side, start_time=start_time, end_time=end_time, page=page, limit=limit) LogInfo.output_list(list_obj, '==query history orders by type==') # case query history orders by side BUY
side: 1:Buy Long, 2:Sell Short, 3:Buy to Close Short, 4:Sell to Close Long type: Limit:limit order Market:market order trig_price: Trigger price expected_quantity: Preset quantity expected_price: Preset price """ contract_code = 'BTCUSDT' # # case condition limit order res = trade_client.create_condition_order(contract_code=contract_code, side=OrderTradeType.BUY_LONG, type=OrderType.LIMIT, trig_price=55000, expected_quantity=10, expected_price=54500) if res and len(res) and res.get('ret', -1) == 0 and res.get('data', False): LogInfo.output("create condition limit order success") else: LogInfo.output("create condition limit order fail:{res}".format(res=res)) # # case condition market order # res = trade_client.create_condition_order(contract_code=contract_code, side=OrderTradeType.BUY_LONG, # type=OrderType.MARKET, trig_price=55000, # expected_quantity=10, expected_price=None) # if res and len(res) and res.get('ret', -1) == 0 and res.get('data', False): # LogInfo.output("create condition market order success") # else: # LogInfo.output("create condition market order fail:{res}".format(res=res))
from hopex.client.wallet import WalletClient from hopex.constant.test import t_api_key, t_secret_key from hopex.utils.log_info import LogInfo wallet_client = WalletClient(api_key=t_api_key, secret_key=t_secret_key) obj = wallet_client.get_user_wallet() LogInfo.output(obj)
""" The condition orders information :params contract_code_list: Contract List, Being blank to search all contracts task_type_list: 1:Buy Long, 2:Sell Short, 3:Buy to Close Short, 4:Sell to Close Long, Being blank to search all trig_type_list: 1:Market Price 2:Faire Price,Being blank to search all task_status_list: 1: Untriggered 2.Canceled 3.Order Submitted 4.Trigger failed, Being blank to search all direct: 1 LONG,2 SHORT,0:search all side: 1:Sell 2Buy,0:search all start_time: 0:search all,Start Time Stamp(Unit microsecond) end_time: 0:search all,End Time Stamp(Unit microsecond) """ # case query condition orders all contract_code_list = ['BTCUSDT', 'ETHUSDT'] task_type_list = [] trig_type_list = [] task_status_list = [] direct = 0 side = 0 start_time = 0 end_time = 0 list_obj = trade_client.req_condition_orders(contract_code_list=contract_code_list, task_type_list=task_type_list, trig_type_list=trig_type_list, task_status_list=task_status_list, direct=direct, side=side, start_time=start_time, end_time=end_time) LogInfo.output_list(list_obj, "==query condition orders all==")
from hopex.client.trade import TradeClient from hopex.constant.test import t_api_key, t_secret_key from hopex.constant.definition import OrderTradeType from hopex.utils.log_info import LogInfo trade_client = TradeClient(api_key=t_api_key, secret_key=t_secret_key) contract_code = 'BTCUSDT' res = trade_client.create_order(contract_code=contract_code, side=OrderTradeType.BUY_LONG, order_quantity=10, order_price=40000) if res and len(res) and res.get('ret', -1) == 0: order_id = res.get('data', 0) LogInfo.output("created order id : {id}".format(id=order_id)) cancel_res = trade_client.cancel_order(contract_code=contract_code, order_id=order_id) if cancel_res and len(cancel_res) and res.get('ret', -1) == 0 and res.get('data', False): LogInfo.output("cancel order {id} done".format(id=order_id)) else: LogInfo.output_list("cancel order fail: {res}".format(res=cancel_res)) else: LogInfo.output_list("create order fail: {res}".format(res=res))
contract_code = 'BTCUSDT' end_time = int(time.time()) before_30min = end_time - 60 * 30 before_24h = end_time - 60 * 60 * 24 before_1week = end_time - 60 * 60 * 24 * 7 before_30day = end_time - 60 * 60 * 24 * 30 before_60day = end_time - 60 * 60 * 24 * 60 before_1year = end_time - 60 * 60 * 24 * 365 # list_obj = market_client.get_kline(contract_code=contract_code, end_time=end_time, start_time=before_30min, # interval=CandlestickInterval.MIN1) list_obj = market_client.get_kline(contract_code=contract_code, end_time=end_time, start_time=before_24h, interval=CandlestickInterval.MIN5) # list_obj = market_client.get_kline(contract_code=contract_code, end_time=end_time, start_time=before_24h, # interval=CandlestickInterval.HOUR1) # list_obj = market_client.get_kline(contract_code=contract_code, end_time=end_time, start_time=before_1week, # interval=CandlestickInterval.DAY1) # list_obj = market_client.get_kline(contract_code=contract_code, end_time=end_time, start_time=before_30day, # interval=CandlestickInterval.WEEK1) # list_obj = market_client.get_kline(contract_code=contract_code, end_time=end_time, start_time=before_1year, # interval=CandlestickInterval.MON1) LogInfo.output_list(list_obj)
res = trade_client.req_condition_orders(contract_code_list=contract_code_list, task_type_list=task_type_list, trig_type_list=trig_type_list, task_status_list=task_status_list, direct=direct, side=side, start_time=start_time, end_time=end_time) if res and len(res) and res.get('ret', -1) == 0: task_data = res.get('data', {}) task_list = task_data.get('result', list()) task_list = list( filter( lambda x: x['taskStatus'] == 1 if x.get('taskStatus') else False, task_list) if len(task_list) else 0) task_id_tmp = task_list[0].get('taskId', 0) if len(task_list) else 0 if task_id_tmp: cancel_res = trade_client.cancel_condition_order( contract_code, task_id_tmp) if cancel_res and len(cancel_res) and cancel_res.get( 'ret', -1) == 0 and cancel_res.get('data', False): LogInfo.output( "cancel condition order {id} done".format(id=task_id_tmp)) else: LogInfo.output_list( "cancel condition order fail: {res}".format(res=cancel_res)) else: LogInfo.output_list("cancel condition order fail: {res}".format(res=res))