@adaptic/utils 0.0.906 → 0.0.908
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 +13 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13 -13
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/rate-limiter.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1315,7 +1315,7 @@ async function fetchWithRetry(url, options = {}, retries = 3, initialBackoff = 1
|
|
|
1315
1315
|
*/
|
|
1316
1316
|
async function validatePolygonApiKey(apiKey) {
|
|
1317
1317
|
try {
|
|
1318
|
-
const response = await fetch(`https://api.
|
|
1318
|
+
const response = await fetch(`https://api.massive.com/v1/meta/symbols?apikey=${apiKey}&limit=1`);
|
|
1319
1319
|
if (response.status === 401) {
|
|
1320
1320
|
throw new Error("Invalid or expired Polygon.io API key");
|
|
1321
1321
|
}
|
|
@@ -1402,7 +1402,7 @@ async function fetchNews$1(symbols, params) {
|
|
|
1402
1402
|
}
|
|
1403
1403
|
else {
|
|
1404
1404
|
APIKey = process.env.ALPACA_API_KEY;
|
|
1405
|
-
APISecret = process.env.ALPACA_SECRET_KEY;
|
|
1405
|
+
APISecret = process.env.ALPACA_API_SECRET || process.env.ALPACA_SECRET_KEY;
|
|
1406
1406
|
}
|
|
1407
1407
|
if (!APIKey || !APISecret) {
|
|
1408
1408
|
throw new Error("No valid Alpaca authentication found. Please provide either auth object or set ALPACA_API_KEY and ALPACA_API_SECRET environment variables.");
|
|
@@ -1592,7 +1592,7 @@ async function closePosition$1(auth, symbolOrAssetId, params) {
|
|
|
1592
1592
|
const alpacaAuth = {
|
|
1593
1593
|
type: "LIVE",
|
|
1594
1594
|
alpacaApiKey: process.env.ALPACA_API_KEY,
|
|
1595
|
-
alpacaApiSecret: process.env.ALPACA_SECRET_KEY,
|
|
1595
|
+
alpacaApiSecret: process.env.ALPACA_API_SECRET || process.env.ALPACA_SECRET_KEY,
|
|
1596
1596
|
};
|
|
1597
1597
|
const quotesResponse = await getLatestQuotes$1(alpacaAuth, {
|
|
1598
1598
|
symbols: [symbolOrAssetId],
|
|
@@ -1685,7 +1685,7 @@ async function closeAllPositions$1(auth, params = { cancel_orders: true, useLimi
|
|
|
1685
1685
|
const alpacaAuth = {
|
|
1686
1686
|
type: "LIVE",
|
|
1687
1687
|
alpacaApiKey: process.env.ALPACA_API_KEY,
|
|
1688
|
-
alpacaApiSecret: process.env.ALPACA_SECRET_KEY,
|
|
1688
|
+
alpacaApiSecret: process.env.ALPACA_API_SECRET || process.env.ALPACA_SECRET_KEY,
|
|
1689
1689
|
};
|
|
1690
1690
|
const symbols = positions.map((position) => position.symbol);
|
|
1691
1691
|
const quotesResponse = await getLatestQuotes$1(alpacaAuth, { symbols });
|
|
@@ -5187,7 +5187,7 @@ const fetchTickerInfo = async (symbol, options) => {
|
|
|
5187
5187
|
}
|
|
5188
5188
|
const apiKey = options?.apiKey || POLYGON_API_KEY;
|
|
5189
5189
|
validatePolygonApiKey$1(apiKey);
|
|
5190
|
-
const baseUrl = `https://api.
|
|
5190
|
+
const baseUrl = `https://api.massive.com/v3/reference/tickers/${encodeURIComponent(symbol)}`;
|
|
5191
5191
|
const params = new URLSearchParams({
|
|
5192
5192
|
apiKey,
|
|
5193
5193
|
});
|
|
@@ -5274,7 +5274,7 @@ const fetchLastTrade = async (symbol, options) => {
|
|
|
5274
5274
|
}
|
|
5275
5275
|
const apiKey = options?.apiKey || POLYGON_API_KEY;
|
|
5276
5276
|
validatePolygonApiKey$1(apiKey);
|
|
5277
|
-
const baseUrl = `https://api.
|
|
5277
|
+
const baseUrl = `https://api.massive.com/v2/last/trade/${encodeURIComponent(symbol)}`;
|
|
5278
5278
|
const params = new URLSearchParams({
|
|
5279
5279
|
apiKey,
|
|
5280
5280
|
});
|
|
@@ -5339,7 +5339,7 @@ const fetchPrices = async (params, options) => {
|
|
|
5339
5339
|
const apiKey = options?.apiKey || POLYGON_API_KEY;
|
|
5340
5340
|
validatePolygonApiKey$1(apiKey);
|
|
5341
5341
|
const { ticker, start, end = Date.now().valueOf(), multiplier, timespan, limit = 1000, } = params;
|
|
5342
|
-
const baseUrl = `https://api.
|
|
5342
|
+
const baseUrl = `https://api.massive.com/v2/aggs/ticker/${encodeURIComponent(ticker)}/range/${multiplier}/${timespan}/${start}/${end}`;
|
|
5343
5343
|
const urlParams = new URLSearchParams({
|
|
5344
5344
|
apiKey,
|
|
5345
5345
|
adjusted: "true",
|
|
@@ -5461,7 +5461,7 @@ const fetchGroupedDaily = async (date, options) => {
|
|
|
5461
5461
|
if (!options?.apiKey && !POLYGON_API_KEY) {
|
|
5462
5462
|
throw new Error("Polygon API key is missing");
|
|
5463
5463
|
}
|
|
5464
|
-
const baseUrl = `https://api.
|
|
5464
|
+
const baseUrl = `https://api.massive.com/v2/aggs/grouped/locale/us/market/stocks/${date}`;
|
|
5465
5465
|
const params = new URLSearchParams({
|
|
5466
5466
|
apiKey: options?.apiKey || POLYGON_API_KEY,
|
|
5467
5467
|
adjusted: options?.adjusted !== false ? "true" : "false",
|
|
@@ -5554,7 +5554,7 @@ symbol, date = new Date(), options) => {
|
|
|
5554
5554
|
throw new Error("Polygon API key is missing");
|
|
5555
5555
|
}
|
|
5556
5556
|
const formattedDate = date.toISOString().split("T")[0]; // Format as YYYY-MM-DD
|
|
5557
|
-
const baseUrl = `https://api.
|
|
5557
|
+
const baseUrl = `https://api.massive.com/v1/open-close/${encodeURIComponent(symbol)}/${formattedDate}`;
|
|
5558
5558
|
const params = new URLSearchParams({
|
|
5559
5559
|
apiKey: options?.apiKey || POLYGON_API_KEY,
|
|
5560
5560
|
adjusted: (options?.adjusted ?? true).toString(),
|
|
@@ -5604,7 +5604,7 @@ const fetchTrades = async (symbol, options) => {
|
|
|
5604
5604
|
if (!options?.apiKey && !POLYGON_API_KEY) {
|
|
5605
5605
|
throw new Error("Polygon API key is missing");
|
|
5606
5606
|
}
|
|
5607
|
-
const baseUrl = `https://api.
|
|
5607
|
+
const baseUrl = `https://api.massive.com/v3/trades/${encodeURIComponent(symbol)}`;
|
|
5608
5608
|
const params = new URLSearchParams({
|
|
5609
5609
|
apiKey: options?.apiKey || POLYGON_API_KEY,
|
|
5610
5610
|
});
|
|
@@ -5670,7 +5670,7 @@ const { ALPACA_INDICES_API_KEY } = process.env;
|
|
|
5670
5670
|
const POLYGON_INDICES_CONCURRENCY_LIMIT = 5;
|
|
5671
5671
|
const polygonIndicesLimit = pLimit(POLYGON_INDICES_CONCURRENCY_LIMIT);
|
|
5672
5672
|
// Base URL for Polygon API
|
|
5673
|
-
const POLYGON_API_BASE_URL = "https://api.
|
|
5673
|
+
const POLYGON_API_BASE_URL = "https://api.massive.com";
|
|
5674
5674
|
/**
|
|
5675
5675
|
* Validates that an API key is available
|
|
5676
5676
|
* @param {string | undefined} apiKey - Optional API key to use
|
|
@@ -15234,7 +15234,7 @@ const rateLimiters = {
|
|
|
15234
15234
|
*
|
|
15235
15235
|
* Configured for 5 requests per second (basic plan).
|
|
15236
15236
|
* Adjust if you have a different subscription tier.
|
|
15237
|
-
* See: https://
|
|
15237
|
+
* See: https://massive.com/pricing
|
|
15238
15238
|
*/
|
|
15239
15239
|
polygon: new TokenBucketRateLimiter({
|
|
15240
15240
|
maxTokens: 5,
|
|
@@ -53467,7 +53467,7 @@ function createAlpacaClient(config) {
|
|
|
53467
53467
|
*/
|
|
53468
53468
|
function createClientFromEnv() {
|
|
53469
53469
|
const apiKey = process.env.ALPACA_API_KEY;
|
|
53470
|
-
const apiSecret = process.env.ALPACA_SECRET_KEY;
|
|
53470
|
+
const apiSecret = process.env.ALPACA_API_SECRET || process.env.ALPACA_SECRET_KEY;
|
|
53471
53471
|
const accountType = process.env.ALPACA_ACCOUNT_TYPE || "PAPER";
|
|
53472
53472
|
if (!apiKey || !apiSecret) {
|
|
53473
53473
|
throw new Error("ALPACA_API_KEY and ALPACA_SECRET_KEY environment variables are required");
|