(self, symbol: str, type, side, amount, price=None, params={})
| 2382 | return await self.create_contract_order(symbol, type, side, amount, price, params) |
| 2383 | |
| 2384 | async def create_spot_order(self, symbol: str, type, side, amount, price=None, params={}): |
| 2385 | await self.load_markets() |
| 2386 | market = self.market(symbol) |
| 2387 | request = { |
| 2388 | 'symbol': market['id'], |
| 2389 | 'side': side.upper(), |
| 2390 | 'type': type.upper(), |
| 2391 | } |
| 2392 | timeInForce = None |
| 2393 | marginMode = None |
| 2394 | marginMode, params = self.handle_margin_mode_and_params('createOrder', params) |
| 2395 | marginOrSpotRequest = 'LEVER' if (marginMode is not None) else 'SPOT' |
| 2396 | request['bizType'] = marginOrSpotRequest |
| 2397 | if type == 'market': |
| 2398 | timeInForce = self.safe_string_upper(params, 'timeInForce', 'FOK') |
| 2399 | if side == 'buy': |
| 2400 | cost = self.safe_string(params, 'cost') |
| 2401 | params = self.omit(params, 'cost') |
| 2402 | createMarketBuyOrderRequiresPrice = self.safe_bool(self.options, 'createMarketBuyOrderRequiresPrice', True) |
| 2403 | if createMarketBuyOrderRequiresPrice: |
| 2404 | if price is None and (cost is None): |
| 2405 | raise InvalidOrder(self.id + ' createOrder() requires a price argument or cost in params for market buy orders on spot markets to calculate the total amount to spend(amount * price), alternatively set the createMarketBuyOrderRequiresPrice option to False and pass in the cost to spend into the amount parameter') |
| 2406 | else: |
| 2407 | amountString = self.number_to_string(amount) |
| 2408 | priceString = self.number_to_string(price) |
| 2409 | costCalculated = None |
| 2410 | if price is not None: |
| 2411 | costCalculated = Precise.string_mul(amountString, priceString) |
| 2412 | else: |
| 2413 | costCalculated = cost |
| 2414 | request['quoteQty'] = self.cost_to_precision(symbol, costCalculated) |
| 2415 | else: |
| 2416 | amountCost = cost if (cost is not None) else amount |
| 2417 | request['quoteQty'] = self.cost_to_precision(symbol, amountCost) |
| 2418 | else: |
| 2419 | timeInForce = self.safe_string_upper(params, 'timeInForce', 'GTC') |
| 2420 | request['price'] = self.price_to_precision(symbol, price) |
| 2421 | if (side == 'sell') or (type == 'limit'): |
| 2422 | request['quantity'] = self.amount_to_precision(symbol, amount) |
| 2423 | request['timeInForce'] = timeInForce |
| 2424 | response = await self.privateSpotPostOrder(self.extend(request, params)) |
| 2425 | # |
| 2426 | # { |
| 2427 | # "rc": 0, |
| 2428 | # "mc": "SUCCESS", |
| 2429 | # "ma": [], |
| 2430 | # "result": { |
| 2431 | # "orderId": "204371980095156544" |
| 2432 | # } |
| 2433 | # } |
| 2434 | # |
| 2435 | order = self.safe_value(response, 'result', {}) |
| 2436 | return self.parse_order(order, market) |
| 2437 | |
| 2438 | async def create_contract_order(self, symbol: str, type, side, amount, price=None, params={}): |
| 2439 | await self.load_markets() |
no test coverage detected