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

Method createOrderRequest

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

Source from the content-addressed store, hash-verified

1329 }
1330
1331 createOrderRequest (symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {}) {
1332 const market = this.market (symbol);
1333 const uppercaseType = type.toUpperCase ();
1334 const request: Dict = {
1335 'instrument_name': market['id'],
1336 'side': (side as string).toUpperCase (),
1337 'quantity': this.amountToPrecision (symbol, amount),
1338 };
1339 if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
1340 request['price'] = this.priceToPrecision (symbol, price);
1341 }
1342 const broker = this.safeString (this.options, 'broker', 'CCXT');
1343 request['broker_id'] = broker;
1344 let marketType: Str = undefined;
1345 let marginMode: Str = undefined;
1346 [ marketType, params ] = this.handleMarketTypeAndParams ('createOrder', market, params);
1347 [ marginMode, params ] = this.customHandleMarginModeAndParams ('createOrder', params);
1348 if ((marketType === 'margin') || (marginMode !== undefined)) {
1349 request['spot_margin'] = 'MARGIN';
1350 } else if (marketType === 'spot') {
1351 request['spot_margin'] = 'SPOT';
1352 }
1353 const timeInForce = this.safeStringUpper2 (params, 'timeInForce', 'time_in_force');
1354 if (timeInForce !== undefined) {
1355 if (timeInForce === 'GTC') {
1356 request['time_in_force'] = 'GOOD_TILL_CANCEL';
1357 } else if (timeInForce === 'IOC') {
1358 request['time_in_force'] = 'IMMEDIATE_OR_CANCEL';
1359 } else if (timeInForce === 'FOK') {
1360 request['time_in_force'] = 'FILL_OR_KILL';
1361 } else {
1362 request['time_in_force'] = timeInForce;
1363 }
1364 }
1365 const postOnly = this.safeBool (params, 'postOnly', false);
1366 if ((postOnly) || (timeInForce === 'PO')) {
1367 request['exec_inst'] = [ 'POST_ONLY' ];
1368 request['time_in_force'] = 'GOOD_TILL_CANCEL';
1369 }
1370 const triggerPrice = this.safeStringN (params, [ 'stopPrice', 'triggerPrice', 'ref_price' ]);
1371 const stopLossPrice = this.safeNumber (params, 'stopLossPrice');
1372 const takeProfitPrice = this.safeNumber (params, 'takeProfitPrice');
1373 const isTrigger = (triggerPrice !== undefined);
1374 const isStopLossTrigger = (stopLossPrice !== undefined);
1375 const isTakeProfitTrigger = (takeProfitPrice !== undefined);
1376 if (isTrigger) {
1377 request['ref_price'] = this.priceToPrecision (symbol, triggerPrice);
1378 const priceString = this.numberToString (price);
1379 if ((uppercaseType === 'LIMIT') || (uppercaseType === 'STOP_LIMIT') || (uppercaseType === 'TAKE_PROFIT_LIMIT')) {
1380 if (side === 'buy') {
1381 if (Precise.stringLt (priceString, triggerPrice)) {
1382 request['type'] = 'TAKE_PROFIT_LIMIT';
1383 } else {
1384 request['type'] = 'STOP_LIMIT';
1385 }
1386 } else {
1387 if (Precise.stringLt (priceString, triggerPrice)) {
1388 request['type'] = 'STOP_LIMIT';

Callers 2

createOrderMethod · 0.95
createOrderWsMethod · 0.95

Calls 14

marketMethod · 0.45
amountToPrecisionMethod · 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

Tested by

no test coverage detected