@adaptic/utils 0.0.382 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10241 -120
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +10057 -121
- package/dist/index.mjs.map +1 -1
- package/dist/types/alpaca/client.d.ts +95 -0
- package/dist/types/alpaca/client.d.ts.map +1 -0
- package/dist/types/alpaca/crypto/data.d.ts +281 -0
- package/dist/types/alpaca/crypto/data.d.ts.map +1 -0
- package/dist/types/alpaca/crypto/index.d.ts +75 -0
- package/dist/types/alpaca/crypto/index.d.ts.map +1 -0
- package/dist/types/alpaca/crypto/orders.d.ts +221 -0
- package/dist/types/alpaca/crypto/orders.d.ts.map +1 -0
- package/dist/types/alpaca/index.d.ts +201 -0
- package/dist/types/alpaca/index.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/bars.d.ts +142 -0
- package/dist/types/alpaca/market-data/bars.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/index.d.ts +13 -0
- package/dist/types/alpaca/market-data/index.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/news.d.ts +87 -0
- package/dist/types/alpaca/market-data/news.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/quotes.d.ts +85 -0
- package/dist/types/alpaca/market-data/quotes.d.ts.map +1 -0
- package/dist/types/alpaca/market-data/trades.d.ts +98 -0
- package/dist/types/alpaca/market-data/trades.d.ts.map +1 -0
- package/dist/types/alpaca/options/contracts.d.ts +279 -0
- package/dist/types/alpaca/options/contracts.d.ts.map +1 -0
- package/dist/types/alpaca/options/data.d.ts +126 -0
- package/dist/types/alpaca/options/data.d.ts.map +1 -0
- package/dist/types/alpaca/options/index.d.ts +17 -0
- package/dist/types/alpaca/options/index.d.ts.map +1 -0
- package/dist/types/alpaca/options/orders.d.ts +366 -0
- package/dist/types/alpaca/options/orders.d.ts.map +1 -0
- package/dist/types/alpaca/options/strategies.d.ts +224 -0
- package/dist/types/alpaca/options/strategies.d.ts.map +1 -0
- package/dist/types/alpaca/streams/base-stream.d.ts +143 -0
- package/dist/types/alpaca/streams/base-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/crypto-stream.d.ts +173 -0
- package/dist/types/alpaca/streams/crypto-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/index.d.ts +54 -0
- package/dist/types/alpaca/streams/index.d.ts.map +1 -0
- package/dist/types/alpaca/streams/option-stream.d.ts +167 -0
- package/dist/types/alpaca/streams/option-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/stock-stream.d.ts +176 -0
- package/dist/types/alpaca/streams/stock-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams/stream-manager.d.ts +277 -0
- package/dist/types/alpaca/streams/stream-manager.d.ts.map +1 -0
- package/dist/types/alpaca/streams/trading-stream.d.ts +186 -0
- package/dist/types/alpaca/streams/trading-stream.d.ts.map +1 -0
- package/dist/types/alpaca/streams.d.ts +88 -0
- package/dist/types/alpaca/streams.d.ts.map +1 -0
- package/dist/types/alpaca/test-imports.d.ts +7 -0
- package/dist/types/alpaca/test-imports.d.ts.map +1 -0
- package/dist/types/alpaca/trading/account.d.ts +198 -0
- package/dist/types/alpaca/trading/account.d.ts.map +1 -0
- package/dist/types/alpaca/trading/bracket-orders.d.ts +162 -0
- package/dist/types/alpaca/trading/bracket-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/index.d.ts +13 -0
- package/dist/types/alpaca/trading/index.d.ts.map +1 -0
- package/dist/types/alpaca/trading/oco-orders.d.ts +203 -0
- package/dist/types/alpaca/trading/oco-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/order-utils.d.ts +404 -0
- package/dist/types/alpaca/trading/order-utils.d.ts.map +1 -0
- package/dist/types/alpaca/trading/orders.d.ts +199 -0
- package/dist/types/alpaca/trading/orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/oto-orders.d.ts +282 -0
- package/dist/types/alpaca/trading/oto-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/positions.d.ts +389 -0
- package/dist/types/alpaca/trading/positions.d.ts.map +1 -0
- package/dist/types/alpaca/trading/smart-orders.d.ts +301 -0
- package/dist/types/alpaca/trading/smart-orders.d.ts.map +1 -0
- package/dist/types/alpaca/trading/trailing-stops.d.ts +240 -0
- package/dist/types/alpaca/trading/trailing-stops.d.ts.map +1 -0
- package/dist/types/index.d.ts +353 -6
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options Strategies Module
|
|
3
|
+
* Build and execute common option strategies using Alpaca SDK
|
|
4
|
+
*/
|
|
5
|
+
import { AlpacaClient } from '../client';
|
|
6
|
+
import { AlpacaOrder, TimeInForce } from '../../types/alpaca-types';
|
|
7
|
+
/**
|
|
8
|
+
* Error class for option strategy operations
|
|
9
|
+
*/
|
|
10
|
+
export declare class OptionStrategyError extends Error {
|
|
11
|
+
code: string;
|
|
12
|
+
strategy?: string | undefined;
|
|
13
|
+
details?: unknown | undefined;
|
|
14
|
+
constructor(message: string, code: string, strategy?: string | undefined, details?: unknown | undefined);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parameters for creating a vertical spread (call or put spread)
|
|
18
|
+
*/
|
|
19
|
+
export interface VerticalSpreadParams {
|
|
20
|
+
/** Underlying stock symbol */
|
|
21
|
+
underlying: string;
|
|
22
|
+
/** Expiration date in YYYY-MM-DD format */
|
|
23
|
+
expirationDate: string;
|
|
24
|
+
/** Option type: call or put */
|
|
25
|
+
type: 'call' | 'put';
|
|
26
|
+
/** Strike price for the long leg */
|
|
27
|
+
longStrike: number;
|
|
28
|
+
/** Strike price for the short leg */
|
|
29
|
+
shortStrike: number;
|
|
30
|
+
/** Number of contracts */
|
|
31
|
+
qty: number;
|
|
32
|
+
/** Debit = buy spread, Credit = sell spread */
|
|
33
|
+
direction: 'debit' | 'credit';
|
|
34
|
+
/** Optional limit price for the spread (net debit or credit) */
|
|
35
|
+
limitPrice?: number;
|
|
36
|
+
/** Time in force for the order */
|
|
37
|
+
timeInForce?: TimeInForce;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Parameters for creating an iron condor
|
|
41
|
+
*/
|
|
42
|
+
export interface IronCondorParams {
|
|
43
|
+
/** Underlying stock symbol */
|
|
44
|
+
underlying: string;
|
|
45
|
+
/** Expiration date in YYYY-MM-DD format */
|
|
46
|
+
expirationDate: string;
|
|
47
|
+
/** Strike price for the long put (lowest strike) */
|
|
48
|
+
putLongStrike: number;
|
|
49
|
+
/** Strike price for the short put */
|
|
50
|
+
putShortStrike: number;
|
|
51
|
+
/** Strike price for the short call */
|
|
52
|
+
callShortStrike: number;
|
|
53
|
+
/** Strike price for the long call (highest strike) */
|
|
54
|
+
callLongStrike: number;
|
|
55
|
+
/** Number of contracts */
|
|
56
|
+
qty: number;
|
|
57
|
+
/** Optional limit price for the spread (net credit) */
|
|
58
|
+
limitPrice?: number;
|
|
59
|
+
/** Time in force for the order */
|
|
60
|
+
timeInForce?: TimeInForce;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Parameters for creating a straddle
|
|
64
|
+
*/
|
|
65
|
+
export interface StraddleParams {
|
|
66
|
+
/** Underlying stock symbol */
|
|
67
|
+
underlying: string;
|
|
68
|
+
/** Expiration date in YYYY-MM-DD format */
|
|
69
|
+
expirationDate: string;
|
|
70
|
+
/** Strike price (same for both call and put) */
|
|
71
|
+
strike: number;
|
|
72
|
+
/** Number of contracts */
|
|
73
|
+
qty: number;
|
|
74
|
+
/** Long = buy both options, Short = sell both options */
|
|
75
|
+
direction: 'long' | 'short';
|
|
76
|
+
/** Optional limit price for the spread */
|
|
77
|
+
limitPrice?: number;
|
|
78
|
+
/** Time in force for the order */
|
|
79
|
+
timeInForce?: TimeInForce;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Parameters for creating a covered call
|
|
83
|
+
*/
|
|
84
|
+
export interface CoveredCallParams {
|
|
85
|
+
/** Underlying stock symbol */
|
|
86
|
+
underlying: string;
|
|
87
|
+
/** Expiration date in YYYY-MM-DD format */
|
|
88
|
+
expirationDate: string;
|
|
89
|
+
/** Strike price for the call option */
|
|
90
|
+
strike: number;
|
|
91
|
+
/** Number of contracts (each contract = 100 shares) */
|
|
92
|
+
qty: number;
|
|
93
|
+
/** Optional limit price for the call option */
|
|
94
|
+
limitPrice?: number;
|
|
95
|
+
/** Time in force for the order */
|
|
96
|
+
timeInForce?: TimeInForce;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parameters for rolling an option position
|
|
100
|
+
*/
|
|
101
|
+
export interface RollPositionParams {
|
|
102
|
+
/** Current option contract symbol to close */
|
|
103
|
+
currentSymbol: string;
|
|
104
|
+
/** New expiration date in YYYY-MM-DD format */
|
|
105
|
+
newExpirationDate: string;
|
|
106
|
+
/** New strike price */
|
|
107
|
+
newStrike: number;
|
|
108
|
+
/** Option type: call or put */
|
|
109
|
+
type: 'call' | 'put';
|
|
110
|
+
/** Optional limit price for the roll (net debit or credit) */
|
|
111
|
+
limitPrice?: number;
|
|
112
|
+
/** Time in force for the order */
|
|
113
|
+
timeInForce?: TimeInForce;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Parameters for creating a strangle
|
|
117
|
+
*/
|
|
118
|
+
export interface StrangleParams {
|
|
119
|
+
/** Underlying stock symbol */
|
|
120
|
+
underlying: string;
|
|
121
|
+
/** Expiration date in YYYY-MM-DD format */
|
|
122
|
+
expirationDate: string;
|
|
123
|
+
/** Strike price for the put option (lower strike) */
|
|
124
|
+
putStrike: number;
|
|
125
|
+
/** Strike price for the call option (higher strike) */
|
|
126
|
+
callStrike: number;
|
|
127
|
+
/** Number of contracts */
|
|
128
|
+
qty: number;
|
|
129
|
+
/** Long = buy both options, Short = sell both options */
|
|
130
|
+
direction: 'long' | 'short';
|
|
131
|
+
/** Optional limit price for the spread */
|
|
132
|
+
limitPrice?: number;
|
|
133
|
+
/** Time in force for the order */
|
|
134
|
+
timeInForce?: TimeInForce;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Parameters for creating a butterfly spread
|
|
138
|
+
*/
|
|
139
|
+
export interface ButterflySpreadParams {
|
|
140
|
+
/** Underlying stock symbol */
|
|
141
|
+
underlying: string;
|
|
142
|
+
/** Expiration date in YYYY-MM-DD format */
|
|
143
|
+
expirationDate: string;
|
|
144
|
+
/** Option type: call or put */
|
|
145
|
+
type: 'call' | 'put';
|
|
146
|
+
/** Lower strike price */
|
|
147
|
+
lowerStrike: number;
|
|
148
|
+
/** Middle strike price (usually ATM) */
|
|
149
|
+
middleStrike: number;
|
|
150
|
+
/** Upper strike price */
|
|
151
|
+
upperStrike: number;
|
|
152
|
+
/** Number of contracts */
|
|
153
|
+
qty: number;
|
|
154
|
+
/** Optional limit price for the spread */
|
|
155
|
+
limitPrice?: number;
|
|
156
|
+
/** Time in force for the order */
|
|
157
|
+
timeInForce?: TimeInForce;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Build an OCC-compliant option symbol
|
|
161
|
+
* Format: ROOT + YYMMDD + C/P + Strike (8 digits with 3 decimals)
|
|
162
|
+
*/
|
|
163
|
+
export declare function buildOptionSymbol(underlying: string, expirationDate: string, type: 'call' | 'put', strike: number): string;
|
|
164
|
+
/**
|
|
165
|
+
* Create a vertical spread (call or put spread)
|
|
166
|
+
* - Bull Call Spread: Buy lower strike call, sell higher strike call
|
|
167
|
+
* - Bear Call Spread: Sell lower strike call, buy higher strike call
|
|
168
|
+
* - Bull Put Spread: Sell higher strike put, buy lower strike put
|
|
169
|
+
* - Bear Put Spread: Buy higher strike put, sell lower strike put
|
|
170
|
+
*/
|
|
171
|
+
export declare function createVerticalSpread(client: AlpacaClient, params: VerticalSpreadParams): Promise<AlpacaOrder>;
|
|
172
|
+
/**
|
|
173
|
+
* Create an iron condor
|
|
174
|
+
* Combines a bull put spread and a bear call spread
|
|
175
|
+
* - Buy put at putLongStrike (lowest)
|
|
176
|
+
* - Sell put at putShortStrike
|
|
177
|
+
* - Sell call at callShortStrike
|
|
178
|
+
* - Buy call at callLongStrike (highest)
|
|
179
|
+
*/
|
|
180
|
+
export declare function createIronCondor(client: AlpacaClient, params: IronCondorParams): Promise<AlpacaOrder>;
|
|
181
|
+
/**
|
|
182
|
+
* Create a straddle (buy/sell both call and put at same strike)
|
|
183
|
+
* - Long straddle: Buy call and put at same strike (expects high volatility)
|
|
184
|
+
* - Short straddle: Sell call and put at same strike (expects low volatility)
|
|
185
|
+
*/
|
|
186
|
+
export declare function createStraddle(client: AlpacaClient, params: StraddleParams): Promise<AlpacaOrder>;
|
|
187
|
+
/**
|
|
188
|
+
* Create a covered call
|
|
189
|
+
* - Buy (or already own) 100 shares per contract
|
|
190
|
+
* - Sell call option against the shares
|
|
191
|
+
*/
|
|
192
|
+
export declare function createCoveredCall(client: AlpacaClient, params: CoveredCallParams): Promise<{
|
|
193
|
+
stockOrder: AlpacaOrder;
|
|
194
|
+
optionOrder: AlpacaOrder;
|
|
195
|
+
}>;
|
|
196
|
+
/**
|
|
197
|
+
* Roll an option position to a new expiration/strike
|
|
198
|
+
* Closes the current position and opens a new one
|
|
199
|
+
*/
|
|
200
|
+
export declare function rollOptionPosition(client: AlpacaClient, params: RollPositionParams): Promise<AlpacaOrder>;
|
|
201
|
+
/**
|
|
202
|
+
* Create a strangle (buy/sell call and put at different strikes)
|
|
203
|
+
* - Long strangle: Buy OTM call and OTM put (expects high volatility)
|
|
204
|
+
* - Short strangle: Sell OTM call and OTM put (expects low volatility)
|
|
205
|
+
*/
|
|
206
|
+
export declare function createStrangle(client: AlpacaClient, params: StrangleParams): Promise<AlpacaOrder>;
|
|
207
|
+
/**
|
|
208
|
+
* Create a butterfly spread
|
|
209
|
+
* - Long butterfly: Buy 1 lower, sell 2 middle, buy 1 upper
|
|
210
|
+
* - Expects price to stay near middle strike
|
|
211
|
+
*/
|
|
212
|
+
export declare function createButterflySpread(client: AlpacaClient, params: ButterflySpreadParams): Promise<AlpacaOrder>;
|
|
213
|
+
declare const _default: {
|
|
214
|
+
buildOptionSymbol: typeof buildOptionSymbol;
|
|
215
|
+
createVerticalSpread: typeof createVerticalSpread;
|
|
216
|
+
createIronCondor: typeof createIronCondor;
|
|
217
|
+
createStraddle: typeof createStraddle;
|
|
218
|
+
createCoveredCall: typeof createCoveredCall;
|
|
219
|
+
rollOptionPosition: typeof rollOptionPosition;
|
|
220
|
+
createStrangle: typeof createStrangle;
|
|
221
|
+
createButterflySpread: typeof createButterflySpread;
|
|
222
|
+
};
|
|
223
|
+
export default _default;
|
|
224
|
+
//# sourceMappingURL=strategies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/options/strategies.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EACL,WAAW,EAEX,WAAW,EAIZ,MAAM,0BAA0B,CAAC;AAYlC;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAGnC,IAAI,EAAE,MAAM;IACZ,QAAQ,CAAC,EAAE,MAAM;IACjB,OAAO,CAAC,EAAE,OAAO;gBAHxB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,YAAA,EACjB,OAAO,CAAC,EAAE,OAAO,YAAA;CAK3B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IACrB,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1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,CAAC,CAoGtB;;;;;;;;;;;AAED,wBASE"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Stream Module
|
|
3
|
+
* Abstract base class for all Alpaca WebSocket streams
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import WebSocket from 'ws';
|
|
7
|
+
import { LogOptions } from '../../types/logging-types';
|
|
8
|
+
import { AlpacaClient } from '../client';
|
|
9
|
+
/**
|
|
10
|
+
* Stream connection state
|
|
11
|
+
*/
|
|
12
|
+
export type StreamState = 'disconnected' | 'connecting' | 'connected' | 'authenticated' | 'error';
|
|
13
|
+
/**
|
|
14
|
+
* Stream configuration options
|
|
15
|
+
*/
|
|
16
|
+
export interface StreamConfig {
|
|
17
|
+
/** Auto-reconnect on disconnect */
|
|
18
|
+
autoReconnect: boolean;
|
|
19
|
+
/** Reconnect delay in milliseconds */
|
|
20
|
+
reconnectDelay: number;
|
|
21
|
+
/** Maximum reconnection attempts (0 = unlimited) */
|
|
22
|
+
maxReconnectAttempts: number;
|
|
23
|
+
/** Connection timeout in milliseconds */
|
|
24
|
+
connectionTimeout: number;
|
|
25
|
+
/** Authentication timeout in milliseconds */
|
|
26
|
+
authTimeout: number;
|
|
27
|
+
/** Heartbeat interval in milliseconds (0 = disabled) */
|
|
28
|
+
heartbeatInterval: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Default stream configuration
|
|
32
|
+
*/
|
|
33
|
+
export declare const DEFAULT_STREAM_CONFIG: StreamConfig;
|
|
34
|
+
/**
|
|
35
|
+
* Subscription request structure
|
|
36
|
+
*/
|
|
37
|
+
export interface SubscriptionRequest {
|
|
38
|
+
trades?: string[];
|
|
39
|
+
quotes?: string[];
|
|
40
|
+
bars?: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Abstract base class for all Alpaca WebSocket streams
|
|
44
|
+
*/
|
|
45
|
+
export declare abstract class BaseStream extends EventEmitter {
|
|
46
|
+
protected client: AlpacaClient;
|
|
47
|
+
protected ws: WebSocket | null;
|
|
48
|
+
protected state: StreamState;
|
|
49
|
+
protected config: StreamConfig;
|
|
50
|
+
protected reconnectAttempts: number;
|
|
51
|
+
protected reconnectTimer: NodeJS.Timeout | null;
|
|
52
|
+
protected heartbeatTimer: NodeJS.Timeout | null;
|
|
53
|
+
protected connectionTimer: NodeJS.Timeout | null;
|
|
54
|
+
protected subscriptions: SubscriptionRequest;
|
|
55
|
+
protected pendingSubscriptions: SubscriptionRequest | null;
|
|
56
|
+
/** Name of the stream for logging */
|
|
57
|
+
protected abstract readonly streamName: string;
|
|
58
|
+
/** WebSocket URL for the stream */
|
|
59
|
+
protected abstract getStreamUrl(): string;
|
|
60
|
+
constructor(client: AlpacaClient, config?: Partial<StreamConfig>);
|
|
61
|
+
/**
|
|
62
|
+
* Log a message with stream context
|
|
63
|
+
*/
|
|
64
|
+
protected log(message: string, options?: LogOptions): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get the current stream state
|
|
67
|
+
*/
|
|
68
|
+
getState(): StreamState;
|
|
69
|
+
/**
|
|
70
|
+
* Check if stream is connected and authenticated
|
|
71
|
+
*/
|
|
72
|
+
isStreamConnected(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Get current subscriptions
|
|
75
|
+
*/
|
|
76
|
+
getSubscriptions(): SubscriptionRequest;
|
|
77
|
+
/**
|
|
78
|
+
* Connect to the WebSocket stream
|
|
79
|
+
*/
|
|
80
|
+
connect(): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Disconnect from the WebSocket stream
|
|
83
|
+
*/
|
|
84
|
+
disconnect(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Subscribe to market data
|
|
87
|
+
*/
|
|
88
|
+
subscribe(request: SubscriptionRequest): void;
|
|
89
|
+
/**
|
|
90
|
+
* Unsubscribe from market data
|
|
91
|
+
*/
|
|
92
|
+
unsubscribe(request: SubscriptionRequest): void;
|
|
93
|
+
/**
|
|
94
|
+
* Authenticate with the WebSocket
|
|
95
|
+
*/
|
|
96
|
+
protected authenticate(): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Send subscription request
|
|
99
|
+
*/
|
|
100
|
+
protected sendSubscription(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Send unsubscription request
|
|
103
|
+
*/
|
|
104
|
+
protected sendUnsubscription(request: SubscriptionRequest): void;
|
|
105
|
+
/**
|
|
106
|
+
* Handle incoming WebSocket messages
|
|
107
|
+
*/
|
|
108
|
+
protected handleMessage(data: WebSocket.Data): void;
|
|
109
|
+
/**
|
|
110
|
+
* Process a single message - to be implemented by subclasses
|
|
111
|
+
*/
|
|
112
|
+
protected abstract processMessage(message: Record<string, unknown>): void;
|
|
113
|
+
/**
|
|
114
|
+
* Handle WebSocket close event
|
|
115
|
+
*/
|
|
116
|
+
protected handleClose(code: number, reason: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* Handle WebSocket error event
|
|
119
|
+
*/
|
|
120
|
+
protected handleError(error: Error): void;
|
|
121
|
+
/**
|
|
122
|
+
* Schedule a reconnection attempt
|
|
123
|
+
*/
|
|
124
|
+
protected scheduleReconnect(): void;
|
|
125
|
+
/**
|
|
126
|
+
* Start heartbeat to keep connection alive
|
|
127
|
+
*/
|
|
128
|
+
protected startHeartbeat(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Stop heartbeat timer
|
|
131
|
+
*/
|
|
132
|
+
protected stopHeartbeat(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Clear connection timer
|
|
135
|
+
*/
|
|
136
|
+
protected clearConnectionTimer(): void;
|
|
137
|
+
/**
|
|
138
|
+
* Clear all timers
|
|
139
|
+
*/
|
|
140
|
+
protected clearAllTimers(): void;
|
|
141
|
+
}
|
|
142
|
+
export default BaseStream;
|
|
143
|
+
//# sourceMappingURL=base-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-stream.d.ts","sourceRoot":"","sources":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AC,cAAc,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAEzE;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAWzD;;OAEG;IACH,SAAS,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAMzC;;OAEG;IACH,SAAS,CAAC,iBAAiB,IAAI,IAAI;IAqBnC;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;IAYhC;;OAEG;IACH,SAAS,CAAC,aAAa,IAAI,IAAI;IAO/B;;OAEG;IACH,SAAS,CAAC,oBAAoB,IAAI,IAAI;IAOtC;;OAEG;IACH,SAAS,CAAC,cAAc,IAAI,IAAI;CAQjC;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crypto Data Stream Module
|
|
3
|
+
* Real-time cryptocurrency quotes, trades, and bars via Alpaca WebSocket (24/7)
|
|
4
|
+
*
|
|
5
|
+
* Uses the official Alpaca SDK crypto_stream_v1beta3 for reliable real-time data.
|
|
6
|
+
* Provides automatic reconnection, subscription management, and type-safe events.
|
|
7
|
+
*/
|
|
8
|
+
import { EventEmitter } from 'events';
|
|
9
|
+
import { AlpacaClient } from '../client';
|
|
10
|
+
import { AlpacaCryptoTradeStream, AlpacaCryptoQuoteStream, AlpacaCryptoBarStream, AlpacaCryptoDailyBarStream, AlpacaCryptoUpdatedBarStream, AlpacaCryptoStreamMessage } from '../../types/alpaca-types';
|
|
11
|
+
import { StreamConfig, StreamState, SubscriptionRequest } from './base-stream';
|
|
12
|
+
/**
|
|
13
|
+
* Crypto stream location
|
|
14
|
+
*/
|
|
15
|
+
export type CryptoStreamLocation = 'us';
|
|
16
|
+
/**
|
|
17
|
+
* Crypto stream configuration
|
|
18
|
+
*/
|
|
19
|
+
export interface CryptoStreamConfig extends StreamConfig {
|
|
20
|
+
/** Location for crypto data */
|
|
21
|
+
location: CryptoStreamLocation;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Default crypto stream configuration
|
|
25
|
+
*/
|
|
26
|
+
export declare const DEFAULT_CRYPTO_STREAM_CONFIG: Partial<CryptoStreamConfig>;
|
|
27
|
+
/**
|
|
28
|
+
* Crypto stream event map for type-safe event handling
|
|
29
|
+
*/
|
|
30
|
+
export interface CryptoStreamEventMap {
|
|
31
|
+
trade: AlpacaCryptoTradeStream;
|
|
32
|
+
quote: AlpacaCryptoQuoteStream;
|
|
33
|
+
bar: AlpacaCryptoBarStream;
|
|
34
|
+
dailyBar: AlpacaCryptoDailyBarStream;
|
|
35
|
+
updatedBar: AlpacaCryptoUpdatedBarStream;
|
|
36
|
+
data: AlpacaCryptoStreamMessage;
|
|
37
|
+
subscription: {
|
|
38
|
+
trades: string[];
|
|
39
|
+
quotes: string[];
|
|
40
|
+
bars: string[];
|
|
41
|
+
};
|
|
42
|
+
authenticated: void;
|
|
43
|
+
connected: void;
|
|
44
|
+
disconnected: {
|
|
45
|
+
code: number;
|
|
46
|
+
reason: string;
|
|
47
|
+
};
|
|
48
|
+
stateChange: StreamState;
|
|
49
|
+
error: Error;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Crypto Data Stream class for receiving real-time cryptocurrency market data
|
|
53
|
+
* Uses the official Alpaca SDK crypto_stream_v1beta3 for WebSocket management.
|
|
54
|
+
* Operates 24/7 for cryptocurrency markets.
|
|
55
|
+
*/
|
|
56
|
+
export declare class CryptoDataStream extends EventEmitter {
|
|
57
|
+
private client;
|
|
58
|
+
private socket;
|
|
59
|
+
private state;
|
|
60
|
+
private location;
|
|
61
|
+
private config;
|
|
62
|
+
private subscriptions;
|
|
63
|
+
private pendingSubscriptions;
|
|
64
|
+
private currentSymbol;
|
|
65
|
+
constructor(client: AlpacaClient, config?: Partial<CryptoStreamConfig>);
|
|
66
|
+
/**
|
|
67
|
+
* Log helper
|
|
68
|
+
*/
|
|
69
|
+
private log;
|
|
70
|
+
/**
|
|
71
|
+
* Get the current stream state
|
|
72
|
+
*/
|
|
73
|
+
getState(): StreamState;
|
|
74
|
+
/**
|
|
75
|
+
* Check if stream is connected and authenticated
|
|
76
|
+
*/
|
|
77
|
+
isStreamConnected(): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Get current subscriptions
|
|
80
|
+
*/
|
|
81
|
+
getSubscriptions(): SubscriptionRequest;
|
|
82
|
+
/**
|
|
83
|
+
* Set the stream location
|
|
84
|
+
*/
|
|
85
|
+
setLocation(location: CryptoStreamLocation): void;
|
|
86
|
+
/**
|
|
87
|
+
* Get the current stream location
|
|
88
|
+
*/
|
|
89
|
+
getLocation(): CryptoStreamLocation;
|
|
90
|
+
/**
|
|
91
|
+
* Connect to the crypto data stream using SDK
|
|
92
|
+
*/
|
|
93
|
+
connect(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Set up all data event handlers for SDK
|
|
96
|
+
*/
|
|
97
|
+
private setupDataHandlers;
|
|
98
|
+
/**
|
|
99
|
+
* Disconnect from the crypto data stream
|
|
100
|
+
*/
|
|
101
|
+
disconnect(): void;
|
|
102
|
+
/**
|
|
103
|
+
* Subscribe to market data
|
|
104
|
+
*/
|
|
105
|
+
subscribe(request: SubscriptionRequest): void;
|
|
106
|
+
/**
|
|
107
|
+
* Unsubscribe from market data
|
|
108
|
+
*/
|
|
109
|
+
unsubscribe(request: SubscriptionRequest): void;
|
|
110
|
+
/**
|
|
111
|
+
* Subscribe to crypto trades
|
|
112
|
+
*/
|
|
113
|
+
subscribeTrades(symbols: string[]): void;
|
|
114
|
+
/**
|
|
115
|
+
* Subscribe to crypto quotes
|
|
116
|
+
*/
|
|
117
|
+
subscribeQuotes(symbols: string[]): void;
|
|
118
|
+
/**
|
|
119
|
+
* Subscribe to crypto bars
|
|
120
|
+
*/
|
|
121
|
+
subscribeBars(symbols: string[]): void;
|
|
122
|
+
/**
|
|
123
|
+
* Subscribe to all data types for crypto symbols
|
|
124
|
+
*/
|
|
125
|
+
subscribeAll(symbols: string[]): void;
|
|
126
|
+
/**
|
|
127
|
+
* Unsubscribe from crypto trades
|
|
128
|
+
*/
|
|
129
|
+
unsubscribeTrades(symbols: string[]): void;
|
|
130
|
+
/**
|
|
131
|
+
* Unsubscribe from crypto quotes
|
|
132
|
+
*/
|
|
133
|
+
unsubscribeQuotes(symbols: string[]): void;
|
|
134
|
+
/**
|
|
135
|
+
* Unsubscribe from crypto bars
|
|
136
|
+
*/
|
|
137
|
+
unsubscribeBars(symbols: string[]): void;
|
|
138
|
+
/**
|
|
139
|
+
* Unsubscribe from all data types for crypto symbols
|
|
140
|
+
*/
|
|
141
|
+
unsubscribeAll(symbols: string[]): void;
|
|
142
|
+
/**
|
|
143
|
+
* Subscribe to popular crypto pairs
|
|
144
|
+
*/
|
|
145
|
+
subscribePopularPairs(): void;
|
|
146
|
+
/**
|
|
147
|
+
* Send subscription request using SDK methods
|
|
148
|
+
*/
|
|
149
|
+
private sendSubscription;
|
|
150
|
+
/**
|
|
151
|
+
* Send unsubscription request using SDK methods
|
|
152
|
+
*/
|
|
153
|
+
private sendUnsubscription;
|
|
154
|
+
private convertTrade;
|
|
155
|
+
private convertQuote;
|
|
156
|
+
private convertBar;
|
|
157
|
+
private convertDailyBar;
|
|
158
|
+
private convertUpdatedBar;
|
|
159
|
+
/**
|
|
160
|
+
* Type-safe event listener registration
|
|
161
|
+
*/
|
|
162
|
+
on<K extends keyof CryptoStreamEventMap>(event: K, listener: (data: CryptoStreamEventMap[K]) => void): this;
|
|
163
|
+
/**
|
|
164
|
+
* Type-safe event emitter
|
|
165
|
+
*/
|
|
166
|
+
emit<K extends keyof CryptoStreamEventMap>(event: K, data?: CryptoStreamEventMap[K]): boolean;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a crypto data stream for a client
|
|
170
|
+
*/
|
|
171
|
+
export declare function createCryptoDataStream(client: AlpacaClient, config?: Partial<CryptoStreamConfig>): CryptoDataStream;
|
|
172
|
+
export default CryptoDataStream;
|
|
173
|
+
//# sourceMappingURL=crypto-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto-stream.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/streams/crypto-stream.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EAE1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAyB,MAAM,eAAe,CAAC;AA8BtG;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,+BAA+B;IAC/B,QAAQ,EAAE,oBAAoB,CAAC;CAChC;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,EAAE,OAAO,CAAC,kBAAkB,CAGpE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,uBAAuB,CAAC;IAC/B,KAAK,EAAE,uBAAuB,CAAC;IAC/B,GAAG,EAAE,qBAAqB,CAAC;IAC3B,QAAQ,EAAE,0BAA0B,CAAC;IACrC,UAAU,EAAE,4BAA4B,CAAC;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,YAAY,EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IACrE,aAAa,EAAE,IAAI,CAAC;IACpB,SAAS,EAAE,IAAI,CAAC;IAChB,YAAY,EAA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AG,IAAI;IAItC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAIrC;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAI1C;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAI1C;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAIxC;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAIvC;;OAEG;IACH,qBAAqB,IAAI,IAAI;IAK7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAwBxB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,UAAU;IAelB,OAAO,CAAC,eAAe;IAevB,OAAO,CAAC,iBAAiB;IAezB;;OAEG;IACH,EAAE,CAAC,CAAC,SAAS,MAAM,oBAAoB,EACrC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,KAAK,IAAI,GAChD,IAAI;IAIP;;OAEG;IACH,IAAI,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAAG,OAAO;CAG9F;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,YAAY,EACpB,MAAM,GAAE,OAAO,CAAC,kBAAkB,CAAM,GACvC,gBAAgB,CAElB;AAED,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Streams Module Index
|
|
3
|
+
* Re-exports all stream-related functionality for Alpaca WebSocket connections.
|
|
4
|
+
*
|
|
5
|
+
* This module provides unified WebSocket streaming for:
|
|
6
|
+
* - Trading updates (order fills, cancellations, etc.)
|
|
7
|
+
* - Stock market data (trades, quotes, bars)
|
|
8
|
+
* - Options market data (trades, quotes, bars)
|
|
9
|
+
* - Crypto market data (trades, quotes, bars)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { createStreamManager, createAlpacaClient } from '@adaptic/utils';
|
|
14
|
+
*
|
|
15
|
+
* const client = createAlpacaClient({
|
|
16
|
+
* apiKey: 'your-api-key',
|
|
17
|
+
* apiSecret: 'your-api-secret',
|
|
18
|
+
* accountType: 'PAPER',
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Use the unified stream manager
|
|
22
|
+
* const manager = createStreamManager(client);
|
|
23
|
+
* await manager.connectAll();
|
|
24
|
+
*
|
|
25
|
+
* // Subscribe to stock data
|
|
26
|
+
* manager.subscribeStocks({
|
|
27
|
+
* trades: ['AAPL', 'MSFT'],
|
|
28
|
+
* quotes: ['AAPL', 'MSFT'],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // Listen for trading updates
|
|
32
|
+
* const tradingStream = manager.getTradingStream();
|
|
33
|
+
* tradingStream?.on('fill', (update) => {
|
|
34
|
+
* console.log(`Order filled: ${update.order.symbol}`);
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Or use individual streams directly
|
|
38
|
+
* import { createStockDataStream, createTradingStream } from '@adaptic/utils';
|
|
39
|
+
*
|
|
40
|
+
* const stockStream = createStockDataStream(client);
|
|
41
|
+
* await stockStream.connect();
|
|
42
|
+
* stockStream.subscribeTrades(['AAPL', 'TSLA']);
|
|
43
|
+
* stockStream.on('trade', (trade) => {
|
|
44
|
+
* console.log(`Trade: ${trade.S} @ ${trade.p}`);
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export { BaseStream, StreamConfig, StreamState, SubscriptionRequest, DEFAULT_STREAM_CONFIG, } from './base-stream';
|
|
49
|
+
export { TradingStream, TradingStreamEvent, TradingStreamEventMap, createTradingStream, } from './trading-stream';
|
|
50
|
+
export { StockDataStream, StockDataFeed, StockStreamConfig, StockStreamEventMap, createStockDataStream, DEFAULT_STOCK_STREAM_CONFIG, } from './stock-stream';
|
|
51
|
+
export { OptionDataStream, OptionDataFeed, OptionStreamConfig, OptionStreamEventMap, createOptionDataStream, DEFAULT_OPTION_STREAM_CONFIG, } from './option-stream';
|
|
52
|
+
export { CryptoDataStream, CryptoStreamLocation, CryptoStreamConfig, CryptoStreamEventMap, createCryptoDataStream, DEFAULT_CRYPTO_STREAM_CONFIG, } from './crypto-stream';
|
|
53
|
+
export { StreamManager, StreamStatus, DetailedStreamStatus, StreamManagerConfig, StreamManagerEventMap, createStreamManager, DEFAULT_STREAM_MANAGER_CONFIG, } from './stream-manager';
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/streams/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAGH,OAAO,EACL,UAAU,EACV,YAAY,EACZ,WAAW,EACX,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,eAAe,EACf,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,6BAA6B,GAC9B,MAAM,kBAAkB,CAAC"}
|