-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
119 lines (99 loc) · 3.9 KB
/
app.js
File metadata and controls
119 lines (99 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
class VectorCycle {
constructor() {
this.market = new BinanceStream();
this.detector = new ArbitrageDetector(this.market);
this.canvas = document.getElementById('network-canvas');
this.renderer = new NetworkRenderer(this.canvas, this.market);
this.terminal = document.getElementById('terminal-log');
this.speed = 5;
this.lastUpdate = 0;
this.updateInterval = 1000;
this.lastLoggedCycles = new Set();
this.market.onStatusChange = (connected) => {
this.updateConnectionStatus(connected);
};
this.setupControls();
this.start();
}
setupControls() {
const feesToggle = document.getElementById('fees-toggle');
const speedSlider = document.getElementById('speed');
const speedValue = document.getElementById('speed-value');
feesToggle.addEventListener('change', (e) => {
this.market.setIncludeFees(e.target.checked);
});
speedSlider.addEventListener('input', (e) => {
this.speed = parseInt(e.target.value);
speedValue.textContent = `${this.speed}x`;
this.updateInterval = Math.max(500, 3000 - this.speed * 250);
});
}
updateConnectionStatus(connected) {
const statusDot = document.querySelector('.status-dot');
const statusText = document.querySelector('.status-text');
if (connected) {
statusDot.style.background = '#10b981';
statusText.textContent = 'LIVE DATA: CONNECTED (Binance Public Stream)';
} else {
statusDot.style.background = '#f59e0b';
statusText.textContent = 'Reconnecting...';
}
}
start() {
const loop = (timestamp) => {
if (timestamp - this.lastUpdate >= this.updateInterval) {
this.update();
this.lastUpdate = timestamp;
}
this.renderer.draw(this.detector.cycles);
requestAnimationFrame(loop);
};
requestAnimationFrame(loop);
}
update() {
const cycles = this.detector.detectArbitrage();
cycles.forEach(cycle => {
if (cycle.profitable) {
const pathKey = cycle.path.join('-');
if (!this.lastLoggedCycles.has(pathKey)) {
this.logArbitrage(cycle);
this.lastLoggedCycles.add(pathKey);
}
}
});
if (this.lastLoggedCycles.size > 50) {
this.lastLoggedCycles.clear();
}
this.updateStats();
}
logArbitrage(cycle) {
const timestamp = new Date().toLocaleTimeString('en-US', {
hour12: false,
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
const path = cycle.path.slice(0, -1).join(' → ');
const spread = cycle.spread.toFixed(3);
const className = cycle.profitable ? 'log-profit' : 'log-loss';
const entry = document.createElement('div');
entry.className = `log-entry ${className}`;
entry.innerHTML = `
<span class="log-timestamp">${timestamp}</span>
<span class="log-path">${path}</span>
<span class="log-spread">${spread > 0 ? '+' : ''}${spread}%</span>
`;
this.terminal.insertBefore(entry, this.terminal.firstChild);
if (this.terminal.children.length > 100) {
this.terminal.removeChild(this.terminal.lastChild);
}
}
updateStats() {
const stats = this.detector.getStats();
document.getElementById('cycles-count').textContent = stats.total;
document.getElementById('profitable-count').textContent = stats.profitable;
}
}
document.addEventListener('DOMContentLoaded', () => {
new VectorCycle();
});