* @method * @name bittrade#createOrder * @description create a trade order * @param {string} symbol unified symbol of the market to create an order in * @param {string} type 'market' or 'limit' * @param {string} side 'buy' or 'sell' * @param {float} amount how much of c
(symbol, type, side, amount, price = undefined, params = {})
| 1466 | * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure} |
| 1467 | */ |
| 1468 | async createOrder(symbol, type, side, amount, price = undefined, params = {}) { |
| 1469 | await this.loadMarkets(); |
| 1470 | await this.loadAccounts(); |
| 1471 | const market = this.market(symbol); |
| 1472 | const request = { |
| 1473 | 'account-id': this.accounts[0]['id'], |
| 1474 | 'symbol': market['id'], |
| 1475 | 'type': side + '-' + type, |
| 1476 | }; |
| 1477 | const clientOrderId = this.safeString2(params, 'clientOrderId', 'client-order-id'); // must be 64 chars max and unique within 24 hours |
| 1478 | if (clientOrderId === undefined) { |
| 1479 | const broker = this.safeValue(this.options, 'broker', {}); |
| 1480 | const brokerId = this.safeString(broker, 'id'); |
| 1481 | request['client-order-id'] = brokerId + this.uuid(); |
| 1482 | } |
| 1483 | else { |
| 1484 | request['client-order-id'] = clientOrderId; |
| 1485 | } |
| 1486 | params = this.omit(params, ['clientOrderId', 'client-order-id']); |
| 1487 | if ((type === 'market') && (side === 'buy')) { |
| 1488 | let quoteAmount = undefined; |
| 1489 | let createMarketBuyOrderRequiresPrice = true; |
| 1490 | [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true); |
| 1491 | const cost = this.safeNumber(params, 'cost'); |
| 1492 | params = this.omit(params, 'cost'); |
| 1493 | if (cost !== undefined) { |
| 1494 | quoteAmount = this.amountToPrecision(symbol, cost); |
| 1495 | } |
| 1496 | else if (createMarketBuyOrderRequiresPrice) { |
| 1497 | if (price === undefined) { |
| 1498 | throw new InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument'); |
| 1499 | } |
| 1500 | else { |
| 1501 | // despite that cost = amount * price is in quote currency and should have quote precision |
| 1502 | // the exchange API requires the cost supplied in 'amount' to be of base precision |
| 1503 | // more about it here: |
| 1504 | // https://github.com/ccxt/ccxt/pull/4395 |
| 1505 | // https://github.com/ccxt/ccxt/issues/7611 |
| 1506 | // we use amountToPrecision here because the exchange requires cost in base precision |
| 1507 | const amountString = this.numberToString(amount); |
| 1508 | const priceString = this.numberToString(price); |
| 1509 | quoteAmount = this.amountToPrecision(symbol, Precise.stringMul(amountString, priceString)); |
| 1510 | } |
| 1511 | } |
| 1512 | else { |
| 1513 | quoteAmount = this.amountToPrecision(symbol, amount); |
| 1514 | } |
| 1515 | request['amount'] = quoteAmount; |
| 1516 | } |
| 1517 | else { |
| 1518 | request['amount'] = this.amountToPrecision(symbol, amount); |
| 1519 | } |
| 1520 | if (type === 'limit' || type === 'ioc' || type === 'limit-maker' || type === 'stop-limit' || type === 'stop-limit-fok') { |
| 1521 | request['price'] = this.priceToPrecision(symbol, price); |
| 1522 | } |
| 1523 | const method = this.options['createOrderMethod']; |
| 1524 | const response = await this[method](this.extend(request, params)); |
| 1525 | const id = this.safeString(response, 'data'); |
no test coverage detected