@adaptic/utils 0.1.43 → 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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"smart-orders.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/trading/smart-orders.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EAEvB,kBAAkB,EAElB,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAkB,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAkB,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAEnB,MAAM,kBAAkB,CAAC;AAS1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AAEjC;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,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S,GACd,MAAM,CAqBR;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAChB,MAAM,CASR;AAED;;GAEG;;;;;;;;;;;;;;;;AACH,wBAqBE"}
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native Trailing Stop Orders Module
|
|
3
|
-
*
|
|
4
|
-
* This module provides functions for creating and managing native trailing stop orders
|
|
5
|
-
* using Alpaca's server-side trailing stop functionality. Native trailing stops are
|
|
6
|
-
* handled by Alpaca's servers, eliminating the need for client-side monitoring.
|
|
7
|
-
*
|
|
8
|
-
* Key benefits of native trailing stops:
|
|
9
|
-
* - Server-side execution ensures stops work even if your application is offline
|
|
10
|
-
* - No need for polling or websocket connections to monitor prices
|
|
11
|
-
* - Automatic high water mark (HWM) tracking by Alpaca
|
|
12
|
-
* - Support for both percentage-based and dollar-based trailing
|
|
13
|
-
*/
|
|
14
|
-
import { AlpacaClient } from "../client";
|
|
15
|
-
import { AlpacaOrder, OrderSide, TimeInForce } from "../../types/alpaca-types";
|
|
16
|
-
/**
|
|
17
|
-
* Parameters for creating a trailing stop order
|
|
18
|
-
*/
|
|
19
|
-
export interface TrailingStopParams {
|
|
20
|
-
/** Stock symbol */
|
|
21
|
-
symbol: string;
|
|
22
|
-
/** Number of shares */
|
|
23
|
-
qty: number;
|
|
24
|
-
/** Order side (usually 'sell' for closing long positions) */
|
|
25
|
-
side: OrderSide;
|
|
26
|
-
/** Trail by percentage (e.g., 1.0 = 1%). Must specify either trailPercent OR trailPrice */
|
|
27
|
-
trailPercent?: number;
|
|
28
|
-
/** Trail by fixed dollar amount. Must specify either trailPercent OR trailPrice */
|
|
29
|
-
trailPrice?: number;
|
|
30
|
-
/** Time in force (default: 'gtc') */
|
|
31
|
-
timeInForce?: TimeInForce;
|
|
32
|
-
/** Extended hours trading */
|
|
33
|
-
extendedHours?: boolean;
|
|
34
|
-
/** Client order ID for tracking */
|
|
35
|
-
clientOrderId?: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Result of trailing stop HWM query
|
|
39
|
-
*/
|
|
40
|
-
export interface TrailingStopHWMResult {
|
|
41
|
-
/** High water mark - the highest price seen since order placement (for sell stops) */
|
|
42
|
-
hwm: number | null;
|
|
43
|
-
/** Current calculated stop price based on HWM and trail amount */
|
|
44
|
-
currentStop: number | null;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Parameters for creating trailing stops across a portfolio
|
|
48
|
-
*/
|
|
49
|
-
export interface PortfolioTrailingStopParams {
|
|
50
|
-
/** Trail by percentage (e.g., 2.0 = 2%) */
|
|
51
|
-
trailPercent: number;
|
|
52
|
-
/** Time in force (default: 'gtc') */
|
|
53
|
-
timeInForce?: TimeInForce;
|
|
54
|
-
/** Symbols to exclude from trailing stop creation */
|
|
55
|
-
excludeSymbols?: string[];
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Validation error for trailing stop parameters
|
|
59
|
-
*/
|
|
60
|
-
export declare class TrailingStopValidationError extends Error {
|
|
61
|
-
constructor(message: string);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Create a native trailing stop order
|
|
65
|
-
*
|
|
66
|
-
* The trailing stop automatically adjusts based on price movement:
|
|
67
|
-
* - For SELL: Stop rises as price rises, locks in when price falls
|
|
68
|
-
* - For BUY: Stop falls as price falls, triggers when price rises
|
|
69
|
-
*
|
|
70
|
-
* Must specify either trailPercent OR trailPrice (not both)
|
|
71
|
-
*
|
|
72
|
-
* @param client - AlpacaClient instance
|
|
73
|
-
* @param params - Trailing stop parameters
|
|
74
|
-
* @returns The created order
|
|
75
|
-
* @throws {TrailingStopValidationError} If parameters are invalid
|
|
76
|
-
* @throws {Error} If order creation fails
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* ```typescript
|
|
80
|
-
* // Trail by 2% on a sell (closing long position)
|
|
81
|
-
* await createTrailingStop(client, {
|
|
82
|
-
* symbol: 'AAPL',
|
|
83
|
-
* qty: 100,
|
|
84
|
-
* side: 'sell',
|
|
85
|
-
* trailPercent: 2.0,
|
|
86
|
-
* });
|
|
87
|
-
*
|
|
88
|
-
* // Trail by $5 on a sell
|
|
89
|
-
* await createTrailingStop(client, {
|
|
90
|
-
* symbol: 'AAPL',
|
|
91
|
-
* qty: 100,
|
|
92
|
-
* side: 'sell',
|
|
93
|
-
* trailPrice: 5.00,
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export declare function createTrailingStop(client: AlpacaClient, params: TrailingStopParams): Promise<AlpacaOrder>;
|
|
98
|
-
/**
|
|
99
|
-
* Update an existing trailing stop order
|
|
100
|
-
*
|
|
101
|
-
* You can update the trail_percent or trail_price of an existing order.
|
|
102
|
-
* Note: Alpaca uses 'trail' parameter for replacements (works for both percent and price).
|
|
103
|
-
*
|
|
104
|
-
* @param client - AlpacaClient instance
|
|
105
|
-
* @param orderId - The ID of the order to update
|
|
106
|
-
* @param updates - New trail parameters (specify one of trailPercent or trailPrice)
|
|
107
|
-
* @returns The updated order
|
|
108
|
-
* @throws {Error} If no update parameters provided or update fails
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* // Tighten trailing stop to 1.5%
|
|
113
|
-
* await updateTrailingStop(client, 'order-id-123', { trailPercent: 1.5 });
|
|
114
|
-
*
|
|
115
|
-
* // Change to $3 trail
|
|
116
|
-
* await updateTrailingStop(client, 'order-id-123', { trailPrice: 3.00 });
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
export declare function updateTrailingStop(client: AlpacaClient, orderId: string, updates: {
|
|
120
|
-
trailPercent?: number;
|
|
121
|
-
trailPrice?: number;
|
|
122
|
-
}): Promise<AlpacaOrder>;
|
|
123
|
-
/**
|
|
124
|
-
* Get the current high water mark (HWM) for a trailing stop
|
|
125
|
-
*
|
|
126
|
-
* The HWM is the highest price seen since order placement (for sell stops)
|
|
127
|
-
* or the lowest price (for buy stops). The current stop price is calculated
|
|
128
|
-
* based on the HWM and the trail amount.
|
|
129
|
-
*
|
|
130
|
-
* @param client - AlpacaClient instance
|
|
131
|
-
* @param orderId - The ID of the trailing stop order
|
|
132
|
-
* @returns Object containing HWM and current stop price (null if not yet established)
|
|
133
|
-
* @throws {Error} If order retrieval fails
|
|
134
|
-
*
|
|
135
|
-
* @example
|
|
136
|
-
* ```typescript
|
|
137
|
-
* const { hwm, currentStop } = await getTrailingStopHWM(client, 'order-id-123');
|
|
138
|
-
* console.log(`High water mark: $${hwm}, Current stop: $${currentStop}`);
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
export declare function getTrailingStopHWM(client: AlpacaClient, orderId: string): Promise<TrailingStopHWMResult>;
|
|
142
|
-
/**
|
|
143
|
-
* Cancel a trailing stop order
|
|
144
|
-
*
|
|
145
|
-
* @param client - AlpacaClient instance
|
|
146
|
-
* @param orderId - The ID of the trailing stop order to cancel
|
|
147
|
-
* @throws {Error} If cancellation fails
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* ```typescript
|
|
151
|
-
* await cancelTrailingStop(client, 'order-id-123');
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export declare function cancelTrailingStop(client: AlpacaClient, orderId: string): Promise<void>;
|
|
155
|
-
/**
|
|
156
|
-
* Create trailing stops for all positions in a portfolio
|
|
157
|
-
*
|
|
158
|
-
* This function creates trailing stop orders for all long positions in the portfolio,
|
|
159
|
-
* which is useful for applying blanket downside protection. Short positions are skipped.
|
|
160
|
-
*
|
|
161
|
-
* @param client - AlpacaClient instance
|
|
162
|
-
* @param params - Configuration for portfolio-wide trailing stops
|
|
163
|
-
* @returns Map of symbol to created order (symbols that failed are not included)
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```typescript
|
|
167
|
-
* // Apply 3% trailing stops to all positions except TSLA and NVDA
|
|
168
|
-
* const orders = await createPortfolioTrailingStops(client, {
|
|
169
|
-
* trailPercent: 3.0,
|
|
170
|
-
* excludeSymbols: ['TSLA', 'NVDA'],
|
|
171
|
-
* });
|
|
172
|
-
*
|
|
173
|
-
* console.log(`Created ${orders.size} trailing stops`);
|
|
174
|
-
* for (const [symbol, order] of orders) {
|
|
175
|
-
* console.log(`${symbol}: ${order.id}`);
|
|
176
|
-
* }
|
|
177
|
-
* ```
|
|
178
|
-
*/
|
|
179
|
-
export declare function createPortfolioTrailingStops(client: AlpacaClient, params: PortfolioTrailingStopParams): Promise<Map<string, AlpacaOrder>>;
|
|
180
|
-
/**
|
|
181
|
-
* Get all open trailing stop orders
|
|
182
|
-
*
|
|
183
|
-
* @param client - AlpacaClient instance
|
|
184
|
-
* @param symbol - Optional symbol to filter by
|
|
185
|
-
* @returns Array of open trailing stop orders
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```typescript
|
|
189
|
-
* // Get all trailing stops
|
|
190
|
-
* const allStops = await getOpenTrailingStops(client);
|
|
191
|
-
*
|
|
192
|
-
* // Get trailing stops for specific symbol
|
|
193
|
-
* const appleStops = await getOpenTrailingStops(client, 'AAPL');
|
|
194
|
-
* ```
|
|
195
|
-
*/
|
|
196
|
-
export declare function getOpenTrailingStops(client: AlpacaClient, symbol?: string): Promise<AlpacaOrder[]>;
|
|
197
|
-
/**
|
|
198
|
-
* Check if a symbol has an active trailing stop order
|
|
199
|
-
*
|
|
200
|
-
* @param client - AlpacaClient instance
|
|
201
|
-
* @param symbol - Stock symbol to check
|
|
202
|
-
* @returns True if an active trailing stop exists for the symbol
|
|
203
|
-
*
|
|
204
|
-
* @example
|
|
205
|
-
* ```typescript
|
|
206
|
-
* if (await hasActiveTrailingStop(client, 'AAPL')) {
|
|
207
|
-
* console.log('AAPL already has a trailing stop');
|
|
208
|
-
* }
|
|
209
|
-
* ```
|
|
210
|
-
*/
|
|
211
|
-
export declare function hasActiveTrailingStop(client: AlpacaClient, symbol: string): Promise<boolean>;
|
|
212
|
-
/**
|
|
213
|
-
* Cancel all trailing stop orders for a specific symbol
|
|
214
|
-
*
|
|
215
|
-
* @param client - AlpacaClient instance
|
|
216
|
-
* @param symbol - Stock symbol
|
|
217
|
-
* @returns Number of orders canceled
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* ```typescript
|
|
221
|
-
* const canceled = await cancelTrailingStopsForSymbol(client, 'AAPL');
|
|
222
|
-
* console.log(`Canceled ${canceled} trailing stop orders for AAPL`);
|
|
223
|
-
* ```
|
|
224
|
-
*/
|
|
225
|
-
export declare function cancelTrailingStopsForSymbol(client: AlpacaClient, symbol: string): Promise<number>;
|
|
226
|
-
/**
|
|
227
|
-
* Default export object with all trailing stop functions
|
|
228
|
-
*/
|
|
229
|
-
declare const _default: {
|
|
230
|
-
createTrailingStop: typeof createTrailingStop;
|
|
231
|
-
updateTrailingStop: typeof updateTrailingStop;
|
|
232
|
-
getTrailingStopHWM: typeof getTrailingStopHWM;
|
|
233
|
-
cancelTrailingStop: typeof cancelTrailingStop;
|
|
234
|
-
createPortfolioTrailingStops: typeof createPortfolioTrailingStops;
|
|
235
|
-
getOpenTrailingStops: typeof getOpenTrailingStops;
|
|
236
|
-
hasActiveTrailingStop: typeof hasActiveTrailingStop;
|
|
237
|
-
cancelTrailingStopsForSymbol: typeof cancelTrailingStopsForSymbol;
|
|
238
|
-
};
|
|
239
|
-
export default _default;
|
|
240
|
-
//# sourceMappingURL=trailing-stops.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trailing-stops.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/trading/trailing-stops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EACL,WAAW,EACX,SAAS,EACT,WAAW,EAE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,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC,WAAW,CAAC,CA0DtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,qBAAqB,CAAC,CAkChC;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC,CA+Bf;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,2BAA2B,GAClC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAoGnC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,EAAE,CAAC,CAiCxB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAGlB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAiCjB;AAED;;GAEG;;;;;;;;;;;AACH,wBASE"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Centralized API Endpoints Configuration
|
|
3
|
-
*
|
|
4
|
-
* This file defines all Alpaca API base URLs to ensure consistency
|
|
5
|
-
* across the codebase and make updates easier.
|
|
6
|
-
*
|
|
7
|
-
* API Version Guidelines:
|
|
8
|
-
* - Trading API: v2 (stable, production-ready)
|
|
9
|
-
* - Market Data (stocks): v2 (stable)
|
|
10
|
-
* - Market Data (crypto): v1beta3 (latest beta)
|
|
11
|
-
* - Market Data (options): v1beta1 (latest beta)
|
|
12
|
-
* - News API: v1beta1 (latest beta)
|
|
13
|
-
*/
|
|
14
|
-
/**
|
|
15
|
-
* Account type for trading
|
|
16
|
-
*/
|
|
17
|
-
export type AccountType = "PAPER" | "LIVE";
|
|
18
|
-
/**
|
|
19
|
-
* Trading API base URLs (v2)
|
|
20
|
-
* Used for orders, positions, account management
|
|
21
|
-
*/
|
|
22
|
-
export declare const TRADING_API: {
|
|
23
|
-
readonly PAPER: "https://paper-api.alpaca.markets/v2";
|
|
24
|
-
readonly LIVE: "https://api.alpaca.markets/v2";
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Get trading API base URL for account type
|
|
28
|
-
*/
|
|
29
|
-
export declare function getTradingApiUrl(accountType: AccountType): string;
|
|
30
|
-
/**
|
|
31
|
-
* Market Data API base URLs
|
|
32
|
-
*/
|
|
33
|
-
export declare const MARKET_DATA_API: {
|
|
34
|
-
/** Stock market data (v2) - bars, quotes, trades */
|
|
35
|
-
readonly STOCKS: "https://data.alpaca.markets/v2";
|
|
36
|
-
/** Cryptocurrency market data (v1beta3) - latest stable beta */
|
|
37
|
-
readonly CRYPTO: "https://data.alpaca.markets/v1beta3";
|
|
38
|
-
/** Options market data (v1beta1) */
|
|
39
|
-
readonly OPTIONS: "https://data.alpaca.markets/v1beta1";
|
|
40
|
-
/** News API (v1beta1) */
|
|
41
|
-
readonly NEWS: "https://data.alpaca.markets/v1beta1";
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* WebSocket stream URLs
|
|
45
|
-
*/
|
|
46
|
-
export declare const WEBSOCKET_STREAMS: {
|
|
47
|
-
/** Trading updates (orders, fills, etc.) */
|
|
48
|
-
readonly TRADING: {
|
|
49
|
-
readonly PAPER: "wss://paper-api.alpaca.markets/stream";
|
|
50
|
-
readonly LIVE: "wss://api.alpaca.markets/stream";
|
|
51
|
-
};
|
|
52
|
-
/** Stock market data stream (v2) */
|
|
53
|
-
readonly STOCKS: {
|
|
54
|
-
readonly PRODUCTION: "wss://stream.data.alpaca.markets/v2/sip";
|
|
55
|
-
readonly TEST: "wss://stream.data.alpaca.markets/v2/test";
|
|
56
|
-
};
|
|
57
|
-
/** Options market data stream (v1beta3) */
|
|
58
|
-
readonly OPTIONS: {
|
|
59
|
-
readonly PRODUCTION: "wss://stream.data.alpaca.markets/v1beta3/options";
|
|
60
|
-
readonly SANDBOX: "wss://stream.data.sandbox.alpaca.markets/v1beta3/options";
|
|
61
|
-
};
|
|
62
|
-
/** Crypto market data stream (v1beta3) */
|
|
63
|
-
readonly CRYPTO: {
|
|
64
|
-
readonly PRODUCTION: "wss://stream.data.alpaca.markets/v1beta3/crypto/us";
|
|
65
|
-
readonly SANDBOX: "wss://stream.data.sandbox.alpaca.markets/v1beta3/crypto/us";
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* Get trading WebSocket URL for account type
|
|
70
|
-
*/
|
|
71
|
-
export declare function getTradingWebSocketUrl(accountType: AccountType): string;
|
|
72
|
-
/**
|
|
73
|
-
* Get stock stream WebSocket URL
|
|
74
|
-
*/
|
|
75
|
-
export declare function getStockStreamUrl(mode?: "PRODUCTION" | "TEST"): string;
|
|
76
|
-
/**
|
|
77
|
-
* Get options stream WebSocket URL
|
|
78
|
-
*/
|
|
79
|
-
export declare function getOptionsStreamUrl(mode?: "PRODUCTION" | "SANDBOX"): string;
|
|
80
|
-
/**
|
|
81
|
-
* Get crypto stream WebSocket URL
|
|
82
|
-
*/
|
|
83
|
-
export declare function getCryptoStreamUrl(mode?: "PRODUCTION" | "SANDBOX"): string;
|
|
84
|
-
/**
|
|
85
|
-
* Legacy support - map old API version references to current
|
|
86
|
-
* @deprecated Use the constants above directly
|
|
87
|
-
*/
|
|
88
|
-
export declare const LEGACY_API_VERSIONS: {
|
|
89
|
-
/** @deprecated Use MARKET_DATA_API.OPTIONS instead */
|
|
90
|
-
readonly v1beta1: "https://data.alpaca.markets/v1beta1";
|
|
91
|
-
/** @deprecated Use MARKET_DATA_API.CRYPTO instead */
|
|
92
|
-
readonly v1beta3: "https://data.alpaca.markets/v1beta3";
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=api-endpoints.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-endpoints.d.ts","sourceRoot":"","sources":["../../../src/config/api-endpoints.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAEjE;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B,oDAAoD;;IAEpD,gEAAgE;;IAEhE,oCAAoC;;IAEpC,yBAAyB;;CAEjB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,iBAAiB;IAC5B,4CAA4C;;;;;IAK5C,oCAAoC;;;;;IAKpC,2CAA2C;;;;;IAK3C,0CAA0C;;;;;CAKlC,CAAC;AAEX;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAEvE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,GAAE,YAAY,GAAG,MAAqB,GACzC,MAAM,CAER;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,GAAE,YAAY,GAAG,SAAwB,GAC5C,MAAM,CAER;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,GAAE,YAAY,GAAG,SAAwB,GAC5C,MAAM,CAER;AAED;;;GAGG;AACH,eAAO,MAAM,mBAAmB;IAC9B,sDAAsD;;IAEtD,qDAAqD;;CAE7C,CAAC"}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Structured error type hierarchy for all API integrations
|
|
3
|
-
*
|
|
4
|
-
* This module provides a comprehensive error handling system for external API integrations,
|
|
5
|
-
* including Alpaca, Polygon, and AlphaVantage services.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Base error class for all @adaptic/utils errors
|
|
9
|
-
* Extends Error with additional context about service, error code, and retry capability
|
|
10
|
-
*/
|
|
11
|
-
export declare class AdapticUtilsError extends Error {
|
|
12
|
-
readonly code: string;
|
|
13
|
-
readonly service: string;
|
|
14
|
-
readonly isRetryable: boolean;
|
|
15
|
-
readonly cause?: unknown | undefined;
|
|
16
|
-
readonly name: string;
|
|
17
|
-
constructor(message: string, code: string, service: string, isRetryable?: boolean, cause?: unknown | undefined);
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Alpaca API specific errors
|
|
21
|
-
* Handles all errors from Alpaca trading and market data APIs
|
|
22
|
-
*/
|
|
23
|
-
export declare class AlpacaApiError extends AdapticUtilsError {
|
|
24
|
-
readonly statusCode?: number | undefined;
|
|
25
|
-
constructor(message: string, code: string, statusCode?: number | undefined, cause?: unknown);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Polygon.io API specific errors
|
|
29
|
-
* Handles all errors from Polygon market data API
|
|
30
|
-
*/
|
|
31
|
-
export declare class PolygonApiError extends AdapticUtilsError {
|
|
32
|
-
readonly statusCode?: number | undefined;
|
|
33
|
-
constructor(message: string, code: string, statusCode?: number | undefined, cause?: unknown);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* AlphaVantage API specific errors
|
|
37
|
-
* Handles all errors from AlphaVantage financial data API
|
|
38
|
-
*/
|
|
39
|
-
export declare class AlphaVantageError extends AdapticUtilsError {
|
|
40
|
-
readonly statusCode?: number | undefined;
|
|
41
|
-
constructor(message: string, code: string, statusCode?: number | undefined, cause?: unknown);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Network timeout errors
|
|
45
|
-
* Used when API requests exceed configured timeout limits
|
|
46
|
-
* Always retryable as timeouts are often transient
|
|
47
|
-
*/
|
|
48
|
-
export declare class TimeoutError extends AdapticUtilsError {
|
|
49
|
-
readonly service: string;
|
|
50
|
-
readonly timeoutMs: number;
|
|
51
|
-
constructor(message: string, service: string, timeoutMs: number, cause?: unknown);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Input validation errors
|
|
55
|
-
* Used when function inputs fail validation checks
|
|
56
|
-
* Never retryable as the inputs need to be corrected
|
|
57
|
-
*/
|
|
58
|
-
export declare class ValidationError extends AdapticUtilsError {
|
|
59
|
-
readonly service: string;
|
|
60
|
-
readonly invalidField?: string | undefined;
|
|
61
|
-
constructor(message: string, service: string, invalidField?: string | undefined, cause?: unknown);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Authentication and authorization errors
|
|
65
|
-
* Used when API credentials are invalid, expired, or lack permissions
|
|
66
|
-
* Never retryable as credentials need to be updated
|
|
67
|
-
*/
|
|
68
|
-
export declare class AuthenticationError extends AdapticUtilsError {
|
|
69
|
-
readonly service: string;
|
|
70
|
-
readonly statusCode?: number | undefined;
|
|
71
|
-
constructor(message: string, service: string, statusCode?: number | undefined, cause?: unknown);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* HTTP client errors (4xx)
|
|
75
|
-
* Used for client-side errors that are not authentication or validation related
|
|
76
|
-
* Generally not retryable unless specific status codes indicate otherwise
|
|
77
|
-
*/
|
|
78
|
-
export declare class HttpClientError extends AdapticUtilsError {
|
|
79
|
-
readonly service: string;
|
|
80
|
-
readonly statusCode: number;
|
|
81
|
-
constructor(message: string, service: string, statusCode: number, cause?: unknown);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* HTTP server errors (5xx)
|
|
85
|
-
* Used for server-side errors from external APIs
|
|
86
|
-
* Always retryable as server issues are often transient
|
|
87
|
-
*/
|
|
88
|
-
export declare class HttpServerError extends AdapticUtilsError {
|
|
89
|
-
readonly service: string;
|
|
90
|
-
readonly statusCode: number;
|
|
91
|
-
constructor(message: string, service: string, statusCode: number, cause?: unknown);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Rate limit errors (429)
|
|
95
|
-
* Used when API rate limits are exceeded
|
|
96
|
-
* Always retryable, often with retry-after header information
|
|
97
|
-
*/
|
|
98
|
-
export declare class RateLimitError extends AdapticUtilsError {
|
|
99
|
-
readonly service: string;
|
|
100
|
-
readonly retryAfterMs?: number | undefined;
|
|
101
|
-
constructor(message: string, service: string, retryAfterMs?: number | undefined, cause?: unknown);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* WebSocket connection errors
|
|
105
|
-
* Used for WebSocket-specific connection and communication failures
|
|
106
|
-
* Retryability depends on the specific error condition
|
|
107
|
-
*/
|
|
108
|
-
export declare class WebSocketError extends AdapticUtilsError {
|
|
109
|
-
readonly service: string;
|
|
110
|
-
constructor(message: string, service: string, isRetryable?: boolean, cause?: unknown);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Network errors (connection failures, DNS issues, etc.)
|
|
114
|
-
* Used for low-level network failures
|
|
115
|
-
* Always retryable as network issues are often transient
|
|
116
|
-
*/
|
|
117
|
-
export declare class NetworkError extends AdapticUtilsError {
|
|
118
|
-
readonly service: string;
|
|
119
|
-
constructor(message: string, service: string, cause?: unknown);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Data parsing and format errors
|
|
123
|
-
* Used when API responses cannot be parsed or are in unexpected format
|
|
124
|
-
* Not retryable as the data format issue needs investigation
|
|
125
|
-
*/
|
|
126
|
-
export declare class DataFormatError extends AdapticUtilsError {
|
|
127
|
-
readonly service: string;
|
|
128
|
-
constructor(message: string, service: string, cause?: unknown);
|
|
129
|
-
}
|
|
130
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sour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O;CAIlB;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,iBAAiB;aAG/B,OAAO,EAAE,MAAM;gBAD/B,OAAO,EAAE,MAAM,EACC,OAAO,EAAE,MAAM,EAC/B,KAAK,CAAC,EAAE,OAAO;CAUlB;AAED;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,iBAAiB;aAGlC,OAAO,EAAE,MAAM;gBAD/B,OAAO,EAAE,MAAM,EACC,OAAO,EAAE,MAAM,EAC/B,KAAK,CAAC,EAAE,OAAO;CAUlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limiter-example.d.ts","sourceRoot":"","sources":["../../../src/examples/rate-limiter-example.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP request timeout utilities
|
|
3
|
-
* Provides configurable timeout handling for external API calls
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Default timeout values for different external APIs (in milliseconds)
|
|
7
|
-
* Can be overridden via environment variables
|
|
8
|
-
*/
|
|
9
|
-
export declare const DEFAULT_TIMEOUTS: {
|
|
10
|
-
readonly ALPACA_API: number;
|
|
11
|
-
readonly POLYGON_API: number;
|
|
12
|
-
readonly ALPHA_VANTAGE: number;
|
|
13
|
-
readonly GENERAL: number;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Wraps a promise with a timeout
|
|
17
|
-
* @param promise - The promise to wrap with timeout
|
|
18
|
-
* @param ms - Timeout duration in milliseconds
|
|
19
|
-
* @param label - Label for error messages to identify the request
|
|
20
|
-
* @returns Promise that rejects if timeout is exceeded
|
|
21
|
-
* @throws Error if the promise takes longer than the specified timeout
|
|
22
|
-
*/
|
|
23
|
-
export declare function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T>;
|
|
24
|
-
/**
|
|
25
|
-
* Creates an AbortSignal that times out after the specified duration
|
|
26
|
-
* Compatible with fetch API
|
|
27
|
-
* @param ms - Timeout duration in milliseconds
|
|
28
|
-
* @returns AbortSignal that will abort after the specified duration
|
|
29
|
-
*/
|
|
30
|
-
export declare function createTimeoutSignal(ms: number): AbortSignal;
|
|
31
|
-
/**
|
|
32
|
-
* Get the appropriate timeout value for a given API
|
|
33
|
-
* @param api - The API type to get timeout for
|
|
34
|
-
* @returns Timeout value in milliseconds
|
|
35
|
-
*/
|
|
36
|
-
export declare function getTimeout(api: keyof typeof DEFAULT_TIMEOUTS): number;
|
|
37
|
-
//# sourceMappingURL=http-timeout.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-timeout.d.ts","sourceRoot":"","sources":["../../src/http-timeout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;CAKnB,CAAC;AAEX;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,CAAC,CAAC,CAUZ;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,CAE3D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,OAAO,gBAAgB,GAAG,MAAM,CAErE"}
|
package/dist/types/logger.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Configurable logger interface compatible with Pino and other logging libraries.
|
|
3
|
-
* Provides structured logging with context support.
|
|
4
|
-
*/
|
|
5
|
-
export interface Logger {
|
|
6
|
-
error(message: string, context?: unknown): void;
|
|
7
|
-
warn(message: string, context?: unknown): void;
|
|
8
|
-
info(message: string, context?: unknown): void;
|
|
9
|
-
debug(message: string, context?: unknown): void;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Sets a custom logger implementation.
|
|
13
|
-
* Call this to integrate with Pino or other logging libraries.
|
|
14
|
-
*
|
|
15
|
-
* @param logger - The logger implementation to use
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import pino from 'pino';
|
|
20
|
-
* import { setLogger } from '@adaptic/utils';
|
|
21
|
-
*
|
|
22
|
-
* const pinoLogger = pino();
|
|
23
|
-
*
|
|
24
|
-
* setLogger({
|
|
25
|
-
* error: (msg, ctx) => pinoLogger.error(ctx, msg),
|
|
26
|
-
* warn: (msg, ctx) => pinoLogger.warn(ctx, msg),
|
|
27
|
-
* info: (msg, ctx) => pinoLogger.info(ctx, msg),
|
|
28
|
-
* debug: (msg, ctx) => pinoLogger.debug(ctx, msg),
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
export declare function setLogger(logger: Logger): void;
|
|
33
|
-
/**
|
|
34
|
-
* Gets the current logger instance.
|
|
35
|
-
* Use this to log messages throughout the application.
|
|
36
|
-
*
|
|
37
|
-
* @returns The current logger instance
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* import { getLogger } from '@adaptic/utils';
|
|
42
|
-
*
|
|
43
|
-
* const logger = getLogger();
|
|
44
|
-
* logger.error('Operation failed', { userId: 123, operation: 'createOrder' });
|
|
45
|
-
* logger.warn('Rate limit approaching', { remaining: 10 });
|
|
46
|
-
* logger.info('Order created', { orderId: 'abc123', symbol: 'AAPL' });
|
|
47
|
-
* logger.debug('Cache hit', { key: 'user:123' });
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
export declare function getLogger(): Logger;
|
|
51
|
-
/**
|
|
52
|
-
* Resets the logger to the default console-based implementation.
|
|
53
|
-
* Useful for testing or cleanup.
|
|
54
|
-
*/
|
|
55
|
-
export declare function resetLogger(): void;
|
|
56
|
-
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CACjD;AA8CD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC"}
|