hedgequantx 2.6.163 → 2.7.1

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.
Files changed (146) hide show
  1. package/README.md +15 -88
  2. package/bin/cli.js +0 -11
  3. package/dist/lib/api.jsc +0 -0
  4. package/dist/lib/api2.jsc +0 -0
  5. package/dist/lib/core.jsc +0 -0
  6. package/dist/lib/core2.jsc +0 -0
  7. package/dist/lib/data.js +1 -1
  8. package/dist/lib/data.jsc +0 -0
  9. package/dist/lib/data2.jsc +0 -0
  10. package/dist/lib/decoder.jsc +0 -0
  11. package/dist/lib/m/mod1.jsc +0 -0
  12. package/dist/lib/m/mod2.jsc +0 -0
  13. package/dist/lib/n/r1.jsc +0 -0
  14. package/dist/lib/n/r2.jsc +0 -0
  15. package/dist/lib/n/r3.jsc +0 -0
  16. package/dist/lib/n/r4.jsc +0 -0
  17. package/dist/lib/n/r5.jsc +0 -0
  18. package/dist/lib/n/r6.jsc +0 -0
  19. package/dist/lib/n/r7.jsc +0 -0
  20. package/dist/lib/o/util1.jsc +0 -0
  21. package/dist/lib/o/util2.jsc +0 -0
  22. package/package.json +8 -5
  23. package/src/app.js +40 -162
  24. package/src/config/constants.js +31 -33
  25. package/src/config/propfirms.js +13 -217
  26. package/src/config/settings.js +0 -43
  27. package/src/lib/api.js +198 -0
  28. package/src/lib/api2.js +353 -0
  29. package/src/lib/core.js +539 -0
  30. package/src/lib/core2.js +341 -0
  31. package/src/lib/data.js +555 -0
  32. package/src/lib/data2.js +492 -0
  33. package/src/lib/decoder.js +599 -0
  34. package/src/lib/m/s1.js +804 -0
  35. package/src/lib/m/s2.js +34 -0
  36. package/src/lib/n/r1.js +454 -0
  37. package/src/lib/n/r2.js +514 -0
  38. package/src/lib/n/r3.js +631 -0
  39. package/src/lib/n/r4.js +401 -0
  40. package/src/lib/n/r5.js +335 -0
  41. package/src/lib/n/r6.js +425 -0
  42. package/src/lib/n/r7.js +530 -0
  43. package/src/lib/o/l1.js +44 -0
  44. package/src/lib/o/l2.js +427 -0
  45. package/src/lib/python-bridge.js +206 -0
  46. package/src/menus/connect.js +14 -176
  47. package/src/menus/dashboard.js +65 -110
  48. package/src/pages/accounts.js +18 -18
  49. package/src/pages/algo/copy-trading.js +210 -240
  50. package/src/pages/algo/index.js +41 -104
  51. package/src/pages/algo/one-account.js +386 -33
  52. package/src/pages/algo/ui.js +312 -151
  53. package/src/pages/orders.js +3 -3
  54. package/src/pages/positions.js +3 -3
  55. package/src/pages/stats/chart.js +74 -0
  56. package/src/pages/stats/display.js +228 -0
  57. package/src/pages/stats/index.js +236 -0
  58. package/src/pages/stats/metrics.js +213 -0
  59. package/src/pages/user.js +6 -6
  60. package/src/services/hqx-server/constants.js +55 -0
  61. package/src/services/hqx-server/index.js +401 -0
  62. package/src/services/hqx-server/latency.js +81 -0
  63. package/src/services/index.js +12 -3
  64. package/src/services/rithmic/accounts.js +7 -32
  65. package/src/services/rithmic/connection.js +1 -204
  66. package/src/services/rithmic/contracts.js +116 -99
  67. package/src/services/rithmic/handlers.js +21 -196
  68. package/src/services/rithmic/index.js +63 -120
  69. package/src/services/rithmic/market.js +31 -0
  70. package/src/services/rithmic/orders.js +5 -111
  71. package/src/services/rithmic/protobuf.js +384 -138
  72. package/src/services/session.js +22 -173
  73. package/src/ui/box.js +10 -18
  74. package/src/ui/index.js +1 -3
  75. package/src/ui/menu.js +1 -1
  76. package/src/utils/prompts.js +2 -2
  77. package/dist/lib/m/s1.js +0 -1
  78. package/src/menus/ai-agent-connect.js +0 -181
  79. package/src/menus/ai-agent-models.js +0 -219
  80. package/src/menus/ai-agent-oauth.js +0 -292
  81. package/src/menus/ai-agent-ui.js +0 -141
  82. package/src/menus/ai-agent.js +0 -484
  83. package/src/pages/algo/algo-config.js +0 -195
  84. package/src/pages/algo/algo-multi.js +0 -801
  85. package/src/pages/algo/algo-utils.js +0 -58
  86. package/src/pages/algo/copy-engine.js +0 -449
  87. package/src/pages/algo/custom-strategy.js +0 -459
  88. package/src/pages/algo/logger.js +0 -245
  89. package/src/pages/algo/smart-logs-data.js +0 -218
  90. package/src/pages/algo/smart-logs.js +0 -387
  91. package/src/pages/algo/ui-constants.js +0 -144
  92. package/src/pages/algo/ui-summary.js +0 -184
  93. package/src/pages/stats-calculations.js +0 -191
  94. package/src/pages/stats-ui.js +0 -381
  95. package/src/pages/stats.js +0 -339
  96. package/src/services/ai/client-analysis.js +0 -194
  97. package/src/services/ai/client-models.js +0 -333
  98. package/src/services/ai/client.js +0 -343
  99. package/src/services/ai/index.js +0 -384
  100. package/src/services/ai/oauth-anthropic.js +0 -265
  101. package/src/services/ai/oauth-gemini.js +0 -223
  102. package/src/services/ai/oauth-iflow.js +0 -269
  103. package/src/services/ai/oauth-openai.js +0 -233
  104. package/src/services/ai/oauth-qwen.js +0 -279
  105. package/src/services/ai/providers/direct-providers.js +0 -323
  106. package/src/services/ai/providers/index.js +0 -62
  107. package/src/services/ai/providers/other-providers.js +0 -104
  108. package/src/services/ai/proxy-install.js +0 -249
  109. package/src/services/ai/proxy-manager.js +0 -494
  110. package/src/services/ai/proxy-remote.js +0 -161
  111. package/src/services/ai/strategy-supervisor.js +0 -1312
  112. package/src/services/ai/supervisor-data.js +0 -195
  113. package/src/services/ai/supervisor-optimize.js +0 -215
  114. package/src/services/ai/supervisor-sync.js +0 -178
  115. package/src/services/ai/supervisor-utils.js +0 -158
  116. package/src/services/ai/supervisor.js +0 -484
  117. package/src/services/ai/validation.js +0 -250
  118. package/src/services/hqx-server-events.js +0 -110
  119. package/src/services/hqx-server-handlers.js +0 -217
  120. package/src/services/hqx-server-latency.js +0 -136
  121. package/src/services/hqx-server.js +0 -403
  122. package/src/services/position-constants.js +0 -28
  123. package/src/services/position-exit-logic.js +0 -174
  124. package/src/services/position-manager.js +0 -438
  125. package/src/services/position-momentum.js +0 -206
  126. package/src/services/projectx/accounts.js +0 -142
  127. package/src/services/projectx/index.js +0 -443
  128. package/src/services/projectx/market.js +0 -172
  129. package/src/services/projectx/stats.js +0 -110
  130. package/src/services/projectx/trading.js +0 -180
  131. package/src/services/rithmic/latency-tracker.js +0 -182
  132. package/src/services/rithmic/market-data-decoders.js +0 -229
  133. package/src/services/rithmic/market-data.js +0 -272
  134. package/src/services/rithmic/orders-fast.js +0 -246
  135. package/src/services/rithmic/proto-decoders.js +0 -403
  136. package/src/services/rithmic/specs.js +0 -146
  137. package/src/services/rithmic/trade-history.js +0 -254
  138. package/src/services/session-history.js +0 -475
  139. package/src/services/strategy/hft-signal-calc.js +0 -147
  140. package/src/services/strategy/hft-tick.js +0 -407
  141. package/src/services/strategy/recovery-math.js +0 -402
  142. package/src/services/tradovate/constants.js +0 -109
  143. package/src/services/tradovate/index.js +0 -392
  144. package/src/services/tradovate/market.js +0 -47
  145. package/src/services/tradovate/orders.js +0 -145
  146. package/src/services/tradovate/websocket.js +0 -97
