@adaptic/utils 0.0.953 → 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,22 +5832,24 @@ async function closePosition$1(auth, symbolOrAssetId, params) {
5832
5832
  account: auth.adapticAccountId || "direct",
5833
5833
  symbol: normalizedSymbol,
5834
5834
  });
5835
- // For crypto symbols, query orders using both the normalized and original
5836
- // formats since Alpaca may store orders under "SOL/USD" while we normalized to "SOLUSD"
5837
- const orderSymbols = isCryptoSymbol(symbolOrAssetId)
5838
- ? [normalizedSymbol, symbolOrAssetId]
5839
- : [normalizedSymbol];
5840
- const openOrders = await getOrders$1(auth, {
5841
- status: "open",
5842
- symbols: orderSymbols,
5843
- });
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;
5844
5842
  for (const order of openOrders) {
5845
- // Normalize both sides for comparison to handle format differences
5846
5843
  const orderSymbolNorm = order.symbol.replace(/[-/]/g, "");
5847
5844
  if (orderSymbolNorm === normalizedSymbol) {
5845
+ getLogger().info(`Cancelling order ${order.id} (${order.symbol}) for ${normalizedSymbol}`, { account: auth.adapticAccountId || "direct", symbol: normalizedSymbol });
5848
5846
  await cancelOrder$1(auth, order.id);
5847
+ cancelledCount++;
5849
5848
  }
5850
5849
  }
5850
+ if (cancelledCount > 0) {
5851
+ getLogger().info(`Cancelled ${cancelledCount} open orders for ${normalizedSymbol}`, { account: auth.adapticAccountId || "direct", symbol: normalizedSymbol });
5852
+ }
5851
5853
  }
5852
5854
  // Crypto positions cannot use limit orders with SIP quotes or time_in_force="day".
5853
5855
  // Use direct DELETE (market order) for crypto regardless of useLimitOrder flag.