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

Method create_order

python/ccxt/async_support/bitmex.py:2012–2097  ·  view source on GitHub ↗

create a trade order https://www.bitmex.com/api/explorer/#not /Order/Order_new :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

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

Source from the content-addressed store, hash-verified

2010 return self.parse_trades(response, market, since, limit)
2011
2012 async def create_order(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
2013 """
2014 create a trade order
2015
2016 https://www.bitmex.com/api/explorer/#not /Order/Order_new
2017
2018 :param str symbol: unified symbol of the market to create an order in
2019 :param str type: 'market' or 'limit'
2020 :param str side: 'buy' or 'sell'
2021 :param float amount: how much of currency you want to trade in units of base currency
2022 :param float [price]: the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
2023 :param dict [params]: extra parameters specific to the exchange API endpoint
2024 :param dict [params.triggerPrice]: the price at which a trigger order is triggered at
2025 :param dict [params.triggerDirection]: the direction whenever the trigger happens with relation to price - 'ascending' or 'descending'
2026 :param float [params.trailingAmount]: the quote amount to trail away from the current market price
2027 :returns dict: an `order structure <https://github.com/ccxt/ccxt/wiki/Manual#order-structure>`
2028 """
2029 await self.load_markets()
2030 market = self.market(symbol)
2031 orderType = self.capitalize(type)
2032 capitalizeOrderType = orderType
2033 reduceOnly = self.safe_value(params, 'reduceOnly')
2034 if reduceOnly is not None:
2035 if (not market['swap']) and (not market['future']):
2036 raise InvalidOrder(self.id + ' createOrder() does not support reduceOnly for ' + market['type'] + ' orders, reduceOnly orders are supported for swap and future markets only')
2037 postOnly = self.safe_bool(params, 'postOnly')
2038 params = self.omit(params, ['reduceOnly', 'postOnly'])
2039 brokerId = self.safe_string(self.options, 'brokerId', 'CCXT')
2040 qty = self.parse_to_int(self.amount_to_precision(symbol, amount))
2041 request = {
2042 'symbol': market['id'],
2043 'side': self.capitalize(side),
2044 'orderQty': qty, # lot size multiplied by the number of contracts
2045 'ordType': capitalizeOrderType,
2046 'text': brokerId,
2047 }
2048 execInstructions = []
2049 if reduceOnly is True:
2050 execInstructions.append('ReduceOnly')
2051 if postOnly is True:
2052 execInstructions.append('ParticipateDoNotInitiate')
2053 execInstLength = len(execInstructions)
2054 if execInstLength > 0:
2055 request['execInst'] = ','.join(execInstructions)
2056 # support for unified trigger format
2057 triggerPrice = self.safe_number_n(params, ['triggerPrice', 'stopPx', 'stopPrice'])
2058 trailingAmount = self.safe_string_2(params, 'trailingAmount', 'pegOffsetValue')
2059 isTriggerOrder = triggerPrice is not None
2060 isTrailingAmountOrder = trailingAmount is not None
2061 if isTriggerOrder or isTrailingAmountOrder:
2062 triggerDirection = self.safe_string(params, 'triggerDirection')
2063 triggerAbove = ((triggerDirection == 'ascending') or (triggerDirection == 'above'))
2064 if (type == 'limit') or (type == 'market'):
2065 self.check_required_argument('createOrder', triggerDirection, 'triggerDirection', ['above', 'below'])
2066 if type == 'limit':
2067 if side == 'buy':
2068 orderType = 'StopLimit' if triggerAbove else 'LimitIfTouched'
2069 else:

Callers

nothing calls this directly

Calls 15

amount_to_precisionMethod · 0.95
parse_orderMethod · 0.95
InvalidOrderClass · 0.90
ArgumentsRequiredClass · 0.90
safe_valueMethod · 0.80
safe_boolMethod · 0.80
safe_stringMethod · 0.80
parse_to_intMethod · 0.80
safe_number_nMethod · 0.80
safe_string_2Method · 0.80
parse_to_numericMethod · 0.80

Tested by

no test coverage detected