hedgequantx 2.9.75 → 2.9.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -219,10 +219,14 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
219
219
|
let sellVolume = 0;
|
|
220
220
|
let barCount = 0;
|
|
221
221
|
|
|
222
|
+
// Track tick arrival times for latency estimation
|
|
223
|
+
let lastTickTime = 0;
|
|
224
|
+
let tickLatencies = [];
|
|
225
|
+
|
|
222
226
|
marketFeed.on('tick', (tick) => {
|
|
223
227
|
tickCount++;
|
|
224
|
-
const
|
|
225
|
-
const currentSecond = Math.floor(
|
|
228
|
+
const now = Date.now();
|
|
229
|
+
const currentSecond = Math.floor(now / 1000);
|
|
226
230
|
|
|
227
231
|
// Count ticks per second
|
|
228
232
|
if (currentSecond === lastTickSecond) {
|
|
@@ -340,16 +344,30 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
|
|
|
340
344
|
timestamp: tick.timestamp || Date.now()
|
|
341
345
|
});
|
|
342
346
|
|
|
343
|
-
// Calculate
|
|
347
|
+
// Calculate latency based on tick timestamp or inter-tick timing
|
|
344
348
|
if (tick.timestamp) {
|
|
345
349
|
const tickTime = typeof tick.timestamp === 'number' ? tick.timestamp : Date.parse(tick.timestamp);
|
|
346
|
-
if (!isNaN(tickTime)) {
|
|
347
|
-
stats.latency = Math.max(0,
|
|
350
|
+
if (!isNaN(tickTime) && tickTime > 1000000000000) { // Valid millisecond timestamp
|
|
351
|
+
stats.latency = Math.max(0, now - tickTime);
|
|
348
352
|
}
|
|
353
|
+
} else if (tick.ssboe && tick.usecs) {
|
|
354
|
+
// Rithmic sends ssboe (seconds since epoch) and usecs (microseconds)
|
|
355
|
+
const tickTimeMs = tick.ssboe * 1000 + Math.floor(tick.usecs / 1000);
|
|
356
|
+
stats.latency = Math.max(0, now - tickTimeMs);
|
|
349
357
|
} else {
|
|
350
|
-
//
|
|
351
|
-
|
|
358
|
+
// Estimate latency from tick frequency - if we're getting real-time data, latency should be low
|
|
359
|
+
if (lastTickTime > 0) {
|
|
360
|
+
const timeSinceLastTick = now - lastTickTime;
|
|
361
|
+
// If ticks are coming frequently, latency is low
|
|
362
|
+
if (timeSinceLastTick < 100) {
|
|
363
|
+
tickLatencies.push(timeSinceLastTick);
|
|
364
|
+
if (tickLatencies.length > 20) tickLatencies.shift();
|
|
365
|
+
// Average of recent inter-tick times as proxy for latency
|
|
366
|
+
stats.latency = Math.round(tickLatencies.reduce((a, b) => a + b, 0) / tickLatencies.length);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
352
369
|
}
|
|
370
|
+
lastTickTime = now;
|
|
353
371
|
});
|
|
354
372
|
|
|
355
373
|
marketFeed.on('connected', () => {
|