@adaptic/utils 0.1.44 → 0.1.45
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 +61 -153
- package/dist/index.cjs +5356 -60315
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +5356 -60054
- package/dist/index.mjs.map +1 -1
- package/dist/test.js +361 -824
- package/dist/test.js.map +1 -1
- package/dist/types/adaptic.d.ts +2 -2
- package/dist/types/adaptic.d.ts.map +1 -1
- package/dist/types/alpaca-functions.d.ts +233 -0
- package/dist/types/alpaca-functions.d.ts.map +1 -0
- package/dist/types/alpaca-market-data-api.d.ts +9 -24
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
- package/dist/types/alpaca-trading-api.d.ts +12 -12
- package/dist/types/alpaca-trading-api.d.ts.map +1 -1
- package/dist/types/alphavantage.d.ts +1 -1
- package/dist/types/alphavantage.d.ts.map +1 -1
- package/dist/types/asset-allocation-algorithm.d.ts +1 -7
- package/dist/types/asset-allocation-algorithm.d.ts.map +1 -1
- package/dist/types/cache/stampede-protected-cache.d.ts.map +1 -1
- package/dist/types/crypto.d.ts +4 -4
- package/dist/types/crypto.d.ts.map +1 -1
- package/dist/types/display-manager.d.ts +1 -1
- package/dist/types/display-manager.d.ts.map +1 -1
- package/dist/types/examples/asset-allocation-example.d.ts +6 -7
- package/dist/types/examples/asset-allocation-example.d.ts.map +1 -1
- package/dist/types/format-tools.d.ts.map +1 -1
- package/dist/types/index.d.ts +55 -393
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logging.d.ts +1 -1
- package/dist/types/logging.d.ts.map +1 -1
- package/dist/types/market-hours.d.ts.map +1 -1
- package/dist/types/market-time.d.ts +13 -75
- package/dist/types/market-time.d.ts.map +1 -1
- package/dist/types/metrics-calcs.d.ts.map +1 -1
- package/dist/types/misc-utils.d.ts +1 -4
- package/dist/types/misc-utils.d.ts.map +1 -1
- package/dist/types/performance-metrics.d.ts +6 -6
- package/dist/types/performance-metrics.d.ts.map +1 -1
- package/dist/types/polygon-indices.d.ts +3 -3
- package/dist/types/polygon-indices.d.ts.map +1 -1
- package/dist/types/polygon.d.ts +1 -1
- package/dist/types/polygon.d.ts.map +1 -1
- package/dist/types/price-utils.d.ts.map +1 -1
- package/dist/types/technical-analysis.d.ts +9 -9
- package/dist/types/technical-analysis.d.ts.map +1 -1
- package/dist/types/time-utils.d.ts.map +1 -1
- package/dist/types/types/adaptic-types.d.ts +1 -1
- package/dist/types/types/adaptic-types.d.ts.map +1 -1
- package/dist/types/types/alpaca-types.d.ts +89 -252
- package/dist/types/types/alpaca-types.d.ts.map +1 -1
- package/dist/types/types/alphavantage-types.d.ts +2 -2
- package/dist/types/types/asset-allocation-types.d.ts +11 -11
- package/dist/types/types/index.d.ts +8 -8
- package/dist/types/types/index.d.ts.map +1 -1
- package/dist/types/types/logging-types.d.ts +2 -2
- package/dist/types/types/logging-types.d.ts.map +1 -1
- package/dist/types/types/market-time-types.d.ts +4 -4
- package/dist/types/types/market-time-types.d.ts.map +1 -1
- package/dist/types/types/metrics-types.d.ts +4 -4
- package/dist/types/types/metrics-types.d.ts.map +1 -1
- package/dist/types/types/polygon-indices-types.d.ts +6 -6
- package/dist/types/types/polygon-types.d.ts +3 -3
- package/dist/types/types/ta-types.d.ts +3 -3
- package/package.json +6 -24
- package/dist/types/__tests__/alpaca-functions.test.d.ts +0 -2
- package/dist/types/__tests__/alpaca-functions.test.d.ts.map +0 -1
- package/dist/types/__tests__/api-endpoints.test.d.ts +0 -2
- package/dist/types/__tests__/api-endpoints.test.d.ts.map +0 -1
- package/dist/types/__tests__/asset-allocation.test.d.ts +0 -2
- package/dist/types/__tests__/asset-allocation.test.d.ts.map +0 -1
- package/dist/types/__tests__/auth-validator.test.d.ts +0 -2
- package/dist/types/__tests__/auth-validator.test.d.ts.map +0 -1
- package/dist/types/__tests__/cache.test.d.ts +0 -2
- package/dist/types/__tests__/cache.test.d.ts.map +0 -1
- package/dist/types/__tests__/errors.test.d.ts +0 -2
- package/dist/types/__tests__/errors.test.d.ts.map +0 -1
- package/dist/types/__tests__/financial-regression.test.d.ts +0 -2
- package/dist/types/__tests__/financial-regression.test.d.ts.map +0 -1
- package/dist/types/__tests__/format-tools.test.d.ts +0 -2
- package/dist/types/__tests__/format-tools.test.d.ts.map +0 -1
- package/dist/types/__tests__/http-keep-alive.test.d.ts +0 -2
- package/dist/types/__tests__/http-keep-alive.test.d.ts.map +0 -1
- package/dist/types/__tests__/http-timeout.test.d.ts +0 -2
- package/dist/types/__tests__/http-timeout.test.d.ts.map +0 -1
- package/dist/types/__tests__/logger.test.d.ts +0 -2
- package/dist/types/__tests__/logger.test.d.ts.map +0 -1
- package/dist/types/__tests__/market-time.test.d.ts +0 -2
- package/dist/types/__tests__/market-time.test.d.ts.map +0 -1
- package/dist/types/__tests__/misc-utils.test.d.ts +0 -2
- package/dist/types/__tests__/misc-utils.test.d.ts.map +0 -1
- package/dist/types/__tests__/paginator.test.d.ts +0 -2
- package/dist/types/__tests__/paginator.test.d.ts.map +0 -1
- package/dist/types/__tests__/performance-metrics.test.d.ts +0 -2
- package/dist/types/__tests__/performance-metrics.test.d.ts.map +0 -1
- package/dist/types/__tests__/polygon.test.d.ts +0 -2
- package/dist/types/__tests__/polygon.test.d.ts.map +0 -1
- package/dist/types/__tests__/price-utils.test.d.ts +0 -2
- package/dist/types/__tests__/price-utils.test.d.ts.map +0 -1
- package/dist/types/__tests__/property-based-financial.test.d.ts +0 -2
- package/dist/types/__tests__/property-based-financial.test.d.ts.map +0 -1
- package/dist/types/__tests__/rate-limiter.test.d.ts +0 -2
- package/dist/types/__tests__/rate-limiter.test.d.ts.map +0 -1
- package/dist/types/__tests__/schema-validation.test.d.ts +0 -2
- package/dist/types/__tests__/schema-validation.test.d.ts.map +0 -1
- package/dist/types/__tests__/technical-analysis.test.d.ts +0 -2
- package/dist/types/__tests__/technical-analysis.test.d.ts.map +0 -1
- package/dist/types/__tests__/time-utils.test.d.ts +0 -2
- package/dist/types/__tests__/time-utils.test.d.ts.map +0 -1
- package/dist/types/alpaca/client.d.ts +0 -95
- package/dist/types/alpaca/client.d.ts.map +0 -1
- package/dist/types/alpaca/crypto/data.d.ts +0 -281
- package/dist/types/alpaca/crypto/data.d.ts.map +0 -1
- package/dist/types/alpaca/crypto/index.d.ts +0 -75
- package/dist/types/alpaca/crypto/index.d.ts.map +0 -1
- package/dist/types/alpaca/crypto/orders.d.ts +0 -221
- package/dist/types/alpaca/crypto/orders.d.ts.map +0 -1
- package/dist/types/alpaca/index.d.ts +0 -205
- package/dist/types/alpaca/index.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/account.d.ts +0 -34
- package/dist/types/alpaca/legacy/account.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/assets.d.ts +0 -13
- package/dist/types/alpaca/legacy/assets.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/auth.d.ts +0 -18
- package/dist/types/alpaca/legacy/auth.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/index.d.ts +0 -15
- package/dist/types/alpaca/legacy/index.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/market-data.d.ts +0 -32
- package/dist/types/alpaca/legacy/market-data.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/orders.d.ts +0 -84
- package/dist/types/alpaca/legacy/orders.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/positions.d.ts +0 -66
- package/dist/types/alpaca/legacy/positions.d.ts.map +0 -1
- package/dist/types/alpaca/legacy/utils.d.ts +0 -18
- package/dist/types/alpaca/legacy/utils.d.ts.map +0 -1
- package/dist/types/alpaca/market-data/bars.d.ts +0 -142
- package/dist/types/alpaca/market-data/bars.d.ts.map +0 -1
- package/dist/types/alpaca/market-data/index.d.ts +0 -13
- package/dist/types/alpaca/market-data/index.d.ts.map +0 -1
- package/dist/types/alpaca/market-data/news.d.ts +0 -87
- package/dist/types/alpaca/market-data/news.d.ts.map +0 -1
- package/dist/types/alpaca/market-data/quotes.d.ts +0 -85
- package/dist/types/alpaca/market-data/quotes.d.ts.map +0 -1
- package/dist/types/alpaca/market-data/trades.d.ts +0 -98
- package/dist/types/alpaca/market-data/trades.d.ts.map +0 -1
- package/dist/types/alpaca/options/contracts.d.ts +0 -279
- package/dist/types/alpaca/options/contracts.d.ts.map +0 -1
- package/dist/types/alpaca/options/data.d.ts +0 -126
- package/dist/types/alpaca/options/data.d.ts.map +0 -1
- package/dist/types/alpaca/options/index.d.ts +0 -17
- package/dist/types/alpaca/options/index.d.ts.map +0 -1
- package/dist/types/alpaca/options/orders.d.ts +0 -366
- package/dist/types/alpaca/options/orders.d.ts.map +0 -1
- package/dist/types/alpaca/options/strategies.d.ts +0 -224
- package/dist/types/alpaca/options/strategies.d.ts.map +0 -1
- package/dist/types/alpaca/streams/base-stream.d.ts +0 -143
- package/dist/types/alpaca/streams/base-stream.d.ts.map +0 -1
- package/dist/types/alpaca/streams/crypto-stream.d.ts +0 -173
- package/dist/types/alpaca/streams/crypto-stream.d.ts.map +0 -1
- package/dist/types/alpaca/streams/index.d.ts +0 -54
- package/dist/types/alpaca/streams/index.d.ts.map +0 -1
- package/dist/types/alpaca/streams/option-stream.d.ts +0 -167
- package/dist/types/alpaca/streams/option-stream.d.ts.map +0 -1
- package/dist/types/alpaca/streams/stock-stream.d.ts +0 -176
- package/dist/types/alpaca/streams/stock-stream.d.ts.map +0 -1
- package/dist/types/alpaca/streams/stream-manager.d.ts +0 -277
- package/dist/types/alpaca/streams/stream-manager.d.ts.map +0 -1
- package/dist/types/alpaca/streams/trading-stream.d.ts +0 -186
- package/dist/types/alpaca/streams/trading-stream.d.ts.map +0 -1
- package/dist/types/alpaca/streams.d.ts +0 -88
- package/dist/types/alpaca/streams.d.ts.map +0 -1
- package/dist/types/alpaca/test-imports.d.ts +0 -7
- package/dist/types/alpaca/test-imports.d.ts.map +0 -1
- package/dist/types/alpaca/trading/account.d.ts +0 -198
- package/dist/types/alpaca/trading/account.d.ts.map +0 -1
- package/dist/types/alpaca/trading/bracket-orders.d.ts +0 -162
- package/dist/types/alpaca/trading/bracket-orders.d.ts.map +0 -1
- package/dist/types/alpaca/trading/clock.d.ts +0 -99
- package/dist/types/alpaca/trading/clock.d.ts.map +0 -1
- package/dist/types/alpaca/trading/index.d.ts +0 -15
- package/dist/types/alpaca/trading/index.d.ts.map +0 -1
- package/dist/types/alpaca/trading/oco-orders.d.ts +0 -203
- package/dist/types/alpaca/trading/oco-orders.d.ts.map +0 -1
- package/dist/types/alpaca/trading/order-utils.d.ts +0 -404
- package/dist/types/alpaca/trading/order-utils.d.ts.map +0 -1
- package/dist/types/alpaca/trading/orders.d.ts +0 -199
- package/dist/types/alpaca/trading/orders.d.ts.map +0 -1
- package/dist/types/alpaca/trading/oto-orders.d.ts +0 -282
- package/dist/types/alpaca/trading/oto-orders.d.ts.map +0 -1
- package/dist/types/alpaca/trading/positions.d.ts +0 -389
- package/dist/types/alpaca/trading/positions.d.ts.map +0 -1
- package/dist/types/alpaca/trading/smart-orders.d.ts +0 -301
- package/dist/types/alpaca/trading/smart-orders.d.ts.map +0 -1
- package/dist/types/alpaca/trading/trailing-stops.d.ts +0 -240
- package/dist/types/alpaca/trading/trailing-stops.d.ts.map +0 -1
- package/dist/types/config/api-endpoints.d.ts +0 -94
- package/dist/types/config/api-endpoints.d.ts.map +0 -1
- package/dist/types/errors/index.d.ts +0 -130
- package/dist/types/errors/index.d.ts.map +0 -1
- package/dist/types/examples/rate-limiter-example.d.ts +0 -7
- package/dist/types/examples/rate-limiter-example.d.ts.map +0 -1
- package/dist/types/http-timeout.d.ts +0 -37
- package/dist/types/http-timeout.d.ts.map +0 -1
- package/dist/types/logger.d.ts +0 -56
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/rate-limiter.d.ts +0 -171
- package/dist/types/rate-limiter.d.ts.map +0 -1
- package/dist/types/schemas/alpaca-schemas.d.ts +0 -779
- package/dist/types/schemas/alpaca-schemas.d.ts.map +0 -1
- package/dist/types/schemas/alphavantage-schemas.d.ts +0 -255
- package/dist/types/schemas/alphavantage-schemas.d.ts.map +0 -1
- package/dist/types/schemas/index.d.ts +0 -21
- package/dist/types/schemas/index.d.ts.map +0 -1
- package/dist/types/schemas/polygon-schemas.d.ts +0 -551
- package/dist/types/schemas/polygon-schemas.d.ts.map +0 -1
- package/dist/types/schemas/validate-response.d.ts +0 -88
- package/dist/types/schemas/validate-response.d.ts.map +0 -1
- package/dist/types/utils/auth-validator.d.ts +0 -32
- package/dist/types/utils/auth-validator.d.ts.map +0 -1
- package/dist/types/utils/http-keep-alive.d.ts +0 -110
- package/dist/types/utils/http-keep-alive.d.ts.map +0 -1
- package/dist/types/utils/paginator.d.ts +0 -154
- package/dist/types/utils/paginator.d.ts.map +0 -1
- package/dist/types/utils/retry.d.ts +0 -78
- package/dist/types/utils/retry.d.ts.map +0 -1
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP connection pooling and keep-alive configuration.
|
|
3
|
-
*
|
|
4
|
-
* Node.js (>=20) uses undici as its built-in fetch implementation, which
|
|
5
|
-
* automatically maintains an internal connection pool with keep-alive enabled
|
|
6
|
-
* by default. This module provides:
|
|
7
|
-
*
|
|
8
|
-
* 1. Explicit documentation of the connection pooling behavior
|
|
9
|
-
* 2. A configured HTTP Agent for use with node:http/node:https if needed
|
|
10
|
-
* 3. Verification utilities to confirm keep-alive is active
|
|
11
|
-
*
|
|
12
|
-
* ## Connection Pooling Behavior
|
|
13
|
-
*
|
|
14
|
-
* **Native fetch (undici):** The global `fetch()` used throughout this package
|
|
15
|
-
* uses Node.js built-in undici which maintains persistent connections by default.
|
|
16
|
-
* Connections are kept alive and reused across requests to the same origin.
|
|
17
|
-
* No additional configuration is needed for fetch-based API calls.
|
|
18
|
-
*
|
|
19
|
-
* **Alpaca SDK (@alpacahq/alpaca-trade-api):** The SDK uses its own internal
|
|
20
|
-
* HTTP client with connection reuse. The SDK is configured through `AlpacaClient`
|
|
21
|
-
* in `src/alpaca/client.ts` via the `createAlpacaClient()` factory which caches
|
|
22
|
-
* client instances by API key + account type.
|
|
23
|
-
*
|
|
24
|
-
* **WebSocket connections:** Trading API and market data WebSocket connections
|
|
25
|
-
* are long-lived persistent connections managed by `AlpacaTradingAPI` and
|
|
26
|
-
* `AlpacaMarketDataAPI` respectively.
|
|
27
|
-
*
|
|
28
|
-
* ## API Client Summary
|
|
29
|
-
*
|
|
30
|
-
* | API Client | Transport | Keep-Alive | Connection Reuse |
|
|
31
|
-
* |------------|-----------|------------|------------------|
|
|
32
|
-
* | Alpaca Trading (direct) | fetch() | Built-in | Undici pool |
|
|
33
|
-
* | Alpaca Market Data | fetch() | Built-in | Undici pool |
|
|
34
|
-
* | Alpaca SDK | internal | Built-in | SDK managed |
|
|
35
|
-
* | Polygon.io | fetch() via fetchWithRetry | Built-in | Undici pool |
|
|
36
|
-
* | Alpha Vantage | fetch() | Built-in | Undici pool |
|
|
37
|
-
* | WebSocket (Trading) | ws | Persistent | Long-lived |
|
|
38
|
-
* | WebSocket (Market Data) | ws | Persistent | Long-lived |
|
|
39
|
-
*/
|
|
40
|
-
import http from "http";
|
|
41
|
-
import https from "https";
|
|
42
|
-
/**
|
|
43
|
-
* Default keep-alive configuration values.
|
|
44
|
-
* These are applied when creating explicit HTTP agents for non-fetch use cases.
|
|
45
|
-
*/
|
|
46
|
-
export declare const KEEP_ALIVE_DEFAULTS: {
|
|
47
|
-
/** Enable keep-alive connections */
|
|
48
|
-
readonly keepAlive: true;
|
|
49
|
-
/** Initial delay before sending keep-alive probes (in milliseconds) */
|
|
50
|
-
readonly keepAliveMsecs: 60000;
|
|
51
|
-
/** Maximum number of sockets per host */
|
|
52
|
-
readonly maxSockets: 50;
|
|
53
|
-
/** Maximum total number of sockets */
|
|
54
|
-
readonly maxTotalSockets: 256;
|
|
55
|
-
/** Maximum number of free (idle) sockets per host */
|
|
56
|
-
readonly maxFreeSockets: 10;
|
|
57
|
-
/** Socket timeout for idle connections (in milliseconds) */
|
|
58
|
-
readonly timeout: 60000;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Pre-configured HTTP agent with keep-alive enabled.
|
|
62
|
-
* Use this when making requests through node:http (not needed for fetch).
|
|
63
|
-
*/
|
|
64
|
-
export declare const httpAgent: http.Agent;
|
|
65
|
-
/**
|
|
66
|
-
* Pre-configured HTTPS agent with keep-alive enabled.
|
|
67
|
-
* Use this when making requests through node:https (not needed for fetch).
|
|
68
|
-
*/
|
|
69
|
-
export declare const httpsAgent: https.Agent;
|
|
70
|
-
/**
|
|
71
|
-
* Connection pool status information
|
|
72
|
-
*/
|
|
73
|
-
export interface ConnectionPoolStatus {
|
|
74
|
-
/** Name of the HTTP agent */
|
|
75
|
-
name: string;
|
|
76
|
-
/** Whether keep-alive is enabled */
|
|
77
|
-
keepAlive: boolean;
|
|
78
|
-
/** Number of active sockets */
|
|
79
|
-
activeSockets: number;
|
|
80
|
-
/** Number of free (idle) sockets */
|
|
81
|
-
freeSockets: number;
|
|
82
|
-
/** Number of pending requests (waiting for a socket) */
|
|
83
|
-
pendingRequests: number;
|
|
84
|
-
/** Maximum sockets per host */
|
|
85
|
-
maxSockets: number;
|
|
86
|
-
/** Maximum free sockets per host */
|
|
87
|
-
maxFreeSockets: number;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get the connection pool status for an HTTP/HTTPS agent.
|
|
91
|
-
* Useful for monitoring and debugging connection reuse.
|
|
92
|
-
*
|
|
93
|
-
* @param agent - The HTTP/HTTPS agent to inspect
|
|
94
|
-
* @param name - A human-readable name for the agent
|
|
95
|
-
* @returns Connection pool status information
|
|
96
|
-
*/
|
|
97
|
-
export declare function getAgentPoolStatus(agent: http.Agent | https.Agent, name?: string): ConnectionPoolStatus;
|
|
98
|
-
/**
|
|
99
|
-
* Verifies that keep-alive is properly configured for the Node.js built-in fetch.
|
|
100
|
-
* Node.js >= 20 uses undici internally, which has keep-alive enabled by default.
|
|
101
|
-
*
|
|
102
|
-
* @returns Object indicating whether keep-alive is expected to be active
|
|
103
|
-
*/
|
|
104
|
-
export declare function verifyFetchKeepAlive(): {
|
|
105
|
-
supported: boolean;
|
|
106
|
-
nodeVersion: string;
|
|
107
|
-
undiciBuiltIn: boolean;
|
|
108
|
-
keepAliveExpected: boolean;
|
|
109
|
-
};
|
|
110
|
-
//# sourceMappingURL=http-keep-alive.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-keep-alive.d.ts","sourceRoot":"","sources":["../../../src/utils/http-keep-alive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;GAGG;AACH,eAAO,MAAM,mBAAmB;IAC9B,oCAAoC;;IAEpC,uEAAuE;;IAEvE,yCAAyC;;IAEzC,sCAAsC;;IAEtC,qDAAqD;;IAErD,4DAA4D;;CAEpD,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,SAAS,YAOpB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,UAAU,aAOrB,CAAC;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,SAAS,EAAE,OAAO,CAAC;IACnB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,eAAe,EAAE,MAAM,CAAC;IACxB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,EAC/B,IAAI,GAAE,MAAkB,GACvB,oBAAoB,CA4BtB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,IAAI;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;CAC5B,CAeA"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configuration for cursor-based pagination.
|
|
3
|
-
* Used by Alpaca APIs that return `next_page_token`.
|
|
4
|
-
*/
|
|
5
|
-
export interface CursorPaginationConfig<TItem, TResponse> {
|
|
6
|
-
/** Pagination strategy type */
|
|
7
|
-
type: "cursor";
|
|
8
|
-
/**
|
|
9
|
-
* Function that fetches a single page of results.
|
|
10
|
-
* @param cursor - The cursor/page token for the next page (undefined for first page)
|
|
11
|
-
* @returns The API response for that page
|
|
12
|
-
*/
|
|
13
|
-
fetchPage: (cursor: string | undefined) => Promise<TResponse>;
|
|
14
|
-
/**
|
|
15
|
-
* Function that extracts items from the API response.
|
|
16
|
-
* @param response - The raw API response
|
|
17
|
-
* @returns Array of items from this page
|
|
18
|
-
*/
|
|
19
|
-
getItems: (response: TResponse) => TItem[];
|
|
20
|
-
/**
|
|
21
|
-
* Function that extracts the next cursor/page token from the response.
|
|
22
|
-
* Returns undefined/null/empty string when there are no more pages.
|
|
23
|
-
* @param response - The raw API response
|
|
24
|
-
* @returns The next page token, or a falsy value if no more pages
|
|
25
|
-
*/
|
|
26
|
-
getNextCursor: (response: TResponse) => string | undefined | null;
|
|
27
|
-
/** Maximum number of items to collect (optional; defaults to no limit) */
|
|
28
|
-
maxItems?: number;
|
|
29
|
-
/** Maximum number of pages to fetch (safety limit; defaults to 1000) */
|
|
30
|
-
maxPages?: number;
|
|
31
|
-
/** Label for logging purposes */
|
|
32
|
-
label?: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Configuration for URL-based pagination.
|
|
36
|
-
* Used by Polygon APIs that return `next_url`.
|
|
37
|
-
*/
|
|
38
|
-
export interface UrlPaginationConfig<TItem, TResponse> {
|
|
39
|
-
/** Pagination strategy type */
|
|
40
|
-
type: "url";
|
|
41
|
-
/**
|
|
42
|
-
* Function that fetches a page from a given URL.
|
|
43
|
-
* For the first page, the URL is the initial request URL.
|
|
44
|
-
* For subsequent pages, the URL comes from the previous response.
|
|
45
|
-
* @param url - The URL to fetch
|
|
46
|
-
* @returns The API response for that page
|
|
47
|
-
*/
|
|
48
|
-
fetchPage: (url: string) => Promise<TResponse>;
|
|
49
|
-
/** The initial URL for the first page */
|
|
50
|
-
initialUrl: string;
|
|
51
|
-
/**
|
|
52
|
-
* Function that extracts items from the API response.
|
|
53
|
-
* @param response - The raw API response
|
|
54
|
-
* @returns Array of items from this page
|
|
55
|
-
*/
|
|
56
|
-
getItems: (response: TResponse) => TItem[];
|
|
57
|
-
/**
|
|
58
|
-
* Function that extracts the next URL from the response.
|
|
59
|
-
* Returns undefined/null/empty string when there are no more pages.
|
|
60
|
-
* @param response - The raw API response
|
|
61
|
-
* @returns The next page URL, or a falsy value if no more pages
|
|
62
|
-
*/
|
|
63
|
-
getNextUrl: (response: TResponse) => string | undefined | null;
|
|
64
|
-
/** Maximum number of items to collect (optional; defaults to no limit) */
|
|
65
|
-
maxItems?: number;
|
|
66
|
-
/** Maximum number of pages to fetch (safety limit; defaults to 1000) */
|
|
67
|
-
maxPages?: number;
|
|
68
|
-
/** Label for logging purposes */
|
|
69
|
-
label?: string;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Configuration for offset-based pagination.
|
|
73
|
-
* Used by APIs that accept page/offset parameters.
|
|
74
|
-
*/
|
|
75
|
-
export interface OffsetPaginationConfig<TItem, TResponse> {
|
|
76
|
-
/** Pagination strategy type */
|
|
77
|
-
type: "offset";
|
|
78
|
-
/**
|
|
79
|
-
* Function that fetches a page at a given offset.
|
|
80
|
-
* @param offset - The current offset (starts at 0)
|
|
81
|
-
* @param limit - The page size
|
|
82
|
-
* @returns The API response for that page
|
|
83
|
-
*/
|
|
84
|
-
fetchPage: (offset: number, limit: number) => Promise<TResponse>;
|
|
85
|
-
/**
|
|
86
|
-
* Function that extracts items from the API response.
|
|
87
|
-
* @param response - The raw API response
|
|
88
|
-
* @returns Array of items from this page
|
|
89
|
-
*/
|
|
90
|
-
getItems: (response: TResponse) => TItem[];
|
|
91
|
-
/** Number of items per page */
|
|
92
|
-
pageSize: number;
|
|
93
|
-
/**
|
|
94
|
-
* Optional function to determine the total number of items.
|
|
95
|
-
* If not provided, pagination stops when a page returns fewer items than pageSize.
|
|
96
|
-
* @param response - The first API response
|
|
97
|
-
* @returns Total number of items available
|
|
98
|
-
*/
|
|
99
|
-
getTotalCount?: (response: TResponse) => number;
|
|
100
|
-
/** Maximum number of items to collect (optional; defaults to no limit) */
|
|
101
|
-
maxItems?: number;
|
|
102
|
-
/** Maximum number of pages to fetch (safety limit; defaults to 1000) */
|
|
103
|
-
maxPages?: number;
|
|
104
|
-
/** Label for logging purposes */
|
|
105
|
-
label?: string;
|
|
106
|
-
}
|
|
107
|
-
/** Union type of all pagination configurations */
|
|
108
|
-
export type PaginationConfig<TItem, TResponse> = CursorPaginationConfig<TItem, TResponse> | UrlPaginationConfig<TItem, TResponse> | OffsetPaginationConfig<TItem, TResponse>;
|
|
109
|
-
/**
|
|
110
|
-
* Creates an async iterator that paginates through API results.
|
|
111
|
-
* Yields individual items one at a time across all pages.
|
|
112
|
-
*
|
|
113
|
-
* @param config - Pagination configuration
|
|
114
|
-
* @returns AsyncGenerator that yields items one at a time
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```typescript
|
|
118
|
-
* // Cursor-based (Alpaca)
|
|
119
|
-
* const iterator = paginate({
|
|
120
|
-
* type: 'cursor',
|
|
121
|
-
* fetchPage: (cursor) => alpacaAPI.getOrders({ page_token: cursor }),
|
|
122
|
-
* getItems: (response) => response.orders,
|
|
123
|
-
* getNextCursor: (response) => response.next_page_token,
|
|
124
|
-
* label: 'getOrders',
|
|
125
|
-
* });
|
|
126
|
-
*
|
|
127
|
-
* for await (const order of iterator) {
|
|
128
|
-
* processOrder(order);
|
|
129
|
-
* }
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
export declare function paginate<TItem, TResponse>(config: PaginationConfig<TItem, TResponse>): AsyncGenerator<TItem, void, undefined>;
|
|
133
|
-
/**
|
|
134
|
-
* Collects all items from a paginated API into a single array.
|
|
135
|
-
* This is a convenience wrapper around `paginate()`.
|
|
136
|
-
*
|
|
137
|
-
* @param config - Pagination configuration
|
|
138
|
-
* @returns Array of all items collected across all pages
|
|
139
|
-
*
|
|
140
|
-
* @example
|
|
141
|
-
* ```typescript
|
|
142
|
-
* // Collect all orders
|
|
143
|
-
* const allOrders = await paginateAll({
|
|
144
|
-
* type: 'cursor',
|
|
145
|
-
* fetchPage: (cursor) => alpacaAPI.getOrders({ page_token: cursor, limit: 100 }),
|
|
146
|
-
* getItems: (response) => response,
|
|
147
|
-
* getNextCursor: (response) => response.next_page_token,
|
|
148
|
-
* maxItems: 500,
|
|
149
|
-
* label: 'getAllOrders',
|
|
150
|
-
* });
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
export declare function paginateAll<TItem, TResponse>(config: PaginationConfig<TItem, TResponse>): Promise<TItem[]>;
|
|
154
|
-
//# sourceMappingURL=paginator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"paginator.d.ts","sourceRoot":"","sources":["../../../src/utils/paginator.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,EAAE,SAAS;IACtD,+BAA+B;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf;;;;OAIG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9D;;;;OAIG;IACH,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,KAAK,EAAE,CAAC;IAC3C;;;;;OAKG;IACH,aAAa,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAClE,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,KAAK,EAAE,SAAS;IACnD,+BAA+B;IAC/B,IAAI,EAAE,KAAK,CAAC;IACZ;;;;;;OAMG;IACH,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IAC/C,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,KAAK,EAAE,CAAC;IAC3C;;;;;OAKG;IACH,UAAU,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAC/D,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CAAC,KAAK,EAAE,SAAS;IACtD,+BAA+B;IAC/B,IAAI,EAAE,QAAQ,CAAC;IACf;;;;;OAKG;IACH,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;IACjE;;;;OAIG;IACH,QAAQ,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,KAAK,EAAE,CAAC;IAC3C,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,KAAK,MAAM,CAAC;IAChD,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,kDAAkD;AAClD,MAAM,MAAM,gBAAgB,CAAC,KAAK,EAAE,SAAS,IACzC,sBAAsB,CAAC,KAAK,EAAE,SAAS,CAAC,GACxC,mBAAmB,CAAC,KAAK,EAAE,SAAS,CAAC,GACrC,sBAAsB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;AAK7C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAuB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAC9C,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,GACzC,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CA8FxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAAC,KAAK,EAAE,SAAS,EAChD,MAAM,EAAE,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,GACzC,OAAO,CAAC,KAAK,EAAE,CAAC,CAQlB"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retry utility with exponential backoff for handling transient errors in external API calls.
|
|
3
|
-
*
|
|
4
|
-
* Features:
|
|
5
|
-
* - Configurable retry attempts and delays
|
|
6
|
-
* - Exponential backoff with jitter to prevent thundering herd
|
|
7
|
-
* - Respects Retry-After headers for rate limiting (429)
|
|
8
|
-
* - Fail-fast for non-retryable errors (4xx client errors)
|
|
9
|
-
* - Detailed error logging with context
|
|
10
|
-
*/
|
|
11
|
-
export interface RetryConfig {
|
|
12
|
-
/** Maximum number of retry attempts (default: 3) */
|
|
13
|
-
maxRetries: number;
|
|
14
|
-
/** Initial delay in milliseconds before first retry (default: 1000) */
|
|
15
|
-
baseDelayMs: number;
|
|
16
|
-
/** Maximum delay in milliseconds between retries (default: 30000) */
|
|
17
|
-
maxDelayMs: number;
|
|
18
|
-
/** HTTP status codes that should trigger a retry (default: [429, 500, 502, 503, 504]) */
|
|
19
|
-
retryableStatusCodes: number[];
|
|
20
|
-
/** Whether to retry on network errors (default: true) */
|
|
21
|
-
retryOnNetworkError: boolean;
|
|
22
|
-
/** Optional callback invoked on each retry attempt */
|
|
23
|
-
onRetry?: (attempt: number, error: unknown) => void;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Wraps an async function with retry logic and exponential backoff.
|
|
27
|
-
*
|
|
28
|
-
* This utility handles transient errors in external API calls by automatically retrying
|
|
29
|
-
* failed requests with intelligent backoff strategies. It respects rate limit headers,
|
|
30
|
-
* fails fast on non-retryable errors, and provides detailed logging.
|
|
31
|
-
*
|
|
32
|
-
* @template T - The return type of the wrapped function
|
|
33
|
-
* @param fn - The async function to wrap with retry logic
|
|
34
|
-
* @param config - Retry configuration (merged with defaults)
|
|
35
|
-
* @param label - A descriptive label for logging (e.g., 'Polygon.fetchTickerInfo')
|
|
36
|
-
* @returns A promise that resolves to the function's return value
|
|
37
|
-
* @throws The last error encountered if all retries are exhausted
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* // Basic usage with defaults
|
|
42
|
-
* const data = await withRetry(
|
|
43
|
-
* async () => fetch('https://api.example.com/data'),
|
|
44
|
-
* {},
|
|
45
|
-
* 'ExampleAPI.fetchData'
|
|
46
|
-
* );
|
|
47
|
-
*
|
|
48
|
-
* // Custom configuration for rate-limited API
|
|
49
|
-
* const result = await withRetry(
|
|
50
|
-
* async () => alphaVantageAPI.getQuote(symbol),
|
|
51
|
-
* {
|
|
52
|
-
* maxRetries: 5,
|
|
53
|
-
* baseDelayMs: 5000,
|
|
54
|
-
* maxDelayMs: 60000,
|
|
55
|
-
* onRetry: (attempt, error) => {
|
|
56
|
-
* getLogger().info(`Retry ${attempt} after error:`, error);
|
|
57
|
-
* }
|
|
58
|
-
* },
|
|
59
|
-
* 'AlphaVantage.getQuote'
|
|
60
|
-
* );
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export declare function withRetry<T>(fn: () => Promise<T>, config?: Partial<RetryConfig>, label?: string): Promise<T>;
|
|
64
|
-
/**
|
|
65
|
-
* API-specific retry configurations for different external services.
|
|
66
|
-
* These configurations are tuned based on each API's rate limits and characteristics.
|
|
67
|
-
*/
|
|
68
|
-
export declare const API_RETRY_CONFIGS: {
|
|
69
|
-
/** Polygon.io API - 5 requests/second rate limit */
|
|
70
|
-
POLYGON: Partial<RetryConfig>;
|
|
71
|
-
/** Alpha Vantage API - 5 requests/minute rate limit (more strict) */
|
|
72
|
-
ALPHA_VANTAGE: Partial<RetryConfig>;
|
|
73
|
-
/** Alpaca API - generally reliable, shorter retry window */
|
|
74
|
-
ALPACA: Partial<RetryConfig>;
|
|
75
|
-
/** Generic crypto API configuration */
|
|
76
|
-
CRYPTO: Partial<RetryConfig>;
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../../src/utils/retry.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;IACpB,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,yFAAyF;IACzF,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,yDAAyD;IACzD,mBAAmB,EAAE,OAAO,CAAC;IAC7B,sDAAsD;IACtD,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CACrD;AA4LD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,wBAAsB,SAAS,CAAC,CAAC,EAC/B,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM,EACjC,KAAK,GAAE,MAAkB,GACxB,OAAO,CAAC,CAAC,CAAC,CAmGZ;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB;IAC5B,oDAAoD;aAO/C,OAAO,CAAC,WAAW,CAAC;IAEzB,qEAAqE;mBAOhE,OAAO,CAAC,WAAW,CAAC;IAEzB,4DAA4D;YAOvD,OAAO,CAAC,WAAW,CAAC;IAEzB,uCAAuC;YAOlC,OAAO,CAAC,WAAW,CAAC;CAC1B,CAAC"}
|