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

Method create_order_request

python/ccxt/bydfi.py:1187–1270  ·  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

1185 return self.parse_order(data, market)
1186
1187 def create_order_request(self, symbol: str, type: OrderType, side: OrderSide, amount: float, price: Num = None, params={}):
1188 market = self.market(symbol)
1189 request = {
1190 'symbol': market['id'],
1191 'side': side.upper(),
1192 # 'positionSide': STRING Position direction, not required in single position mode, default and can only be BOTH; required in dual position mode, and can only choose LONG or SHORT
1193 # 'type': STRING Order type LIMIT / MARKET / STOP / TAKE_PROFIT / STOP_MARKET / TAKE_PROFIT_MARKET / TRAILING_STOP_MARKET
1194 # 'reduceOnly': BOOL True, False; defaults to False in non-dual mode; not accepted in dual mode; not supported when using closePosition.
1195 # 'quantity': DECIMAL Order quantity, not supported with closePosition.
1196 # 'price': DECIMAL Order price
1197 # 'clientOrderId': STRING User-defined order number, must not be repeated in pending orders. If blank, the system will assign automatically
1198 # 'stopPrice': DECIMAL Trigger price, only required for STOP, STOP_MARKET, TAKE_PROFIT, TAKE_PROFIT_MARKET
1199 # 'closePosition': BOOL True, False; all positions closed after triggering, only supported in STOP_MARKET and TAKE_PROFIT_MARKET; not used with quantity; has a self-closing effect, not used with reduceOnly
1200 # 'activationPrice': DECIMAL Trailing stop activation price, required for TRAILING_STOP_MARKET, default to current market price upon order(supports different workingType)
1201 # 'callbackRate': DECIMAL Trailing stop callback rate, can range from [0.1, 5], where 1 represents 1%, only required for TRAILING_STOP_MARKET
1202 # 'timeInForce': STRING Validity method GTC / FOK / POST_ONLY / IOC / TRAILING_STOP
1203 # 'workingType': STRING stopPrice trigger type: MARK_PRICE(marking price), CONTRACT_PRICE(latest contract price). Default CONTRACT_PRICE
1204 }
1205 stopLossPrice = self.safe_string(params, 'stopLossPrice')
1206 isStopLossOrder = (stopLossPrice is not None)
1207 takeProfitPrice = self.safe_string(params, 'takeProfitPrice')
1208 isTakeProfitOrder = (takeProfitPrice is not None)
1209 trailingPercent = self.safe_string(params, 'trailingPercent')
1210 isTailingStopOrder = (trailingPercent is not None)
1211 stopPrice = None
1212 if isStopLossOrder or isTakeProfitOrder:
1213 stopPrice = stopLossPrice if isStopLossOrder else takeProfitPrice
1214 params = self.omit(params, ['stopLossPrice', 'takeProfitPrice'])
1215 request['stopPrice'] = self.price_to_precision(symbol, stopPrice)
1216 elif isTailingStopOrder:
1217 params = self.omit(params, ['trailingPercent'])
1218 request['callbackRate'] = trailingPercent
1219 trailingTriggerPrice = self.number_to_string(price)
1220 trailingTriggerPrice, params = self.handle_param_string(params, 'trailingTriggerPrice', trailingTriggerPrice)
1221 if trailingTriggerPrice is not None:
1222 request['activationPrice'] = self.price_to_precision(symbol, trailingTriggerPrice)
1223 params = self.omit(params, ['trailingTriggerPrice'])
1224 type = type.upper()
1225 isMarketOrder = ((type == 'MARKET') or (type == 'STOP_MARKET') or (type == 'TAKE_PROFIT_MARKET') or (type == 'TRAILING_STOP_MARKET'))
1226 if isMarketOrder:
1227 if type == 'MARKET':
1228 if isStopLossOrder:
1229 type = 'STOP_MARKET'
1230 elif isTakeProfitOrder:
1231 type = 'TAKE_PROFIT_MARKET'
1232 elif isTailingStopOrder:
1233 type = 'TRAILING_STOP_MARKET'
1234 else:
1235 if price is None:
1236 raise ArgumentsRequired(self.id + ' createOrder() requires a price argument for a ' + type + ' order')
1237 request['price'] = self.price_to_precision(symbol, price)
1238 if isStopLossOrder:
1239 type = 'STOP'
1240 elif isTakeProfitOrder:
1241 type = 'TAKE_PROFIT'
1242 request['type'] = type
1243 hedged = False
1244 hedged, params = self.handle_option_and_params(params, 'createOrder', 'hedged', hedged)

Callers 2

create_orderMethod · 0.95
create_ordersMethod · 0.95

Calls 14

encode_working_typeMethod · 0.95
ArgumentsRequiredClass · 0.90
NotSupportedClass · 0.90
safe_stringMethod · 0.80
handle_param_stringMethod · 0.80
safe_boolMethod · 0.80
handle_time_in_forceMethod · 0.80
handle_post_onlyMethod · 0.80
marketMethod · 0.45
omitMethod · 0.45
price_to_precisionMethod · 0.45

Tested by

no test coverage detected