0bps

Strategy vault / Other

Cancel All Orders

Cancel All Orders

JavaScriptOther
Author
Zero
Complexity
Starter · 47 lines
Parameters
0

Cancel All Orders

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]);
    }
}

Published by Zero on the FMZ strategy square · last modified 2014-10-07. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Cancel-All-Orders.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open