hedgequantx 2.9.191 → 2.9.192

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hedgequantx",
3
- "version": "2.9.191",
3
+ "version": "2.9.192",
4
4
  "description": "HedgeQuantX - Prop Futures Trading CLI",
5
5
  "main": "src/app.js",
6
6
  "bin": {
@@ -486,6 +486,35 @@ const executeAlgo = async ({ service, account, contract, config, strategy: strat
486
486
  clearInterval(refreshInterval);
487
487
  clearInterval(pnlInterval);
488
488
  clearInterval(liveLogInterval);
489
+
490
+ // Flatten any open position before stopping
491
+ if (currentPosition !== 0) {
492
+ ui.addLog('system', `Flattening position: ${currentPosition > 0 ? 'LONG' : 'SHORT'} ${Math.abs(currentPosition)}`);
493
+ sessionLogger.log('EXIT', `Flattening position: ${currentPosition}`);
494
+ try {
495
+ const flattenResult = await service.placeOrder({
496
+ accountId: account.rithmicAccountId || account.accountId,
497
+ symbol: symbolCode,
498
+ exchange: contract.exchange || 'CME',
499
+ type: 2, // Market
500
+ side: currentPosition > 0 ? 1 : 0, // Sell if long, Buy if short
501
+ size: Math.abs(currentPosition)
502
+ });
503
+ if (flattenResult.success) {
504
+ ui.addLog('fill_' + (currentPosition > 0 ? 'sell' : 'buy'), `Position flattened @ market`);
505
+ sessionLogger.log('EXIT', `Position flattened successfully`);
506
+ } else {
507
+ ui.addLog('error', `Flatten failed: ${flattenResult.error}`);
508
+ sessionLogger.log('EXIT', `Flatten failed: ${flattenResult.error}`);
509
+ }
510
+ } catch (e) {
511
+ ui.addLog('error', `Flatten error: ${e.message}`);
512
+ sessionLogger.log('EXIT', `Flatten error: ${e.message}`);
513
+ }
514
+ // Wait for fill
515
+ await new Promise(r => setTimeout(r, 2000));
516
+ }
517
+
489
518
  await marketFeed.disconnect();
490
519
  if (cleanupKeys) cleanupKeys();
491
520
  ui.cleanup();