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

Method create_order_request

python/ccxt/bybit.py:4017–4256  ·  view source on GitHub ↗
(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}, isUTA=True)

Source from the content-addressed store, hash-verified

4015 return self.parse_order(order, market)
4016
4017 def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}, isUTA=True):
4018 market = self.market(symbol)
4019 symbol = market['symbol']
4020 lowerCaseType = type.lower()
4021 request = {
4022 'symbol': market['id'],
4023 # 'side': self.capitalize(side),
4024 # 'orderType': self.capitalize(lowerCaseType), # limit or market
4025 # 'timeInForce': 'GTC', # IOC, FOK, PostOnly
4026 # 'takeProfit': 123.45, # take profit price, only take effect upon opening the position
4027 # 'stopLoss': 123.45, # stop loss price, only take effect upon opening the position
4028 # 'reduceOnly': False, # reduce only, required for linear orders
4029 # when creating a closing order, bybit recommends a True value for
4030 # closeOnTrigger to avoid failing due to insufficient available margin
4031 # 'closeOnTrigger': False, required for linear orders
4032 # 'orderLinkId': 'string', # unique client order id, max 36 characters
4033 # 'triggerPrice': 123.46, # trigger price, required for conditional orders
4034 # 'triggerBy': 'MarkPrice', # IndexPrice, MarkPrice, LastPrice
4035 # 'tpTriggerby': 'MarkPrice', # IndexPrice, MarkPrice, LastPrice
4036 # 'slTriggerBy': 'MarkPrice', # IndexPrice, MarkPrice, LastPrice
4037 # 'mmp': False # market maker protection
4038 # 'positionIdx': 0, # Position mode. Unified account has one-way mode only(0)
4039 # 'triggerDirection': 1, # Conditional order param. Used to identify the expected direction of the conditional order. 1: triggered when market price rises to triggerPrice 2: triggered when market price falls to triggerPrice
4040 # Valid for spot only.
4041 # 'isLeverage': 0, # Whether to borrow. 0(default): False, 1: True
4042 # 'orderFilter': 'Order' # Order,tpslOrder. If not passed, Order by default
4043 # Valid for option only.
4044 # 'orderIv': '0', # Implied volatility; parameters are passed according to the real value; for example, for 10%, 0.1 is passed
4045 }
4046 hedged = self.safe_bool(params, 'hedged', False)
4047 reduceOnly = self.safe_bool(params, 'reduceOnly')
4048 triggerPrice = self.safe_value_2(params, 'triggerPrice', 'stopPrice')
4049 stopLossTriggerPrice = self.safe_value(params, 'stopLossPrice')
4050 takeProfitTriggerPrice = self.safe_value(params, 'takeProfitPrice')
4051 stopLoss = self.safe_value(params, 'stopLoss')
4052 takeProfit = self.safe_value(params, 'takeProfit')
4053 trailingTriggerPrice = self.safe_string_2(params, 'trailingTriggerPrice', 'activePrice', self.number_to_string(price))
4054 trailingAmount = self.safe_string_2(params, 'trailingAmount', 'trailingStop')
4055 isTrailingOrder = trailingAmount is not None
4056 isTriggerOrder = triggerPrice is not None
4057 isStopLossOrder = stopLossTriggerPrice is not None
4058 isTakeProfitOrder = takeProfitTriggerPrice is not None
4059 hasStopLoss = stopLoss is not None
4060 hasTakeProfit = takeProfit is not None
4061 isMarket = lowerCaseType == 'market'
4062 isLimit = lowerCaseType == 'limit'
4063 isBuy = side == 'buy'
4064 switchToOco = (isStopLossOrder and isTakeProfitOrder) or self.safe_bool(params, 'tradingStopEndpoint', False)
4065 defaultMethod = None
4066 if isTrailingOrder or switchToOco:
4067 defaultMethod = 'privatePostV5PositionTradingStop'
4068 else:
4069 defaultMethod = 'privatePostV5OrderCreate'
4070 method = None
4071 method, params = self.handle_option_and_params(params, 'createOrder', 'method', defaultMethod)
4072 endpointIsTradingStop = method == 'privatePostV5PositionTradingStop'
4073 if (price is None) and (lowerCaseType == 'limit') and not endpointIsTradingStop:
4074 raise ArgumentsRequired(self.id + ' createOrder requires a price argument for limit orders')

Callers 2

create_orderMethod · 0.95
create_ordersMethod · 0.95

Calls 15

get_amountMethod · 0.95
get_priceMethod · 0.95
get_bybit_typeMethod · 0.95
get_costMethod · 0.95
ArgumentsRequiredClass · 0.90
InvalidOrderClass · 0.90
NotSupportedClass · 0.90
safe_boolMethod · 0.80
safe_value_2Method · 0.80
safe_valueMethod · 0.80
safe_string_2Method · 0.80

Tested by

no test coverage detected