hedgequantx 1.8.12 → 1.8.14
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
|
@@ -10,6 +10,7 @@ const { connections } = require('../../services');
|
|
|
10
10
|
const { HQXServerService } = require('../../services/hqx-server');
|
|
11
11
|
const { AlgoUI } = require('./ui');
|
|
12
12
|
const { logger, prompts } = require('../../utils');
|
|
13
|
+
const { checkMarketHours } = require('../../services/projectx/market');
|
|
13
14
|
|
|
14
15
|
const log = logger.scope('CopyTrading');
|
|
15
16
|
|
|
@@ -18,6 +19,18 @@ const log = logger.scope('CopyTrading');
|
|
|
18
19
|
*/
|
|
19
20
|
const copyTradingMenu = async () => {
|
|
20
21
|
log.info('Copy Trading menu opened');
|
|
22
|
+
|
|
23
|
+
// Check if market is open
|
|
24
|
+
const market = checkMarketHours();
|
|
25
|
+
if (!market.isOpen) {
|
|
26
|
+
console.log();
|
|
27
|
+
console.log(chalk.red(` ${market.message}`));
|
|
28
|
+
console.log(chalk.gray(' Algo trading is only available when market is open'));
|
|
29
|
+
console.log();
|
|
30
|
+
await prompts.waitForEnter();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
21
34
|
const allConns = connections.getAll();
|
|
22
35
|
|
|
23
36
|
if (allConns.length < 2) {
|
|
@@ -10,11 +10,23 @@ const { connections } = require('../../services');
|
|
|
10
10
|
const { HQXServerService } = require('../../services/hqx-server');
|
|
11
11
|
const { AlgoUI } = require('./ui');
|
|
12
12
|
const { prompts } = require('../../utils');
|
|
13
|
+
const { checkMarketHours } = require('../../services/projectx/market');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* One Account Menu
|
|
16
17
|
*/
|
|
17
18
|
const oneAccountMenu = async (service) => {
|
|
19
|
+
// Check if market is open
|
|
20
|
+
const market = checkMarketHours();
|
|
21
|
+
if (!market.isOpen) {
|
|
22
|
+
console.log();
|
|
23
|
+
console.log(chalk.red(` ${market.message}`));
|
|
24
|
+
console.log(chalk.gray(' Algo trading is only available when market is open'));
|
|
25
|
+
console.log();
|
|
26
|
+
await prompts.waitForEnter();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
const spinner = ora({ text: 'Fetching active accounts...', color: 'yellow' }).start();
|
|
19
31
|
|
|
20
32
|
const allAccounts = await connections.getAllAccounts();
|
|
@@ -59,34 +71,27 @@ const oneAccountMenu = async (service) => {
|
|
|
59
71
|
};
|
|
60
72
|
|
|
61
73
|
/**
|
|
62
|
-
* Symbol selection
|
|
74
|
+
* Symbol selection - same as copy-trading
|
|
63
75
|
*/
|
|
64
76
|
const selectSymbol = async (service, account) => {
|
|
65
|
-
const spinner = ora({ text: 'Loading
|
|
77
|
+
const spinner = ora({ text: 'Loading symbols...', color: 'yellow' }).start();
|
|
66
78
|
|
|
67
79
|
const contractsResult = await service.getContracts();
|
|
68
|
-
if (!contractsResult.success) {
|
|
80
|
+
if (!contractsResult.success || !contractsResult.contracts?.length) {
|
|
69
81
|
spinner.fail('Failed to load contracts');
|
|
70
82
|
return null;
|
|
71
83
|
}
|
|
72
84
|
|
|
73
|
-
|
|
85
|
+
// Normalize contract structure - API returns { name: "ESH6", description: "E-mini S&P 500..." }
|
|
86
|
+
const contracts = contractsResult.contracts.map(c => ({
|
|
87
|
+
...c,
|
|
88
|
+
symbol: c.name || c.symbol,
|
|
89
|
+
name: c.description || c.name || c.symbol
|
|
90
|
+
}));
|
|
74
91
|
|
|
75
|
-
|
|
76
|
-
const categories = {};
|
|
77
|
-
for (const c of contractsResult.contracts) {
|
|
78
|
-
const cat = c.group || 'Other';
|
|
79
|
-
if (!categories[cat]) categories[cat] = [];
|
|
80
|
-
categories[cat].push(c);
|
|
81
|
-
}
|
|
92
|
+
spinner.succeed(`Found ${contracts.length} contracts`);
|
|
82
93
|
|
|
83
|
-
|
|
84
|
-
const options = [];
|
|
85
|
-
for (const [cat, contracts] of Object.entries(categories)) {
|
|
86
|
-
for (const c of contracts.slice(0, 10)) {
|
|
87
|
-
options.push({ label: `[${cat}] ${c.name || c.symbol}`, value: c });
|
|
88
|
-
}
|
|
89
|
-
}
|
|
94
|
+
const options = contracts.map(c => ({ label: c.name, value: c }));
|
|
90
95
|
options.push({ label: '< Back', value: 'back' });
|
|
91
96
|
|
|
92
97
|
const contract = await prompts.selectOption('Select Symbol:', options);
|