0bps

Strategy vault / Other

Timed Order Cancellation

Timed Order Cancellation

JavaScriptOther
Author
亚瑟d
Complexity
Starter · 42 lines
Parameters
1
Backtest bar
1m · intraday
Tested on
BTC/USD · spot

Timed Order Cancellation

Parameters

NameDefaultWhat it controls
LoopInterval30Polling interval (minutes)

Source JavaScript

// Backtesting Environment
/*backtest
start: 2018-01-01 00:00:00
end: 2018-08-01 11:00:00
period: 1m
exchanges: [{"eid":"Bitfinex","currency":"BTC_USD"}]
*/



// Cancel Order Function
function CancelPendingOrders() {
    Sleep(1000); // Sleep for 1 second
    var ret = false;
    while (true) {
        var orders = null;
        // Continuously fetch the array of unexecuted orders; if an exception is returned, continue fetching
        while (!(orders = exchange.GetOrders())) {
            Sleep(1000); // Sleep for 1 second
        }
        if (orders.length == 0) { // If the order array is empty
            return ret; // Return to order cancellation status
        }
        for (var j = 0; j < orders.length; j++) { // Iterate through the array of unfilled orders
            exchange.CancelOrder(orders[j].Id); // Cancel unfilled orders one by one
            ret = true;
            if (j < (orders.length - 1)) {
                Sleep(1000); // Sleep for 1 second
            }
        }
    }
}


// Main Function
function main() {
    while (true) { // Polling Mode
            CancelPendingOrders(); // Cancel unfilled orders
            Log(_C(exchange.GetAccount)); // Print current account information
        Sleep(LoopInterval * 60000); // Hibernate
    }
}

Published by 亚瑟d on the FMZ strategy square · last modified 2021-05-25. 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/Timed-Order-Cancellation.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