0bps

Strategy vault / Tools & templates

Function Automatic Fault Tolerance Template

After checking the box to call this template, it will automatically retry fault tolerance for the specified API function, supporting multiple exchanges

Author
Zero
Complexity
Starter · 34 lines
Parameters
4

After checking the box to call this template, it will automatically retry fault tolerance for the specified API function, supporting multiple exchanges

Parameters

NameDefaultWhat it controls
RetryInterval500Fault-tolerant retry interval (milliseconds)
DebugtrueDisplay retry records
EnableErrorFilterfalseFilter out common network error messages
ApiListGetAccount,GetDepth,GetTicker,GetRecords,GetTrades,GetOrders,SetContractTypeFault-tolerant API list

Source JavaScript

// Called during template initialization
function init() {
    // Filter common errors
    if (EnableErrorFilter) {
        SetErrorFilter("502:|503:|tcp|character|connection|unexpected|network|timeout|WSARecv|Connect|GetAddr|no such|reset|http|received|EOF|reused");
    }
    // Redefine functions that require fault tolerance
    var names = ApiList.split(',');
    _.each(exchanges, function(e) {
        _.each(names, function(name) {
            if (typeof(e[name]) !== 'function') {
                throw "Try fault tolerance " + name + " Failed, Please confirm existence of thisAPIAnd enter correctly.";
            }
            var old = e[name];
            e[name] = function() {
                var r;
                while (!(r = old.apply(this, Array.prototype.slice.call(arguments)))) {
                    if (Debug) {
                        Log(e.GetLabel(), name, "Call failed", RetryInterval, "Retry after milliseconds...");
                    }
                    Sleep(RetryInterval);
                }
                return r;
            };
        });
    });
    Log("Fault-tolerance mechanism enabled", names);
}

// Test
function main() {
    // At This MomentGetTickerNo need to retry
    Log(exchange.GetTicker());
}

Published by Zero on the FMZ strategy square · last modified 2016-04-03. 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 tested, production-ready module from strategies/Function-Automatic-Fault-Tolerance-Template.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