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

Method create_order

python/ccxt/async_support/derive.py:1154–1340  ·  view source on GitHub ↗

create a trade order https://docs.derive.xyz/reference/post_private-order :param str symbol: unified symbol of the market to create an order in :param str type: 'market' or 'limit' :param str side: 'buy' or 'sell' :param float amount: how much of cu

(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})

Source from the content-addressed store, hash-verified

1152 return Precise.string_mul(num, dec)
1153
1154 async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1155 """
1156 create a trade order
1157
1158 https://docs.derive.xyz/reference/post_private-order
1159
1160 :param str symbol: unified symbol of the market to create an order in
1161 :param str type: 'market' or 'limit'
1162 :param str side: 'buy' or 'sell'
1163 :param float amount: how much of currency you want to trade in units of base currency
1164 :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
1165 :param dict [params]: extra parameters specific to the exchange API endpoint
1166 :param str [params.subaccount_id]: *required* the subaccount id
1167 :param float [params.triggerPrice]: The price a trigger order is triggered at
1168 :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered(perpetual swap markets only)
1169 :param float [params.takeProfit.triggerPrice]: take profit trigger price
1170 :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered(perpetual swap markets only)
1171 :param float [params.stopLoss.triggerPrice]: stop loss trigger price
1172 :param float [params.max_fee]: *required* the maximum fee you are willing to pay for the order
1173 :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
1174 """
1175 await self.load_markets()
1176 market = self.market(symbol)
1177 if price is None:
1178 raise ArgumentsRequired(self.id + ' createOrder() requires a price argument')
1179 subaccountId = None
1180 subaccountId, params = self.handle_derive_subaccount_id('createOrder', params)
1181 test = self.safe_bool(params, 'test', False)
1182 reduceOnly = self.safe_bool_2(params, 'reduceOnly', 'reduce_only')
1183 timeInForce = self.safe_string_lower_2(params, 'timeInForce', 'time_in_force')
1184 postOnly = self.safe_bool(params, 'postOnly')
1185 orderType = type.lower()
1186 orderSide = side.lower()
1187 nonce = self.milliseconds()
1188 # Order signature expiry must be between 2592000 and 7776000 sec from now
1189 signatureExpiry = self.safe_integer(params, 'signature_expiry_sec', self.seconds() + 7776000)
1190 ACTION_TYPEHASH = self.base16_to_binary('4d7a9f27c403ff9c0f19bce61d76d82f9aa29f8d6d4b0c5474607d9770d1af17')
1191 sandboxMode = self.safe_bool(self.options, 'sandboxMode', False)
1192 TRADE_MODULE_ADDRESS = '0x87F2863866D85E3192a35A73b388BD625D83f2be' if (sandboxMode) else '0xB8D20c2B7a1Ad2EE33Bc50eF10876eD3035b5e7b'
1193 priceString = self.number_to_string(price)
1194 maxFee = None
1195 maxFee, params = self.handle_option_and_params(params, 'createOrder', 'max_fee')
1196 if maxFee is None:
1197 raise ArgumentsRequired(self.id + ' createOrder() requires a max_fee argument in params')
1198 maxFeeString = self.number_to_string(maxFee)
1199 amountString = self.number_to_string(amount)
1200 tradeModuleDataHash = self.hash(self.eth_abi_encode([
1201 'address', 'uint', 'int', 'int', 'uint', 'uint', 'bool',
1202 ], [
1203 market['info']['base_asset_address'],
1204 self.parse_to_numeric(market['info']['base_asset_sub_id']),
1205 self.convert_to_big_int((self.parse_units(priceString))),
1206 self.convert_to_big_int((self.parse_units((self.amount_to_precision(symbol, amountString))))),
1207 self.convert_to_big_int((self.parse_units(maxFeeString))),
1208 subaccountId,
1209 orderSide == 'buy',
1210 ]), 'keccak', 'binary')
1211 deriveWalletAddress = None

Callers

nothing calls this directly

Calls 15

parse_unitsMethod · 0.95
sign_orderMethod · 0.95
parse_orderMethod · 0.95
ArgumentsRequiredClass · 0.90
InvalidOrderClass · 0.90
safe_boolMethod · 0.80
safe_bool_2Method · 0.80
safe_string_lower_2Method · 0.80
safe_integerMethod · 0.80
base16_to_binaryMethod · 0.80

Tested by

no test coverage detected