@adaptic/utils 0.0.954 → 0.0.956
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 +24 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +24 -21
- package/dist/index.mjs.map +1 -1
- package/dist/types/alpaca/legacy/positions.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/misc-utils.d.ts +6 -1
- package/dist/types/misc-utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5273,7 +5273,12 @@ const API_RETRY_CONFIGS = {
|
|
|
5273
5273
|
// Utility function for debug logging
|
|
5274
5274
|
/**
|
|
5275
5275
|
* Debug logging utility that respects environment debug flags.
|
|
5276
|
-
* Logs messages
|
|
5276
|
+
* Logs messages through the configured structured logger when LUMIC_DEBUG
|
|
5277
|
+
* is enabled. The level is preserved by routing through the corresponding
|
|
5278
|
+
* logger method — the structured logger already encodes the level, so we
|
|
5279
|
+
* do NOT prefix the message text with `[DEBUG][LEVEL]` (that produced
|
|
5280
|
+
* malformed `[INFO] [DEBUG][INFO] ...` lines in downstream consumers
|
|
5281
|
+
* that wrap this logger with Pino).
|
|
5277
5282
|
*
|
|
5278
5283
|
* @param message - The message to log.
|
|
5279
5284
|
* @param data - Optional data to log alongside the message. This can be any type of data.
|
|
@@ -5290,31 +5295,29 @@ const logIfDebug = (message, data, type = "info") => {
|
|
|
5290
5295
|
false;
|
|
5291
5296
|
if (!debugMode)
|
|
5292
5297
|
return;
|
|
5293
|
-
const prefix = `[DEBUG][${type.toUpperCase()}]`;
|
|
5294
5298
|
const logger = getLogger();
|
|
5295
5299
|
const context = data !== undefined
|
|
5296
5300
|
? typeof data === "object" && data !== null
|
|
5297
5301
|
? data
|
|
5298
5302
|
: { data }
|
|
5299
5303
|
: undefined;
|
|
5300
|
-
const fullMessage = prefix + " " + message;
|
|
5301
5304
|
switch (type) {
|
|
5302
5305
|
case "error":
|
|
5303
|
-
logger.error(
|
|
5306
|
+
logger.error(message, context);
|
|
5304
5307
|
break;
|
|
5305
5308
|
case "warn":
|
|
5306
|
-
logger.warn(
|
|
5309
|
+
logger.warn(message, context);
|
|
5307
5310
|
break;
|
|
5308
5311
|
case "debug":
|
|
5309
|
-
logger.debug(
|
|
5312
|
+
logger.debug(message, context);
|
|
5310
5313
|
break;
|
|
5311
5314
|
case "trace":
|
|
5312
5315
|
// trace maps to debug in our logger interface
|
|
5313
|
-
logger.debug(
|
|
5316
|
+
logger.debug(message, context);
|
|
5314
5317
|
break;
|
|
5315
5318
|
case "info":
|
|
5316
5319
|
default:
|
|
5317
|
-
logger.info(
|
|
5320
|
+
logger.info(message, context);
|
|
5318
5321
|
}
|
|
5319
5322
|
};
|
|
5320
5323
|
/**
|
|
@@ -5832,24 +5835,24 @@ async function closePosition$1(auth, symbolOrAssetId, params) {
|
|
|
5832
5835
|
account: auth.adapticAccountId || "direct",
|
|
5833
5836
|
symbol: normalizedSymbol,
|
|
5834
5837
|
});
|
|
5835
|
-
// Alpaca stores
|
|
5836
|
-
//
|
|
5837
|
-
//
|
|
5838
|
-
const
|
|
5839
|
-
|
|
5840
|
-
|
|
5841
|
-
|
|
5842
|
-
const openOrders = await getOrders$1(auth, {
|
|
5843
|
-
status: "open",
|
|
5844
|
-
symbols: orderSymbols,
|
|
5845
|
-
});
|
|
5838
|
+
// For crypto, Alpaca stores orders under "SOL/USD" (slash format) but the
|
|
5839
|
+
// symbols filter may not match across formats reliably. Fetch all open
|
|
5840
|
+
// orders without symbol filter and match client-side via normalization.
|
|
5841
|
+
const openOrders = isCryptoSymbol(symbolOrAssetId)
|
|
5842
|
+
? await getOrders$1(auth, { status: "open" })
|
|
5843
|
+
: await getOrders$1(auth, { status: "open", symbols: [normalizedSymbol] });
|
|
5844
|
+
let cancelledCount = 0;
|
|
5846
5845
|
for (const order of openOrders) {
|
|
5847
|
-
// Normalize both sides for comparison to handle format differences
|
|
5848
5846
|
const orderSymbolNorm = order.symbol.replace(/[-/]/g, "");
|
|
5849
5847
|
if (orderSymbolNorm === normalizedSymbol) {
|
|
5848
|
+
getLogger().info(`Cancelling order ${order.id} (${order.symbol}) for ${normalizedSymbol}`, { account: auth.adapticAccountId || "direct", symbol: normalizedSymbol });
|
|
5850
5849
|
await cancelOrder$1(auth, order.id);
|
|
5850
|
+
cancelledCount++;
|
|
5851
5851
|
}
|
|
5852
5852
|
}
|
|
5853
|
+
if (cancelledCount > 0) {
|
|
5854
|
+
getLogger().info(`Cancelled ${cancelledCount} open orders for ${normalizedSymbol}`, { account: auth.adapticAccountId || "direct", symbol: normalizedSymbol });
|
|
5855
|
+
}
|
|
5853
5856
|
}
|
|
5854
5857
|
// Crypto positions cannot use limit orders with SIP quotes or time_in_force="day".
|
|
5855
5858
|
// Use direct DELETE (market order) for crypto regardless of useLimitOrder flag.
|
|
@@ -8339,7 +8342,7 @@ const fetchTrades = async (symbol, options) => {
|
|
|
8339
8342
|
return massiveLimit(async () => {
|
|
8340
8343
|
const url = `${baseUrl}?${params.toString()}`;
|
|
8341
8344
|
try {
|
|
8342
|
-
|
|
8345
|
+
logIfDebug(`Fetching trades for ${symbol} from ${url}`);
|
|
8343
8346
|
const response = await fetchWithRetry(url, {}, 3, 1000);
|
|
8344
8347
|
const data = (await response.json());
|
|
8345
8348
|
if ("message" in data) {
|