Strategy vault / Tools & templates
Multi Exchange Concurrent Plugin
JavaScript strategy by @cqz.
JavaScriptTools & templates
The original spec has no written description. Read the source below.
Parameters
| Name | Default | What it controls |
|---|---|---|
| AsyncTimeout | 2000 | Asynchronous operation timeout |
Source JavaScript
/*
-- After the strategy references this template, use it directly $.Test() Call this method
-- main The function will not be triggered in the strategy, only serves as an entry point for template debugging
*/
//AsyncTimeout
function asyncExchangeCmd(param) {
let beginTime = new Date().getTime();
let elapses = [];
let results = [];
while (true) {
for (let i = 0; i < exchanges.length; i++) {
if (results[i] == null && (elapses[i] == null || elapses[i] <= AsyncTimeout)) {
// Create Asynchronous Operation
results[i] = exchanges[i].Go.apply(this, param)
}
}
let failed = 0;
for (let i = 0; i < exchanges.length; i++) {
if (results[i] == null) {
continue;
}
if (typeof (results[i].wait) != "undefined") {
// Waiting for results
let result = results[i].wait(2);
if (typeof (result) != "undefined") {
if (result) {
results[i] = result;
} else {
// Try again
results[i] = null;
failed++;
}
} else {
failed++;
}
elapses[i] = new Date().getTime() - beginTime;
}
}
if (failed === 0) {
break;
}
}
let failed = 0;
for (let i = 0; i < exchanges.length; i++) {
if (results[i] == null) {
failed++;
}
}
let finishTime = new Date().getTime();
return {
"failed": failed,
"totalElapse": finishTime - beginTime,
"elapses": elapses,
"results": results
};
}
$.GetTickerInfo = function () {
return asyncExchangeCmd(["GetTicker"]);
};
$.GetDepthInfo = function () {
return asyncExchangeCmd(["GetDepth"]);
};
function main() {
var depthInfo = $.GetDepthInfo();
Log(JSON.stringify(depthInfo));
}Published by @cqz on the FMZ strategy square · last modified 2022-05-24. 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/Multi-Exchange-Concurrent-Plugin.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