def get_contract_history_orders(self, contract_code, trade_type, type, status, create_date, page_index=None, page_size=None): """ 获取合约历史委托 :param contract_code: 支持大小写,"BTC-USDT" ... :param trade_type: 0:全部,1:买入开多,2: 卖出开空,3: 买入平空,4: 卖出平多,5: 卖出强平,6: 买入强平,7:交割平多,8: 交割平空, 11:减仓平多,12:减仓平空 :param type: 1:所有订单,2:结束状态的订单 :param status: 可查询多个状态,"3,4,5" , 0:全部,3:未成交, 4: 部分成交,5: 部分成交已撤单,6: 全部成交,7:已撤单 :param create_date: 可随意输入正整数,如果参数超过90则默认查询90天的数据 :param page_index: 页码,不填默认第1页 :param page_size: 每页条数,不填默认20 :return: """ params = { "contract_code": contract_code, "trade_type": trade_type, "type": type, "status": status, "create_date": create_date } if page_index: params["page_index"] = page_index if page_size: params["page_size"] = page_size request_path = '/linear-swap-api/v1/swap_hisorders' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_history_orders(self, symbol, trade_type, type, status, create_date, page_index=None, page_size=None): """ 参数名称 是否必须 类型 描述 取值范围 symbol true string 品种代码 "BTC","ETH"... trade_type true int 交易类型 0:全部,1:买入开多,2: 卖出开空,3: 买入平空,4: 卖出平多,5: 卖出强平,6: 买入强平,7:交割平多,8: 交割平空 type true int 类型 1:所有订单、2:结束汏订单 status true int 订单状态 0:全部,3:未成交, 4: 部分成交,5: 部分成交已撤单,6: 全部成交,7:已撤单 create_date true int 日期 7,90(7天或者90天) page_index false int 页码,不填默认第1页 page_size false int 不填默认20,不得多于50 """ params = {"symbol": symbol, "trade_type": trade_type, "type": type, "status": status, "create_date": create_date} if page_index: params["page_index"] = page_index if page_size: params["page_size"] = page_size request_path = '/api/v1/contract_hisorders' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def send_contract_order(self, symbol, contract_type, contract_code, client_order_id, price, volume, direction, offset, lever_rate, order_price_type): """ :symbol: "BTC","ETH".. :contract_type: "this_week", "next_week", "quarter" :contract_code: "BTC181228" :client_order_id: 客户自己填写和维护,这次一定要大于上一次 :price 必填 价格 :volume 必填 委托数量(张) :direction 必填 "buy" "sell" :offset 必填 "open", "close" :lever_rate 必填 杠杆倍数 :order_price_type 必填 "limit"限价, "opponent" 对手价 备注:如果contract_code填了值,那就按照contract_code去下单,如果contract_code没有填值,则按照symbol+contract_type去下单。 : """ params = {"price": price, "volume": volume, "direction": direction, "offset": offset, "lever_rate": lever_rate, "order_price_type": order_price_type} if symbol: params["symbol"] = symbol if contract_type: params['contract_type'] = contract_type if contract_code: params['contract_code'] = contract_code if client_order_id: params['client_order_id'] = client_order_id request_path = '/api/v1/contract_order' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_order_detail(self, contract_code, order_id, order_type, created_at, page_index=None, page_size=None): """ 获取合约订单明细信息 :param contract_code: 合约代码,支持大小写,"BTC-USDT" :param order_id: 订单id :param order_type: 订单类型,1:报单 、 2:撤单 、 3:强平、4:交割 :param created_at: 下单时间戳 :param page_index: 第几页,不填第一页 :param page_size: 不填默认20,不得多于50 :return: """ params = { "contract_code": contract_code, "order_id": order_id, "order_type": order_type, "created_at": created_at } if page_index: params["page_index"] = page_index if page_size: params["page_size"] = page_size request_path = '/linear-swap-api/v1/swap_order_detail' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def cancel_all_contract_order(self, symbol): """ symbol: BTC, ETH, ... """ params = {"symbol": symbol} request_path = '/api/v1/contract_cancelall' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def send_contract_batchorder(self, orders_data): """ 合约批量下单 :param orders_data: 详见https://docs.huobigroup.com/docs/coin_margined_swap/v1/cn/#33123f0c09 :return: """ params = orders_data request_path = '/swap-api/v1/swap_batchorder' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def cancel_all_contract_order(self, contract_code): """ 全部撤单 :param contract_code: 合约代码,支持大小写,"BTC-USD" :return: """ params = {"contract_code": contract_code} request_path = '/swap-api/v1/swap_cancelall' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_position_info(self, contract_code=''): """ 获取用户持仓信息 :param contract_code: 合约代码 支持大小写,"BTC-USD"... ,如果缺省,默认返回所有合约 :return: """ params = {} if contract_code: params["contract_code"] = contract_code request_path = '/swap-api/v1/swap_position_info' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_position_info(self, symbol=''): """ :param symbol: "BTC","ETH"...如果缺省,默认返回所有品种 :return: """ params = {} if symbol: params["symbol"] = symbol request_path = '/api/v1/contract_position_info' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_account_info(self, contract_code=''): """ 获取用户账户信息 :param contract_code: 支持大小写, "BTC-USDT"... ,如果缺省,默认返回所有合约 :return: """ params = {} if contract_code: params["contract_code"] = contract_code request_path = '/linear-swap-api/v1/swap_account_info' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_order_info(self, contract_code, order_id='', client_order_id=''): """ 获取合约订单信息 :param contract_code: 合约代码,支持大小写,"BTC-USD" :param order_id: 订单ID(多个订单ID中间以","分隔,一次最多允许查询50个订单) :param client_order_id: 客户订单ID(多个订单ID中间以","分隔,一次最多允许查询50个订单) :return: """ params = {"contract_code": contract_code} if order_id: params["order_id"] = order_id if client_order_id: params["client_order_id"] = client_order_id request_path = '/swap-api/v1/swap_order_info' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_order_info(self, symbol, order_id='', client_order_id=''): """ 参数名称 是否必须 类型 描述 symbol true string BTC, ETH, ... order_id false string 订单ID( 多个订单ID中间以","分隔,一次最多允许查询20个订单 ) client_order_id false string 客户订单ID(多个订单ID中间以","分隔,一次最多允许查询20个订单) 备注:order_id和client_order_id都可以用来查询,同时只可以设置其中一种,如果设置了两种,默认以order_id来查询。 """ params = {"symbol": symbol} if order_id: params["order_id"] = order_id if client_order_id: params["client_order_id"] = client_order_id request_path = '/api/v1/contract_order_info' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_open_orders(self, symbol=None, page_index=None, page_size=None): """ 参数名称 是否必须 类型 描述 symbol false string "BTC","ETH"... page_index false int 第几页,不填第一页 page_size false int 不填默认20,不得多于50 """ params = {} if symbol: params["symbol"] = symbol if page_index: params["page_index"] = page_index if page_size: params["page_size"] = page_size request_path = '/api/v1/contract_openorders' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_open_orders(self, contract_code=None, page_index=None, page_size=None): """ 获取合约当前未成交委托 :param contract_code: 合约代码 支持大小写,"BTC-USD" ... :param page_index: 页码,不填默认第1页 :param page_size: 不填默认20,不得多于50 :return: """ params = {} if contract_code: params["contract_code"] = contract_code if page_index: params["page_index"] = page_index if page_size: params["page_size"] = page_size request_path = '/swap-api/v1/swap_openorders' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def send_contract_order(self, contract_code, client_order_id, price, volume, direction, offset, lever_rate, order_price_type): """ 合约下单 :param contract_code: 合约代码,支持大小写,"BTC-USDT" :param client_order_id: 客户自己填写和维护,必须为数字, 请注意必须小于等于9223372036854775807 :param price: 价格 :param volume: 委托数量(张) :param direction: "buy":买 "sell":卖 :param offset: "open":开 "close":平 :param lever_rate: 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单;首次使用高倍杠杆(>20倍),请使用主账号登录web端同意高倍杠杆协议后,才能使用接口下高倍杠杆(>20倍)] :param order_price_type: 订单报价类型 "limit":限价 "opponent":对手价 "post_only":只做maker单, post only下单只受用户持仓数量限制, optimal_5:最优5档、optimal_10:最优10档、optimal_20:最优20档, "fok":FOK订单, "ioc":IOC订单, opponent_ioc": 对手价-IOC下单, "optimal_5_ioc":最优5档-IOC下单, "optimal_10_ioc":最优10档-IOC下单, "optimal_20_ioc":最优20档-IOC下单, "opponent_fok": 对手价-FOK下单, "optimal_5_fok":最优5档-FOK下单, "optimal_10_fok":最优10档-FOK下单, "optimal_20_fok":最优20档-FOK下单 :return: """ params = { "price": price, "volume": volume, "direction": direction, "offset": offset, "lever_rate": lever_rate, "order_price_type": order_price_type } if contract_code: params['contract_code'] = contract_code if client_order_id: params['client_order_id'] = client_order_id request_path = '/linear-swap-api/v1/swap_order' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def send_contract_batchorder(self, orders_data): """ orders_data: example: orders_data = {'orders_data': [ {'symbol': 'BTC', 'contract_type': 'quarter', 'contract_code':'BTC181228', 'client_order_id':'', 'price':1, 'volume':1, 'direction':'buy', 'offset':'open', 'leverRate':20, 'orderPriceType':'limit'}, {'symbol': 'BTC','contract_type': 'quarter', 'contract_code':'BTC181228', 'client_order_id':'', 'price':2, 'volume':2, 'direction':'buy', 'offset':'open', 'leverRate':20, 'orderPriceType':'limit'}]} Parameters of each order: refer to send_contract_order """ params = orders_data request_path = '/api/v1/contract_batchorder' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def cancel_contract_order(self, contract_code, order_id='', client_order_id=''): """ 撤销订单 :param contract_code: 合约代码,支持大小写,"BTC-USDT" :param order_id: 订单ID(多个订单ID中间以","分隔,一次最多允许撤消10个订单) :param client_order_id: 客户订单ID(多个订单ID中间以","分隔,一次最多允许撤消10个订单) :return: """ params = {"contract_code": contract_code} if order_id: params["order_id"] = order_id if client_order_id: params["client_order_id"] = client_order_id request_path = '/linear-swap-api/v1/swap_cancel' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)
def get_contract_order_detail(self, symbol, order_id, order_type, created_at, page_index=None, page_size=None): """ 参数名称 是否必须 类型 描述 symbol true string "BTC","ETH"... order_id true long 订单id order_type true int 订单类型。1:报单, 2:撤单, 3:爆仓, 4:交割 created_at true number 订单创建时间 page_index false int 第几页,不填第一页 page_size false int 不填默认20,不得多于50 """ params = {"symbol": symbol, "order_id": order_id, "order_type": order_type, "created_at": created_at} if page_index: params["page_index"] = page_index if page_size: params["page_size"] = page_size request_path = '/api/v1/contract_order_detail' return api_key_post(self.__url, request_path, params, self.__access_key, self.__secret_key)