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

Method create_order

python/ccxt/async_support/bybit.py:3946–4016  ·  view source on GitHub ↗

create a trade order https://bybit-exchange.github.io/docs/v5/order/create-order https://bybit-exchange.github.io/docs/v5/position/trading-stop :param str symbol: unified symbol of the market to create an order in :param str type: 'market' or 'limit'

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

Source from the content-addressed store, hash-verified

3944 return await self.create_order(symbol, 'market', 'sell', -1, None, self.extend(req, params))
3945
3946 async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}) -> Order:
3947 """
3948 create a trade order
3949
3950 https://bybit-exchange.github.io/docs/v5/order/create-order
3951 https://bybit-exchange.github.io/docs/v5/position/trading-stop
3952
3953 :param str symbol: unified symbol of the market to create an order in
3954 :param str type: 'market' or 'limit'
3955 :param str side: 'buy' or 'sell'
3956 :param float amount: how much of currency you want to trade in units of base currency
3957 :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
3958 :param dict [params]: extra parameters specific to the exchange API endpoint
3959 :param str [params.timeInForce]: "GTC", "IOC", "FOK"
3960 :param bool [params.postOnly]: True or False whether the order is post-only
3961 :param bool [params.reduceOnly]: True or False whether the order is reduce-only
3962 :param str [params.positionIdx]: *contracts only* 0 for one-way mode, 1 buy side of hedged mode, 2 sell side of hedged mode
3963 :param bool [params.hedged]: *contracts only* True for hedged mode, False for one way mode, default is False
3964 :param int [params.isLeverage]: *unified spot only* False then spot trading True then margin trading
3965 :param str [params.tpslMode]: *contract only* 'Full' or 'Partial'
3966 :param str [params.mmp]: *option only* market maker protection
3967 :param str [params.triggerDirection]: *contract only* the direction for trigger orders, 'ascending' or 'descending'
3968 :param float [params.triggerPrice]: The price at which a trigger order is triggered at
3969 :param float [params.stopLossPrice]: The price at which a stop loss order is triggered at
3970 :param float [params.stopLossLimitPrice]: The limit price for a stoploss order(only when used in OCO with takeProfitPrice)
3971 :param float [params.takeProfitPrice]: The price at which a take profit order is triggered at
3972 :param float [params.takeProfitLimitPrice]: The limit price for a takeprofit order(only when used in OCO combination with stopLossPrice)
3973 :param dict [params.takeProfit]: *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
3974 :param float [params.takeProfit.triggerPrice]: take profit trigger price
3975 :param dict [params.stopLoss]: *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
3976 :param float [params.stopLoss.triggerPrice]: stop loss trigger price
3977 :param str [params.trailingAmount]: the quote amount to trail away from the current market price
3978 :param str [params.trailingTriggerPrice]: the price to trigger a trailing order, default uses the price argument
3979 :param boolean [params.tradingStopEndpoint]: whether to enforce using the tradingStop(https://bybit-exchange.github.io/docs/v5/position/trading-stop) endpoint, makes difference when submitting single tp/sl order
3980 :returns dict: an `order structure <https://docs.ccxt.com/?id=order-structure>`
3981 """
3982 await self.load_markets()
3983 market = self.market(symbol)
3984 parts = await self.is_unified_enabled()
3985 enableUnifiedAccount = parts[1]
3986 isTrailingOrder = self.safe_string_2(params, 'trailingAmount', 'trailingStop') is not None
3987 isStopLossOrder = self.safe_string(params, 'stopLossPrice') is not None
3988 isTakeProfitOrder = self.safe_string(params, 'takeProfitPrice') is not None
3989 orderRequest = self.create_order_request(symbol, type, side, amount, price, params, enableUnifiedAccount)
3990 switchToOco = (isStopLossOrder and isTakeProfitOrder) or self.safe_bool(params, 'tradingStopEndpoint', False)
3991 defaultMethod = None
3992 if (isTrailingOrder or switchToOco) and not market['spot']:
3993 defaultMethod = 'privatePostV5PositionTradingStop'
3994 else:
3995 defaultMethod = 'privatePostV5OrderCreate'
3996 method = None
3997 method, params = self.handle_option_and_params(params, 'createOrder', 'method', defaultMethod)
3998 response: dict
3999 if method == 'privatePostV5PositionTradingStop':
4000 response = await self.privatePostV5PositionTradingStop(orderRequest)
4001 else:
4002 response = await self.privatePostV5OrderCreate(orderRequest)
4003 #

Calls 12

is_unified_enabledMethod · 0.95
create_order_requestMethod · 0.95
parse_orderMethod · 0.95
safe_string_2Method · 0.80
safe_stringMethod · 0.80
safe_boolMethod · 0.80
safe_dictMethod · 0.80
load_marketsMethod · 0.45
marketMethod · 0.45

Tested by

no test coverage detected