@adaptic/utils 0.1.0 → 0.1.2
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 +153 -61
- package/dist/index.cjs +55882 -11299
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +55809 -11299
- package/dist/index.mjs.map +1 -1
- package/dist/test.js +709 -383
- package/dist/test.js.map +1 -1
- 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 +2 -2
- package/dist/types/adaptic.d.ts.map +1 -1
- package/dist/types/alpaca/client.d.ts +4 -4
- package/dist/types/alpaca/client.d.ts.map +1 -1
- package/dist/types/alpaca/crypto/data.d.ts +5 -5
- package/dist/types/alpaca/crypto/data.d.ts.map +1 -1
- package/dist/types/alpaca/crypto/index.d.ts +2 -2
- package/dist/types/alpaca/crypto/orders.d.ts +2 -2
- package/dist/types/alpaca/crypto/orders.d.ts.map +1 -1
- package/dist/types/alpaca/index.d.ts +36 -34
- package/dist/types/alpaca/index.d.ts.map +1 -1
- 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 +4 -4
- package/dist/types/alpaca/market-data/bars.d.ts.map +1 -1
- package/dist/types/alpaca/market-data/index.d.ts +8 -8
- package/dist/types/alpaca/market-data/news.d.ts +3 -3
- package/dist/types/alpaca/market-data/news.d.ts.map +1 -1
- package/dist/types/alpaca/market-data/quotes.d.ts +2 -2
- package/dist/types/alpaca/market-data/quotes.d.ts.map +1 -1
- package/dist/types/alpaca/market-data/trades.d.ts +2 -2
- package/dist/types/alpaca/market-data/trades.d.ts.map +1 -1
- package/dist/types/alpaca/options/contracts.d.ts +2 -2
- package/dist/types/alpaca/options/contracts.d.ts.map +1 -1
- package/dist/types/alpaca/options/data.d.ts +5 -5
- package/dist/types/alpaca/options/data.d.ts.map +1 -1
- package/dist/types/alpaca/options/index.d.ts +12 -12
- package/dist/types/alpaca/options/index.d.ts.map +1 -1
- package/dist/types/alpaca/options/orders.d.ts +4 -4
- package/dist/types/alpaca/options/orders.d.ts.map +1 -1
- package/dist/types/alpaca/options/strategies.d.ts +9 -9
- package/dist/types/alpaca/options/strategies.d.ts.map +1 -1
- package/dist/types/alpaca/streams/base-stream.d.ts +5 -5
- package/dist/types/alpaca/streams/base-stream.d.ts.map +1 -1
- package/dist/types/alpaca/streams/crypto-stream.d.ts +5 -5
- package/dist/types/alpaca/streams/crypto-stream.d.ts.map +1 -1
- package/dist/types/alpaca/streams/index.d.ts +6 -6
- package/dist/types/alpaca/streams/option-stream.d.ts +5 -5
- package/dist/types/alpaca/streams/option-stream.d.ts.map +1 -1
- package/dist/types/alpaca/streams/stock-stream.d.ts +5 -5
- package/dist/types/alpaca/streams/stock-stream.d.ts.map +1 -1
- package/dist/types/alpaca/streams/stream-manager.d.ts +16 -16
- package/dist/types/alpaca/streams/stream-manager.d.ts.map +1 -1
- package/dist/types/alpaca/streams/trading-stream.d.ts +28 -28
- package/dist/types/alpaca/streams/trading-stream.d.ts.map +1 -1
- package/dist/types/alpaca/streams.d.ts +2 -2
- package/dist/types/alpaca/streams.d.ts.map +1 -1
- package/dist/types/alpaca/trading/account.d.ts +2 -2
- package/dist/types/alpaca/trading/account.d.ts.map +1 -1
- package/dist/types/alpaca/trading/bracket-orders.d.ts +3 -3
- package/dist/types/alpaca/trading/bracket-orders.d.ts.map +1 -1
- package/dist/types/alpaca/trading/index.d.ts +12 -12
- package/dist/types/alpaca/trading/oco-orders.d.ts +2 -2
- package/dist/types/alpaca/trading/oco-orders.d.ts.map +1 -1
- package/dist/types/alpaca/trading/order-utils.d.ts +9 -9
- package/dist/types/alpaca/trading/order-utils.d.ts.map +1 -1
- package/dist/types/alpaca/trading/orders.d.ts +2 -2
- package/dist/types/alpaca/trading/orders.d.ts.map +1 -1
- package/dist/types/alpaca/trading/oto-orders.d.ts +3 -3
- package/dist/types/alpaca/trading/oto-orders.d.ts.map +1 -1
- package/dist/types/alpaca/trading/positions.d.ts +3 -3
- package/dist/types/alpaca/trading/positions.d.ts.map +1 -1
- package/dist/types/alpaca/trading/smart-orders.d.ts +12 -12
- package/dist/types/alpaca/trading/smart-orders.d.ts.map +1 -1
- package/dist/types/alpaca/trading/trailing-stops.d.ts +2 -2
- package/dist/types/alpaca/trading/trailing-stops.d.ts.map +1 -1
- package/dist/types/alpaca-market-data-api.d.ts +10 -10
- 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 +7 -1
- 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/config/api-endpoints.d.ts +94 -0
- package/dist/types/config/api-endpoints.d.ts.map +1 -0
- package/dist/types/crypto.d.ts +2 -2
- 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/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 +7 -6
- package/dist/types/examples/asset-allocation-example.d.ts.map +1 -1
- 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.map +1 -1
- 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 +59 -72
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/logger.d.ts +56 -0
- package/dist/types/logger.d.ts.map +1 -0
- 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 +75 -13
- 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 +4 -1
- package/dist/types/misc-utils.d.ts.map +1 -1
- package/dist/types/performance-metrics.d.ts +4 -4
- 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/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 +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 +172 -98
- 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 +3 -3
- 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/dist/types/utils/auth-validator.d.ts +27 -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 +22 -5
- package/dist/types/alpaca-functions.d.ts +0 -233
- package/dist/types/alpaca-functions.d.ts.map +0 -1
|
@@ -0,0 +1,154 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,C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;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"}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptic/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"author": "Adaptic.ai",
|
|
5
5
|
"description": "Utility functions used in Adaptic app and Lambda functions",
|
|
6
6
|
"always-build-npm": true,
|
|
@@ -23,10 +23,17 @@
|
|
|
23
23
|
"build": "npm run clean && rollup -c",
|
|
24
24
|
"prepare": "npm run build",
|
|
25
25
|
"prepublishOnly": "npm run build",
|
|
26
|
-
"test": "
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"test:watch": "vitest",
|
|
28
|
+
"test:coverage": "vitest run --coverage",
|
|
29
|
+
"test:legacy": "npm run build && node dist/test.js",
|
|
30
|
+
"build:analyze": "ANALYZE_BUNDLE=true npm run build",
|
|
31
|
+
"docs": "typedoc",
|
|
32
|
+
"docs:watch": "typedoc --watch",
|
|
33
|
+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
|
|
27
34
|
},
|
|
28
35
|
"dependencies": {
|
|
29
|
-
"@adaptic/backend-legacy": "^0.0.
|
|
36
|
+
"@adaptic/backend-legacy": "^0.0.59",
|
|
30
37
|
"@adaptic/lumic-utils": "^1.0.6",
|
|
31
38
|
"@alpacahq/alpaca-trade-api": "^3.1.3",
|
|
32
39
|
"@apollo/client": "^3.13.8",
|
|
@@ -35,12 +42,16 @@
|
|
|
35
42
|
"date-fns-tz": "^3.2.0",
|
|
36
43
|
"lru-cache": "^11.2.2",
|
|
37
44
|
"ms": "^2.1.3",
|
|
38
|
-
"p-limit": "^6.2.0"
|
|
45
|
+
"p-limit": "^6.2.0",
|
|
46
|
+
"zod": "^3.25.76"
|
|
39
47
|
},
|
|
40
48
|
"peerDependencies": {
|
|
41
49
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
42
50
|
},
|
|
43
51
|
"license": "ISC",
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=20.0.0"
|
|
54
|
+
},
|
|
44
55
|
"devDependencies": {
|
|
45
56
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
46
57
|
"@rollup/plugin-json": "^6.1.0",
|
|
@@ -49,10 +60,16 @@
|
|
|
49
60
|
"@types/date-fns": "^2.6.3",
|
|
50
61
|
"@types/ms": "^2.1.0",
|
|
51
62
|
"@types/ws": "^8.18.1",
|
|
63
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
64
|
+
"conventional-changelog-cli": "^5.0.0",
|
|
65
|
+
"fast-check": "^4.5.3",
|
|
52
66
|
"lightweight-charts": "^5.0.8",
|
|
53
67
|
"react": "^19.1.0",
|
|
54
68
|
"rollup": "^4.46.2",
|
|
55
69
|
"rollup-cli": "^1.0.9",
|
|
56
|
-
"
|
|
70
|
+
"rollup-plugin-visualizer": "^6.0.5",
|
|
71
|
+
"typedoc": "^0.28.16",
|
|
72
|
+
"typescript": "^5.8.3",
|
|
73
|
+
"vitest": "^4.0.18"
|
|
57
74
|
}
|
|
58
75
|
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import { types } from '@adaptic/backend-legacy';
|
|
2
|
-
import { AccountConfiguration, AlpacaPosition, SimpleNews, CreateOrderParams, GetOrdersParams, AlpacaOrder, ReplaceOrderParams, AlpacaAuth, AlpacaAccountDetails, PortfolioHistoryResponse, FetchPortfolioHistoryProps, AlpacaAsset, DataFeed, LatestQuotesResponse } from './types/alpaca-types';
|
|
3
|
-
import { ApolloClientType, NormalizedCacheObject } from '@adaptic/backend-legacy';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a new order in Alpaca.
|
|
6
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
7
|
-
* @param {CreateOrderParams} params - The parameters for creating the order.
|
|
8
|
-
* @returns {Promise<Order>} The created order.
|
|
9
|
-
*/
|
|
10
|
-
export declare function createOrder(auth: AlpacaAuth, params: CreateOrderParams): Promise<AlpacaOrder>;
|
|
11
|
-
/**
|
|
12
|
-
* Retrieves a list of orders from Alpaca.
|
|
13
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
14
|
-
* @param {GetOrdersParams} [params={}] - The parameters for fetching orders.
|
|
15
|
-
* @returns {Promise<AlpacaOrder[]>} The list of orders.
|
|
16
|
-
*/
|
|
17
|
-
export declare function getOrders(auth: AlpacaAuth, params?: GetOrdersParams): Promise<AlpacaOrder[]>;
|
|
18
|
-
/**
|
|
19
|
-
* Cancels all orders in Alpaca.
|
|
20
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
21
|
-
* @returns {Promise<{ id: string; status: number }[]>} The list of canceled orders with their statuses.
|
|
22
|
-
*/
|
|
23
|
-
export declare function cancelAllOrders(auth: AlpacaAuth): Promise<{
|
|
24
|
-
id: string;
|
|
25
|
-
status: number;
|
|
26
|
-
}[]>;
|
|
27
|
-
/**
|
|
28
|
-
* Retrieves a specific order from Alpaca.
|
|
29
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
30
|
-
* @param {string} orderId - The ID of the order to retrieve.
|
|
31
|
-
* @param {boolean} [nested] - Whether to include nested details.
|
|
32
|
-
* @returns {Promise<Order>} The requested order.
|
|
33
|
-
*/
|
|
34
|
-
export declare function getOrder(auth: AlpacaAuth, orderId: string, nested?: boolean): Promise<AlpacaOrder>;
|
|
35
|
-
/**
|
|
36
|
-
* Replaces an existing order in Alpaca.
|
|
37
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
38
|
-
* @param {string} orderId - The ID of the order to replace.
|
|
39
|
-
* @param {ReplaceOrderParams} params - The parameters for replacing the order.
|
|
40
|
-
* @returns {Promise<Order>} The updated order.
|
|
41
|
-
*/
|
|
42
|
-
export declare function replaceOrder(auth: AlpacaAuth, orderId: string, params: ReplaceOrderParams): Promise<AlpacaOrder>;
|
|
43
|
-
/**
|
|
44
|
-
* Cancels a specific order in Alpaca.
|
|
45
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
46
|
-
* @param {string} orderId - The ID of the order to cancel.
|
|
47
|
-
* @returns {Promise<{ success: boolean; message?: string }>} - Success status and optional message if order not found.
|
|
48
|
-
*/
|
|
49
|
-
export declare function cancelOrder(auth: AlpacaAuth, orderId: string): Promise<{
|
|
50
|
-
success: boolean;
|
|
51
|
-
message?: string;
|
|
52
|
-
}>;
|
|
53
|
-
/**
|
|
54
|
-
* Fetches news articles from Alpaca API for specified symbols.
|
|
55
|
-
* @param {string} symbols - The symbols to fetch news for (comma-separated for multiple symbols, e.g. "AAPL,MSFT,GOOG")
|
|
56
|
-
* @param {Object} params - Optional parameters for fetching news
|
|
57
|
-
* @param {AlpacaAuth} params.auth - Optional Alpaca authentication details
|
|
58
|
-
* @param {Date | string} params.start - Start date for fetching news (default is last 24 hours)
|
|
59
|
-
* @param {Date | string} params.end - End date for fetching news (default is now)
|
|
60
|
-
* @param {number} params.limit - Maximum number of articles to return (default is 10)
|
|
61
|
-
* @param {'asc' | 'desc'} params.sort - Sorting order (default is descending)
|
|
62
|
-
* @param {string} params.page_token - Token for pagination
|
|
63
|
-
* @param {boolean} params.include_content - Whether to include content in the news articles (default is true)
|
|
64
|
-
* @returns {Promise<{ news: SimpleNews[]; nextPageToken?: string }>} The fetched news articles.
|
|
65
|
-
*/
|
|
66
|
-
export declare function fetchNews(symbols: string, params?: {
|
|
67
|
-
auth?: AlpacaAuth;
|
|
68
|
-
start?: Date | string;
|
|
69
|
-
end?: Date | string;
|
|
70
|
-
limit?: number;
|
|
71
|
-
sort?: 'asc' | 'desc';
|
|
72
|
-
page_token?: string;
|
|
73
|
-
include_content?: boolean;
|
|
74
|
-
}): Promise<{
|
|
75
|
-
news: SimpleNews[];
|
|
76
|
-
nextPageToken?: string;
|
|
77
|
-
}>;
|
|
78
|
-
export interface FetchAccountDetailsProps {
|
|
79
|
-
auth?: AlpacaAuth;
|
|
80
|
-
accountId?: string;
|
|
81
|
-
client?: ApolloClientType<NormalizedCacheObject>;
|
|
82
|
-
alpacaAccount?: types.AlpacaAccount;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Fetches account details from Alpaca API.
|
|
86
|
-
* @param {FetchAccountDetailsProps} props - The properties for fetching account details.
|
|
87
|
-
* @returns {Promise<AlpacaAccountDetails>} The account details.
|
|
88
|
-
*/
|
|
89
|
-
export declare function fetchAccountDetails({ accountId, client, alpacaAccount, auth }: FetchAccountDetailsProps): Promise<AlpacaAccountDetails>;
|
|
90
|
-
/**
|
|
91
|
-
* Fetches portfolio history for one Alpaca account.
|
|
92
|
-
* @param {FetchPortfolioHistoryProps} props - The properties for fetching portfolio history.
|
|
93
|
-
* @returns {Promise<PortfolioHistoryResponse>} The portfolio history.
|
|
94
|
-
*/
|
|
95
|
-
/** Fetches portfolio history for one Alpaca account, as stored in Adaptic backend
|
|
96
|
-
*/
|
|
97
|
-
export declare function fetchPortfolioHistory({ params, accountId, client, alpacaAccount }: FetchPortfolioHistoryProps): Promise<PortfolioHistoryResponse>;
|
|
98
|
-
/**
|
|
99
|
-
* Fetches all positions for an Alpaca trading account.
|
|
100
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
101
|
-
* @returns {Promise<AlpacaPosition[]>} The list of positions.
|
|
102
|
-
*/
|
|
103
|
-
export declare function fetchAllPositions(auth: AlpacaAuth): Promise<AlpacaPosition[]>;
|
|
104
|
-
/**
|
|
105
|
-
* Fetches a specific position for an Alpaca account.
|
|
106
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
107
|
-
* @param {string} symbolOrAssetId - The symbol or asset ID to fetch the position for.
|
|
108
|
-
* @returns {Promise<{ position: AlpacaPosition | null; message?: string }>} The position details or null with message if not found.
|
|
109
|
-
*/
|
|
110
|
-
export declare function fetchPosition(auth: AlpacaAuth, symbolOrAssetId: string): Promise<{
|
|
111
|
-
position: AlpacaPosition | null;
|
|
112
|
-
message?: string;
|
|
113
|
-
}>;
|
|
114
|
-
/**
|
|
115
|
-
* Closes a specific position in Alpaca.
|
|
116
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
117
|
-
* @param {string} symbolOrAssetId - The symbol or asset ID of the position to close.
|
|
118
|
-
* @param {Object} [params] - Optional parameters for closing the position.
|
|
119
|
-
* @param {number} [params.qty] - Quantity of shares to close (up to 9 decimal places).
|
|
120
|
-
* @param {number} [params.percentage] - Percentage of position to close (0-100, up to 9 decimal places).
|
|
121
|
-
* @param {boolean} [params.useLimitOrder] - Whether to use a limit order to close the position.
|
|
122
|
-
* @param {boolean} [params.cancelOrders] - Whether to cancel open orders for the symbol before closing.
|
|
123
|
-
* @param {number} [params.slippagePercent1] - Slippage percentage for limit orders (default: 0.1).
|
|
124
|
-
* @param {boolean} [params.extendedHours] - Whether to enable extended hours trading (default: false).
|
|
125
|
-
* @returns {Promise<AlpacaOrder>} The order created to close the position.
|
|
126
|
-
*/
|
|
127
|
-
export declare function closePosition(auth: AlpacaAuth, symbolOrAssetId: string, params?: {
|
|
128
|
-
qty?: number;
|
|
129
|
-
percentage?: number;
|
|
130
|
-
useLimitOrder?: boolean;
|
|
131
|
-
cancelOrders?: boolean;
|
|
132
|
-
slippagePercent1?: number;
|
|
133
|
-
extendedHours?: boolean;
|
|
134
|
-
}): Promise<AlpacaOrder>;
|
|
135
|
-
export declare function makeRequest(auth: AlpacaAuth, params: {
|
|
136
|
-
endpoint: string;
|
|
137
|
-
method: string;
|
|
138
|
-
body?: any;
|
|
139
|
-
queryString?: string;
|
|
140
|
-
apiBaseUrl?: string;
|
|
141
|
-
}): Promise<any>;
|
|
142
|
-
/**
|
|
143
|
-
* Create a limit order
|
|
144
|
-
* @param symbol (string) - the symbol of the order
|
|
145
|
-
* @param qty (number) - the quantity of the order
|
|
146
|
-
* @param side (string) - the side of the order
|
|
147
|
-
* @param limitPrice (number) - the limit price of the order
|
|
148
|
-
* @param position_intent (string) - the position intent of the order
|
|
149
|
-
* @param extended_hours (boolean) - whether the order is in extended hours
|
|
150
|
-
* @param client_order_id (string) - the client order id of the order
|
|
151
|
-
*/
|
|
152
|
-
export declare function createLimitOrder(auth: AlpacaAuth, params?: {
|
|
153
|
-
symbol: string;
|
|
154
|
-
qty: number;
|
|
155
|
-
side: 'buy' | 'sell';
|
|
156
|
-
limitPrice: number;
|
|
157
|
-
position_intent: 'buy_to_open' | 'buy_to_close' | 'sell_to_open' | 'sell_to_close';
|
|
158
|
-
extended_hours: boolean;
|
|
159
|
-
client_order_id?: string;
|
|
160
|
-
}): Promise<AlpacaOrder>;
|
|
161
|
-
/**
|
|
162
|
-
* Closes all positions in Alpaca.
|
|
163
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
164
|
-
* @param {Object} [params] - Optional parameters for closing all positions.
|
|
165
|
-
* @param {boolean} [params.cancelOrders] - If true, cancels all open orders before closing positions.
|
|
166
|
-
* @param {boolean} [params.useLimitOrders] - If true, uses limit orders to close positions.
|
|
167
|
-
* @returns {Promise<Array<{ symbol: string; status: number; body?: Order }>>} The status of each position closure attempt.
|
|
168
|
-
*/
|
|
169
|
-
export declare function closeAllPositions(auth: AlpacaAuth, params?: {
|
|
170
|
-
cancel_orders?: boolean;
|
|
171
|
-
useLimitOrders?: boolean;
|
|
172
|
-
slippagePercent1?: number;
|
|
173
|
-
}): Promise<Array<{
|
|
174
|
-
symbol: string;
|
|
175
|
-
status: number;
|
|
176
|
-
body?: AlpacaOrder;
|
|
177
|
-
}> | void>;
|
|
178
|
-
/**
|
|
179
|
-
* Close all positions using limit orders during extended hours trading
|
|
180
|
-
* @param cancelOrders Whether to cancel related orders (default: true)
|
|
181
|
-
* @returns Promise that resolves when all positions are closed
|
|
182
|
-
*/
|
|
183
|
-
/**
|
|
184
|
-
* Closes all positions in Alpaca using limit orders during extended hours trading.
|
|
185
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
186
|
-
* @param {Object} [params] - Optional parameters for closing all positions.
|
|
187
|
-
* @param {boolean} [params.cancelOrders] - If true, cancels all open orders before closing positions.
|
|
188
|
-
* @returns {Promise<Array<{ symbol: string; status: number; body?: Order }>>} The status of each position closure attempt.
|
|
189
|
-
*/
|
|
190
|
-
export declare function closeAllPositionsAfterHours(auth: AlpacaAuth, params?: {
|
|
191
|
-
cancel_orders?: boolean;
|
|
192
|
-
slippagePercent1?: number;
|
|
193
|
-
}): Promise<Array<{
|
|
194
|
-
symbol: string;
|
|
195
|
-
status: number;
|
|
196
|
-
body?: AlpacaOrder;
|
|
197
|
-
}> | void>;
|
|
198
|
-
/**
|
|
199
|
-
* Get the most recent quotes for requested symbols
|
|
200
|
-
* @param symbols Array of stock symbols to query
|
|
201
|
-
* @param feed Optional data source (sip/iex/delayed_sip)
|
|
202
|
-
* @param currency Optional currency in ISO 4217 format
|
|
203
|
-
* @returns Latest quote data for each symbol
|
|
204
|
-
* @throws Error if request fails or rate limit exceeded
|
|
205
|
-
*/
|
|
206
|
-
export declare function getLatestQuotes(auth: AlpacaAuth, params: {
|
|
207
|
-
symbols: string[];
|
|
208
|
-
feed?: DataFeed;
|
|
209
|
-
currency?: string;
|
|
210
|
-
}): Promise<LatestQuotesResponse>;
|
|
211
|
-
/**
|
|
212
|
-
* Retrieves the configuration for a specific Alpaca account.
|
|
213
|
-
* @param {types.AlpacaAccount} account - The Alpaca account to retrieve the configuration for.
|
|
214
|
-
* @returns {Promise<AccountConfiguration>} The account configuration.
|
|
215
|
-
*/
|
|
216
|
-
export declare function getConfiguration(account: types.AlpacaAccount): Promise<AccountConfiguration>;
|
|
217
|
-
/**
|
|
218
|
-
* Updates the configuration for a specific Alpaca account.
|
|
219
|
-
* @param {types.User} user - The user making the update.
|
|
220
|
-
* @param {types.AlpacaAccount} account - The Alpaca account to update.
|
|
221
|
-
* @param {AccountConfiguration} updatedConfig - The updated configuration.
|
|
222
|
-
* @returns {Promise<AccountConfiguration>} The updated account configuration.
|
|
223
|
-
*/
|
|
224
|
-
export declare function updateConfiguration(user: types.User, account: types.AlpacaAccount, updatedConfig: AccountConfiguration): Promise<AccountConfiguration>;
|
|
225
|
-
export declare function cleanContent(htmlContent: string): string;
|
|
226
|
-
/**
|
|
227
|
-
* Retrieves an asset from Alpaca by symbol or asset ID.
|
|
228
|
-
* @param {AlpacaAuth} auth - The authentication details for Alpaca.
|
|
229
|
-
* @param {string} symbolOrAssetId - The symbol or asset ID to retrieve.
|
|
230
|
-
* @returns {Promise<Asset>} The requested asset.
|
|
231
|
-
*/
|
|
232
|
-
export declare function getAsset(auth: AlpacaAuth, symbolOrAssetId: string): Promise<AlpacaAsset>;
|
|
233
|
-
//# sourceMappingURL=alpaca-functions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"alpaca-functions.d.ts","sourceRoot":"","sources":["../../src/alpaca-functions.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAGhD,OAAO,EACL,oBAAoB,EACpB,cAAc,EAEd,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,kBAAkB,EAClB,UAAU,EACV,oBAAoB,EACpB,wB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