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

Method createContractOrderRequest

js/src/toobit.js:1626–1701  ·  view source on GitHub ↗
(symbol, type, side, amount, price = undefined, params = {})

Source from the content-addressed store, hash-verified

1624 return [request, params];
1625 }
1626 createContractOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1627 const market = this.market(symbol);
1628 const request = {
1629 'symbol': market['id'],
1630 'quantity': this.amountToPrecision(symbol, amount),
1631 };
1632 let reduceOnly = undefined;
1633 [reduceOnly, params] = this.handleParamBool(params, 'reduceOnly');
1634 if (side === 'buy') {
1635 side = reduceOnly ? 'SELL_CLOSE' : 'BUY_OPEN';
1636 }
1637 else if (side === 'sell') {
1638 side = reduceOnly ? 'BUY_CLOSE' : 'SELL_OPEN';
1639 }
1640 request['side'] = side;
1641 if (price !== undefined) {
1642 request['price'] = this.priceToPrecision(symbol, price);
1643 }
1644 if (this.inArray(type, ['limit', 'LIMIT'])) {
1645 request['type'] = type.toUpperCase();
1646 request['price'] = this.priceToPrecision(symbol, price);
1647 }
1648 else if (type === 'market') {
1649 request['type'] = 'LIMIT'; // weird, but exchange works this way
1650 request['priceType'] = 'MARKET';
1651 }
1652 let isPostOnly = undefined;
1653 [isPostOnly, params] = this.handlePostOnly(type === 'market', false, params);
1654 if (isPostOnly) {
1655 request['timeInForce'] = 'LIMIT_MAKER';
1656 }
1657 const values = this.handleTriggerPricesAndParams(symbol, params);
1658 const triggerPrice = values[0];
1659 params = values[3];
1660 if (triggerPrice !== undefined) {
1661 request['stopPrice'] = triggerPrice;
1662 }
1663 const stopLoss = this.safeDict(params, 'stopLoss');
1664 const takeProfit = this.safeDict(params, 'takeProfit');
1665 const hasStopLoss = (stopLoss !== undefined);
1666 const hasTakeProfit = (takeProfit !== undefined);
1667 const triggerPriceTypes = {
1668 'mark': 'MARK_PRICE',
1669 'last': 'CONTRACT_PRICE',
1670 };
1671 if (hasStopLoss) {
1672 request['stopLoss'] = this.safeValue(stopLoss, 'triggerPrice');
1673 const limitPrice = this.safeValue(stopLoss, 'price');
1674 if (limitPrice !== undefined) {
1675 request['slOrderType'] = 'LIMIT';
1676 request['slLimitPrice'] = this.priceToPrecision(symbol, limitPrice);
1677 }
1678 const triggerPriceType = this.safeString(stopLoss, 'triggerPriceType');
1679 if (triggerPriceType !== undefined) {
1680 request['slTriggerBy'] = this.safeString(triggerPriceTypes, triggerPriceType, triggerPriceType);
1681 }
1682 params = this.omit(params, 'stopLoss');
1683 }

Callers 1

createOrderMethod · 0.95

Calls 12

marketMethod · 0.45
amountToPrecisionMethod · 0.45
handleParamBoolMethod · 0.45
priceToPrecisionMethod · 0.45
inArrayMethod · 0.45
handlePostOnlyMethod · 0.45
safeDictMethod · 0.45
safeValueMethod · 0.45
safeStringMethod · 0.45
omitMethod · 0.45
uuidMethod · 0.45

Tested by

no test coverage detected