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