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
After checking the box to call this template, it will automatically retry fault tolerance for the specified API function, supporting multiple exchanges
Parameters
| Name | Default | What it controls |
|---|---|---|
| RetryInterval | 500 | Fault-tolerant retry interval (milliseconds) |
| Debug | true | Display retry records |
| EnableErrorFilter | false | Filter out common network error messages |
| ApiList | GetAccount,GetDepth,GetTicker,GetRecords,GetTrades,GetOrders,SetContractType | Fault-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.
/agenkit build a tested, production-ready module from strategies/Function-Automatic-Fault-Tolerance-Template.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.
Related specs
- Binance Account Cross Transfer Small ToolJavaScript · Tools & templates
- Get cryptocurrency current and max supplyJavaScript · Tools & templates
- Interaction TemplateJavaScript · Tools & templates
- KuCoin Fund Transfer PluginJavaScript · Tools & templates
- Moving Average Bot 30 linesJavaScript · Tools & templates · 1d
- OKEx V5 Candlestick Data Paginated Query ExampleJavaScript · Tools & templates