@adaptic/utils 0.0.954 → 0.0.955

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/dist/index.mjs CHANGED
@@ -5832,24 +5832,24 @@ async function closePosition$1(auth, symbolOrAssetId, params) {
5832
5832
  account: auth.adapticAccountId || "direct",
5833
5833
  symbol: normalizedSymbol,
5834
5834
  });
5835
- // Alpaca stores crypto orders under "SOL/USD" (slash format) but we may
5836
- // receive "SOL-USD" (hyphen) or "SOLUSD" (concatenated). Query all three
5837
- // formats so getOrders returns matching open orders for cancellation.
5838
- const slashSymbol = normalizedSymbol.replace(/^([A-Z]+)(USD[TC]?)$/i, "$1/$2");
5839
- const orderSymbols = isCryptoSymbol(symbolOrAssetId)
5840
- ? [...new Set([normalizedSymbol, symbolOrAssetId, slashSymbol])]
5841
- : [normalizedSymbol];
5842
- const openOrders = await getOrders$1(auth, {
5843
- status: "open",
5844
- symbols: orderSymbols,
5845
- });
5835
+ // For crypto, Alpaca stores orders under "SOL/USD" (slash format) but the
5836
+ // symbols filter may not match across formats reliably. Fetch all open
5837
+ // orders without symbol filter and match client-side via normalization.
5838
+ const openOrders = isCryptoSymbol(symbolOrAssetId)
5839
+ ? await getOrders$1(auth, { status: "open" })
5840
+ : await getOrders$1(auth, { status: "open", symbols: [normalizedSymbol] });
5841
+ let cancelledCount = 0;
5846
5842
  for (const order of openOrders) {
5847
- // Normalize both sides for comparison to handle format differences
5848
5843
  const orderSymbolNorm = order.symbol.replace(/[-/]/g, "");
5849
5844
  if (orderSymbolNorm === normalizedSymbol) {
5845
+ getLogger().info(`Cancelling order ${order.id} (${order.symbol}) for ${normalizedSymbol}`, { account: auth.adapticAccountId || "direct", symbol: normalizedSymbol });
5850
5846
  await cancelOrder$1(auth, order.id);
5847
+ cancelledCount++;
5851
5848
  }
5852
5849
  }
5850
+ if (cancelledCount > 0) {
5851
+ getLogger().info(`Cancelled ${cancelledCount} open orders for ${normalizedSymbol}`, { account: auth.adapticAccountId || "direct", symbol: normalizedSymbol });
5852
+ }
5853
5853
  }
5854
5854
  // Crypto positions cannot use limit orders with SIP quotes or time_in_force="day".
5855
5855
  // Use direct DELETE (market order) for crypto regardless of useLimitOrder flag.