(self, symbol: Str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})
| 1422 | } |
| 1423 | |
| 1424 | def create_order_request(self, symbol: Str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}): |
| 1425 | market = self.market(symbol) |
| 1426 | request = { |
| 1427 | 'market': market['id'], |
| 1428 | 'side': side, |
| 1429 | 'orderType': type, |
| 1430 | } |
| 1431 | isMarketOrder = (type == 'market') or (type == 'stopLoss') or (type == 'takeProfit') |
| 1432 | isLimitOrder = (type == 'limit') or (type == 'stopLossLimit') or (type == 'takeProfitLimit') |
| 1433 | timeInForce = self.safe_string(params, 'timeInForce') |
| 1434 | triggerPrice = self.safe_string_n(params, ['triggerPrice', 'stopPrice', 'triggerAmount']) |
| 1435 | postOnly = self.is_post_only(isMarketOrder, False, params) |
| 1436 | stopLossPrice = self.safe_value(params, 'stopLossPrice') # trigger when price crosses from above to below self value |
| 1437 | takeProfitPrice = self.safe_value(params, 'takeProfitPrice') # trigger when price crosses from below to above self value |
| 1438 | params = self.omit(params, ['timeInForce', 'triggerPrice', 'stopPrice', 'stopLossPrice', 'takeProfitPrice']) |
| 1439 | if isMarketOrder: |
| 1440 | cost = None |
| 1441 | if price is not None: |
| 1442 | priceString = self.number_to_string(price) |
| 1443 | amountString = self.number_to_string(amount) |
| 1444 | quoteAmount = Precise.string_mul(amountString, priceString) |
| 1445 | cost = self.parse_number(quoteAmount) |
| 1446 | else: |
| 1447 | cost = self.safe_number(params, 'cost') |
| 1448 | if cost is not None: |
| 1449 | precision = self.currency(market['quote'])['precision'] |
| 1450 | request['amountQuote'] = self.decimal_to_precision(cost, TRUNCATE, precision, self.precisionMode) |
| 1451 | else: |
| 1452 | request['amount'] = self.amount_to_precision(symbol, amount) |
| 1453 | params = self.omit(params, ['cost']) |
| 1454 | elif isLimitOrder: |
| 1455 | request['price'] = self.price_to_precision(symbol, price) |
| 1456 | request['amount'] = self.amount_to_precision(symbol, amount) |
| 1457 | isTakeProfit = (takeProfitPrice is not None) or (type == 'takeProfit') or (type == 'takeProfitLimit') |
| 1458 | isStopLoss = (stopLossPrice is not None) or (triggerPrice is not None) and (not isTakeProfit) or (type == 'stopLoss') or (type == 'stopLossLimit') |
| 1459 | if isStopLoss: |
| 1460 | if stopLossPrice is not None: |
| 1461 | triggerPrice = stopLossPrice |
| 1462 | request['orderType'] = 'stopLoss' if isMarketOrder else 'stopLossLimit' |
| 1463 | elif isTakeProfit: |
| 1464 | if takeProfitPrice is not None: |
| 1465 | triggerPrice = takeProfitPrice |
| 1466 | request['orderType'] = 'takeProfit' if isMarketOrder else 'takeProfitLimit' |
| 1467 | if triggerPrice is not None: |
| 1468 | request['triggerAmount'] = self.price_to_precision(symbol, triggerPrice) |
| 1469 | request['triggerType'] = 'price' |
| 1470 | request['triggerReference'] = 'lastTrade' # 'bestBid', 'bestAsk', 'midPrice' |
| 1471 | if (timeInForce is not None) and (timeInForce != 'PO'): |
| 1472 | request['timeInForce'] = timeInForce |
| 1473 | if postOnly: |
| 1474 | request['postOnly'] = True |
| 1475 | operatorId = None |
| 1476 | operatorId, params = self.handle_option_and_params(params, 'createOrder', 'operatorId') |
| 1477 | if operatorId is not None: |
| 1478 | request['operatorId'] = self.parse_to_int(operatorId) |
| 1479 | else: |
| 1480 | raise ArgumentsRequired(self.id + ' createOrder() requires an operatorId in params or options, eg: exchange.options[\'operatorId\'] = 1234567890') |
| 1481 | selfTradePrevention = None |
no test coverage detected