@@ -1,142 +0,0 @@
1
- /**
2
- * ProjectX Account Management
3
- * @module services/projectx/accounts
4
- *
5
- * Account enrichment and P&L calculations.
6
- */
7
-
8
- const { logger } = require('../../utils/logger');
9
-
10
- const log = logger.scope('ProjectX');
11
-
12
- /**
13
- * Enrich account with P&L data from API
14
- * @param {Function} request - Request function
15
- * @param {Object} propfirm - Propfirm config
16
- * @param {Object} account - Account object
17
- * @param {Array} templates - Account templates
18
- */
19
- async function enrichAccount(request, propfirm, account, templates) {
20
- const template = templates.find(t =>
21
- account.accountName && (
22
- account.accountName.includes(t.title) ||
23
- t.title.includes(account.accountName)
24
- )
25
- );
26
-
27
- const enriched = {
28
- accountId: account.accountId,
29
- accountName: account.accountName,
30
- balance: account.balance,
31
- status: account.status,
32
- type: account.type,
33
- startingBalance: template?.startingBalance || null,
34
- platform: 'ProjectX',
35
- propfirm: propfirm.name,
36
- openPnL: null,
37
- todayPnL: null,
38
- profitAndLoss: null,
39
- };
40
-
41
- // Only fetch P&L for active accounts
42
- if (account.status !== 0) {
43
- return enriched;
44
- }
45
-
46
- // Get unrealized P&L from open positions
47
- let openPnL = 0;
48
- try {
49
- const posRes = await request(
50
- propfirm.userApi,
51
- `/Position?accountId=${account.accountId}`,
52
- 'GET'
53
- );
54
-
55
- if (posRes.statusCode === 200 && Array.isArray(posRes.data)) {
56
- for (const pos of posRes.data) {
57
- if (pos.profitAndLoss != null) {
58
- openPnL += pos.profitAndLoss;
59
- }
60
- }
61
- }
62
- } catch {
63
- log.debug('Failed to get positions', { accountId: account.accountId });
64
- }
65
-
66
- // Get realized P&L from today's trades
67
- let todayPnL = 0;
68
- try {
69
- const today = new Date();
70
- today.setHours(0, 0, 0, 0);
71
-
72
- const tradesRes = await request(
73
- propfirm.gatewayApi,
74
- '/api/Trade/search',
75
- 'POST',
76
- {
77
- accountId: account.accountId,
78
- startTimestamp: today.toISOString(),
79
- endTimestamp: new Date().toISOString(),
80
- }
81
- );
82
-
83
- if (tradesRes.statusCode === 200) {
84
- const trades = Array.isArray(tradesRes.data) ? tradesRes.data : (tradesRes.data.trades || []);
85
- for (const trade of trades) {
86
- if (trade.profitAndLoss != null) {
87
- todayPnL += trade.profitAndLoss;
88
- }
89
- }
90
- }
91
- } catch {
92
- log.debug('Failed to get today trades', { accountId: account.accountId });
93
- }
94
-
95
- enriched.openPnL = openPnL;
96
- enriched.todayPnL = todayPnL;
97
- enriched.profitAndLoss = openPnL + todayPnL;
98
-
99
- return enriched;
100
- }
101
-
102
- /**
103
- * Get trading accounts with REAL P&L from API
104
- * @param {Function} request - Request function
105
- * @param {Object} propfirm - Propfirm config
106
- */
107
- async function getTradingAccounts(request, propfirm) {
108
- try {
109
- const response = await request(propfirm.userApi, '/TradingAccount', 'GET');
110
-
111
- if (response.statusCode !== 200) {
112
- return { success: false, accounts: [], error: 'Failed to get accounts' };
113
- }
114
-
115
- const accounts = Array.isArray(response.data) ? response.data : [];
116
-
117
- // Get account templates for startingBalance
118
- let templates = [];
119
- try {
120
- const templateRes = await request(propfirm.userApi, '/AccountTemplate/userTemplates', 'GET');
121
- if (templateRes.statusCode === 200 && Array.isArray(templateRes.data)) {
122
- templates = templateRes.data;
123
- }
124
- } catch {
125
- log.debug('Failed to get templates');
126
- }
127
-
128
- const enrichedAccounts = await Promise.all(
129
- accounts.map(account => enrichAccount(request, propfirm, account, templates))
130
- );
131
-
132
- return { success: true, accounts: enrichedAccounts };
133
- } catch (err) {
134
- log.error('Failed to get accounts', { error: err.message });
135
- return { success: false, accounts: [], error: err.message };
136
- }
137
- }
138
-
139
- module.exports = {
140
- enrichAccount,
141
- getTradingAccounts,
142
- };
@@ -1,443 +0,0 @@
1
- /**
2
- * @fileoverview ProjectX API Service
3
- * @module services/projectx
4
- *
5
- * STRICT RULE: Display ONLY values returned by API. No estimation, no simulation.
6
- */
7
-
8
- const { request } = require('../../utils/http');
9
- const { PROPFIRMS } = require('../../config');
10
- const { TIMEOUTS, DEBUG } = require('../../config/settings');
11
- const { getLimiter } = require('../../security/rateLimit');
12
- const {
13
- validateUsername,
14
- validatePassword,
15
- validateApiKey,
16
- validateAccountId,
17
- sanitizeString,
18
- maskSensitive,
19
- } = require('../../security');
20
- const { getMarketHolidays, checkHoliday, checkMarketHours } = require('./market');
21
- const { calculateLifetimeStats, calculateDailyPnL, formatTrades } = require('./stats');
22
- const { logger } = require('../../utils/logger');
23
- const trading = require('./trading');
24
- const accounts = require('./accounts');
25
-
26
- const log = logger.scope('ProjectX');
27
-
28
- /**
29
- * ProjectX API Service for prop firm connections
30
- */
31
- class ProjectXService {
32
- /**
33
- * @param {string} [propfirmKey='topstep'] - PropFirm identifier
34
- */
35
- constructor(propfirmKey = 'topstep') {
36
- this.propfirm = PROPFIRMS[propfirmKey] || PROPFIRMS.topstep;
37
- this.propfirmKey = propfirmKey;
38
- this.token = null;
39
- this.user = null;
40
- this._limiters = {
41
- api: getLimiter('api'),
42
- login: getLimiter('login'),
43
- orders: getLimiter('orders'),
44
- };
45
- }
46
-
47
- // ==================== GETTERS ====================
48
-
49
- getToken() { return this.token; }
50
- getPropfirm() { return this.propfirmKey; }
51
-
52
- /**
53
- * Store credentials for token refresh
54
- * @param {string} userName - Username
55
- * @param {string} password - Password
56
- */
57
- storeCredentials(userName, password) {
58
- this._credentials = { userName, password };
59
- }
60
-
61
- /**
62
- * Get a fresh token by re-authenticating
63
- * Required for WebSocket connections as TopStep invalidates old sessions
64
- * @returns {Promise<string|null>} Fresh token or null if failed
65
- */
66
- async getFreshToken() {
67
- if (this._credentials) {
68
- const result = await this.login(this._credentials.userName, this._credentials.password);
69
- if (result.success) {
70
- return this.token;
71
- }
72
- }
73
- return this.token; // Fallback to existing token
74
- }
75
-
76
- // ==================== HTTP ====================
77
-
78
- /**
79
- * Make an API request with rate limiting
80
- * @private
81
- */
82
- async _request(host, path, method = 'GET', data = null, limiterType = 'api') {
83
- const limiter = this._limiters[limiterType] || this._limiters.api;
84
- return limiter.execute(() => this._doRequest(host, path, method, data));
85
- }
86
-
87
- /**
88
- * Execute the actual HTTP request
89
- * @private
90
- */
91
- async _doRequest(host, path, method, data) {
92
- const url = `https://${host}${path}`;
93
-
94
- try {
95
- const response = await request(url, {
96
- method,
97
- body: data,
98
- token: this.token,
99
- timeout: TIMEOUTS.API_REQUEST,
100
- });
101
-
102
- return response;
103
- } catch (err) {
104
- log.error('Request failed', { path, error: err.message });
105
- throw err;
106
- }
107
- }
108
-
109
- // ==================== AUTH ====================
110
-
111
- /**
112
- * Login with username and password
113
- * @param {string} userName - Username
114
- * @param {string} password - Password
115
- * @returns {Promise<{success: boolean, token?: string, error?: string}>}
116
- */
117
- async login(userName, password) {
118
- try {
119
- validateUsername(userName);
120
- validatePassword(password, { requireUppercase: false, requireNumber: false });
121
-
122
- const response = await this._request(
123
- this.propfirm.userApi, '/Login', 'POST',
124
- { userName: sanitizeString(userName), password },
125
- 'login'
126
- );
127
-
128
- if (response.statusCode === 200 && response.data.token) {
129
- this.token = response.data.token;
130
- this.storeCredentials(userName, password); // Store for token refresh
131
- log.info('Login successful', { user: sanitizeString(userName) });
132
- return { success: true, token: maskSensitive(this.token) };
133
- }
134
-
135
- const error = response.data.errorMessage || 'Invalid credentials';
136
- log.warn('Login failed', { error });
137
- return { success: false, error };
138
- } catch (err) {
139
- log.error('Login error', { error: err.message });
140
- return { success: false, error: err.message };
141
- }
142
- }
143
-
144
- /**
145
- * Login with API key
146
- * @param {string} userName - Username
147
- * @param {string} apiKey - API key
148
- * @returns {Promise<{success: boolean, token?: string, error?: string}>}
149
- */
150
- async loginWithApiKey(userName, apiKey) {
151
- try {
152
- validateUsername(userName);
153
- validateApiKey(apiKey);
154
-
155
- const response = await this._request(
156
- this.propfirm.userApi, '/Login/key', 'POST',
157
- { userName: sanitizeString(userName), apiKey },
158
- 'login'
159
- );
160
-
161
- if (response.statusCode === 200 && response.data.token) {
162
- this.token = response.data.token;
163
- log.info('API key login successful');
164
- return { success: true, token: maskSensitive(this.token) };
165
- }
166
-
167
- return { success: false, error: response.data.errorMessage || 'Invalid API key' };
168
- } catch (err) {
169
- log.error('API key login error', { error: err.message });
170
- return { success: false, error: err.message };
171
- }
172
- }
173
-
174
- /**
175
- * Logout and clear token
176
- */
177
- logout() {
178
- this.token = null;
179
- this.user = null;
180
- log.debug('Logged out');
181
- }
182
-
183
- // ==================== USER ====================
184
-
185
- /**
186
- * Get user information
187
- * @returns {Promise<{success: boolean, user?: Object, error?: string}>}
188
- */
189
- async getUser() {
190
- try {
191
- const response = await this._request(this.propfirm.userApi, '/User', 'GET');
192
-
193
- if (response.statusCode === 200) {
194
- this.user = response.data;
195
- return { success: true, user: response.data };
196
- }
197
-
198
- return { success: false, error: 'Failed to get user info' };
199
- } catch (err) {
200
- return { success: false, error: err.message };
201
- }
202
- }
203
-
204
- // ==================== ACCOUNTS ====================
205
-
206
- /**
207
- * Get trading accounts with REAL P&L from API
208
- * @returns {Promise<{success: boolean, accounts: Array, error?: string}>}
209
- */
210
- async getTradingAccounts() {
211
- return accounts.getTradingAccounts(
212
- (host, path, method, data) => this._request(host, path, method, data),
213
- this.propfirm
214
- );
215
- }
216
-
217
- // ==================== TRADING ====================
218
-
219
- /** Get open positions */
220
- async getPositions(accountId) {
221
- return trading.getPositions(
222
- (host, path, method, data) => this._request(host, path, method, data),
223
- this.propfirm.gatewayApi, accountId
224
- );
225
- }
226
-
227
- /** Get open orders */
228
- async getOrders(accountId) {
229
- return trading.getOrders(
230
- (host, path, method, data) => this._request(host, path, method, data),
231
- this.propfirm.gatewayApi, accountId
232
- );
233
- }
234
-
235
- /** Get trades for today */
236
- async getTrades(accountId) {
237
- return trading.getTrades(
238
- (host, path, method, data) => this._request(host, path, method, data),
239
- this.propfirm.gatewayApi, accountId
240
- );
241
- }
242
-
243
- /** Place an order */
244
- async placeOrder(orderData) {
245
- return trading.placeOrder(
246
- (host, path, method, data, limiter) => this._request(host, path, method, data, limiter),
247
- this.propfirm.gatewayApi, orderData
248
- );
249
- }
250
-
251
- /** Cancel an order */
252
- async cancelOrder(orderId) {
253
- return trading.cancelOrder(
254
- (host, path, method, data, limiter) => this._request(host, path, method, data, limiter),
255
- this.propfirm.gatewayApi, orderId
256
- );
257
- }
258
-
259
- /** Cancel all open orders */
260
- async cancelAllOrders(accountId) {
261
- return trading.cancelAllOrders(
262
- (host, path, method, data, limiter) => this._request(host, path, method, data, limiter),
263
- this.propfirm.gatewayApi, accountId
264
- );
265
- }
266
-
267
- /** Close a position */
268
- async closePosition(accountId, contractId) {
269
- return trading.closePosition(
270
- (host, path, method, data, limiter) => this._request(host, path, method, data, limiter),
271
- this.propfirm.gatewayApi, accountId, contractId
272
- );
273
- }
274
-
275
- // ==================== TRADES & STATS ====================
276
-
277
- /**
278
- * Get trade history
279
- * @param {number|string} accountId - Account ID
280
- * @param {number} [days=30] - Days of history
281
- * @returns {Promise<{success: boolean, trades: Array, error?: string}>}
282
- */
283
- async getTradeHistory(accountId, days = 30) {
284
- try {
285
- const id = validateAccountId(accountId);
286
- const endDate = new Date();
287
- const startDate = new Date();
288
- startDate.setDate(startDate.getDate() - days);
289
-
290
- const response = await this._request(
291
- this.propfirm.gatewayApi,
292
- '/api/Trade/search',
293
- 'POST',
294
- {
295
- accountId: id,
296
- startTimestamp: startDate.toISOString(),
297
- endTimestamp: endDate.toISOString(),
298
- }
299
- );
300
-
301
- if (response.statusCode === 200 && response.data) {
302
- const trades = Array.isArray(response.data) ? response.data : (response.data.trades || []);
303
- return { success: true, trades: formatTrades(trades) };
304
- }
305
-
306
- return { success: true, trades: [] };
307
- } catch (err) {
308
- return { success: true, trades: [], error: err.message };
309
- }
310
- }
311
-
312
- /**
313
- * Get daily statistics
314
- * @param {number|string} accountId - Account ID
315
- * @returns {Promise<{success: boolean, stats: Array, error?: string}>}
316
- */
317
- async getDailyStats(accountId) {
318
- try {
319
- const id = validateAccountId(accountId);
320
- const now = new Date();
321
- const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
322
-
323
- const response = await this._request(
324
- this.propfirm.gatewayApi,
325
- '/api/Trade/search',
326
- 'POST',
327
- {
328
- accountId: id,
329
- startTimestamp: startOfMonth.toISOString(),
330
- endTimestamp: now.toISOString(),
331
- }
332
- );
333
-
334
- if (response.statusCode === 200 && response.data) {
335
- const trades = Array.isArray(response.data) ? response.data : (response.data.trades || []);
336
- return { success: true, stats: calculateDailyPnL(trades) };
337
- }
338
-
339
- return { success: false, stats: [] };
340
- } catch (err) {
341
- return { success: false, stats: [], error: err.message };
342
- }
343
- }
344
-
345
- /**
346
- * Get lifetime statistics
347
- * @param {number|string} accountId - Account ID
348
- * @returns {Promise<{success: boolean, stats: Object|null, error?: string}>}
349
- */
350
- async getLifetimeStats(accountId) {
351
- try {
352
- const tradesResult = await this.getTradeHistory(accountId, 90);
353
-
354
- if (!tradesResult.success || !tradesResult.trades.length) {
355
- return { success: true, stats: null };
356
- }
357
-
358
- return { success: true, stats: calculateLifetimeStats(tradesResult.trades) };
359
- } catch (err) {
360
- return { success: false, stats: null, error: err.message };
361
- }
362
- }
363
-
364
- // ==================== CONTRACTS ====================
365
-
366
- /**
367
- * Get available contracts from Gateway API
368
- * Returns RAW data from API - NO static mapping, NO mock data
369
- *
370
- * @returns {Promise<{success: boolean, contracts: Array, error?: string}>}
371
- */
372
- async getContracts() {
373
- try {
374
- const response = await this._request(
375
- this.propfirm.gatewayApi,
376
- '/api/Contract/available',
377
- 'POST',
378
- { live: false }
379
- );
380
-
381
- if (response.statusCode === 200) {
382
- const rawContracts = response.data.contracts || response.data || [];
383
-
384
- // Return active contracts with RAW API data only
385
- const contracts = rawContracts
386
- .filter(c => c.activeContract === true)
387
- .sort((a, b) => {
388
- const grpA = a.contractGroup || '';
389
- const grpB = b.contractGroup || '';
390
- if (grpA !== grpB) return grpA.localeCompare(grpB);
391
- return (a.name || '').localeCompare(b.name || '');
392
- });
393
-
394
- return { success: true, contracts };
395
- }
396
-
397
- return { success: false, contracts: [], error: 'Failed to fetch contracts' };
398
- } catch (err) {
399
- return { success: false, contracts: [], error: err.message };
400
- }
401
- }
402
-
403
- /**
404
- * Search contracts
405
- * @param {string} searchText - Search text
406
- * @returns {Promise<{success: boolean, contracts: Array, error?: string}>}
407
- */
408
- async searchContracts(searchText) {
409
- try {
410
- const response = await this._request(
411
- this.propfirm.gatewayApi,
412
- '/api/Contract/search',
413
- 'POST',
414
- { searchText: sanitizeString(searchText), live: false }
415
- );
416
-
417
- if (response.statusCode === 200) {
418
- return { success: true, contracts: response.data.contracts || response.data || [] };
419
- }
420
-
421
- return { success: false, contracts: [] };
422
- } catch (err) {
423
- return { success: false, contracts: [], error: err.message };
424
- }
425
- }
426
-
427
- // ==================== MARKET STATUS ====================
428
-
429
- getMarketHolidays() { return getMarketHolidays(); }
430
- checkHoliday() { return checkHoliday(); }
431
- checkMarketHours() { return checkMarketHours(); }
432
-
433
- /**
434
- * Get market status
435
- * @returns {Promise<{success: boolean, isOpen: boolean, message: string}>}
436
- */
437
- async getMarketStatus() {
438
- const hours = checkMarketHours();
439
- return { success: true, isOpen: hours.isOpen, message: hours.message };
440
- }
441
- }
442
-
443
- module.exports = { ProjectXService };