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

Method create_order

python/ccxt/bybit.py:3945–4015  ·  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

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

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