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