hedgequantx 2.6.158 → 2.6.160

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.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Algo Trading Utilities
3
+ * Shared functions and constants for algo trading
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ /**
9
+ * Format price to avoid floating point errors
10
+ * @param {number} price - Raw price
11
+ * @param {number} tickSize - Tick size (default 0.25)
12
+ * @returns {string} - Formatted price string
13
+ */
14
+ const formatPrice = (price, tickSize = 0.25) => {
15
+ if (price === null || price === undefined || isNaN(price)) return '--';
16
+ const rounded = Math.round(price / tickSize) * tickSize;
17
+ const decimals = tickSize < 1 ? Math.max(0, -Math.floor(Math.log10(tickSize))) : 0;
18
+ return rounded.toFixed(decimals);
19
+ };
20
+
21
+ /**
22
+ * Check if service supports fast path (Rithmic direct)
23
+ * @param {Object} service - Trading service
24
+ * @returns {boolean}
25
+ */
26
+ const isRithmicFastPath = (service) => {
27
+ return typeof service.fastEntry === 'function' &&
28
+ typeof service.fastExit === 'function' &&
29
+ service.orderConn?.isConnected;
30
+ };
31
+
32
+ // Maximum symbols for multi-symbol trading
33
+ const MAX_MULTI_SYMBOLS = 5;
34
+
35
+ // Use HFT tick-based strategy for Rithmic
36
+ const USE_HFT_STRATEGY = true;
37
+
38
+ // Timeout for async operations
39
+ const TIMEOUT_MS = 5000;
40
+
41
+ /**
42
+ * Wrap promise with timeout
43
+ */
44
+ const withTimeout = (promise, ms) => {
45
+ return Promise.race([
46
+ promise,
47
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), ms))
48
+ ]);
49
+ };
50
+
51
+ module.exports = {
52
+ formatPrice,
53
+ isRithmicFastPath,
54
+ MAX_MULTI_SYMBOLS,
55
+ USE_HFT_STRATEGY,
56
+ TIMEOUT_MS,
57
+ withTimeout
58
+ };