资源加载中... loading...

exchange.GetOrders

The exchange.GetOrders() function is used to get outstanding orders.

The exchange.GetOrders() function returns an array of {@struct/Order Order} structures if the request for data succeeds, and it returns null values if the request for data fails. {@struct/Order Order} array, null value

exchange.GetOrders() exchange.GetOrders(symbol)

The parameter symbol is used to set the transaction symbol or transaction symbol range to be queried. For spot exchange objects, if the symbol parameter is not passed, the uncompleted order data of all spot products will be requested. For futures exchange objects, if the symbol parameter is not passed, the default is to request the uncompleted order data of all varieties in the dimension range of the current trading pair and contract code.

symbol false string

/*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 out the information once and then return to prevent the order from being executed during the subsequent backtest and affecting data observation
    return
}
'''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
/*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 spot exchange object to place buy orders for multiple different trading pairs at half the current price, and then query the outstanding order information.

/*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 out the information once and then return to prevent the order from being executed during the subsequent backtest and affecting data observation
    return
}
'''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
/*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 type in the Order structure is TId, which is encoded using a C++ function to_string built into the FMZ platform.
            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 futures exchange objects to place orders for multiple different trading pairs and contract codes. Place orders at prices far away from the counterparty price, keep orders in an unfulfilled state, and query orders in multiple ways.

function main() {
    var orders = exchange.GetOrders("BTC_USDT")           // Examples of spot products
    // var orders = exchange.GetOrders("BTC_USDT.swap")   // Examples of futures products
    Log("orders:", orders)
}
def main():
    orders = exchange.GetOrders("BTC_USDT")          # Examples of spot products
    # orders = exchange.GetOrders("BTC_USDT.swap")   # Examples of futures products
    Log("orders:", orders)
void main() {
    auto orders = exchange.GetOrders("BTC_USDT");           // Examples of spot products
    // auto orders = exchange.GetOrders("BTC_USDT.swap");   // Examples of futures products
    Log("orders:", orders);
}

When calling the exchange.GetOrders() function, pass in the Symbol parameter to request order data for a specific trading pair and contract code.

In the GetOrders function, the usage scenarios of the symbol parameter are summarized as follows:

Exchange Object Classification symbol Parameters Query Scope Remark
Spot Do not pass symbol parameter Query all spot trading pairs For all calling scenarios, if the exchange interface does not support it, an error will be reported and a null value will be returned. No further explanation will be given.
Spot Specify the trading type, the symbol parameter is: “BTC_USDT” Query the specified BTC_USDT trading pair For spot exchange objects, the symbol parameter format is: “BTC_USDT”
Futures Do not pass symbol parameter Query all trading products within the current trading pair and contract code dimension range If the current trading pair is BTC_USDT and the contract code is swap, all USDT-margined perpetual contracts will be queried. This is equivalent to calling GetOrders("USDT.swap")
Futures Specify the trading type, the symbol parameter is: “BTC_USDT.swap” Query the USDT-based perpetual contract for a specified BTC For futures exchange objects, the parameter symbol format is: a combination of trading pair and contract code defined by the FMZ platform, separated by the characters "..
Futures Specify the range of trading products, the symbol parameter is: “USDT.swap” Query all USDT-based perpetual contracts -
Futures exchanges that support options Do not pass symbol parameter Query all option contracts within the current trading pair dimension range If the current trading pair is BTC_USDT, the contract is set to an option contract, for example, Binance option contract: BTC-240108-40000-C
Futures exchanges that support options Specify specific trading products Query the specified option contract For example, for Binance Futures Exchange, the symbol parameter is: BTC_USDT.BTC-240108-40000-C
Futures exchanges that support options Specify the range of trading products, the symbol parameter is: “USDT.option” Query all USDT-based options contracts -

In the GetOrders function, the futures exchange object query dimension range is summarized as follows:

symbol Parameters Request Range Definition Remark
USDT.swap USDT-based perpetual contract range. For

dimensions that are not supported by the exchange API interface, an error will be reported and a null value will be returned when calling. | | USDT.futures | USDT-based delivery contract range. | - | | USD.swap | Range of currency-based perpetual contracts. | - | | USD.futures | Range of currency-based delivery contracts. | - | | USDT.option | USDT-based options contract range. | - | | USD.option | Currency-based options contract range. | - | | USDT.futures_combo | Range of CFD combinations. | Futures_Deribit Exchange | | USD.futures_ff | Range of mixed margin delivery contracts. | Futures_Kraken Exchange | | USD.swap_pf | Range of mixed margin perpetual contracts. | Futures_Kraken Exchange |

When the account represented by the exchange object exchange has no pending orders within the query range or specified trading instruments (active orders in an unfulfilled state), calling this function returns an empty array, that is: []. The following exchanges require the instrument to pass in the instrument parameter when querying the currently uncompleted orders. When calling the GetOrders function with these exchanges, if the instrument parameter is not passed in, only the uncompleted orders of the current instrument are requested, not the uncompleted orders of all instruments (because the exchange interface does not support this). Zaif, MEXC, LBank, Korbit, Coinw, BitMart, Bithumb, BitFlyer, BigONE.

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

Function Name Unsupported Spot Exchanges Unsupported Futures Exchanges
GetOrders Futures_Bibox

{@struct/Order Order}, {@fun/Trade/exchange.GetOrder exchange.GetOrder}, {@fun/Trade/exchange.GetHistoryOrders exchange.GetHistoryOrders}

exchange.GetOrder exchange.GetHistoryOrders