exchange.CreateOrder
The exchange.CreateOrder() function is used to place an order.
exchange.CreateOrder(symbol, side, price, amount)
exchange.CreateOrder(symbol, side, price, amount, ...args)Examples
-
Spot exchange objects and futures exchange objects call the
exchange.CreateOrder()function to place orders.javascriptfunction main() { var id = exchange.CreateOrder("BTC_USDT", "buy", 60000, 0.01) // Spot exchange object places order for BTC_USDT spot trading pair // var id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01) // Futures exchange object places order for BTC USDT-margined perpetual contract Log("Order Id:", id) }pythondef main(): id = exchange.CreateOrder("BTC_USDT", "buy", 60000, 0.01) # Spot exchange object places order for BTC_USDT spot trading pair # id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01) # Futures exchange object places order for BTC USDT-margined perpetual contract Log("Order Id:", id)c++void main() { auto id = exchange.CreateOrder("BTC_USDT", "buy", 60000, 0.01); // Spot exchange object places order for BTC_USDT spot trading pair // auto id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01); // Futures exchange object places order for BTC USDT-margined perpetual contract Log("Order Id:", id); } -
Place orders using additional parameters (option) to pass exchange-specific parameters.
javascriptfunction main() { // Pass option parameter in JSON format var option = { "type": "TRAILING_STOP_MARKET", "activationPrice": "2300", "callbackRate": "0.1" } var sideWithOption = "buy;" + JSON.stringify(option) var id = exchange.CreateOrder("SOL_USDT.swap", sideWithOption, -1, 1) Log("Order Id:", id) Sleep(2000) Log(exchange.GetOrder(id)) }pythonimport json def main(): # Pass option parameter in JSON format option = { "type": "TRAILING_STOP_MARKET", "activationPrice": "2300", "callbackRate": "0.1" } sideWithOption = "buy;" + json.dumps(option) id = exchange.CreateOrder("SOL_USDT.swap", sideWithOption, -1, 1) Log("Order Id:", id) Sleep(2000) Log(exchange.GetOrder(id))c++void main() { // Pass option parameter in JSON format json option = R"({ "type": "TRAILING_STOP_MARKET", "activationPrice": "2300", "callbackRate": "0.1" })"_json; string sideWithOption = "buy;" + option.dump(); auto id = exchange.CreateOrder("SOL_USDT.swap", sideWithOption, -1, 1); Log("Order Id:", id); Sleep(2000); Log(exchange.GetOrder(id)); }
Returns
| Type | Description |
string / null value | Returns the order Id if the order is placed successfully, returns null value if the order fails. The When calling the |
Arguments
| Name | Type | Required | Description |
symbol | string | Yes | The parameter When calling the When calling the When calling the |
side | string | Yes | The parameter For spot exchange objects, the optional values for the For futures exchange objects, the optional values for the Supports additional parameters (option): Additional parameters can be passed through the For example: Additional parameters are used to pass exchange-specific parameters (such as order type, time-in-force rules, etc.), and the specific supported parameters depend on the exchange API. |
price | number | Yes | The parameter |
amount | number | Yes | The parameter |
arg | string / number / bool / object / array / any (any type supported by the platform) | No | Extended parameters, can output additional information to this order log, the |
See Also
Remarks
Supports passing additional parameters (option) through the side parameter to pass exchange-specific parameters. The additional parameters need to be merged with the side parameter in the format "side;{JSON object}" (recommended) or "side;key=value&key=value" (URL-encoded format). For example: "buy;{\"type\":\"TRAILING_STOP_MARKET\"}".
Different exchanges support different option parameters. Please refer to the exchange API documentation for specific supported parameters. Common parameters include: order type (type), time in force (timeInForce), activation price (activationPrice), callback rate (callbackRate), etc.
When using the option parameter, the price and amount parameters still need to be provided. If certain parameters in the exchange API have already been passed through option, these basic parameters may be overridden by the corresponding parameters in option. The specific behavior depends on the exchange API implementation.