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

Method create_order_request

python/ccxt/cryptocom.py:1309–1389  ·  view source on GitHub ↗
(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={})

Source from the content-addressed store, hash-verified

1307 return self.parse_order(order, market)
1308
1309 def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1310 market = self.market(symbol)
1311 uppercaseType = type.upper()
1312 request = {
1313 'instrument_name': market['id'],
1314 'side': side.upper(),
1315 'quantity': self.amount_to_precision(symbol, amount),
1316 }
1317 if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
1318 request['price'] = self.price_to_precision(symbol, price)
1319 broker = self.safe_string(self.options, 'broker', 'CCXT')
1320 request['broker_id'] = broker
1321 marketType = None
1322 marginMode = None
1323 marketType, params = self.handle_market_type_and_params('createOrder', market, params)
1324 marginMode, params = self.custom_handle_margin_mode_and_params('createOrder', params)
1325 if (marketType == 'margin') or (marginMode is not None):
1326 request['spot_margin'] = 'MARGIN'
1327 elif marketType == 'spot':
1328 request['spot_margin'] = 'SPOT'
1329 timeInForce = self.safe_string_upper_2(params, 'timeInForce', 'time_in_force')
1330 if timeInForce is not None:
1331 if timeInForce == 'GTC':
1332 request['time_in_force'] = 'GOOD_TILL_CANCEL'
1333 elif timeInForce == 'IOC':
1334 request['time_in_force'] = 'IMMEDIATE_OR_CANCEL'
1335 elif timeInForce == 'FOK':
1336 request['time_in_force'] = 'FILL_OR_KILL'
1337 else:
1338 request['time_in_force'] = timeInForce
1339 postOnly = self.safe_bool(params, 'postOnly', False)
1340 if (postOnly) or (timeInForce == 'PO'):
1341 request['exec_inst'] = ['POST_ONLY']
1342 request['time_in_force'] = 'GOOD_TILL_CANCEL'
1343 triggerPrice = self.safe_string_n(params, ['stopPrice', 'triggerPrice', 'ref_price'])
1344 stopLossPrice = self.safe_number(params, 'stopLossPrice')
1345 takeProfitPrice = self.safe_number(params, 'takeProfitPrice')
1346 isTrigger = (triggerPrice is not None)
1347 isStopLossTrigger = (stopLossPrice is not None)
1348 isTakeProfitTrigger = (takeProfitPrice is not None)
1349 if isTrigger:
1350 request['ref_price'] = self.price_to_precision(symbol, triggerPrice)
1351 priceString = self.number_to_string(price)
1352 if (uppercaseType == 'LIMIT') or (uppercaseType == 'STOP_LIMIT') or (uppercaseType == 'TAKE_PROFIT_LIMIT'):
1353 if side == 'buy':
1354 if Precise.string_lt(priceString, triggerPrice):
1355 request['type'] = 'TAKE_PROFIT_LIMIT'
1356 else:
1357 request['type'] = 'STOP_LIMIT'
1358 else:
1359 if Precise.string_lt(priceString, triggerPrice):
1360 request['type'] = 'STOP_LIMIT'
1361 else:
1362 request['type'] = 'TAKE_PROFIT_LIMIT'
1363 else:
1364 if side == 'buy':
1365 if Precise.string_lt(priceString, triggerPrice):
1366 request['type'] = 'TAKE_PROFIT'

Callers 1

create_orderMethod · 0.95

Calls 13

safe_stringMethod · 0.80
safe_string_upper_2Method · 0.80
safe_boolMethod · 0.80
safe_string_nMethod · 0.80
safe_numberMethod · 0.80
string_ltMethod · 0.80
marketMethod · 0.45
amount_to_precisionMethod · 0.45
price_to_precisionMethod · 0.45
omitMethod · 0.45

Tested by

no test coverage detected