コード例 #1
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)
コード例 #2
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)
コード例 #3
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):

        params = {
            "trigger_type": trigger_type,
            "trigger_price": trigger_price,
            "order_price": order_price,
            "order_price_type": order_price_type,
            "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

        request_path = '/api/v1/contract_trigger_order'
        return api_key_post(self.__url, request_path, params,
                            self.__access_key, self.__secret_key)
コード例 #4
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)
コード例 #5
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)
コード例 #6
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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
0
    def api_key_post_retry(self, path, params):

        retry_count = 3
        while retry_count > 0:
            ret = api_key_post(self.__url, path, params, self.__access_key,
                               self.__secret_key)
            if ret["status"] in ["fail", "error"]:
                retry_count -= 1
            else:
                return ret
        self.TODOSendAlert(ret)
コード例 #10
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)
コード例 #11
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)
コード例 #12
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)
コード例 #13
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)
コード例 #14
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)
コード例 #15
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)
コード例 #16
0
 def get_contract_order_detail(self, symbol, order_id, page_index=None, page_size=None):
     """
     参数名称     是否必须  类型    描述
     symbol      true	    string "BTC","ETH"...
     order_id    true	    long	   订单id
     page_index  false   int    第几页,不填第一页
     page_size   false   int    不填默认20,不得多于50
     """
     
     params = {"symbol": symbol,
               "order_id": order_id}
     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)
コード例 #17
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)
コード例 #18
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)