Type/to search
Built-in Functions
Global
Version
Sleep
IsVirtual
Mail
Mail_Go
SetErrorFilter
GetPid
GetLastError
GetCommand
GetMeta
Dial
HttpQuery
HttpQuery_Go
Encode
UnixNano
Unix
GetOS
MD5
DBExec
UUID
EventLoop
__Serve
_G
_D
_N
_C
_Cross
JSON.parse
JSON.stringify
SetChannelData
GetChannelData
Log
Market
Trade
Account
Futures
NetSettings
Threads
threading
Thread
getThread
mainThread
currentThread
Lock
Condition
Event
Dict
pending
Thread
ThreadLock
ThreadEvent
ThreadCondition
ThreadDict
Web3
TA
Talib
talib.CDL2CROWS
talib.CDL3BLACKCROWS
talib.CDL3INSIDE
talib.CDL3LINESTRIKE
talib.CDL3OUTSIDE
talib.CDL3STARSINSOUTH
talib.CDL3WHITESOLDIERS
talib.CDLABANDONEDBABY
talib.CDLADVANCEBLOCK
talib.CDLBELTHOLD
talib.CDLBREAKAWAY
talib.CDLCLOSINGMARUBOZU
talib.CDLCONCEALBABYSWALL
talib.CDLCOUNTERATTACK
talib.CDLDARKCLOUDCOVER
talib.CDLDOJI
talib.CDLDOJISTAR
talib.CDLDRAGONFLYDOJI
talib.CDLENGULFING
talib.CDLEVENINGDOJISTAR
talib.CDLEVENINGSTAR
talib.CDLGAPSIDESIDEWHITE
talib.CDLGRAVESTONEDOJI
talib.CDLHAMMER
talib.CDLHANGINGMAN
talib.CDLHARAMI
talib.CDLHARAMICROSS
talib.CDLHIGHWAVE
talib.CDLHIKKAKE
talib.CDLHIKKAKEMOD
talib.CDLHOMINGPIGEON
talib.CDLIDENTICAL3CROWS
talib.CDLINNECK
talib.CDLINVERTEDHAMMER
talib.CDLKICKING
talib.CDLKICKINGBYLENGTH
talib.CDLLADDERBOTTOM
talib.CDLLONGLEGGEDDOJI
talib.CDLLONGLINE
talib.CDLMARUBOZU
talib.CDLMATCHINGLOW
talib.CDLMATHOLD
talib.CDLMORNINGDOJISTAR
talib.CDLMORNINGSTAR
talib.CDLONNECK
talib.CDLPIERCING
talib.CDLRICKSHAWMAN
talib.CDLRISEFALL3METHODS
talib.CDLSEPARATINGLINES
talib.CDLSHOOTINGSTAR
talib.CDLSHORTLINE
talib.CDLSPINNINGTOP
talib.CDLSTALLEDPATTERN
talib.CDLSTICKSANDWICH
talib.CDLTAKURI
talib.CDLTASUKIGAP
talib.CDLTHRUSTING
talib.CDLTRISTAR
talib.CDLUNIQUE3RIVER
talib.CDLUPSIDEGAP2CROWS
talib.CDLXSIDEGAP3METHODS
talib.AD
talib.ADOSC
talib.OBV
talib.ACOS
talib.ASIN
talib.ATAN
talib.CEIL
talib.COS
talib.COSH
talib.EXP
talib.FLOOR
talib.LN
talib.LOG10
talib.SIN
talib.SINH
talib.SQRT
talib.TAN
talib.TANH
talib.MAX
talib.MAXINDEX
talib.MIN
talib.MININDEX
talib.MINMAX
talib.MINMAXINDEX
talib.SUM
talib.HT_DCPERIOD
talib.HT_DCPHASE
talib.HT_PHASOR
talib.HT_SINE
talib.HT_TRENDMODE
talib.ATR
talib.NATR
talib.TRANGE
talib.BBANDS
talib.DEMA
talib.EMA
talib.HT_TRENDLINE
talib.KAMA
talib.MA
talib.MAMA
talib.MIDPOINT
talib.MIDPRICE
talib.SAR
talib.SAREXT
talib.SMA
talib.T3
talib.TEMA
talib.TRIMA
talib.WMA
talib.LINEARREG
talib.LINEARREG_ANGLE
talib.LINEARREG_INTERCEPT
talib.LINEARREG_SLOPE
talib.STDDEV
talib.TSF
talib.VAR
talib.ADX
talib.ADXR
talib.APO
talib.AROON
talib.AROONOSC
talib.BOP
talib.CCI
talib.CMO
talib.DX
talib.MACD
talib.MACDEXT
talib.MACDFIX
talib.MFI
talib.MINUS_DI
talib.MINUS_DM
talib.MOM
talib.PLUS_DI
talib.PLUS_DM
talib.PPO
talib.ROC
talib.ROCP
talib.ROCR
talib.ROCR100
talib.RSI
talib.STOCH
talib.STOCHF
talib.STOCHRSI
talib.TRIX
talib.ULTOSC
talib.WILLR
talib.AVGPRICE
talib.MEDPRICE
talib.TYPPRICE
talib.WCLPRICE
OS
Structures
Built-in Variables

