exchange.CreateOrder
exchange.CreateOrder() function is used to place orders.
exchange.CreateOrder(symbol, side, price, amount)
exchange.CreateOrder(symbol, side, price, amount, ...args)Examples
-
Both spot exchange objects and futures exchange objects place orders by calling the
exchange.CreateOrder()function.javascriptfunction main() { var id = exchange.CreateOrder("BTC_USDT", "buy", 60000, 0.01) // Spot exchange object places an order, trading the BTC_USDT spot trading pair // var id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01) // Futures exchange object places an order, trading BTC's USDT-margined perpetual contract Log("Order Id:", id) }pythondef main(): id = exchange.CreateOrder("BTC_USDT", "buy", 60000, 0.01) # Spot exchange object places an order, trading the BTC_USDT spot trading pair # id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01) # Futures exchange object places an order, trading BTC's USDT-margined perpetual contract Log("Order Id:", id)rustfn main() { let id = exchange.CreateOrder("BTC_USDT", "buy", 60000, 0.01); // Spot exchange object places an order, trading the BTC_USDT spot trading pair // let id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01); // Futures exchange object places an order, trading BTC's 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 an order, trading the BTC_USDT spot trading pair // auto id = exchange.CreateOrder("BTC_USDT.swap", "buy", 60000, 0.01); // Futures exchange object places an order, trading BTC's USDT-margined perpetual contract Log("Order Id:", id); } -
Place an order with additional parameters (option), used to pass exchange-specific parameters.
javascriptfunction main() { // Pass the 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 the 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))rustfn main() { // Pass the option parameter in JSON format (Rust does not support JSON.stringify, so construct the JSON text directly using a raw string) let option = r#"{"type": "TRAILING_STOP_MARKET", "activationPrice": "2300", "callbackRate": "0.1"}"#; let sideWithOption = format!("buy;{}", option); let id = exchange.CreateOrder("SOL_USDT.swap", &sideWithOption, -1, 1).unwrap(); Log!("Order Id:", id); Sleep(2000); Log!(exchange.GetOrder(&id)); }c++void main() { // Pass the 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 when the order is placed successfully, and returns a null value when the order fails. The When calling the |
Arguments
| Name | Type | Required | Description |
symbol | string | Yes | The When calling the When calling the When calling the |
side | string | Yes | The For spot exchange objects, the available values for the For futures exchange objects, the available values for the Supports additional parameters (option): You can pass additional parameters via the For example: Additional parameters are used to pass exchange-specific parameters (such as order type, time-in-force rules, etc.); the specific parameters supported depend on the exchange API. |
price | number | Yes | The |
amount | number | Yes | The |
arg | string / number / bool / object / array / any (any type supported by the platform) | No | An extension parameter used to output accompanying information to the log of this order; the |
See Also
Remarks
Additional parameters (option) can be passed via the side parameter to specify exchange-specific parameters. The additional parameters must be merged into 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\"}".
The option parameters supported by different exchanges vary. The specific supported parameters are subject to the exchange's API documentation. Common parameters include: order type (type), time in force (timeInForce), activation price (activationPrice), callback rate (callbackRate), etc.
When using the option parameters, you still need to provide the price and amount parameters. If certain parameters have already been passed via option, these base parameters may be overridden by the corresponding parameters in option; the specific behavior depends on the exchange's API implementation.