@adaptic/utils 0.0.374 → 0.0.376
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 +94 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +94 -0
- package/dist/index.mjs.map +1 -1
- package/dist/types/crypto.d.ts +31 -1
- package/dist/types/crypto.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -5294,6 +5294,98 @@ async function fetchNews(params, auth) {
|
|
|
5294
5294
|
}
|
|
5295
5295
|
return newsArticles;
|
|
5296
5296
|
}
|
|
5297
|
+
/**
|
|
5298
|
+
* Fetches the latest trades for the specified cryptocurrency symbols.
|
|
5299
|
+
* This function retrieves the most recent trade price and volume for each symbol.
|
|
5300
|
+
*
|
|
5301
|
+
* @param params - The parameters for fetching latest trades.
|
|
5302
|
+
* @param params.symbols - An array of cryptocurrency symbols to fetch data for (e.g., ['BTC-USD', 'ETH-USD']).
|
|
5303
|
+
* @param params.loc - The location identifier (default: 'us'). Options: 'us' (Alpaca US), 'us-1' (Kraken US), 'eu-1' (Kraken EU).
|
|
5304
|
+
* @param auth - The Alpaca authentication object containing API key and secret.
|
|
5305
|
+
* @returns A promise that resolves to an object containing the latest trade for each symbol.
|
|
5306
|
+
* @throws Will throw an error if required parameters are missing or if fetching fails.
|
|
5307
|
+
*/
|
|
5308
|
+
async function fetchLatestTrades(params, auth) {
|
|
5309
|
+
const { symbols, loc = 'us' } = params;
|
|
5310
|
+
if (!auth.APIKey || !auth.APISecret) {
|
|
5311
|
+
throw new Error('Alpaca API key and secret are required');
|
|
5312
|
+
}
|
|
5313
|
+
if (!symbols || symbols.length === 0) {
|
|
5314
|
+
throw new Error('At least one symbol is required');
|
|
5315
|
+
}
|
|
5316
|
+
// Convert symbols array to comma-separated string
|
|
5317
|
+
const symbolsParam = symbols.join(',');
|
|
5318
|
+
const queryParams = new URLSearchParams({
|
|
5319
|
+
symbols: symbolsParam,
|
|
5320
|
+
});
|
|
5321
|
+
const url = `${ALPACA_API_BASE}/crypto/${loc}/latest/trades?${queryParams}`;
|
|
5322
|
+
logIfDebug(`Fetching crypto latest trades from: ${url}`);
|
|
5323
|
+
try {
|
|
5324
|
+
const response = await fetch(url, {
|
|
5325
|
+
headers: {
|
|
5326
|
+
'APCA-API-KEY-ID': auth.APIKey,
|
|
5327
|
+
'APCA-API-SECRET-KEY': auth.APISecret,
|
|
5328
|
+
},
|
|
5329
|
+
});
|
|
5330
|
+
if (!response.ok) {
|
|
5331
|
+
const errorText = await response.text();
|
|
5332
|
+
throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
|
|
5333
|
+
}
|
|
5334
|
+
const data = await response.json();
|
|
5335
|
+
logIfDebug(`Received latest trades for ${Object.keys(data.trades).length} symbols`);
|
|
5336
|
+
return data;
|
|
5337
|
+
}
|
|
5338
|
+
catch (error) {
|
|
5339
|
+
logIfDebug(`Error fetching crypto latest trades: ${error}`);
|
|
5340
|
+
throw error;
|
|
5341
|
+
}
|
|
5342
|
+
}
|
|
5343
|
+
/**
|
|
5344
|
+
* Fetches the latest quotes (bid/ask prices) for the specified cryptocurrency symbols.
|
|
5345
|
+
* This function retrieves the most recent bid and ask prices for each symbol.
|
|
5346
|
+
*
|
|
5347
|
+
* @param params - The parameters for fetching latest quotes.
|
|
5348
|
+
* @param params.symbols - An array of cryptocurrency symbols to fetch data for (e.g., ['BTC-USD', 'ETH-USD']).
|
|
5349
|
+
* @param params.loc - The location identifier (default: 'us'). Options: 'us' (Alpaca US), 'us-1' (Kraken US), 'eu-1' (Kraken EU).
|
|
5350
|
+
* @param auth - The Alpaca authentication object containing API key and secret.
|
|
5351
|
+
* @returns A promise that resolves to an object containing the latest quote for each symbol.
|
|
5352
|
+
* @throws Will throw an error if required parameters are missing or if fetching fails.
|
|
5353
|
+
*/
|
|
5354
|
+
async function fetchLatestQuotes(params, auth) {
|
|
5355
|
+
const { symbols, loc = 'us' } = params;
|
|
5356
|
+
if (!auth.APIKey || !auth.APISecret) {
|
|
5357
|
+
throw new Error('Alpaca API key and secret are required');
|
|
5358
|
+
}
|
|
5359
|
+
if (!symbols || symbols.length === 0) {
|
|
5360
|
+
throw new Error('At least one symbol is required');
|
|
5361
|
+
}
|
|
5362
|
+
// Convert symbols array to comma-separated string
|
|
5363
|
+
const symbolsParam = symbols.join(',');
|
|
5364
|
+
const queryParams = new URLSearchParams({
|
|
5365
|
+
symbols: symbolsParam,
|
|
5366
|
+
});
|
|
5367
|
+
const url = `${ALPACA_API_BASE}/crypto/${loc}/latest/quotes?${queryParams}`;
|
|
5368
|
+
logIfDebug(`Fetching crypto latest quotes from: ${url}`);
|
|
5369
|
+
try {
|
|
5370
|
+
const response = await fetch(url, {
|
|
5371
|
+
headers: {
|
|
5372
|
+
'APCA-API-KEY-ID': auth.APIKey,
|
|
5373
|
+
'APCA-API-SECRET-KEY': auth.APISecret,
|
|
5374
|
+
},
|
|
5375
|
+
});
|
|
5376
|
+
if (!response.ok) {
|
|
5377
|
+
const errorText = await response.text();
|
|
5378
|
+
throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
|
|
5379
|
+
}
|
|
5380
|
+
const data = await response.json();
|
|
5381
|
+
logIfDebug(`Received latest quotes for ${Object.keys(data.quotes).length} symbols`);
|
|
5382
|
+
return data;
|
|
5383
|
+
}
|
|
5384
|
+
catch (error) {
|
|
5385
|
+
logIfDebug(`Error fetching crypto latest quotes: ${error}`);
|
|
5386
|
+
throw error;
|
|
5387
|
+
}
|
|
5388
|
+
}
|
|
5297
5389
|
|
|
5298
5390
|
/**
|
|
5299
5391
|
* Calculates Bollinger Bands for a given set of price data.
|
|
@@ -16719,6 +16811,8 @@ const adaptic = {
|
|
|
16719
16811
|
crypto: {
|
|
16720
16812
|
fetchBars: fetchBars,
|
|
16721
16813
|
fetchNews: fetchNews,
|
|
16814
|
+
fetchLatestTrades: fetchLatestTrades,
|
|
16815
|
+
fetchLatestQuotes: fetchLatestQuotes,
|
|
16722
16816
|
},
|
|
16723
16817
|
format: {
|
|
16724
16818
|
capitalize: capitalize,
|