Timed Order Cancellation
Timed Order Cancellation
JavaScriptOther
Timed Order Cancellation
Parameters
| Name | Default | What it controls |
|---|---|---|
| LoopInterval | 30 | Polling 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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Timed-Order-Cancellation.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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.