The exchange.CreateConditionOrder() function is used to create a conditional order. A conditional order is a type of order that is automatically executed when specific trigger conditions are met.

exchange.CreateConditionOrder(symbol, side, amount, condition)
exchange.CreateConditionOrder(symbol, side, amount, condition, ...args)

Examples

  • Create a take-profit order (TP): automatically sell when the price rises to the target price.

    javascript
    function main() { // Create a take-profit order: when the BTC_USDT price rises to 65000, sell 0.01 BTC at the price of 65000 var condition = { ConditionType: ORDER_CONDITION_TYPE_TP, // Take-profit order TpTriggerPrice: 65000, // Trigger price TpOrderPrice: 65000 // Execution price, can also be set to -1 for a market order } var id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition) Log("TP order Id:", id) }
    python
    def main(): # Create a take-profit order: when the BTC_USDT price rises to 65000, sell 0.01 BTC at the price of 65000 condition = { "ConditionType": ORDER_CONDITION_TYPE_TP, # Take-profit order "TpTriggerPrice": 65000, # Trigger price "TpOrderPrice": 65000 # Execution price, can also be set to -1 for a market order } id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition) Log("TP order Id:", id)
    rust
    fn main() { // Create a take-profit order: when the BTC_USDT price rises to 65000, sell 0.01 BTC at the price of 65000 let condition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, // Take-profit order TpTriggerPrice: 65000.0, // Trigger price TpOrderPrice: 65000.0, // Execution price, can also be set to -1 for a market order ..Default::default() }; let id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, &condition); Log!("TP order Id:", id); }
    c++
    void main() { // Create a take-profit order: when the BTC_USDT price rises to 65000, sell 0.01 BTC at the price of 65000 OrderCondition condition = {.ConditionType = ORDER_CONDITION_TYPE_TP, .TpTriggerPrice = 65000, .TpOrderPrice = 65000}; auto id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition); Log("TP order Id:", id); }
  • Create a stop-loss order (SL): when the price drops to the stop-loss trigger price, automatically sell in the configured manner.

    javascript
    function main() { // Create a stop-loss order: when the BTC_USDT price drops to 58000, sell 0.01 BTC at market price var condition = { ConditionType: ORDER_CONDITION_TYPE_SL, // Stop-loss order SlTriggerPrice: 58000, // Trigger price SlOrderPrice: -1 // -1 indicates a market order } var id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition) Log("SL order Id:", id) }
    python
    def main(): # Create a stop-loss order: when the BTC_USDT price drops to 58000, sell 0.01 BTC at market price condition = { "ConditionType": ORDER_CONDITION_TYPE_SL, # Stop-loss order "SlTriggerPrice": 58000, # Trigger price "SlOrderPrice": -1 # -1 indicates a market order } id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition) Log("SL order Id:", id)
    rust
    fn main() { // Create a stop-loss order: when the BTC_USDT price drops to 58000, sell 0.01 BTC at market price let condition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_SL, // Stop-loss order SlTriggerPrice: 58000.0, // Trigger price SlOrderPrice: -1.0, // -1 indicates a market order ..Default::default() }; let id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, &condition); Log!("SL order Id:", id); }
    c++
    void main() { // Create a stop-loss order: when the BTC_USDT price drops to 58000, sell 0.01 BTC at market price OrderCondition condition = {.ConditionType = ORDER_CONDITION_TYPE_SL, .SlTriggerPrice = 58000, .SlOrderPrice = -1}; auto id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition); Log("SL order Id:", id); }
  • Create an OCO order: set take-profit and stop-loss simultaneously. Once either one is triggered, the other is automatically canceled.

    javascript
    function main() { // Create an OCO order: take-profit price 65000, stop-loss price 58000 var condition = { ConditionType: ORDER_CONDITION_TYPE_OCO, // OCO order TpTriggerPrice: 65000, // Take-profit trigger price TpOrderPrice: 65000, // Take-profit execution price SlTriggerPrice: 58000, // Stop-loss trigger price SlOrderPrice: 58000 // Stop-loss execution price } var id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition) Log("OCO order Id:", id) }
    python
    def main(): # Create an OCO order: take-profit price 65000, stop-loss price 58000 condition = { "ConditionType": ORDER_CONDITION_TYPE_OCO, # OCO order "TpTriggerPrice": 65000, # Take-profit trigger price "TpOrderPrice": 65000, # Take-profit execution price "SlTriggerPrice": 58000, # Stop-loss trigger price "SlOrderPrice": 58000 # Stop-loss execution price } id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition) Log("OCO order Id:", id)
    rust
    fn main() { // Create an OCO order: take-profit price 65000, stop-loss price 58000 let condition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_OCO, // OCO order TpTriggerPrice: 65000.0, // Take-profit trigger price TpOrderPrice: 65000.0, // Take-profit execution price SlTriggerPrice: 58000.0, // Stop-loss trigger price SlOrderPrice: 58000.0 // Stop-loss execution price }; let id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, &condition); Log!("OCO order Id:", id); }
    c++
    void main() { // Create an OCO order: take-profit price 65000, stop-loss price 58000 OrderCondition condition = {.ConditionType = ORDER_CONDITION_TYPE_OCO, .TpTriggerPrice = 65000, .TpOrderPrice = 65000, .SlTriggerPrice = 58000, .SlOrderPrice = 58000}; auto id = exchange.CreateConditionOrder("BTC_USDT", "sell", 0.01, condition); Log("OCO order Id:", id); }
  • Create a conditional order with an additional parameter (option), used to pass exchange-specific parameters.

    javascript
    function main() { // Pass the option parameter in JSON format var option = { "type": "TRAILING_STOP_MARKET", "activatePrice": "300", "callbackRate": "0.1" } var sideWithOption = "buy;" + JSON.stringify(option) var condition = { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 77, TpOrderPrice: 71 } var id = exchange.CreateConditionOrder("SOL_USDT.swap", sideWithOption, 1, condition) Log("Condition Order Id:", id) Sleep(2000) Log(exchange.GetConditionOrder(id)) }
    python
    import json def main(): # Pass the option parameter in JSON format option = { "type": "TRAILING_STOP_MARKET", "activatePrice": "300", "callbackRate": "0.1" } sideWithOption = "buy;" + json.dumps(option) condition = { "ConditionType": ORDER_CONDITION_TYPE_TP, "TpTriggerPrice": 77, "TpOrderPrice": 71 } id = exchange.CreateConditionOrder("SOL_USDT.swap", sideWithOption, 1, condition) Log("Condition Order Id:", id) Sleep(2000) Log(exchange.GetConditionOrder(id))
    rust
    fn main() { // Pass the option parameter in JSON format (Rust has no JSON serialization capability, so a raw string is used directly here to construct it) let option = r#"{"type": "TRAILING_STOP_MARKET", "activatePrice": "300", "callbackRate": "0.1"}"#; let sideWithOption = format!("buy;{}", option); let condition = OrderCondition { ConditionType: ORDER_CONDITION_TYPE_TP, TpTriggerPrice: 77.0, TpOrderPrice: 71.0, ..Default::default() }; let id = exchange.CreateConditionOrder("SOL_USDT.swap", &sideWithOption, 1, &condition).unwrap(); Log!("Condition Order Id:", id); Sleep(2000); Log!(exchange.GetConditionOrder(&id)); }
    c++
    void main() { // Pass the option parameter in JSON format json option = R"({ "type": "TRAILING_STOP_MARKET", "activatePrice": "300", "callbackRate": "0.1" })"_json; string sideWithOption = "buy;" + option.dump(); OrderCondition condition = {.ConditionType = ORDER_CONDITION_TYPE_TP, .TpTriggerPrice = 77, .TpOrderPrice = 71}; auto id = exchange.CreateConditionOrder("SOL_USDT.swap", sideWithOption, 1, condition); Log("Condition Order Id:", id); Sleep(2000); Log(exchange.GetConditionOrder(id)); }

Returns

TypeDescription

string / null value

When the conditional order is created successfully, the conditional order Id is returned; when creation fails, a null value is returned. The format of the conditional order Id is similar to that of an ordinary order Id, consisting of the exchange symbol code and the exchange's original conditional order Id, separated by an English comma.

Arguments

NameTypeRequiredDescription

symbol

string

Yes

The symbol parameter is used to specify the trading pair or contract code corresponding to the conditional order.

When calling the exchange.CreateConditionOrder(symbol, side, amount, condition) function to place a conditional order, if exchange is a spot exchange object and the order's quote currency is USDT and the base currency is BTC, then the symbol parameter is: "BTC_USDT", whose format is the trading pair format defined by the FMZ platform.

When calling the exchange.CreateConditionOrder(symbol, side, amount, condition) function to place a conditional order, if exchange is a futures exchange object and the order is a BTC USDT-margined perpetual contract order, then the symbol parameter is: "BTC_USDT.swap", whose format is a combination of the trading pair and contract code defined by the FMZ platform, separated by the character ".".

When calling the exchange.CreateConditionOrder(symbol, side, amount, condition) function to place a conditional order, if exchange is a futures exchange object and the order is a BTC USDT-margined options contract order, then the symbol parameter is: "BTC_USDT.BTC-240108-40000-C" (taking the Binance option BTC-240108-40000-C as an example), whose format is a combination of the trading pair defined by the FMZ platform and the specific options contract code defined by the exchange, separated by the character ".".

side

string

Yes

The side parameter is used to specify the trading direction of the conditional order.

For a spot exchange object, the available values of the side parameter are: buy, sell. buy means buy, and sell means sell.

For a futures exchange object, the available values of the side parameter are: buy, closebuy, sell, closesell. Among them, buy means open long position, closebuy means close long position, sell means open short position, and closesell means close short position.

Additional parameters (option) are supported: additional parameters can be passed through the side parameter, in the format: "side;{JSON object}" or "side;key=value&key=value".

For example: "buy;{\"type\":\"TRAILING_STOP_MARKET\",\"activatePrice\":\"300\"}" or "buy;type=TRAILING_STOP_MARKET&activatePrice=300".

Additional parameters are used to pass exchange-specific parameters (such as order type, effective rules, etc.). The specific supported parameters depend on the exchange API.

amount

number

Yes

The amount parameter is used to set the order size of the conditional order. Note that when the order is a spot market buy order, the order size represents the purchase amount; for some individual spot exchanges, the order size of a market buy order is the quantity of the base currency. For details, please refer to the Exchange Special Notes in the "User Guide". For a futures exchange object, the order size parameter amount is always measured in the number of contracts.

condition

object

Yes

The condition parameter is an object used to set the trigger conditions and execution price of the conditional order. The structure of this object refers to the Condition structure and contains the following properties:

arg

string / number / bool / object / array / any (any type supported by the platform)

No

An extension parameter used to output additional information to the log of this conditional order. Multiple arg parameters can be passed in.

See Also

Remarks

Whether conditional orders are supported depends on the specific exchange; some exchanges may not support conditional orders.

A conditional order does not lock up account funds before it is triggered; the order is only actually placed and funds are only committed after it is triggered.

Different exchanges may vary in their level of support for conditional orders and in the specific parameters involved. Please consult the API documentation of the corresponding exchange before use.

Additional parameters (option) can be passed via the side parameter to supply 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 vary from exchange to exchange; the specific supported parameters depend on the exchange's API documentation. Common parameters include: order type (type), time in force (timeInForce), activation price (activatePrice), callback rate (callbackRate), and so on.

When using option parameters, you still need to provide the amount and condition parameters. If certain parameters in the exchange API have already been passed via option, these base parameters may be overridden by the corresponding parameters in option; the exact behavior depends on the exchange API's implementation.