コード例 #1
0
    def get_contract_trigger_openorders(self,
                                        symbol,
                                        contract_code=None,
                                        page_index=None,
                                        page_size=None):
        """
        @author: liaoy
        属性	        数据类型	    是否必填	说明
        symbol	        String	    true	支持大小写,BTC,LTC...
        contract_code	String	    false	支持大小写,合约code
        page_index	    int	        false	第几页,不填默认第一页
        page_size	    int	        false	不填默认20,不得多于50
        """

        params = {"symbol": symbol}
        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 = '/api/v1/contract_trigger_openorders'
        return api_key_post(self.__url, request_path, params,
                            self.__access_key, self.__secret_key)
コード例 #2
0
    def send_lightning_close_position(self, symbol, contract_type,
                                      contract_code, volume, direction,
                                      client_order_id, order_price_type):
        """
        @author liaoy
        参数名称	            是否必须	类型	描述	    取值范围
        symbol	            false	string	品种代码	    支持大小写,"BTC","ETH"...
        contract_type	    false	string	合约类型	    “this_week”:当周,“next_week”:次周,“quarter”:当季, "next_quarter":次季
        contract_code	    false	string	合约代码	    BTC190903
        volume	            true	int	    委托数量(张)
        direction	        true	string	“buy”:买,“sell”:卖
        client_order_id	    false	long	(API)客户自己填写和维护,必须保持唯一,请注意必须小于等于9223372036854775807
        order_price_type    false	string	订单报价类型	不填,默认为“闪电平仓”,"lightning":闪电平仓,"lightning_fok":闪电平仓-FOK,"lightning_ioc":闪电平仓-IOC
        """

        params = {"volume": volume, "direction": direction}
        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
        if order_price_type:
            params['order_price_type'] = order_price_type

        request_path = '/api/v1/lightning_close_position'
        return api_key_post(self.__url, request_path, params,
                            self.__access_key, self.__secret_key)
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
    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)
コード例 #6
0
    def cancel_all_contract_trigger(self, symbol):
        """
        属性	        数据类型	    是否必填	    说明
        symbol	        String	    true	    支持大小写,BTC、LTC...
        contract_code	String	    false	    合约代码,"BTC180914" ...
        contract_type	String	    false	    合约类型 当周:"this_week", 次周:"next_week", 当季:"quarter", 次季:"next_quarter"
        """
        params = {"symbol": symbol}

        request_path = '/api/v1/contract_trigger_cancelall'
        return api_key_post(self.__url, request_path, params,
                            self.__access_key, self.__secret_key)
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    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)
コード例 #10
0
    def send_contract_trigger_order(self, symbol, contract_type, contract_code,
                                    trigger_type, trigger_price, order_price,
                                    order_price_type, volume, direction,
                                    offset, lever_rate):
        """
        参数名称	            是否必须	    类型	描述	    取值范围
        symbol	            false	    String	品种代码	    支持大小写,"BTC","ETH"...
        contract_type	    false	    String	合约类型	“this_week”:当周,“next_week”:次周,“quarter”:当季, "next_quarter":次季
        contract_code	    false	    String	合约代码	BTC190903
        trigger_type	    true	    String	触发类型: ge大于等于(触发价比最新价大);le小于(触发价比最新价小)
        trigger_price	    true	    Decimal	触发价,精度超过最小变动单位会报错
        order_price	        true	    Decimal	委托价,精度超过最小变动单位会报错
        order_price_type	false		委托类型: 不填默认为limit; 限价:limit ,最优5档:optimal_5,最优10档:optimal_10,最优20档:optimal_20
        volume	            true	    int	委托数量(张)
        direction	        true	    String	buy:买 sell:卖
        offset	            true	    String	open:开 close:平
        lever_rate	        true	    int	杠杆倍数[开仓若有10倍多单,就不能再下20倍多单;lever_rate 支持用户在该次下单所选合约品种下的所有实际可用 杠杆倍数,不局限为原来的 1、5、10、20]
        """

        params = {
            "trigger_type": trigger_type,
            "trigger_price": trigger_price,
            "order_price": order_price,
            "volume": volume,
            "direction": direction,
            "offset": offset,
            "lever_rate": lever_rate
        }
        if symbol:
            params["symbol"] = symbol
        if contract_type:
            params['contract_type'] = contract_type
        if contract_code:
            params['contract_code'] = contract_code
        if order_price_type:
            params['order_price_type'] = order_price_type

        request_path = '/api/v1/contract_trigger_order'
        return api_key_post(self.__url, request_path, params,
                            self.__access_key, self.__secret_key)
コード例 #11
0
    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)
コード例 #12
0
    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)
コード例 #13
0
    def get_contract_account_position_info(self, symbol=''):
        params = {'symbol': symbol}

        request_path = '/api/v1/contract_account_position_info'
        return api_key_post(self.__url, request_path, params,
                            self.__access_key, self.__secret_key)