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.GetOrders() function is used to obtain the current unfilled orders.

exchange.GetOrders()
exchange.GetOrders(symbol)

Examples

  • Using a spot exchange object, place buy orders for multiple different trading pairs at half of the current price as the order price, then query the information of unfilled orders.

    javascript
    /*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ function main() { var arrSymbol = ["ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"] for (var symbol of arrSymbol) { var t = exchange.GetTicker(symbol) exchange.CreateOrder(symbol, "buy", t.Last / 2, 0.01) } var spotOrders = exchange.GetOrders() var tbls = [] for (var orders of [spotOrders]) { var tbl = {type: "table", title: "test GetOrders", cols: ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], rows: []} for (var order of orders) { tbl.rows.push([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType]) } tbls.push(tbl) } LogStatus("`" + JSON.stringify(tbls) + "`") // Print the information once and then return, to prevent orders from being filled during subsequent backtesting, which would affect data observation return }
    python
    '''backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] ''' import json def main(): arrSymbol = ["ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"] for symbol in arrSymbol: t = exchange.GetTicker(symbol) exchange.CreateOrder(symbol, "buy", t["Last"] / 2, 0.01) spotOrders = exchange.GetOrders() tbls = [] for orders in [spotOrders]: tbl = {"type": "table", "title": "test GetOrders", "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": []} for order in orders: tbl["rows"].append([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType]) tbls.append(tbl) LogStatus("`" + json.dumps(tbls) + "`") return
    rust
    /*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ fn main() { let arrSymbol = ["ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"]; for symbol in arrSymbol { let t = exchange.GetTicker(symbol).unwrap(); let _ = exchange.CreateOrder(symbol, "buy", t.Last / 2.0, 0.01); } let spotOrders = exchange.GetOrders(None).unwrap(); // Rust does not support JSON.stringify, use format! to build the table's JSON text let mut tbls = Vec::new(); for orders in [&spotOrders] { let mut rows = Vec::new(); for order in orders { rows.push(format!(r#"["{}", "{}", {}, {}, {}, {}, {}, {}, {}, "{}"]"#, order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType)); } let tbl = format!(r#"{{"type": "table", "title": "test GetOrders", "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": [{}]}}"#, rows.join(",")); tbls.push(tbl); } LogStatus!(format!("`[{}]`", tbls.join(","))); // Print the information once and then return, to prevent orders from being filled during subsequent backtesting, which would affect data observation return; }
    c++
    /*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Binance","currency":"BTC_USDT"}] */ void main() { auto arrSymbol = {"ETH_USDT", "BTC_USDT", "LTC_USDT", "SOL_USDT"}; for (const auto& symbol : arrSymbol) { auto t = exchange.GetTicker(symbol); exchange.CreateOrder(symbol, "buy", t.Last / 2, 0.01); } auto spotOrders = exchange.GetOrders(); json tbls = R"([])"_json; std::vector<std::vector<Order>> arr = {spotOrders}; for (const auto& orders : arr) { json tbl = R"({ "type": "table", "title": "test GetOrders", "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": [] })"_json; for (const auto& order : orders) { json arrJson = R"([])"_json; arrJson.push_back("Symbol"); arrJson.push_back("Id"); arrJson.push_back(order.Price); arrJson.push_back(order.Amount); arrJson.push_back(order.DealAmount); arrJson.push_back(order.AvgPrice); arrJson.push_back(order.Status); arrJson.push_back(order.Type); arrJson.push_back(order.Offset); arrJson.push_back(order.ContractType); tbl["rows"].push_back(arrJson); } tbls.push_back(tbl); } LogStatus(_D(), "\n", "`" + tbls.dump() + "`"); return; }
  • Use the futures exchange object to place orders on multiple symbols with different trading pairs and contract codes. The order prices are set far away from the counterparty price at the top of the order book, keeping the orders in an unfilled state, and then query the orders in various ways.

    javascript
    /*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ function main() { var arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"] for (var symbol of arrSymbol) { var t = exchange.GetTicker(symbol) exchange.CreateOrder(symbol, "buy", t.Last / 2, 1) exchange.CreateOrder(symbol, "sell", t.Last * 2, 1) } var defaultOrders = exchange.GetOrders() var swapOrders = exchange.GetOrders("USDT.swap") var futuresOrders = exchange.GetOrders("USDT.futures") var btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap") var tbls = [] var arr = [defaultOrders, swapOrders, futuresOrders, btcUsdtSwapOrders] var tblDesc = ["defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"] for (var index in arr) { var orders = arr[index] var tbl = {type: "table", title: tblDesc[index], cols: ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], rows: []} for (var order of orders) { tbl.rows.push([order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType]) } tbls.push(tbl) } LogStatus("`" + JSON.stringify(tbls) + "`") // Print the output once and then return immediately, to prevent orders from being filled later in the backtest and affecting the data observation return }
    python
    '''backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] ''' import json def main(): arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"] for symbol in arrSymbol: t = exchange.GetTicker(symbol) exchange.CreateOrder(symbol, "buy", t["Last"] / 2, 1) exchange.CreateOrder(symbol, "sell", t["Last"] * 2, 1) defaultOrders = exchange.GetOrders() swapOrders = exchange.GetOrders("USDT.swap") futuresOrders = exchange.GetOrders("USDT.futures") btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap") tbls = [] arr = [defaultOrders, swapOrders, futuresOrders, btcUsdtSwapOrders] tblDesc = ["defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"] for index in range(len(arr)): orders = arr[index] tbl = {"type": "table", "title": tblDesc[index], "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": []} for order in orders: tbl["rows"].append([order["Symbol"], order["Id"], order["Price"], order["Amount"], order["DealAmount"], order["AvgPrice"], order["Status"], order["Type"], order["Offset"], order["ContractType"]]) tbls.append(tbl) LogStatus("`" + json.dumps(tbls) + "`") return
    rust
    /*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ fn main() { let arrSymbol = ["BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"]; for symbol in arrSymbol { let t = exchange.GetTicker(symbol).unwrap(); let _ = exchange.CreateOrder(symbol, "buy", t.Last / 2.0, 1); let _ = exchange.CreateOrder(symbol, "sell", t.Last * 2.0, 1); } let defaultOrders = exchange.GetOrders(None).unwrap(); let swapOrders = exchange.GetOrders("USDT.swap").unwrap(); let futuresOrders = exchange.GetOrders("USDT.futures").unwrap(); let btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap").unwrap(); // Rust does not support JSON.stringify, so format! is used here to assemble the JSON text of the table let mut tbls = Vec::new(); let arr = [&defaultOrders, &swapOrders, &futuresOrders, &btcUsdtSwapOrders]; let tblDesc = ["defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"]; for index in 0..arr.len() { let orders = arr[index]; let mut rows = Vec::new(); for order in orders { rows.push(format!(r#"["{}", "{}", {}, {}, {}, {}, {}, {}, {}, "{}"]"#, order.Symbol, order.Id, order.Price, order.Amount, order.DealAmount, order.AvgPrice, order.Status, order.Type, order.Offset, order.ContractType)); } let tbl = format!(r#"{{"type": "table", "title": "{}", "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": [{}]}}"#, tblDesc[index], rows.join(",")); tbls.push(tbl); } LogStatus!(format!("`[{}]`", tbls.join(","))); // Print the output once and then return immediately, to prevent orders from being filled later in the backtest and affecting the data observation return; }
    c++
    /*backtest start: 2024-05-21 00:00:00 end: 2024-09-05 00:00:00 period: 5m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ void main() { auto arrSymbol = {"BTC_USDT.swap", "BTC_USDT.quarter", "ETH_USDT.swap", "ETH_USDT.quarter"}; for (const auto& symbol : arrSymbol) { auto t = exchange.GetTicker(symbol); exchange.CreateOrder(symbol, "buy", t.Last / 2, 1); exchange.CreateOrder(symbol, "sell", t.Last * 2, 1); } auto defaultOrders = exchange.GetOrders(); auto swapOrders = exchange.GetOrders("USDT.swap"); auto futuresOrders = exchange.GetOrders("USDT.futures"); auto btcUsdtSwapOrders = exchange.GetOrders("BTC_USDT.swap"); json tbls = R"([])"_json; std::vector<std::vector<Order>> arr = {defaultOrders, swapOrders, futuresOrders, btcUsdtSwapOrders}; std::string tblDesc[] = {"defaultOrders", "swapOrders", "futuresOrders", "btcUsdtSwapOrders"}; for (int index = 0; index < arr.size(); index++) { auto orders = arr[index]; json tbl = R"({ "type": "table", "cols": ["Symbol", "Id", "Price", "Amount", "DealAmount", "AvgPrice", "Status", "Type", "Offset", "ContractType"], "rows": [] })"_json; tbl["title"] = tblDesc[index]; for (const auto& order : orders) { json arrJson = R"([])"_json; arrJson.push_back(order.Symbol); arrJson.push_back(to_string(order.Id)); // The Id attribute in the Order struct is of type TId, so the FMZ platform's built-in C++ function to_string is used here for encoding arrJson.push_back(order.Price); arrJson.push_back(order.Amount); arrJson.push_back(order.DealAmount); arrJson.push_back(order.AvgPrice); arrJson.push_back(order.Status); arrJson.push_back(order.Type); arrJson.push_back(order.Offset); arrJson.push_back(order.ContractType); tbl["rows"].push_back(arrJson); } tbls.push_back(tbl); } LogStatus(_D(), "\n", "`" + tbls.dump() + "`"); return; }
  • When calling the exchange.GetOrders() function, you can pass in the Symbol parameter to request order data for a specific trading pair or contract code.

    javascript
    function main() { var orders = exchange.GetOrders("BTC_USDT") // Spot symbol example // var orders = exchange.GetOrders("BTC_USDT.swap") // Futures symbol example Log("orders:", orders) }
    python
    def main(): orders = exchange.GetOrders("BTC_USDT") # Spot symbol example # orders = exchange.GetOrders("BTC_USDT.swap") # Futures symbol example Log("orders:", orders)
    rust
    fn main() { let orders = exchange.GetOrders("BTC_USDT"); // Spot symbol example // let orders = exchange.GetOrders("BTC_USDT.swap"); // Futures symbol example Log!("orders:", orders); }
    c++
    void main() { auto orders = exchange.GetOrders("BTC_USDT"); // Spot symbol example // auto orders = exchange.GetOrders("BTC_USDT.swap"); // Futures symbol example Log("orders:", orders); }

Returns

TypeDescription

Order array / null value

The exchange.GetOrders() function returns a Order structure array when the data request succeeds, and returns a null value when the data request fails.

Arguments

NameTypeRequiredDescription

symbol

string

No

The symbol parameter is used to specify the trading instrument or range of trading instruments to be queried.

For a spot exchange object, if the symbol parameter is not passed in, the unfilled order data for all spot instruments is requested.

For a futures exchange object, if the symbol parameter is not passed in, the unfilled order data for all instruments within the dimension range of the current trading pair and contract code is requested by default.

See Also

Remarks

In the GetOrders function, the use cases of the symbol parameter are summarized as follows:

Exchange Object Categorysymbol ParameterQuery RangeRemarks
SpotDo not pass the symbol parameterQuery all spot trading pairsApplicable to all calling scenarios; if the exchange interface does not support it, an error is reported and a null value is returned, which will not be repeated below
SpotSpecify a trading instrument, with the symbol parameter as: "BTC_USDT"Query the specified BTC_USDT trading pairFor a spot exchange object, the format of the symbol parameter is: "BTC_USDT"
FuturesDo not pass the symbol parameterQuery all trading instruments within the dimension range of the current trading pair and contract codeIf the current trading pair is BTC_USDT and the contract code is swap, this queries all USDT-margined perpetual contracts. Equivalent to calling GetOrders("USDT.swap")
FuturesSpecify a trading instrument, with the symbol parameter as: "BTC_USDT.swap"Query the specified BTC USDT-margined perpetual contractFor a futures exchange object, the format of the symbol parameter is: a combination of the trading pair and contract code defined by the FMZ platform, separated by the character ".".
FuturesSpecify a range of trading instruments, with the symbol parameter as: "USDT.swap"Query all USDT-margined perpetual contracts-
Futures exchange supporting optionsDo not pass the symbol parameterQuery all option contracts within the dimension range of the current trading pairIf the current trading pair is BTC_USDT and the contract is set to an option contract, for example the Binance option contract: BTC-240108-40000-C
Futures exchange supporting optionsSpecify a specific trading instrumentQuery the specified option contractFor example, for the Binance futures exchange, the symbol parameter is: BTC_USDT.BTC-240108-40000-C
Futures exchange supporting optionsSpecify a range of trading instruments, with the symbol parameter as: "USDT.option"Query all USDT-margined option contracts-

In the GetOrders function, the query dimension ranges for a futures exchange object are summarized as follows:

symbol ParameterRequest Range DefinitionRemarks
USDT.swapRange of USDT-margined perpetual contracts.For dimensions not supported by the exchange API interface, an error is reported and a null value is returned when called.
USDT.futuresRange of USDT-margined delivery contracts.-
USD.swapRange of coin-margined perpetual contracts.-
USD.futuresRange of coin-margined delivery contracts.-
USDT.optionRange of USDT-margined option contracts.-
USD.optionRange of coin-margined option contracts.-
USDT.futures_comboRange of spread combo contracts.Futures_Deribit exchange
USD.futures_ffRange of multi-collateral delivery contracts.Futures_Kraken exchange
USD.swap_pfRange of multi-collateral perpetual contracts.Futures_Kraken exchange

When the account represented by the exchange object exchange has no open orders (i.e., active orders in an unfilled state) within the query range or on the specified trading instrument, calling this function will return an empty array, that is: [].

The following exchanges require a symbol parameter to be passed in for the interface that queries current unfilled orders. When calling the GetOrders function on these exchanges, if the symbol parameter is not passed in, only the unfilled orders of the current instrument are requested, rather than the unfilled orders of all instruments (because the exchange interface does not support it).

Zaif, MEXC, LBank, Korbit, Coinw, BitMart, Bithumb, BitFlyer, BigONE.

Exchanges that do not support the exchange.GetOrders() function:

Function NameUnsupported Spot ExchangesUnsupported Futures Exchanges
GetOrders--Futures_Bibox