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