@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.cjs
CHANGED
|
@@ -5316,6 +5316,98 @@ async function fetchNews(params, auth) {
|
|
|
5316
5316
|
}
|
|
5317
5317
|
return newsArticles;
|
|
5318
5318
|
}
|
|
5319
|
+
/**
|
|
5320
|
+
* Fetches the latest trades for the specified cryptocurrency symbols.
|
|
5321
|
+
* This function retrieves the most recent trade price and volume for each symbol.
|
|
5322
|
+
*
|
|
5323
|
+
* @param params - The parameters for fetching latest trades.
|
|
5324
|
+
* @param params.symbols - An array of cryptocurrency symbols to fetch data for (e.g., ['BTC-USD', 'ETH-USD']).
|
|
5325
|
+
* @param params.loc - The location identifier (default: 'us'). Options: 'us' (Alpaca US), 'us-1' (Kraken US), 'eu-1' (Kraken EU).
|
|
5326
|
+
* @param auth - The Alpaca authentication object containing API key and secret.
|
|
5327
|
+
* @returns A promise that resolves to an object containing the latest trade for each symbol.
|
|
5328
|
+
* @throws Will throw an error if required parameters are missing or if fetching fails.
|
|
5329
|
+
*/
|
|
5330
|
+
async function fetchLatestTrades(params, auth) {
|
|
5331
|
+
const { symbols, loc = 'us' } = params;
|
|
5332
|
+
if (!auth.APIKey || !auth.APISecret) {
|
|
5333
|
+
throw new Error('Alpaca API key and secret are required');
|
|
5334
|
+
}
|
|
5335
|
+
if (!symbols || symbols.length === 0) {
|
|
5336
|
+
throw new Error('At least one symbol is required');
|
|
5337
|
+
}
|
|
5338
|
+
// Convert symbols array to comma-separated string
|
|
5339
|
+
const symbolsParam = symbols.join(',');
|
|
5340
|
+
const queryParams = new URLSearchParams({
|
|
5341
|
+
symbols: symbolsParam,
|
|
5342
|
+
});
|
|
5343
|
+
const url = `${ALPACA_API_BASE}/crypto/${loc}/latest/trades?${queryParams}`;
|
|
5344
|
+
logIfDebug(`Fetching crypto latest trades from: ${url}`);
|
|
5345
|
+
try {
|
|
5346
|
+
const response = await fetch(url, {
|
|
5347
|
+
headers: {
|
|
5348
|
+
'APCA-API-KEY-ID': auth.APIKey,
|
|
5349
|
+
'APCA-API-SECRET-KEY': auth.APISecret,
|
|
5350
|
+
},
|
|
5351
|
+
});
|
|
5352
|
+
if (!response.ok) {
|
|
5353
|
+
const errorText = await response.text();
|
|
5354
|
+
throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
|
|
5355
|
+
}
|
|
5356
|
+
const data = await response.json();
|
|
5357
|
+
logIfDebug(`Received latest trades for ${Object.keys(data.trades).length} symbols`);
|
|
5358
|
+
return data;
|
|
5359
|
+
}
|
|
5360
|
+
catch (error) {
|
|
5361
|
+
logIfDebug(`Error fetching crypto latest trades: ${error}`);
|
|
5362
|
+
throw error;
|
|
5363
|
+
}
|
|
5364
|
+
}
|
|
5365
|
+
/**
|
|
5366
|
+
* Fetches the latest quotes (bid/ask prices) for the specified cryptocurrency symbols.
|
|
5367
|
+
* This function retrieves the most recent bid and ask prices for each symbol.
|
|
5368
|
+
*
|
|
5369
|
+
* @param params - The parameters for fetching latest quotes.
|
|
5370
|
+
* @param params.symbols - An array of cryptocurrency symbols to fetch data for (e.g., ['BTC-USD', 'ETH-USD']).
|
|
5371
|
+
* @param params.loc - The location identifier (default: 'us'). Options: 'us' (Alpaca US), 'us-1' (Kraken US), 'eu-1' (Kraken EU).
|
|
5372
|
+
* @param auth - The Alpaca authentication object containing API key and secret.
|
|
5373
|
+
* @returns A promise that resolves to an object containing the latest quote for each symbol.
|
|
5374
|
+
* @throws Will throw an error if required parameters are missing or if fetching fails.
|
|
5375
|
+
*/
|
|
5376
|
+
async function fetchLatestQuotes(params, auth) {
|
|
5377
|
+
const { symbols, loc = 'us' } = params;
|
|
5378
|
+
if (!auth.APIKey || !auth.APISecret) {
|
|
5379
|
+
throw new Error('Alpaca API key and secret are required');
|
|
5380
|
+
}
|
|
5381
|
+
if (!symbols || symbols.length === 0) {
|
|
5382
|
+
throw new Error('At least one symbol is required');
|
|
5383
|
+
}
|
|
5384
|
+
// Convert symbols array to comma-separated string
|
|
5385
|
+
const symbolsParam = symbols.join(',');
|
|
5386
|
+
const queryParams = new URLSearchParams({
|
|
5387
|
+
symbols: symbolsParam,
|
|
5388
|
+
});
|
|
5389
|
+
const url = `${ALPACA_API_BASE}/crypto/${loc}/latest/quotes?${queryParams}`;
|
|
5390
|
+
logIfDebug(`Fetching crypto latest quotes from: ${url}`);
|
|
5391
|
+
try {
|
|
5392
|
+
const response = await fetch(url, {
|
|
5393
|
+
headers: {
|
|
5394
|
+
'APCA-API-KEY-ID': auth.APIKey,
|
|
5395
|
+
'APCA-API-SECRET-KEY': auth.APISecret,
|
|
5396
|
+
},
|
|
5397
|
+
});
|
|
5398
|
+
if (!response.ok) {
|
|
5399
|
+
const errorText = await response.text();
|
|
5400
|
+
throw new Error(`Alpaca API error (${response.status}): ${errorText}`);
|
|
5401
|
+
}
|
|
5402
|
+
const data = await response.json();
|
|
5403
|
+
logIfDebug(`Received latest quotes for ${Object.keys(data.quotes).length} symbols`);
|
|
5404
|
+
return data;
|
|
5405
|
+
}
|
|
5406
|
+
catch (error) {
|
|
5407
|
+
logIfDebug(`Error fetching crypto latest quotes: ${error}`);
|
|
5408
|
+
throw error;
|
|
5409
|
+
}
|
|
5410
|
+
}
|
|
5319
5411
|
|
|
5320
5412
|
/**
|
|
5321
5413
|
* Calculates Bollinger Bands for a given set of price data.
|
|
@@ -16741,6 +16833,8 @@ const adaptic = {
|
|
|
16741
16833
|
crypto: {
|
|
16742
16834
|
fetchBars: fetchBars,
|
|
16743
16835
|
fetchNews: fetchNews,
|
|
16836
|
+
fetchLatestTrades: fetchLatestTrades,
|
|
16837
|
+
fetchLatestQuotes: fetchLatestQuotes,
|
|
16744
16838
|
},
|
|
16745
16839
|
format: {
|
|
16746
16840
|
capitalize: capitalize,
|