0bps

Strategy vault / Other

Multi Platform Account Statistics

Multi-Platform Account Statistics

JavaScriptOther
Author
数·狂
Complexity
Starter · 51 lines
Parameters
4

Multi-Platform Account Statistics

Parameters

NameDefaultWhat it controls
Interval20Detection Interval (Seconds))
Type0Display type: Total assets | Net assets | Total money | Total coins
coverStocksfalseTotal coins to close
Thr0.1Report threshold

Source JavaScript

function EnsureCall(e, method) {
    var r;
    while (!(r = e[method].apply(this, Array.prototype.slice.call(arguments).slice(2)))) {
        Sleep(Interval);
    }
    return r;
}

var lastReport = 0;

function onTick() {
    var allBalance = 0;
    var allStocks = 0;
    var asset = 0;
    for (var i = 0; i < exchanges.length; i++) {
        var account = EnsureCall(exchanges[i],"GetAccount");
        var ticker = EnsureCall(exchanges[i],"GetTicker");
        allBalance += account.Balance + account.FrozenBalance;
        allStocks += account.Stocks + account.FrozenStocks;
        asset += (account.Balance + account.FrozenBalance) + (account.Stocks + account.FrozenStocks) * ticker.Last;
    }
    
    if (Type === 0 && Math.abs(asset - lastReport) >= Thr) {
        LogProfit(asset, "Total money:", allBalance, "Total coins:", allStocks, "Total assets:", asset);
        lastReport = asset;
    }
    else if (Type == 1) {
        var netAsset = asset - coverStocks * (asset - allBalance) / allStocks;
        if (Math.abs(netAsset - lastReport) >= Thr) {
            LogProfit(netAsset, "Total money:", allBalance, "Total coins:", allStocks, "Total assets:", asset);
            lastReport = netAsset;
        }
    }
    else if (Type == 2 && Math.abs(allBalance - lastReport) >= Thr){
        LogProfit(allBalance, "Total money:", allBalance, "Total coins:", allStocks, "Total assets:", asset);
        lastReport = allBalance;
    }
    else if (Type == 3 && Math.abs(allStocks - lastReport) >= Thr) {
        LogProfit(allStocks, "Total money:", allBalance, "Total coins:", allStocks, "Total assets:", asset);
        lastReport = allStocks;
    }
    
}

function main() {
    while (1) {
        onTick();
        Sleep(Interval*1000);
    }
}

Published by 数·狂 on the FMZ strategy square · last modified 2015-12-08. 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/Multi-Platform-Account-Statistics.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