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

exchange.GetOrders

exchange.GetOrders()函数用于获取所有合约的未完成的订单,支持查询指定合约的未完成订单。

exchange.GetOrders()函数请求数据成功时返回{@struct/Order Order}结构数组,请求数据失败时返回空值。 {@struct/Order Order}数组、空值

exchange.GetOrders() exchange.GetOrders(symbol)

参数symbol用于指定所要查询的订单数据的合约代码。不传该参数时默认请求所有合约的当前未完成订单数据。

symbol false string

function main(){
    // 鉴于测试代码,不使用商品期货策略一般架构,这里仅仅判断exchange.IO("status")函数,判断连接期货公司前置机成功后立即执行测试代码。股票证券无需使用exchange.IO("status")判断连接状态
    while (!exchange.IO("status")) {
        Sleep(1000)
    }
    // 设置合约代码
    exchange.SetContractType("rb888")
    // 设置下单方向
    exchange.SetDirection("sell")
    
    // 下单价格只是举例,较大的价格不会成交,订单会处于订单薄中待成交状态,具体测试可以自行调整价格
    exchange.Sell(99999, 1)
    exchange.Sell(88888, 1)
    var orders = exchange.GetOrders()
    Log("未完成订单一的信息,ID:", orders[0].Id, "Price:", orders[0].Price, "Amount:", orders[0].Amount,
        "DealAmount:", orders[0].DealAmount, "Type:", orders[0].Type, "Symbol:", orders[0].Symbol)
    Log("未完成订单二的信息,ID:", orders[1].Id, "Price:", orders[1].Price, "Amount:", orders[1].Amount,
        "DealAmount:", orders[1].DealAmount, "Type:", orders[1].Type, "Symbol:", orders[1].Symbol)
}
def main():
    while not exchange.IO("status"):
        Sleep(1000)
    exchange.SetContractType("rb888")
    exchange.SetDirection("sell")
    
    exchange.Sell(99999, 1)
    exchange.Sell(88888, 1)
    orders = exchange.GetOrders()
    Log("未完成订单一的信息,ID:", orders[0]["Id"], "Price:", orders[0]["Price"], "Amount:", orders[0]["Amount"], 
        "DealAmount:", orders[0]["DealAmount"], "Type:", orders[0]["Type"], "Symbol:", orders[0]["Symbol"])
    Log("未完成订单二的信息,ID:", orders[1]["Id"], "Price:", orders[1]["Price"], "Amount:", orders[1]["Amount"],
        "DealAmount:", orders[1]["DealAmount"], "Type:", orders[1]["Type"], "Symbol:", orders[1]["Symbol"])
void main() {
    while (exchange.IO("status") == 0) {
        Sleep(1000);
    }
    exchange.SetContractType("rb888");
    exchange.SetDirection("sell");
    
    exchange.Sell(99999, 1);
    exchange.Sell(88888, 1);
    auto orders = exchange.GetOrders();
    Log("未完成订单一的信息,ID:", orders[0].Id, "Price:", orders[0].Price, "Amount:", orders[0].Amount, 
        "DealAmount:", orders[0].DealAmount, "Type:", orders[0].Type, "Symbol:", orders[0].Symbol);
    Log("未完成订单二的信息,ID:", orders[1].Id, "Price:", orders[1].Price, "Amount:", orders[1].Amount,
        "DealAmount:", orders[1].DealAmount, "Type:", orders[1].Type, "Symbol:", orders[1].Symbol);
}

以一个很高的价格下单,然后查询未完成订单信息。

/*backtest
start: 2020-06-17 10:00:00
end: 2020-06-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/

function main() {
    var contractTypeList = ["MA009", "rb2010", "i2009"]
    while (true) {
        if (exchange.IO("status")) {
            for (var i = 0; i < contractTypeList.length; i++) {
                var ret = exchange.SetContractType(contractTypeList[i])
                var ticker = exchange.GetTicker()
                exchange.SetDirection("sell")
                var id = exchange.Sell(ticker.Sell + 5, 1)
                Log(contractTypeList[i], "开空仓订单ID:", id)
            }
            var orders = exchange.GetOrders()
            for (var j = 0; j < orders.length; j++) {
                Log(orders[j])
            }
            break
        } else {
            LogStatus(_D(), "未连接")
        }
    }
}
'''backtest
start: 2020-06-17 10:00:00
end: 2020-06-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
'''

def main():
    contractTypeList = ["MA009", "rb2010", "i2009"]
    while True:
        if exchange.IO("status"):
            for i in range(len(contractTypeList)):
                ret = exchange.SetContractType(contractTypeList[i])
                ticker = exchange.GetTicker()
                exchange.SetDirection("sell")
                id = exchange.Sell(ticker["Sell"] + 5, 1)
                Log(contractTypeList[i], "开空仓订单ID:", id)
            
            orders = exchange.GetOrders()
            for i in range(len(orders)):
                Log(orders[i])                            
            break
        else:
            LogStatus(_D(), "未连接")
/*backtest
start: 2020-06-17 10:00:00
end: 2020-06-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}]
*/

void main() {
    vector<string> contractTypeList = {"MA009", "rb2010", "i2009"};
    while (true) {
        if (exchange.IO("status") == 1) {
            for (int i = 0 ; i < contractTypeList.size(); i++) {
                auto ret = exchange.SetContractType(contractTypeList[i]);
                auto ticker = exchange.GetTicker();
                exchange.SetDirection("sell");
                auto id = exchange.Sell(ticker.Sell + 5.0, 1);
                Log(contractTypeList[i], "开空仓订单ID:", id);
            }
            auto orders = exchange.GetOrders();
            for (int j = 0; j < orders.size(); j++) {
                Log(orders[j]);
            }
            break;
        } else {
            LogStatus(_D(), "未完成");
        }
    } 
}

exchange.GetOrders()函数在商品期货、股票证券中获取的是所有未完成订单。 在商品期货中exchange.GetOrders()函数获取的订单与当前设置的合约无关。可以使用以下例子进行回测、模拟盘、实盘测试。

当交易所对象exchange代表的账户没有挂单(处于未成交状态的活动订单)时,调用exchange.GetOrders()函数返回空数组,即:[]exchange.GetOrders()函数不依赖于当前合约代码设置,不传symbol参数时获取所有合约的未完成订单。

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

exchange.GetOrder exchange.GetHistoryOrders