* @method * @name exmo#createOrder * @description create a trade order * @see https://documenter.getpostman.com/view/10287440/SzYXWKPi#80daa469-ec59-4d0a-b229-6a311d8dd1cd * @see https://documenter.getpostman.com/view/10287440/SzYXWKPi#de6f4321-eeac-468c-87f7-c4ad7062e265 // sto
(symbol, type, side, amount, price = undefined, params = {})
| 1573 | * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure} |
| 1574 | */ |
| 1575 | async createOrder(symbol, type, side, amount, price = undefined, params = {}) { |
| 1576 | await this.loadMarkets(); |
| 1577 | const market = this.market(symbol); |
| 1578 | const isMarket = (type === 'market') && (price === undefined); |
| 1579 | let marginMode = undefined; |
| 1580 | [marginMode, params] = this.handleMarginModeAndParams('createOrder', params); |
| 1581 | if (marginMode === 'cross') { |
| 1582 | throw new BadRequest(this.id + ' only supports isolated margin'); |
| 1583 | } |
| 1584 | const isSpot = (marginMode !== 'isolated'); |
| 1585 | const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'stop_price']); |
| 1586 | const cost = this.safeString(params, 'cost'); |
| 1587 | const request = { |
| 1588 | 'pair': market['id'], |
| 1589 | // 'leverage': 2, |
| 1590 | // 'quantity': this.amountToPrecision (market['symbol'], amount), |
| 1591 | // spot - buy, sell, market_buy, market_sell, market_buy_total, market_sell_total |
| 1592 | // margin - limit_buy, limit_sell, market_buy, market_sell, stop_buy, stop_sell, stop_limit_buy, stop_limit_sell, trailing_stop_buy, trailing_stop_sell |
| 1593 | // 'stop_price': this.priceToPrecision (symbol, stopPrice), |
| 1594 | // 'distance': 0, // distance for trailing stop orders |
| 1595 | // 'expire': 0, // expiration timestamp in UTC timezone for the order, unless expire is 0 |
| 1596 | // 'client_id': 123, // optional, must be a positive integer |
| 1597 | // 'comment': '', // up to 50 latin symbols, whitespaces, underscores |
| 1598 | }; |
| 1599 | if (cost === undefined) { |
| 1600 | request['quantity'] = this.amountToPrecision(market['symbol'], amount); |
| 1601 | } |
| 1602 | else { |
| 1603 | request['quantity'] = this.costToPrecision(market['symbol'], cost); |
| 1604 | } |
| 1605 | let clientOrderId = this.safeValue2(params, 'client_id', 'clientOrderId'); |
| 1606 | if (clientOrderId !== undefined) { |
| 1607 | clientOrderId = this.safeInteger2(params, 'client_id', 'clientOrderId'); |
| 1608 | if (clientOrderId === undefined) { |
| 1609 | throw new BadRequest(this.id + ' createOrder() client order id must be an integer / numeric literal'); |
| 1610 | } |
| 1611 | else { |
| 1612 | request['client_id'] = clientOrderId; |
| 1613 | } |
| 1614 | } |
| 1615 | const leverage = this.safeNumber(params, 'leverage'); |
| 1616 | if (!isSpot && (leverage === undefined)) { |
| 1617 | throw new ArgumentsRequired(this.id + ' createOrder requires an extra param params["leverage"] for margin orders'); |
| 1618 | } |
| 1619 | params = this.omit(params, ['stopPrice', 'stop_price', 'triggerPrice', 'timeInForce', 'client_id', 'clientOrderId', 'cost']); |
| 1620 | if (price !== undefined) { |
| 1621 | request['price'] = this.priceToPrecision(market['symbol'], price); |
| 1622 | } |
| 1623 | let response; |
| 1624 | if (isSpot) { |
| 1625 | if (triggerPrice !== undefined) { |
| 1626 | if (type === 'limit') { |
| 1627 | throw new BadRequest(this.id + ' createOrder () cannot create stop limit orders for spot, only stop market'); |
| 1628 | } |
| 1629 | else { |
| 1630 | request['type'] = side; |
| 1631 | request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice); |
| 1632 | } |
no test coverage detected