MCPcopy Index your code
hub / github.com/ccxt/ccxt / createAdvancedOrderRequest

Method createAdvancedOrderRequest

ts/src/cryptocom.ts:1547–1659  ·  view source on GitHub ↗
(symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {})

Source from the content-addressed store, hash-verified

1545 }
1546
1547 createAdvancedOrderRequest (symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {}) {
1548 // differs slightly from createOrderRequest
1549 // since the advanced order endpoint requires a different set of parameters
1550 // namely here we don't support ref_price or spot_margin
1551 // and market-buy orders need to send notional instead of quantity
1552 const market = this.market (symbol);
1553 const uppercaseType = type.toUpperCase ();
1554 const request: Dict = {
1555 'instrument_name': market['id'],
1556 'side': (side as string).toUpperCase (),
1557 };
1558 if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
1559 request['price'] = this.priceToPrecision (symbol, price);
1560 }
1561 const broker = this.safeString (this.options, 'broker', 'CCXT');
1562 request['broker_id'] = broker;
1563 const timeInForce = this.safeStringUpper2 (params, 'timeInForce', 'time_in_force');
1564 if (timeInForce !== undefined) {
1565 if (timeInForce === 'GTC') {
1566 request['time_in_force'] = 'GOOD_TILL_CANCEL';
1567 } else if (timeInForce === 'IOC') {
1568 request['time_in_force'] = 'IMMEDIATE_OR_CANCEL';
1569 } else if (timeInForce === 'FOK') {
1570 request['time_in_force'] = 'FILL_OR_KILL';
1571 } else {
1572 request['time_in_force'] = timeInForce;
1573 }
1574 }
1575 const postOnly = this.safeBool (params, 'postOnly', false);
1576 if ((postOnly) || (timeInForce === 'PO')) {
1577 request['exec_inst'] = [ 'POST_ONLY' ];
1578 request['time_in_force'] = 'GOOD_TILL_CANCEL';
1579 }
1580 const triggerPrice = this.safeStringN (params, [ 'stopPrice', 'triggerPrice', 'ref_price' ]);
1581 const stopLossPrice = this.safeNumber (params, 'stopLossPrice');
1582 const takeProfitPrice = this.safeNumber (params, 'takeProfitPrice');
1583 const isTrigger = (triggerPrice !== undefined);
1584 const isStopLossTrigger = (stopLossPrice !== undefined);
1585 const isTakeProfitTrigger = (takeProfitPrice !== undefined);
1586 if (isTrigger) {
1587 const priceString = this.numberToString (price);
1588 if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
1589 if (side === 'buy') {
1590 if (Precise.stringLt (priceString, triggerPrice)) {
1591 request['type'] = 'TAKE_PROFIT_LIMIT';
1592 } else {
1593 request['type'] = 'STOP_LIMIT';
1594 }
1595 } else {
1596 if (Precise.stringLt (priceString, triggerPrice)) {
1597 request['type'] = 'STOP_LIMIT';
1598 } else {
1599 request['type'] = 'TAKE_PROFIT_LIMIT';
1600 }
1601 }
1602 } else {
1603 if (side === 'buy') {
1604 if (Precise.stringLt (priceString, triggerPrice)) {

Callers 1

createOrdersMethod · 0.95

Calls 15

marketMethod · 0.45
priceToPrecisionMethod · 0.45
safeStringMethod · 0.45
safeStringUpper2Method · 0.45
safeBoolMethod · 0.45
safeStringNMethod · 0.45
safeNumberMethod · 0.45
numberToStringMethod · 0.45
stringLtMethod · 0.45
handleOptionAndParamsMethod · 0.45
safeNumber2Method · 0.45
omitMethod · 0.45

Tested by

no test coverage detected