Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1.24 KB

取消所有订单.md

File metadata and controls

74 lines (55 loc) · 1.24 KB

Name

取消所有订单

Author

Zero

Strategy Description

取消所有订单

Source (javascript)

var Interval = 1000;

function GetAccount(e) {
    if (typeof(e) == 'undefined') {
        e = exchange;
    }
    var account;
    while (!(account = e.GetAccount())) {
        Sleep(Interval);
    }
    return account;
}

function cancelPending(e) {
    Log(e.GetName(), GetAccount(e));
    var ret = false;
    var isFutures = e.GetName().indexOf("796") != -1;
    while (true) {
        if (ret) {
            Sleep(Interval);
        }
        var orders = null;
        while (!(orders = e.GetOrders())) {
            Sleep(Interval);
        }

        if (orders.length == 0) {
            break;
        }

        for (var j = 0; j < orders.length; j++) {
            if (isFutures) {
                e.SetDirection(orders[j].Type == ORDER_TYPE_BUY ? "buy" : "sell");
            }
            e.CancelOrder(orders[j].Id, orders[j]);
            ret = true;
        }
    }
    Log(e.GetName(), GetAccount(e));
    return ret;
}

function main() {
    for (var i = 0; i < exchanges.length; i++) {
        cancelPending(exchanges[i]);
    }
}

Detail

https://www.fmz.com/strategy/280

Last Modified

2014-10-07 21:11:05