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

Method createOrderRequest

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

Source from the content-addressed store, hash-verified

4451 return this.parseOrders(response);
4452 }
4453 createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
4454 const market = this.market(symbol);
4455 const contract = market['contract'];
4456 const trigger = this.safeValue(params, 'trigger');
4457 const triggerPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
4458 const stopLossPrice = this.safeValue(params, 'stopLossPrice', triggerPrice);
4459 const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
4460 const isStopLossOrder = stopLossPrice !== undefined;
4461 const isTakeProfitOrder = takeProfitPrice !== undefined;
4462 const isTpsl = isStopLossOrder || isTakeProfitOrder;
4463 if (isStopLossOrder && isTakeProfitOrder) {
4464 throw new ExchangeError(this.id + ' createOrder() stopLossPrice and takeProfitPrice cannot both be defined');
4465 }
4466 const reduceOnly = this.safeValue(params, 'reduceOnly');
4467 const exchangeSpecificTimeInForce = this.safeStringLowerN(params, ['timeInForce', 'tif', 'time_in_force']);
4468 let postOnly = undefined;
4469 [postOnly, params] = this.handlePostOnly(type === 'market', exchangeSpecificTimeInForce === 'poc', params);
4470 let timeInForce = this.handleTimeInForce(params);
4471 if (postOnly) {
4472 timeInForce = 'poc';
4473 }
4474 // we only omit the unified params here
4475 // this is because the other params will get extended into the request
4476 let clientOrderId = this.safeString2(params, 'text', 'clientOrderId');
4477 params = this.omit(params, ['stopPrice', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'reduceOnly', 'timeInForce', 'postOnly', 'clientOrderId']);
4478 const isLimitOrder = (type === 'limit');
4479 const isMarketOrder = (type === 'market');
4480 if (isLimitOrder && price === undefined) {
4481 throw new ArgumentsRequired(this.id + ' createOrder () requires a price argument for ' + type + ' orders');
4482 }
4483 if (isMarketOrder) {
4484 if ((timeInForce === 'poc') || (timeInForce === 'gtc')) {
4485 throw new ExchangeError(this.id + ' createOrder () timeInForce for market order can only be "FOK" or "IOC"');
4486 }
4487 else {
4488 if (timeInForce === undefined) {
4489 const defaultTif = this.safeString(this.options, 'defaultTimeInForce', 'IOC');
4490 const exchangeSpecificTif = this.safeString(this.options['timeInForce'], defaultTif, 'ioc');
4491 timeInForce = exchangeSpecificTif;
4492 }
4493 }
4494 if (contract) {
4495 price = 0;
4496 }
4497 }
4498 if (contract) {
4499 const isClose = this.safeValue(params, 'close');
4500 if (isClose) {
4501 amount = 0;
4502 }
4503 else {
4504 const amountToPrecision = this.amountToPrecision(symbol, amount);
4505 const signedAmount = (side === 'sell') ? Precise.stringNeg(amountToPrecision) : amountToPrecision;
4506 amount = parseInt(signedAmount);
4507 }
4508 }
4509 let request = undefined;
4510 const nonTriggerOrder = !isTpsl && (trigger === undefined);

Callers 3

createOrderMethod · 0.95
createOrdersRequestMethod · 0.95
createOrderWsMethod · 0.95

Calls 15

getMarginModeMethod · 0.95
parseIntFunction · 0.85
marketMethod · 0.45
safeValueMethod · 0.45
safeValue2Method · 0.45
safeStringLowerNMethod · 0.45
handlePostOnlyMethod · 0.45
handleTimeInForceMethod · 0.45
safeString2Method · 0.45
omitMethod · 0.45
safeStringMethod · 0.45
amountToPrecisionMethod · 0.45

Tested by

no test coverage detected