Resolve symbol from positioned contract in copy-trade
Instead of relying on the scheduler state (which may be 'Auto'), look up each enabled symbol's front-month contract and match by contractId to determine which symbol the positioned accounts are actually trading. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
df793bfd70
commit
9a24692c1a
+24
-10
@@ -326,7 +326,7 @@ export async function copyTrade() {
|
||||
|
||||
// Find all accounts with open positions to determine direction + symbol
|
||||
let resolvedAction: 'Buy' | 'Sell' | null = null;
|
||||
let resolvedSymbol: string | null = null;
|
||||
let positionContractId: number | null = null;
|
||||
let positionedCount = 0;
|
||||
|
||||
for (const firm of firms) {
|
||||
@@ -338,11 +338,7 @@ export async function copyTrade() {
|
||||
positionedCount++;
|
||||
if (!resolvedAction) {
|
||||
resolvedAction = pos.netPos > 0 ? 'Buy' : 'Sell';
|
||||
}
|
||||
// Determine the symbol from the scheduler state (positions only have contractId)
|
||||
if (!resolvedSymbol) {
|
||||
const state = getState();
|
||||
resolvedSymbol = state.symbol === 'Auto' ? null : state.symbol;
|
||||
positionContractId = pos.contractId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,11 +348,29 @@ export async function copyTrade() {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Fall back to enabled instruments if symbol unknown
|
||||
if (!resolvedSymbol) {
|
||||
// Resolve symbol from the positioned contract's contractId
|
||||
let resolvedSymbol: string | null = null;
|
||||
const instruments = getInstruments();
|
||||
const enabled = instruments.filter(i => i.enabled).map(i => i.symbol);
|
||||
resolvedSymbol = enabled[0] ?? 'NQ';
|
||||
const enabledSymbols = instruments.filter(i => i.enabled).map(i => i.symbol);
|
||||
|
||||
// Try each enabled symbol to find which one matches the positioned contractId
|
||||
for (const firm of firms) {
|
||||
const client = clients.get(firm.id);
|
||||
if (!client) continue;
|
||||
for (const sym of enabledSymbols) {
|
||||
const contract = await client.findFrontMonthContract(sym);
|
||||
if (contract && contract.id === positionContractId) {
|
||||
resolvedSymbol = sym;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (resolvedSymbol) break;
|
||||
}
|
||||
|
||||
// Fall back to scheduler symbol or first enabled
|
||||
if (!resolvedSymbol) {
|
||||
const state = getState();
|
||||
resolvedSymbol = state.symbol !== 'Auto' ? state.symbol : (enabledSymbols[0] ?? 'NQ');
|
||||
}
|
||||
|
||||
const pointValue = POINT_VALUES[resolvedSymbol];
|
||||
|
||||
Reference in New Issue
Block a user