@adaptic/utils 0.0.99
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/README.md +916 -0
- package/dist/index.cjs +71971 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +71677 -0
- package/dist/index.mjs.map +1 -0
- package/dist/test.js +7799 -0
- package/dist/test.js.map +1 -0
- package/dist/types/__tests__/alpaca-functions.test.d.ts +2 -0
- package/dist/types/__tests__/alpaca-functions.test.d.ts.map +1 -0
- package/dist/types/__tests__/api-endpoints.test.d.ts +2 -0
- package/dist/types/__tests__/api-endpoints.test.d.ts.map +1 -0
- package/dist/types/__tests__/asset-allocation.test.d.ts +2 -0
- package/dist/types/__tests__/asset-allocation.test.d.ts.map +1 -0
- package/dist/types/__tests__/auth-validator.test.d.ts +2 -0
- package/dist/types/__tests__/auth-validator.test.d.ts.map +1 -0
- package/dist/types/__tests__/cache.test.d.ts +2 -0
- package/dist/types/__tests__/cache.test.d.ts.map +1 -0
- package/dist/types/__tests__/errors.test.d.ts +2 -0
- package/dist/types/__tests__/errors.test.d.ts.map +1 -0
- package/dist/types/__tests__/financial-regression.test.d.ts +2 -0
- package/dist/types/__tests__/financial-regression.test.d.ts.map +1 -0
- package/dist/types/__tests__/format-tools.test.d.ts +2 -0
- package/dist/types/__tests__/format-tools.test.d.ts.map +1 -0
- package/dist/types/__tests__/http-keep-alive.test.d.ts +2 -0
- package/dist/types/__tests__/http-keep-alive.test.d.ts.map +1 -0
- package/dist/types/__tests__/http-timeout.test.d.ts +2 -0
- package/dist/types/__tests__/http-timeout.test.d.ts.map +1 -0
- package/dist/types/__tests__/logger.test.d.ts +2 -0
- package/dist/types/__tests__/logger.test.d.ts.map +1 -0
- package/dist/types/__tests__/market-time.test.d.ts +2 -0
- package/dist/types/__tests__/market-time.test.d.ts.map +1 -0
- package/dist/types/__tests__/misc-utils.test.d.ts +2 -0
- package/dist/types/__tests__/misc-utils.test.d.ts.map +1 -0
- package/dist/types/__tests__/paginator.test.d.ts +2 -0
- package/dist/types/__tests__/paginator.test.d.ts.map +1 -0
- package/dist/types/__tests__/performance-metrics.test.d.ts +2 -0
- package/dist/types/__tests__/performance-metrics.test.d.ts.map +1 -0
- package/dist/types/__tests__/polygon.test.d.ts +2 -0
- package/dist/types/__tests__/polygon.test.d.ts.map +1 -0
- package/dist/types/__tests__/price-utils.test.d.ts +2 -0
- package/dist/types/__tests__/price-utils.test.d.ts.map +1 -0
- package/dist/types/__tests__/property-based-financial.test.d.ts +2 -0
- package/dist/types/__tests__/property-based-financial.test.d.ts.map +1 -0
- package/dist/types/__tests__/rate-limiter.test.d.ts +2 -0
- package/dist/types/__tests__/rate-limiter.test.d.ts.map +1 -0
- package/dist/types/__tests__/schema-validation.test.d.ts +2 -0
- package/dist/types/__tests__/schema-validation.test.d.ts.map +1 -0
- package/dist/types/__tests__/technical-analysis.test.d.ts +2 -0
- package/dist/types/__tests__/technical-analysis.test.d.ts.map +1 -0
- package/dist/types/__tests__/time-utils.test.d.ts +2 -0
- package/dist/types/__tests__/time-utils.test.d.ts.map +1 -0
- package/dist/types/adaptic.d.ts +52 -0
- package/dist/types/adaptic.d.ts.map +1 -0
- package/dist/types/alpaca/client.d.ts +95 -0
- package/dist/types/alpaca/client.d.ts.map +1 -0
- package/dist/types/alpaca/crypto/data.d.ts +281 -0
- package/dist/types/alpaca/crypto/data.d.ts.map +1 -0
- package/dist/types/alpaca/crypto/index.d.ts +75 -0
- package/dist/types/alpaca/crypto/index.d.ts.map +1 -0
- package/dist/types/alpaca/crypto/orders.d.ts +221 -0
- package/dist/types/alpaca/crypto/orders.d.ts.map +1 -0
- package/dist/types/alpaca/index.d.ts +205 -0
- package/dist/types/alpaca/index.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/account.d.ts +34 -0
- package/dist/types/alpaca/legacy/account.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/assets.d.ts +13 -0
- package/dist/types/alpaca/legacy/assets.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/auth.d.ts +18 -0
- package/dist/types/alpaca/legacy/auth.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/index.d.ts +15 -0
- package/dist/types/alpaca/legacy/index.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/market-data.d.ts +32 -0
- package/dist/types/alpaca/legacy/market-data.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/orders.d.ts +84 -0
- package/dist/types/alpaca/legacy/orders.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/positions.d.ts +66 -0
- package/dist/types/alpaca/legacy/positions.d.ts.map +1 -0
- package/dist/types/alpaca/legacy/utils.d.ts +18 -0
- package/dist/types/alpaca/legacy/utils.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/bars.d.ts +142 -0
- package/dist/types/alpaca/market-data/bars.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/index.d.ts +13 -0
- package/dist/types/alpaca/market-data/index.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/news.d.ts +87 -0
- package/dist/types/alpaca/market-data/news.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/quotes.d.ts +85 -0
- package/dist/types/alpaca/market-data/quotes.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/trades.d.ts +98 -0
- package/dist/types/alpaca/market-data/trades.d.ts.map +1 -0
- package/dist/types/alpaca/options/contracts.d.ts +279 -0
- package/dist/types/alpaca/options/contracts.d.ts.map +1 -0
- package/dist/types/alpaca/options/data.d.ts +126 -0
- package/dist/types/alpaca/options/data.d.ts.map +1 -0
- package/dist/types/alpaca/options/index.d.ts +17 -0
- package/dist/types/alpaca/options/index.d.ts.map +1 -0
- package/dist/types/alpaca/options/orders.d.ts +366 -0
- package/dist/types/alpaca/options/orders.d.ts.map +1 -0
- package/dist/types/alpaca/options/strategies.d.ts +224 -0
- package/dist/types/alpaca/options/strategies.d.ts.map +1 -0
- package/dist/types/alpaca/streams/base-stream.d.ts +143 -0
- package/dist/types/alpaca/streams/base-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/crypto-stream.d.ts +173 -0
- package/dist/types/alpaca/streams/crypto-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/index.d.ts +54 -0
- package/dist/types/alpaca/streams/index.d.ts.map +1 -0
- package/dist/types/alpaca/streams/option-stream.d.ts +167 -0
- package/dist/types/alpaca/streams/option-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/stock-stream.d.ts +176 -0
- package/dist/types/alpaca/streams/stock-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/stream-manager.d.ts +277 -0
- package/dist/types/alpaca/streams/stream-manager.d.ts.map +1 -0
- package/dist/types/alpaca/streams/trading-stream.d.ts +186 -0
- package/dist/types/alpaca/streams/trading-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams.d.ts +88 -0
- package/dist/types/alpaca/streams.d.ts.map +1 -0
- package/dist/types/alpaca/test-imports.d.ts +7 -0
- package/dist/types/alpaca/test-imports.d.ts.map +1 -0
- package/dist/types/alpaca/trading/account.d.ts +198 -0
- package/dist/types/alpaca/trading/account.d.ts.map +1 -0
- package/dist/types/alpaca/trading/bracket-orders.d.ts +162 -0
- package/dist/types/alpaca/trading/bracket-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/clock.d.ts +99 -0
- package/dist/types/alpaca/trading/clock.d.ts.map +1 -0
- package/dist/types/alpaca/trading/index.d.ts +15 -0
- package/dist/types/alpaca/trading/index.d.ts.map +1 -0
- package/dist/types/alpaca/trading/oco-orders.d.ts +203 -0
- package/dist/types/alpaca/trading/oco-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/order-utils.d.ts +404 -0
- package/dist/types/alpaca/trading/order-utils.d.ts.map +1 -0
- package/dist/types/alpaca/trading/orders.d.ts +199 -0
- package/dist/types/alpaca/trading/orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/oto-orders.d.ts +282 -0
- package/dist/types/alpaca/trading/oto-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/positions.d.ts +389 -0
- package/dist/types/alpaca/trading/positions.d.ts.map +1 -0
- package/dist/types/alpaca/trading/smart-orders.d.ts +301 -0
- package/dist/types/alpaca/trading/smart-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/trailing-stops.d.ts +240 -0
- package/dist/types/alpaca/trading/trailing-stops.d.ts.map +1 -0
- package/dist/types/alpaca-market-data-api.d.ts +386 -0
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -0
- package/dist/types/alpaca-trading-api.d.ts +315 -0
- package/dist/types/alpaca-trading-api.d.ts.map +1 -0
- package/dist/types/alphavantage.d.ts +44 -0
- package/dist/types/alphavantage.d.ts.map +1 -0
- package/dist/types/asset-allocation-algorithm.d.ts +143 -0
- package/dist/types/asset-allocation-algorithm.d.ts.map +1 -0
- package/dist/types/cache/stampede-protected-cache.d.ts +565 -0
- package/dist/types/cache/stampede-protected-cache.d.ts.map +1 -0
- package/dist/types/config/api-endpoints.d.ts +94 -0
- package/dist/types/config/api-endpoints.d.ts.map +1 -0
- package/dist/types/crypto.d.ts +76 -0
- package/dist/types/crypto.d.ts.map +1 -0
- package/dist/types/display-manager.d.ts +24 -0
- package/dist/types/display-manager.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +130 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/examples/asset-allocation-example.d.ts +36 -0
- package/dist/types/examples/asset-allocation-example.d.ts.map +1 -0
- package/dist/types/examples/rate-limiter-example.d.ts +7 -0
- package/dist/types/examples/rate-limiter-example.d.ts.map +1 -0
- package/dist/types/format-tools.d.ts +54 -0
- package/dist/types/format-tools.d.ts.map +1 -0
- package/dist/types/http-timeout.d.ts +37 -0
- package/dist/types/http-timeout.d.ts.map +1 -0
- package/dist/types/index.d.ts +766 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts +56 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logging.d.ts +12 -0
- package/dist/types/logging.d.ts.map +1 -0
- package/dist/types/market-hours.d.ts +24 -0
- package/dist/types/market-hours.d.ts.map +1 -0
- package/dist/types/market-time.d.ts +246 -0
- package/dist/types/market-time.d.ts.map +1 -0
- package/dist/types/metrics-calcs.d.ts +6 -0
- package/dist/types/metrics-calcs.d.ts.map +1 -0
- package/dist/types/misc-utils.d.ts +52 -0
- package/dist/types/misc-utils.d.ts.map +1 -0
- package/dist/types/performance-metrics.d.ts +88 -0
- package/dist/types/performance-metrics.d.ts.map +1 -0
- package/dist/types/polygon-indices.d.ts +85 -0
- package/dist/types/polygon-indices.d.ts.map +1 -0
- package/dist/types/polygon.d.ts +126 -0
- package/dist/types/polygon.d.ts.map +1 -0
- package/dist/types/price-utils.d.ts +26 -0
- package/dist/types/price-utils.d.ts.map +1 -0
- package/dist/types/rate-limiter.d.ts +171 -0
- package/dist/types/rate-limiter.d.ts.map +1 -0
- package/dist/types/schemas/alpaca-schemas.d.ts +779 -0
- package/dist/types/schemas/alpaca-schemas.d.ts.map +1 -0
- package/dist/types/schemas/alphavantage-schemas.d.ts +255 -0
- package/dist/types/schemas/alphavantage-schemas.d.ts.map +1 -0
- package/dist/types/schemas/index.d.ts +21 -0
- package/dist/types/schemas/index.d.ts.map +1 -0
- package/dist/types/schemas/polygon-schemas.d.ts +551 -0
- package/dist/types/schemas/polygon-schemas.d.ts.map +1 -0
- package/dist/types/schemas/validate-response.d.ts +88 -0
- package/dist/types/schemas/validate-response.d.ts.map +1 -0
- package/dist/types/technical-analysis.d.ts +90 -0
- package/dist/types/technical-analysis.d.ts.map +1 -0
- package/dist/types/test.d.ts +2 -0
- package/dist/types/test.d.ts.map +1 -0
- package/dist/types/testing/options-ws.d.ts +2 -0
- package/dist/types/testing/options-ws.d.ts.map +1 -0
- package/dist/types/time-utils.d.ts +17 -0
- package/dist/types/time-utils.d.ts.map +1 -0
- package/dist/types/types/adaptic-types.d.ts +11 -0
- package/dist/types/types/adaptic-types.d.ts.map +1 -0
- package/dist/types/types/alpaca-types.d.ts +1165 -0
- package/dist/types/types/alpaca-types.d.ts.map +1 -0
- package/dist/types/types/alphavantage-types.d.ts +66 -0
- package/dist/types/types/alphavantage-types.d.ts.map +1 -0
- package/dist/types/types/asset-allocation-types.d.ts +328 -0
- package/dist/types/types/asset-allocation-types.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +21 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/logging-types.d.ts +10 -0
- package/dist/types/types/logging-types.d.ts.map +1 -0
- package/dist/types/types/market-time-types.d.ts +59 -0
- package/dist/types/types/market-time-types.d.ts.map +1 -0
- package/dist/types/types/metrics-types.d.ts +33 -0
- package/dist/types/types/metrics-types.d.ts.map +1 -0
- package/dist/types/types/polygon-indices-types.d.ts +190 -0
- package/dist/types/types/polygon-indices-types.d.ts.map +1 -0
- package/dist/types/types/polygon-types.d.ts +204 -0
- package/dist/types/types/polygon-types.d.ts.map +1 -0
- package/dist/types/types/ta-types.d.ts +89 -0
- package/dist/types/types/ta-types.d.ts.map +1 -0
- package/dist/types/utils/auth-validator.d.ts +32 -0
- package/dist/types/utils/auth-validator.d.ts.map +1 -0
- package/dist/types/utils/http-keep-alive.d.ts +110 -0
- package/dist/types/utils/http-keep-alive.d.ts.map +1 -0
- package/dist/types/utils/paginator.d.ts +154 -0
- package/dist/types/utils/paginator.d.ts.map +1 -0
- package/dist/types/utils/retry.d.ts +78 -0
- package/dist/types/utils/retry.d.ts.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**********************************************************************************
|
|
2
|
+
* Polygon.io calls
|
|
3
|
+
**********************************************************************************/
|
|
4
|
+
import { PolygonQuote, PolygonPriceData, PolygonGroupedDailyResponse, PolygonTickerInfo, PolygonDailyOpenClose, PolygonTradesResponse } from "./types";
|
|
5
|
+
/**
|
|
6
|
+
* Fetches general information about a stock ticker.
|
|
7
|
+
* @param {string} symbol - The stock ticker symbol to fetch information for.
|
|
8
|
+
* @param {Object} [options] - Optional parameters.
|
|
9
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
10
|
+
* @returns {Promise<PolygonTickerInfo | null>} The ticker information or null if not found.
|
|
11
|
+
*/
|
|
12
|
+
export declare const fetchTickerInfo: (symbol: string, options?: {
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
}) => Promise<PolygonTickerInfo | null>;
|
|
15
|
+
/**
|
|
16
|
+
* Fetches the last trade for a given stock ticker.
|
|
17
|
+
* @param {string} symbol - The stock ticker symbol to fetch the last trade for.
|
|
18
|
+
* @param {Object} [options] - Optional parameters.
|
|
19
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
20
|
+
* @returns {Promise<PolygonQuote>} The last trade information.
|
|
21
|
+
*/
|
|
22
|
+
export declare const fetchLastTrade: (symbol: string, options?: {
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
}) => Promise<PolygonQuote>;
|
|
25
|
+
/**
|
|
26
|
+
* Fetches price data for a given stock ticker.
|
|
27
|
+
* @param {Object} params - The parameters for fetching price data.
|
|
28
|
+
* @param {string} params.ticker - The stock ticker symbol.
|
|
29
|
+
* @param {number} params.start - The start timestamp for fetching price data.
|
|
30
|
+
* @param {number} [params.end] - The end timestamp for fetching price data.
|
|
31
|
+
* @param {number} params.multiplier - The multiplier for the price data.
|
|
32
|
+
* @param {string} params.timespan - The timespan for the price data.
|
|
33
|
+
* @param {number} [params.limit] - The maximum number of price data points to fetch.
|
|
34
|
+
* @param {Object} [options] - Optional parameters.
|
|
35
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
36
|
+
* @returns {Promise<PolygonPriceData[]>} The fetched price data.
|
|
37
|
+
*/
|
|
38
|
+
export declare const fetchPrices: (params: {
|
|
39
|
+
ticker: string;
|
|
40
|
+
start: number;
|
|
41
|
+
end?: number;
|
|
42
|
+
multiplier: number;
|
|
43
|
+
timespan: string;
|
|
44
|
+
limit?: number;
|
|
45
|
+
}, options?: {
|
|
46
|
+
apiKey?: string;
|
|
47
|
+
}) => Promise<PolygonPriceData[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Analyzes the price data for a given stock.
|
|
50
|
+
* @param {PolygonPriceData[]} priceData - The price data to analyze.
|
|
51
|
+
* @returns {string} The analysis report.
|
|
52
|
+
*/
|
|
53
|
+
export declare function analysePolygonPriceData(priceData: PolygonPriceData[]): string;
|
|
54
|
+
/**
|
|
55
|
+
* Fetches grouped daily price data for a specific date.
|
|
56
|
+
* @param {string} date - The date to fetch grouped daily data for.
|
|
57
|
+
* @param {Object} [options] - Optional parameters.
|
|
58
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
59
|
+
* @param {boolean} [options.adjusted] - Whether to adjust the data.
|
|
60
|
+
* @param {boolean} [options.includeOTC] - Whether to include OTC data.
|
|
61
|
+
* @returns {Promise<PolygonGroupedDailyResponse>} The grouped daily response.
|
|
62
|
+
*/
|
|
63
|
+
export declare const fetchGroupedDaily: (date: string, options?: {
|
|
64
|
+
apiKey?: string;
|
|
65
|
+
adjusted?: boolean;
|
|
66
|
+
includeOTC?: boolean;
|
|
67
|
+
}) => Promise<PolygonGroupedDailyResponse>;
|
|
68
|
+
/**
|
|
69
|
+
* Formats the price data into a readable string.
|
|
70
|
+
* @param {PolygonPriceData[]} priceData - The price data to format.
|
|
71
|
+
* @returns {string} The formatted price data.
|
|
72
|
+
*/
|
|
73
|
+
export declare function formatPriceData(priceData: PolygonPriceData[]): string;
|
|
74
|
+
export declare const fetchDailyOpenClose: (
|
|
75
|
+
/**
|
|
76
|
+
* Fetches the daily open and close data for a given stock ticker.
|
|
77
|
+
* @param {string} symbol - The stock ticker symbol to fetch data for.
|
|
78
|
+
* @param {Date} [date=new Date()] - The date to fetch data for.
|
|
79
|
+
* @param {Object} [options] - Optional parameters.
|
|
80
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
81
|
+
* @param {boolean} [options.adjusted] - Whether to adjust the data.
|
|
82
|
+
* @returns {Promise<PolygonDailyOpenClose>} The daily open and close data.
|
|
83
|
+
*/
|
|
84
|
+
symbol: string, date?: Date, options?: {
|
|
85
|
+
apiKey?: string;
|
|
86
|
+
adjusted?: boolean;
|
|
87
|
+
}) => Promise<PolygonDailyOpenClose>;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the previous close price for a given stock ticker.
|
|
90
|
+
* @param {string} symbol - The stock ticker symbol to fetch the previous close for.
|
|
91
|
+
* @param {Date} [referenceDate] - The reference date to use for fetching the previous close.
|
|
92
|
+
* @returns {Promise<{ close: number; date: Date }>} The previous close price and date.
|
|
93
|
+
*/
|
|
94
|
+
export declare function getPreviousClose(symbol: string, referenceDate?: Date, options?: {
|
|
95
|
+
apiKey?: string;
|
|
96
|
+
}): Promise<{
|
|
97
|
+
close: number;
|
|
98
|
+
date: Date;
|
|
99
|
+
}>;
|
|
100
|
+
/**
|
|
101
|
+
* Fetches trade data for a given stock ticker.
|
|
102
|
+
* @param {string} symbol - The stock ticker symbol to fetch trades for.
|
|
103
|
+
* @param {Object} [options] - Optional parameters.
|
|
104
|
+
* @param {string} [options.apiKey] - The API key to use for the request.
|
|
105
|
+
* @param {string | number} [options.timestamp] - The timestamp for fetching trades.
|
|
106
|
+
* @param {string | number} [options.timestampgt] - Greater than timestamp for fetching trades.
|
|
107
|
+
* @param {string | number} [options.timestampgte] - Greater than or equal to timestamp for fetching trades.
|
|
108
|
+
* @param {string | number} [options.timestamplt] - Less than timestamp for fetching trades.
|
|
109
|
+
* @param {string | number} [options.timestamplte] - Less than or equal to timestamp for fetching trades.
|
|
110
|
+
* @param {'asc' | 'desc'} [options.order] - The order of the trades.
|
|
111
|
+
* @param {number} [options.limit] - The maximum number of trades to fetch.
|
|
112
|
+
* @param {string} [options.sort] - The sort order for the trades.
|
|
113
|
+
* @returns {Promise<PolygonTradesResponse>} The fetched trades response.
|
|
114
|
+
*/
|
|
115
|
+
export declare const fetchTrades: (symbol: string, options?: {
|
|
116
|
+
apiKey?: string;
|
|
117
|
+
timestamp?: string | number;
|
|
118
|
+
timestampgt?: string | number;
|
|
119
|
+
timestampgte?: string | number;
|
|
120
|
+
timestamplt?: string | number;
|
|
121
|
+
timestamplte?: string | number;
|
|
122
|
+
order?: "asc" | "desc";
|
|
123
|
+
limit?: number;
|
|
124
|
+
sort?: string;
|
|
125
|
+
}) => Promise<PolygonTradesResponse>;
|
|
126
|
+
//# sourceMappingURL=polygon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polygon.d.ts","sourceRoot":"","sources":["../../src/polygon.ts"],"names":[],"mappings":"AAAA;;oFAEoF;AAIpF,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,2BAA2B,EAE3B,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EAEtB,MAAM,SAAS,CAAC;AAajB;;;;;;GAMG;AAEH,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAiGlC,CAAC;AAGF;;;;;;GAMG;AAEH,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,YAAY,CAmEtB,CAAC;AAGF;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,WAAW,GACtB,QAAQ;IACN,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,EACD,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,gBAAgB,EAAE,CAgG5B,CAAC;AAEF;;;;GAIG;AAEH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,CA8C7E;AAID;;;;;;;;GAQG;AAEH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,KACA,OAAO,CAAC,2BAA2B,CAoErC,CAAC;AAEF;;;;GAIG;AAEH,wBAAgB,eAAe,CAAC,SAAS,EAAE,gBAAgB,EAAE,GAAG,MAAM,CAoBrE;AAED,eAAO,MAAM,mBAAmB;AAC9B;;;;;;;;GAQG;AAEH,QAAQ,MAAM,EACd,OAAM,IAAiB,EACvB,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,KACA,OAAO,CAAC,qBAAqB,CA6B/B,CAAC;AAIF;;;;;GAKG;AAEH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,IAAI,EACpB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAcxC;AAED;;;;;;;;;;;;;;GAcG;AAEH,eAAO,MAAM,WAAW,GACtB,QAAQ,MAAM,EACd,UAAU;IACR,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,KACA,OAAO,CAAC,qBAAqB,CAgE/B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { types } from "@adaptic/backend-legacy";
|
|
2
|
+
import { EquityPoint, AlpacaPortfolioHistory } from "./types/index";
|
|
3
|
+
import { MarketTimeUtil } from "./market-time";
|
|
4
|
+
export declare const computeTotalFees: (trade: types.Trade) => Promise<number>;
|
|
5
|
+
/**
|
|
6
|
+
* Rounds price based on value:
|
|
7
|
+
* - For prices >= $1, rounds to nearest $0.01
|
|
8
|
+
* - For prices < $1, rounds to nearest $0.0001
|
|
9
|
+
*/
|
|
10
|
+
export declare function roundStockPrice(price: number): number;
|
|
11
|
+
export declare function getEquityValues(equityData: EquityPoint[], portfolioHistory?: AlpacaPortfolioHistory, marketTimeUtil?: MarketTimeUtil, period?: string): {
|
|
12
|
+
latestEquity: number;
|
|
13
|
+
initialEquity: number;
|
|
14
|
+
latestTimestamp?: undefined;
|
|
15
|
+
initialTimestamp?: undefined;
|
|
16
|
+
baseValueAsOf?: undefined;
|
|
17
|
+
baseValue?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
latestEquity: number;
|
|
20
|
+
initialEquity: number;
|
|
21
|
+
latestTimestamp: import("lightweight-charts").Time;
|
|
22
|
+
initialTimestamp: import("lightweight-charts").Time;
|
|
23
|
+
baseValueAsOf: string | undefined;
|
|
24
|
+
baseValue: number | undefined;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=price-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"price-utils.d.ts","sourceRoot":"","sources":["../../src/price-utils.ts"],"names":[],"mappings":"AAEA,OAAgB,EAAS,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAe,cAAc,EAAE,MAAM,eAAe,CAAC;AAyE5D,eAAO,MAAM,gBAAgB,GAAU,OAAO,KAAK,CAAC,KAAK,KAAG,OAAO,CAAC,MAAM,CAiBzE,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED,wBAAgB,eAAe,CAC7B,UAAU,EAAE,WAAW,EAAE,EACzB,gBAAgB,CAAC,EAAE,sBAAsB,EACzC,cAAc,CAAC,EAAE,cAAc,EAC/B,MAAM,CAAC,EAAE,MAAM;;;;;;;;;;;;;;EAsHhB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token bucket rate limiter for external API integrations
|
|
3
|
+
*
|
|
4
|
+
* Implements client-side rate limiting to prevent exceeding API quotas
|
|
5
|
+
* and ensure fair usage of external services like Alpaca, Polygon, and AlphaVantage.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { rateLimiters } from '@adaptic/utils';
|
|
10
|
+
*
|
|
11
|
+
* // Before making an API call
|
|
12
|
+
* await rateLimiters.alpaca.acquire();
|
|
13
|
+
* const result = await makeAlpacaApiCall();
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
import { RateLimitError } from "./errors";
|
|
17
|
+
export { RateLimitError };
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for a rate limiter instance
|
|
20
|
+
*/
|
|
21
|
+
export interface RateLimiterConfig {
|
|
22
|
+
/** Maximum number of tokens (requests) that can be accumulated */
|
|
23
|
+
maxTokens: number;
|
|
24
|
+
/** Rate at which tokens are refilled (tokens per second) */
|
|
25
|
+
refillRate: number;
|
|
26
|
+
/** Human-readable label for logging and error messages */
|
|
27
|
+
label: string;
|
|
28
|
+
/** Maximum time to wait for a token before timing out (milliseconds) */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Token bucket rate limiter implementation
|
|
33
|
+
*
|
|
34
|
+
* Uses the token bucket algorithm to control the rate of API requests.
|
|
35
|
+
* Tokens are consumed on each request and refilled at a constant rate.
|
|
36
|
+
* Requests that exceed the available tokens are queued and processed
|
|
37
|
+
* when tokens become available.
|
|
38
|
+
*/
|
|
39
|
+
export declare class TokenBucketRateLimiter {
|
|
40
|
+
private readonly config;
|
|
41
|
+
private tokens;
|
|
42
|
+
private lastRefill;
|
|
43
|
+
private queue;
|
|
44
|
+
private readonly timeoutMs;
|
|
45
|
+
private processingQueue;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new rate limiter instance
|
|
48
|
+
*
|
|
49
|
+
* @param config - Rate limiter configuration
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Alpaca: 200 requests per minute
|
|
54
|
+
* const alpacaLimiter = new TokenBucketRateLimiter({
|
|
55
|
+
* maxTokens: 200,
|
|
56
|
+
* refillRate: 200 / 60, // ~3.33 per second
|
|
57
|
+
* label: 'alpaca',
|
|
58
|
+
* timeoutMs: 60000
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
constructor(config: RateLimiterConfig);
|
|
63
|
+
/**
|
|
64
|
+
* Acquires a token for making an API request
|
|
65
|
+
*
|
|
66
|
+
* If a token is available, it is consumed immediately.
|
|
67
|
+
* If no tokens are available, the request is queued and will resolve
|
|
68
|
+
* when a token becomes available or reject if it times out.
|
|
69
|
+
*
|
|
70
|
+
* @throws {RateLimitError} If the request times out waiting for a token
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* try {
|
|
75
|
+
* await limiter.acquire();
|
|
76
|
+
* // Make API call
|
|
77
|
+
* } catch (error) {
|
|
78
|
+
* if (error instanceof RateLimitError) {
|
|
79
|
+
* // Handle rate limit timeout
|
|
80
|
+
* }
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
acquire(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Refills tokens based on elapsed time and processes queued requests
|
|
87
|
+
*
|
|
88
|
+
* Tokens are refilled at the configured rate up to the maximum capacity.
|
|
89
|
+
* If tokens are available after refilling, queued requests are processed.
|
|
90
|
+
*/
|
|
91
|
+
private refill;
|
|
92
|
+
/**
|
|
93
|
+
* Processes queued requests when tokens are available
|
|
94
|
+
*
|
|
95
|
+
* Prevents concurrent queue processing to ensure FIFO order.
|
|
96
|
+
*/
|
|
97
|
+
private processQueue;
|
|
98
|
+
/**
|
|
99
|
+
* Gets the current number of available tokens
|
|
100
|
+
*
|
|
101
|
+
* @returns Number of tokens currently available
|
|
102
|
+
*/
|
|
103
|
+
getAvailableTokens(): number;
|
|
104
|
+
/**
|
|
105
|
+
* Gets the current queue length
|
|
106
|
+
*
|
|
107
|
+
* @returns Number of requests waiting for tokens
|
|
108
|
+
*/
|
|
109
|
+
getQueueLength(): number;
|
|
110
|
+
/**
|
|
111
|
+
* Clears all queued requests and resets the token bucket
|
|
112
|
+
*
|
|
113
|
+
* All queued requests will be rejected with a RateLimitError.
|
|
114
|
+
* Useful for cleanup or when changing rate limit configurations.
|
|
115
|
+
*/
|
|
116
|
+
reset(): void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Pre-configured rate limiters for common external APIs
|
|
120
|
+
*
|
|
121
|
+
* These limiters are configured based on the documented rate limits
|
|
122
|
+
* for each service. Adjust the configurations if you have different
|
|
123
|
+
* tier access or if limits change.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import { rateLimiters } from '@adaptic/utils';
|
|
128
|
+
*
|
|
129
|
+
* // Use before making API calls
|
|
130
|
+
* await rateLimiters.alpaca.acquire();
|
|
131
|
+
* await rateLimiters.polygon.acquire();
|
|
132
|
+
* await rateLimiters.alphaVantage.acquire();
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare const rateLimiters: {
|
|
136
|
+
/**
|
|
137
|
+
* Alpaca API rate limiter
|
|
138
|
+
*
|
|
139
|
+
* Configured for 200 requests per minute.
|
|
140
|
+
* See: https://alpaca.markets/docs/api-references/trading-api/#rate-limit
|
|
141
|
+
*/
|
|
142
|
+
alpaca: TokenBucketRateLimiter;
|
|
143
|
+
/**
|
|
144
|
+
* Polygon.io API rate limiter
|
|
145
|
+
*
|
|
146
|
+
* Configured for 5 requests per second (basic plan).
|
|
147
|
+
* Adjust if you have a different subscription tier.
|
|
148
|
+
* See: https://polygon.io/pricing
|
|
149
|
+
*/
|
|
150
|
+
polygon: TokenBucketRateLimiter;
|
|
151
|
+
/**
|
|
152
|
+
* AlphaVantage API rate limiter
|
|
153
|
+
*
|
|
154
|
+
* Configured for 5 requests per minute (free tier).
|
|
155
|
+
* For premium tier (75/min), create a custom limiter:
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const premiumAV = new TokenBucketRateLimiter({
|
|
160
|
+
* maxTokens: 75,
|
|
161
|
+
* refillRate: 75 / 60,
|
|
162
|
+
* label: 'alphaVantage-premium',
|
|
163
|
+
* timeoutMs: 60000,
|
|
164
|
+
* });
|
|
165
|
+
* ```
|
|
166
|
+
*
|
|
167
|
+
* See: https://www.alphavantage.co/premium/
|
|
168
|
+
*/
|
|
169
|
+
alphaVantage: TokenBucketRateLimiter;
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=rate-limiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limiter.d.ts","sourceRoot":"","sources":["../../src/rate-limiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,CAAC;AAE1B;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,SAAS,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,KAAK,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAcD;;;;;;;GAOG;AACH,qBAAa,sBAAsB;IAuBrB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAtBnC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,eAAe,CAAkB;IAEzC;;;;;;;;;;;;;;;OAeG;gBAC0B,MAAM,EAAE,iBAAiB;IAMtD;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkD9B;;;;;OAKG;IACH,OAAO,CAAC,MAAM;IAYd;;;;OAIG;IACH,OAAO,CAAC,YAAY;IA6BpB;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;IAK5B;;;;OAIG;IACH,cAAc,IAAI,MAAM;IAIxB;;;;;OAKG;IACH,KAAK,IAAI,IAAI;CAwBd;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,YAAY;IACvB;;;;;OAKG;;IAQH;;;;;;OAMG;;IAQH;;;;;;;;;;;;;;;;;OAiBG;;CAOJ,CAAC"}
|