<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Indicator Math Wasm Example</title>
<style>
body { font-family: sans-serif; padding: 20px; }
pre { background: #f4f4f4; padding: 15px; border-radius: 5px; overflow-x: auto; }
button { padding: 10px 20px; font-size: 16px; cursor: pointer; }
</style>
</head>
<body>
<h1>Indicator Math Wasm CPU Benchmark</h1>
<button id="runBtn">Run Wasm Analysis</button>
<pre id="output"></pre>
<script type="module">
import init, { WasmAnalysisGenerator } from './wasm_dist/indicatorMath_ULTRA_Rust.js';
async function run() {
const out = document.getElementById('output');
out.innerText += "Loading Wasm module...\n";
try {
await init();
out.innerText += "✅ Wasm loaded successfully!\n\n";
const options = {
ema1_period: 20,
ema1_type: "EMA",
ema2_period: 50,
ema2_type: "EMA",
ema3_period: 200,
ema3_type: "EMA",
atr_period: 14,
atr_multiplier: 2.0,
bb_period: 20,
ci_period: 14,
adx_period: 14,
rsi_period: 14,
flat_threshold: 0.1,
macd_narrow: 0.05
};
const generator = new WasmAnalysisGenerator(JSON.stringify(options));
const history = [];
let price = 100;
for(let i=0; i<300; i++) {
const volatility = (Math.random() - 0.5) * 5;
price += volatility;
history.push({
time: 1700000000 + i * 60,
open: price,
high: price + Math.abs(volatility),
low: price - Math.abs(volatility),
close: price + volatility * 0.5
});
}
out.innerText += `Processing ${history.length} history candles...\n`;
const t0 = performance.now();
generator.initialize(JSON.stringify(history));
const t1 = performance.now();
out.innerText += `✅ Initialized in ${(t1 - t0).toFixed(2)} ms.\n\n`;
out.innerText += "Simulating live ticks...\n";
const tickStart = performance.now();
let lastResult = null;
for(let i=0; i<100; i++) {
price += (Math.random() - 0.5);
const timeTick = history[history.length-1].time + (i * 2); let result = generator.append_tick(price, timeTick);
if(result !== null && result !== undefined) {
lastResult = result;
}
}
const tickEnd = performance.now();
out.innerText += `✅ Processed 100 ticks in ${(tickEnd - tickStart).toFixed(2)} ms.\n\n`;
if(lastResult) {
out.innerText += `📊 Latest Closed Candle Result (Status: ${lastResult.status_desc}):\n`;
out.innerText += JSON.stringify(lastResult, null, 2);
} else {
out.innerText += "No candle closed during tick simulation.";
}
} catch (err) {
out.innerText += `❌ Error: ${err}\n`;
}
}
document.getElementById('runBtn').addEventListener('click', () => {
document.getElementById('output').innerText = "";
run();
});
</script>
</body>
</html>