hedgequantx 2.7.15 → 2.7.17
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 +1 -1
- package/src/app.js +10 -10
- package/src/lib/data.js +245 -471
- package/src/lib/m/s1-models.js +173 -0
- package/src/lib/m/s1.js +354 -735
- package/src/menus/dashboard.js +8 -5
- package/src/lib/api.js +0 -198
- package/src/lib/api2.js +0 -353
- package/src/lib/core.js +0 -539
- package/src/lib/core2.js +0 -341
- package/src/lib/data2.js +0 -492
- package/src/lib/decoder.js +0 -599
- package/src/lib/m/s2.js +0 -34
- package/src/lib/n/r1.js +0 -454
- package/src/lib/n/r2.js +0 -514
- package/src/lib/n/r3.js +0 -631
- package/src/lib/n/r4.js +0 -401
- package/src/lib/n/r5.js +0 -335
- package/src/lib/n/r6.js +0 -425
- package/src/lib/n/r7.js +0 -530
- package/src/lib/o/l1.js +0 -44
- package/src/lib/o/l2.js +0 -427
- package/src/lib/python-bridge.js +0 -206
package/src/lib/n/r1.js
DELETED
|
@@ -1,454 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rithmic Adapter - Main Entry Point
|
|
3
|
-
* Complete Rithmic integration for CLI
|
|
4
|
-
*
|
|
5
|
-
* Features:
|
|
6
|
-
* - Market Data (TICKER_PLANT): Real-time quotes and trades
|
|
7
|
-
* - Trading (ORDER_PLANT): Full order management
|
|
8
|
-
* - P&L (PNL_PLANT): Real-time account and position P&L
|
|
9
|
-
* - Connection Pool: Optimized connection reuse
|
|
10
|
-
*
|
|
11
|
-
* Supported PropFirms:
|
|
12
|
-
* - Apex Trader Funding
|
|
13
|
-
* - TopstepTrader (Rithmic)
|
|
14
|
-
* - Bulenox (Rithmic)
|
|
15
|
-
* - MES Capital
|
|
16
|
-
* - Earn2Trade
|
|
17
|
-
* - TradeFundrr
|
|
18
|
-
* - The Trading Pit
|
|
19
|
-
* - Funded Futures Network
|
|
20
|
-
* - PropShop Trader
|
|
21
|
-
* - 4PropTrader
|
|
22
|
-
* - DayTraders.com
|
|
23
|
-
* - 10X Futures
|
|
24
|
-
* - Lucid Trading
|
|
25
|
-
* - Thrive Trading
|
|
26
|
-
* - Legends Trading
|
|
27
|
-
* - TradeSea
|
|
28
|
-
* - UProfit
|
|
29
|
-
* - FastTrack Trading
|
|
30
|
-
* - My Funded Futures
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
const EventEmitter = require('events');
|
|
34
|
-
|
|
35
|
-
// Core modules
|
|
36
|
-
const { RithmicConnection } = require('./r2');
|
|
37
|
-
const { RithmicMarketData } = require('./r4');
|
|
38
|
-
const { RithmicTrading } = require('./r3');
|
|
39
|
-
const { RithmicPnL } = require('./r5');
|
|
40
|
-
const { RithmicConnectionPool, rithmicPool } = require('./r6');
|
|
41
|
-
|
|
42
|
-
// Constants
|
|
43
|
-
const constants = require('./r7');
|
|
44
|
-
const {
|
|
45
|
-
RITHMIC_GATEWAYS,
|
|
46
|
-
RITHMIC_PROPFIRMS,
|
|
47
|
-
TEMPLATE_IDS,
|
|
48
|
-
INFRA_TYPES,
|
|
49
|
-
ORDER_TYPES,
|
|
50
|
-
NOTIFY_TYPES,
|
|
51
|
-
EXCHANGES,
|
|
52
|
-
getPropFirmConfig,
|
|
53
|
-
isRithmicPropFirm,
|
|
54
|
-
getSupportedPropFirms,
|
|
55
|
-
buildRithmicSymbol,
|
|
56
|
-
getCurrentFrontMonth
|
|
57
|
-
} = constants;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* RithmicAdapter - High-level adapter that manages all connections
|
|
61
|
-
*/
|
|
62
|
-
class RithmicAdapter extends EventEmitter {
|
|
63
|
-
constructor(options = {}) {
|
|
64
|
-
super();
|
|
65
|
-
|
|
66
|
-
this.marketData = null;
|
|
67
|
-
this.trading = null;
|
|
68
|
-
this.pnl = null;
|
|
69
|
-
|
|
70
|
-
this.credentials = null;
|
|
71
|
-
this.propfirmConfig = null;
|
|
72
|
-
|
|
73
|
-
this.debug = options.debug || false;
|
|
74
|
-
this.usePool = options.usePool !== false; // Default true
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Connect to all Rithmic plants
|
|
79
|
-
* @param {Object} credentials
|
|
80
|
-
* @param {string} credentials.userId - Rithmic username
|
|
81
|
-
* @param {string} credentials.password - Rithmic password
|
|
82
|
-
* @param {string} credentials.propfirm - PropFirm name (e.g., 'apex', 'topsteptrader')
|
|
83
|
-
* @param {Object} options
|
|
84
|
-
* @param {boolean} options.marketData - Connect to market data (default: true)
|
|
85
|
-
* @param {boolean} options.trading - Connect to trading (default: true)
|
|
86
|
-
* @param {boolean} options.pnl - Connect to P&L (default: true)
|
|
87
|
-
*/
|
|
88
|
-
async connect(credentials, options = {}) {
|
|
89
|
-
const {
|
|
90
|
-
marketData = true,
|
|
91
|
-
trading = true,
|
|
92
|
-
pnl = true
|
|
93
|
-
} = options;
|
|
94
|
-
|
|
95
|
-
this.credentials = credentials;
|
|
96
|
-
this.propfirmConfig = getPropFirmConfig(credentials.propfirm);
|
|
97
|
-
|
|
98
|
-
if (!this.propfirmConfig) {
|
|
99
|
-
throw new Error(`Unknown PropFirm: ${credentials.propfirm}. Use getSupportedPropFirms() to see available options.`);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const fullCredentials = {
|
|
103
|
-
userId: credentials.userId,
|
|
104
|
-
password: credentials.password,
|
|
105
|
-
propfirm: credentials.propfirm,
|
|
106
|
-
systemName: this.propfirmConfig.systemName,
|
|
107
|
-
gateway: this.propfirmConfig.gateway
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const connectPromises = [];
|
|
111
|
-
|
|
112
|
-
// Connect to market data
|
|
113
|
-
if (marketData) {
|
|
114
|
-
if (this.usePool) {
|
|
115
|
-
connectPromises.push(
|
|
116
|
-
rithmicPool.getMarketData(fullCredentials).then(client => {
|
|
117
|
-
this.marketData = client;
|
|
118
|
-
this._forwardEvents(client, 'marketData');
|
|
119
|
-
})
|
|
120
|
-
);
|
|
121
|
-
} else {
|
|
122
|
-
this.marketData = new RithmicMarketData({ debug: this.debug });
|
|
123
|
-
connectPromises.push(
|
|
124
|
-
this.marketData.connect(fullCredentials).then(() => {
|
|
125
|
-
this._forwardEvents(this.marketData, 'marketData');
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Connect to trading
|
|
132
|
-
if (trading) {
|
|
133
|
-
if (this.usePool) {
|
|
134
|
-
connectPromises.push(
|
|
135
|
-
rithmicPool.getTrading(fullCredentials).then(client => {
|
|
136
|
-
this.trading = client;
|
|
137
|
-
this._forwardEvents(client, 'trading');
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
} else {
|
|
141
|
-
this.trading = new RithmicTrading({ debug: this.debug });
|
|
142
|
-
connectPromises.push(
|
|
143
|
-
this.trading.connect(fullCredentials).then(() => {
|
|
144
|
-
this._forwardEvents(this.trading, 'trading');
|
|
145
|
-
})
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Connect to P&L
|
|
151
|
-
if (pnl) {
|
|
152
|
-
if (this.usePool) {
|
|
153
|
-
connectPromises.push(
|
|
154
|
-
rithmicPool.getPnL(fullCredentials).then(client => {
|
|
155
|
-
this.pnl = client;
|
|
156
|
-
this._forwardEvents(client, 'pnl');
|
|
157
|
-
})
|
|
158
|
-
);
|
|
159
|
-
} else {
|
|
160
|
-
this.pnl = new RithmicPnL({ debug: this.debug });
|
|
161
|
-
connectPromises.push(
|
|
162
|
-
this.pnl.connect(fullCredentials).then(() => {
|
|
163
|
-
this._forwardEvents(this.pnl, 'pnl');
|
|
164
|
-
})
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Wait for all connections
|
|
170
|
-
await Promise.all(connectPromises);
|
|
171
|
-
|
|
172
|
-
this.emit('connected', {
|
|
173
|
-
propfirm: this.propfirmConfig.displayName,
|
|
174
|
-
marketData: !!this.marketData,
|
|
175
|
-
trading: !!this.trading,
|
|
176
|
-
pnl: !!this.pnl
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Forward events from sub-modules
|
|
184
|
-
*/
|
|
185
|
-
_forwardEvents(module, prefix) {
|
|
186
|
-
const events = ['tick', 'quote', 'trade', 'order', 'fill', 'reject', 'cancel', 'position', 'accountPnL', 'instrumentPnL', 'error'];
|
|
187
|
-
|
|
188
|
-
for (const event of events) {
|
|
189
|
-
module.on(event, (data) => {
|
|
190
|
-
this.emit(`${prefix}:${event}`, data);
|
|
191
|
-
this.emit(event, data); // Also emit without prefix
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// ===========================================================================
|
|
197
|
-
// MARKET DATA
|
|
198
|
-
// ===========================================================================
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Subscribe to market data
|
|
202
|
-
* @param {string} symbol - Rithmic symbol (e.g., 'MNQH5')
|
|
203
|
-
* @param {string} exchange - Exchange (default: 'CME')
|
|
204
|
-
*/
|
|
205
|
-
async subscribe(symbol, exchange = 'CME') {
|
|
206
|
-
if (!this.marketData) {
|
|
207
|
-
throw new Error('Market data not connected');
|
|
208
|
-
}
|
|
209
|
-
return this.marketData.subscribe(symbol, exchange);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Unsubscribe from market data
|
|
214
|
-
*/
|
|
215
|
-
async unsubscribe(symbol, exchange = 'CME') {
|
|
216
|
-
if (!this.marketData) return false;
|
|
217
|
-
return this.marketData.unsubscribe(symbol, exchange);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Get last price
|
|
222
|
-
*/
|
|
223
|
-
getLastPrice(symbol) {
|
|
224
|
-
if (!this.marketData) return 0;
|
|
225
|
-
return this.marketData.getLastPrice(symbol);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Get current quote
|
|
230
|
-
*/
|
|
231
|
-
getQuote(symbol) {
|
|
232
|
-
if (!this.marketData) return null;
|
|
233
|
-
return this.marketData.getQuote(symbol);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// ===========================================================================
|
|
237
|
-
// TRADING
|
|
238
|
-
// ===========================================================================
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Place a market order
|
|
242
|
-
* @param {string} accountId - Account ID
|
|
243
|
-
* @param {string} symbol - Symbol (e.g., 'MNQH6')
|
|
244
|
-
* @param {string} side - 'buy' or 'sell'
|
|
245
|
-
* @param {number} quantity - Number of contracts
|
|
246
|
-
* @param {string} exchange - Exchange (default: 'CME')
|
|
247
|
-
*/
|
|
248
|
-
async placeMarketOrder(accountId, symbol, side, quantity, exchange = 'CME') {
|
|
249
|
-
if (!this.trading) {
|
|
250
|
-
throw new Error('Trading not connected');
|
|
251
|
-
}
|
|
252
|
-
// trading.placeMarketOrder expects: (accountId, symbol, exchange, side, quantity)
|
|
253
|
-
return this.trading.placeMarketOrder(accountId, symbol, exchange, side, quantity);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Place a limit order
|
|
258
|
-
*/
|
|
259
|
-
async placeLimitOrder(accountId, symbol, side, quantity, price, exchange = 'CME') {
|
|
260
|
-
if (!this.trading) {
|
|
261
|
-
throw new Error('Trading not connected');
|
|
262
|
-
}
|
|
263
|
-
// trading.placeLimitOrder expects: (accountId, symbol, exchange, side, quantity, price)
|
|
264
|
-
return this.trading.placeLimitOrder(accountId, symbol, exchange, side, quantity, price);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Place a stop market order
|
|
269
|
-
*/
|
|
270
|
-
async placeStopMarketOrder(accountId, symbol, side, quantity, stopPrice, exchange = 'CME') {
|
|
271
|
-
if (!this.trading) {
|
|
272
|
-
throw new Error('Trading not connected');
|
|
273
|
-
}
|
|
274
|
-
return this.trading.placeStopMarketOrder(accountId, symbol, exchange, side, quantity, stopPrice);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Place a stop limit order
|
|
279
|
-
*/
|
|
280
|
-
async placeStopLimitOrder(accountId, symbol, side, quantity, stopPrice, limitPrice, exchange = 'CME') {
|
|
281
|
-
if (!this.trading) {
|
|
282
|
-
throw new Error('Trading not connected');
|
|
283
|
-
}
|
|
284
|
-
return this.trading.placeStopLimitOrder(accountId, symbol, exchange, side, quantity, stopPrice, limitPrice);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Cancel an order
|
|
289
|
-
*/
|
|
290
|
-
async cancelOrder(basketId) {
|
|
291
|
-
if (!this.trading) {
|
|
292
|
-
throw new Error('Trading not connected');
|
|
293
|
-
}
|
|
294
|
-
return this.trading.cancelOrder(basketId);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Cancel all orders
|
|
299
|
-
*/
|
|
300
|
-
async cancelAllOrders(accountId) {
|
|
301
|
-
if (!this.trading) {
|
|
302
|
-
throw new Error('Trading not connected');
|
|
303
|
-
}
|
|
304
|
-
return this.trading.cancelAllOrders(accountId);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/**
|
|
308
|
-
* Close a position
|
|
309
|
-
*/
|
|
310
|
-
async closePosition(accountId, symbol, exchange = 'CME') {
|
|
311
|
-
if (!this.trading) {
|
|
312
|
-
throw new Error('Trading not connected');
|
|
313
|
-
}
|
|
314
|
-
return this.trading.closePosition(accountId, symbol, exchange);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Get open orders
|
|
319
|
-
*/
|
|
320
|
-
getOpenOrders() {
|
|
321
|
-
if (!this.trading) return [];
|
|
322
|
-
return this.trading.getOpenOrders();
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
* Get accounts
|
|
327
|
-
*/
|
|
328
|
-
getAccounts() {
|
|
329
|
-
if (!this.trading) return [];
|
|
330
|
-
return this.trading.getAccounts();
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// ===========================================================================
|
|
334
|
-
// P&L
|
|
335
|
-
// ===========================================================================
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Subscribe to P&L updates
|
|
339
|
-
*/
|
|
340
|
-
async subscribePnL(accountId) {
|
|
341
|
-
if (!this.pnl) {
|
|
342
|
-
throw new Error('P&L not connected');
|
|
343
|
-
}
|
|
344
|
-
return this.pnl.subscribe(accountId);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Get account P&L
|
|
349
|
-
*/
|
|
350
|
-
getAccountPnL(accountId) {
|
|
351
|
-
if (!this.pnl) return null;
|
|
352
|
-
return this.pnl.getAccountPnL(accountId);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Get instrument P&L
|
|
357
|
-
*/
|
|
358
|
-
getInstrumentPnL(accountId, symbol) {
|
|
359
|
-
if (!this.pnl) return null;
|
|
360
|
-
return this.pnl.getInstrumentPnL(accountId, symbol);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Get all positions
|
|
365
|
-
*/
|
|
366
|
-
getPositions(accountId) {
|
|
367
|
-
if (!this.pnl) return [];
|
|
368
|
-
return this.pnl.getPositions(accountId);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// ===========================================================================
|
|
372
|
-
// STATUS
|
|
373
|
-
// ===========================================================================
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Check if fully connected
|
|
377
|
-
*/
|
|
378
|
-
get isConnected() {
|
|
379
|
-
return (
|
|
380
|
-
(!this.marketData || this.marketData.isConnected) &&
|
|
381
|
-
(!this.trading || this.trading.isConnected) &&
|
|
382
|
-
(!this.pnl || this.pnl.isConnected)
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Get connection status
|
|
388
|
-
*/
|
|
389
|
-
getStatus() {
|
|
390
|
-
return {
|
|
391
|
-
propfirm: this.propfirmConfig?.displayName || 'Not connected',
|
|
392
|
-
marketData: this.marketData?.isConnected || false,
|
|
393
|
-
trading: this.trading?.isConnected || false,
|
|
394
|
-
pnl: this.pnl?.isConnected || false,
|
|
395
|
-
pool: this.usePool ? rithmicPool.getStats() : null
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Disconnect all
|
|
401
|
-
*/
|
|
402
|
-
async disconnect() {
|
|
403
|
-
if (this.usePool && this.credentials) {
|
|
404
|
-
// Release to pool
|
|
405
|
-
rithmicPool.release(
|
|
406
|
-
this.credentials.userId,
|
|
407
|
-
this.propfirmConfig?.systemName || 'unknown'
|
|
408
|
-
);
|
|
409
|
-
} else {
|
|
410
|
-
// Disconnect directly
|
|
411
|
-
if (this.marketData) await this.marketData.disconnect();
|
|
412
|
-
if (this.trading) await this.trading.disconnect();
|
|
413
|
-
if (this.pnl) await this.pnl.disconnect();
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
this.marketData = null;
|
|
417
|
-
this.trading = null;
|
|
418
|
-
this.pnl = null;
|
|
419
|
-
|
|
420
|
-
this.emit('disconnected');
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Export everything
|
|
425
|
-
module.exports = {
|
|
426
|
-
// Main adapter
|
|
427
|
-
RithmicAdapter,
|
|
428
|
-
|
|
429
|
-
// Individual modules
|
|
430
|
-
RithmicConnection,
|
|
431
|
-
RithmicMarketData,
|
|
432
|
-
RithmicTrading,
|
|
433
|
-
RithmicPnL,
|
|
434
|
-
RithmicConnectionPool,
|
|
435
|
-
|
|
436
|
-
// Singleton pool
|
|
437
|
-
rithmicPool,
|
|
438
|
-
|
|
439
|
-
// Constants
|
|
440
|
-
RITHMIC_GATEWAYS,
|
|
441
|
-
RITHMIC_PROPFIRMS,
|
|
442
|
-
TEMPLATE_IDS,
|
|
443
|
-
INFRA_TYPES,
|
|
444
|
-
ORDER_TYPES,
|
|
445
|
-
NOTIFY_TYPES,
|
|
446
|
-
EXCHANGES,
|
|
447
|
-
|
|
448
|
-
// Helpers
|
|
449
|
-
getPropFirmConfig,
|
|
450
|
-
isRithmicPropFirm,
|
|
451
|
-
getSupportedPropFirms,
|
|
452
|
-
buildRithmicSymbol,
|
|
453
|
-
getCurrentFrontMonth
|
|
454
|
-
};
|