MCPcopy Create free account
hub / github.com/ccxt/ccxt / create_contract_order_request

Method create_contract_order_request

python/ccxt/async_support/htx.py:5021–5172  ·  view source on GitHub ↗

@ignore helper function to build request :param str symbol: unified symbol of the market to create an order in :param str type: 'market' or 'limit' :param str side: 'buy' or 'sell' :param float amount: how much you want to trade in units of the base currency

(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})

Source from the content-addressed store, hash-verified

5019 return self.extend(request, params)
5020
5021 def create_contract_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
5022 """
5023 @ignore
5024 helper function to build request
5025 :param str symbol: unified symbol of the market to create an order in
5026 :param str type: 'market' or 'limit'
5027 :param str side: 'buy' or 'sell'
5028 :param float amount: how much you want to trade in units of the base currency
5029 :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
5030 :param dict [params]: extra parameters specific to the exchange API endpoint
5031 :param str [params.timeInForce]: supports 'IOC' and 'FOK'
5032 :param float [params.trailingPercent]: *contract only* the percent to trail away from the current market price
5033 :param float [params.trailingTriggerPrice]: *contract only* the price to trigger a trailing order, default uses the price argument
5034 :param dict [params.takeProfit]: *takeProfit object in params, linear swap only* containing the triggerPrice at which the attached take profit order will be triggered
5035 :param float [params.takeProfit.triggerPrice]: take profit trigger price
5036 :param float [params.takeProfit.price]: take profit order price take profit orders
5037 :param str [params.takeProfit.type]: market is the default, limit, optimal_5, optimal_10, optimal_20
5038 :param dict [params.stopLoss]: *stopLoss object in params, linear swap only* containing the triggerPrice at which the attached stop loss order will be triggered
5039 :param float [params.stopLoss.triggerPrice]: stop loss trigger price
5040 :param float [params.stopLoss.price]: stop loss order price for stop loss orders
5041 :param str [params.stopLoss.type]: market is the default, limit, optimal_5, optimal_10, optimal_20
5042 :returns dict: request to be sent to the exchange
5043 """
5044 market = self.market(symbol)
5045 request = {
5046 'contract_code': market['id'],
5047 'volume': self.amount_to_precision(symbol, amount),
5048 }
5049 postOnly = None
5050 postOnly, params = self.handle_post_only(type == 'market', type == 'post_only', params)
5051 if postOnly:
5052 type = 'post_only'
5053 subType = None
5054 subType, params = self.handle_sub_type_and_params('createOrder', market, params)
5055 isLinear = (subType == 'linear')
5056 reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only', False)
5057 hedged = self.safe_bool(params, 'hedged', False)
5058 timeInForce = self.safe_string_lower_2(params, 'timeInForce', 'time_in_force', 'gtc')
5059 if isLinear:
5060 marginMode = None
5061 marginMode, params = self.handle_margin_mode_and_params('createOrder', params, 'cross')
5062 request['margin_mode'] = marginMode
5063 request['side'] = side
5064 if timeInForce is not None:
5065 request['time_in_force'] = timeInForce.lower()
5066 stopLoss = self.safe_dict(params, 'stopLoss')
5067 takeProfit = self.safe_dict(params, 'takeProfit')
5068 stopLossTriggerPriceAttached = self.safe_number(stopLoss, 'triggerPrice')
5069 stopLossOrderPrice = self.safe_number(stopLoss, 'price')
5070 stopLossType = self.safe_string(stopLoss, 'type')
5071 takeProfitTriggerPriceAttached = self.safe_number(takeProfit, 'triggerPrice')
5072 takeProfitOrderPrice = self.safe_number(takeProfit, 'price')
5073 takeProfitType = self.safe_string(takeProfit, 'type')
5074 # on htx for attached tpsl orders sl_order_price or tp_order_price need to be filled and the sl_trigger_price or tp_trigger_price are optional
5075 if stopLoss is not None:
5076 if stopLossTriggerPriceAttached is not None:
5077 request['sl_trigger_price'] = self.price_to_precision(symbol, stopLossTriggerPriceAttached)
5078 if stopLossOrderPrice is not None:

Callers 2

create_orderMethod · 0.95
create_ordersMethod · 0.95

Calls 15

handle_post_onlyMethod · 0.80
safe_bool_2Method · 0.80
safe_boolMethod · 0.80
safe_string_lower_2Method · 0.80
safe_dictMethod · 0.80
safe_numberMethod · 0.80
safe_stringMethod · 0.80
safe_number_nMethod · 0.80
safe_number_2Method · 0.80
safe_string_2Method · 0.80
safe_integer_nMethod · 0.80

Tested by

no test coverage detected