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

Method createOrder

ts/src/derive.ts:1202–1378  ·  view source on GitHub ↗

* @method * @name derive#createOrder * @description create a trade order * @see https://docs.derive.xyz/reference/post_private-order * @param {string} symbol unified symbol of the market to create an order in * @param {string} type 'market' or 'limit' * @param {string}

(symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {})

Source from the content-addressed store, hash-verified

1200 * @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
1201 */
1202 async createOrder (symbol: string, type: OrderType, side: OrderSide, amount: number, price: Num = undefined, params = {}) {
1203 await this.loadMarkets ();
1204 const market = this.market (symbol);
1205 if (price === undefined) {
1206 throw new ArgumentsRequired (this.id + ' createOrder() requires a price argument');
1207 }
1208 let subaccountId: Str | Dict = undefined;
1209 [ subaccountId, params ] = this.handleDeriveSubaccountId ('createOrder', params);
1210 const test = this.safeBool (params, 'test', false);
1211 const reduceOnly = this.safeBool2 (params, 'reduceOnly', 'reduce_only');
1212 const timeInForce = this.safeStringLower2 (params, 'timeInForce', 'time_in_force');
1213 const postOnly = this.safeBool (params, 'postOnly');
1214 const orderType = type.toLowerCase ();
1215 const orderSide = (side as string).toLowerCase ();
1216 const nonce = this.milliseconds ();
1217 // Order signature expiry must be between 2592000 and 7776000 sec from now
1218 const signatureExpiry = this.safeInteger (params, 'signature_expiry_sec', this.seconds () + 7776000);
1219 const ACTION_TYPEHASH = this.base16ToBinary ('4d7a9f27c403ff9c0f19bce61d76d82f9aa29f8d6d4b0c5474607d9770d1af17');
1220 const sandboxMode = this.safeBool (this.options, 'sandboxMode', false);
1221 const TRADE_MODULE_ADDRESS = (sandboxMode) ? '0x87F2863866D85E3192a35A73b388BD625D83f2be' : '0xB8D20c2B7a1Ad2EE33Bc50eF10876eD3035b5e7b';
1222 const priceString = this.numberToString (price) as string;
1223 let maxFee: Num = undefined;
1224 [ maxFee, params ] = this.handleOptionAndParams (params, 'createOrder', 'max_fee');
1225 if (maxFee === undefined) {
1226 throw new ArgumentsRequired (this.id + ' createOrder() requires a max_fee argument in params');
1227 }
1228 const maxFeeString = this.numberToString (maxFee) as string;
1229 const amountString = this.numberToString (amount) as string;
1230 const tradeModuleDataHash = this.hash (this.ethAbiEncode ([
1231 'address', 'uint', 'int', 'int', 'uint', 'uint', 'bool',
1232 ], [
1233 market['info']['base_asset_address'],
1234 this.parseToNumeric (market['info']['base_asset_sub_id']),
1235 this.convertToBigInt ((this.parseUnits (priceString) as string)),
1236 this.convertToBigInt ((this.parseUnits ((this.amountToPrecision (symbol, amountString) as string)) as string)),
1237 this.convertToBigInt ((this.parseUnits (maxFeeString) as string)),
1238 subaccountId,
1239 orderSide === 'buy',
1240 ]), keccak, 'binary');
1241 let deriveWalletAddress: Str | Dict = undefined;
1242 [ deriveWalletAddress, params ] = this.handleDeriveWalletAddress ('createOrder', params);
1243 const signature = this.signOrder ([
1244 ACTION_TYPEHASH,
1245 subaccountId,
1246 nonce,
1247 TRADE_MODULE_ADDRESS,
1248 tradeModuleDataHash,
1249 signatureExpiry,
1250 deriveWalletAddress,
1251 this.walletAddress,
1252 ], this.privateKey);
1253 const request: Dict = {
1254 'instrument_name': market['id'],
1255 'direction': orderSide,
1256 'order_type': orderType,
1257 'nonce': nonce,
1258 'amount': amountString,
1259 'limit_price': priceString,

Callers

nothing calls this directly

Calls 15

parseUnitsMethod · 0.95
signOrderMethod · 0.95
parseOrderMethod · 0.95
privatePostOrderDebugMethod · 0.65
privatePostOrderMethod · 0.65
loadMarketsMethod · 0.45
marketMethod · 0.45
safeBoolMethod · 0.45
safeBool2Method · 0.45
safeStringLower2Method · 0.45

Tested by

no test coverage detected