@fullstackcraftllc/floe 0.0.8 → 0.0.10
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 +1 -1
- package/dist/client/FloeClient.js +1 -1
- package/dist/client/brokers/BaseBrokerClient.d.ts +296 -0
- package/dist/client/brokers/BaseBrokerClient.js +509 -0
- package/dist/client/brokers/SchwabClient.d.ts +11 -128
- package/dist/client/brokers/SchwabClient.js +37 -246
- package/dist/client/brokers/TastyTradeClient.d.ts +17 -120
- package/dist/client/brokers/TastyTradeClient.js +35 -319
- package/dist/client/brokers/TradeStationClient.d.ts +31 -128
- package/dist/client/brokers/TradeStationClient.js +37 -201
- package/dist/client/brokers/TradierClient.d.ts +16 -196
- package/dist/client/brokers/TradierClient.js +19 -421
- package/package.json +1 -1
|
@@ -1,29 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type AggressorSide = 'buy' | 'sell' | 'unknown';
|
|
6
|
-
/**
|
|
7
|
-
* Intraday trade information with aggressor classification
|
|
8
|
-
*/
|
|
9
|
-
export interface IntradayTrade {
|
|
10
|
-
/** OCC option symbol */
|
|
11
|
-
occSymbol: string;
|
|
12
|
-
/** Trade price */
|
|
13
|
-
price: number;
|
|
14
|
-
/** Trade size (number of contracts) */
|
|
15
|
-
size: number;
|
|
16
|
-
/** Bid at time of trade */
|
|
17
|
-
bid: number;
|
|
18
|
-
/** Ask at time of trade */
|
|
19
|
-
ask: number;
|
|
20
|
-
/** Aggressor side determined from price vs NBBO */
|
|
21
|
-
aggressorSide: AggressorSide;
|
|
22
|
-
/** Timestamp of the trade */
|
|
23
|
-
timestamp: number;
|
|
24
|
-
/** Estimated OI change: +size for buy aggressor (new longs), -size for sell aggressor (closing longs/new shorts) */
|
|
25
|
-
estimatedOIChange: number;
|
|
26
|
-
}
|
|
1
|
+
import { BaseBrokerClient, BaseBrokerClientOptions, AggressorSide, IntradayTrade, FlowSummary, BrokerClientEventType, BrokerEventListener } from './BaseBrokerClient';
|
|
2
|
+
export { AggressorSide, IntradayTrade, FlowSummary };
|
|
3
|
+
export type TradierClientEventType = BrokerClientEventType;
|
|
4
|
+
export type TradierEventListener<T> = BrokerEventListener<T>;
|
|
27
5
|
/**
|
|
28
6
|
* Tradier option chain item from REST API
|
|
29
7
|
* GET /v1/markets/options/chains
|
|
@@ -78,13 +56,12 @@ interface TradierOptionChainItem {
|
|
|
78
56
|
};
|
|
79
57
|
}
|
|
80
58
|
/**
|
|
81
|
-
*
|
|
82
|
-
*/
|
|
83
|
-
type TradierClientEventType = 'tickerUpdate' | 'optionUpdate' | 'optionTrade' | 'connected' | 'disconnected' | 'error';
|
|
84
|
-
/**
|
|
85
|
-
* Event listener callback type
|
|
59
|
+
* Tradier client configuration options
|
|
86
60
|
*/
|
|
87
|
-
|
|
61
|
+
export interface TradierClientOptions extends BaseBrokerClientOptions {
|
|
62
|
+
/** Tradier API authentication token */
|
|
63
|
+
authToken: string;
|
|
64
|
+
}
|
|
88
65
|
/**
|
|
89
66
|
* TradierClient handles real-time streaming connections to the Tradier API.
|
|
90
67
|
*
|
|
@@ -95,7 +72,7 @@ type TradierEventListener<T> = (data: T) => void;
|
|
|
95
72
|
*
|
|
96
73
|
* @example
|
|
97
74
|
* ```typescript
|
|
98
|
-
* const client = new TradierClient('your-api-key');
|
|
75
|
+
* const client = new TradierClient({ authToken: 'your-api-key' });
|
|
99
76
|
*
|
|
100
77
|
* client.on('tickerUpdate', (ticker) => {
|
|
101
78
|
* console.log(`${ticker.symbol}: ${ticker.spot}`);
|
|
@@ -105,7 +82,8 @@ type TradierEventListener<T> = (data: T) => void;
|
|
|
105
82
|
* client.subscribe(['QQQ', 'AAPL 240119C00500000']);
|
|
106
83
|
* ```
|
|
107
84
|
*/
|
|
108
|
-
export declare class TradierClient {
|
|
85
|
+
export declare class TradierClient extends BaseBrokerClient {
|
|
86
|
+
protected readonly brokerName = "Tradier";
|
|
109
87
|
/** Tradier API authentication token */
|
|
110
88
|
private authToken;
|
|
111
89
|
/** Current streaming session */
|
|
@@ -114,51 +92,18 @@ export declare class TradierClient {
|
|
|
114
92
|
private ws;
|
|
115
93
|
/** Connection state */
|
|
116
94
|
private connected;
|
|
117
|
-
/** Currently subscribed symbols (tickers and options) */
|
|
118
|
-
private subscribedSymbols;
|
|
119
|
-
/** Cached ticker data (for merging quote and trade events) */
|
|
120
|
-
private tickerCache;
|
|
121
|
-
/** Cached option data (for merging quote and trade events) */
|
|
122
|
-
private optionCache;
|
|
123
|
-
/**
|
|
124
|
-
* Base open interest from REST API - used as t=0 reference for live OI calculation
|
|
125
|
-
* Key: OCC symbol, Value: open interest at start of day / time of fetch
|
|
126
|
-
*/
|
|
127
|
-
private baseOpenInterest;
|
|
128
|
-
/**
|
|
129
|
-
* Cumulative estimated OI change from intraday trades
|
|
130
|
-
* Key: OCC symbol, Value: net estimated change (positive = more contracts opened)
|
|
131
|
-
*/
|
|
132
|
-
private cumulativeOIChange;
|
|
133
|
-
/**
|
|
134
|
-
* History of intraday trades with aggressor classification
|
|
135
|
-
* Key: OCC symbol, Value: array of trades
|
|
136
|
-
*/
|
|
137
|
-
private intradayTrades;
|
|
138
|
-
/** Event listeners */
|
|
139
|
-
private eventListeners;
|
|
140
|
-
/** Reconnection attempt counter */
|
|
141
|
-
private reconnectAttempts;
|
|
142
|
-
/** Maximum reconnection attempts */
|
|
143
|
-
private readonly maxReconnectAttempts;
|
|
144
|
-
/** Reconnection delay in ms (doubles with each attempt) */
|
|
145
|
-
private readonly baseReconnectDelay;
|
|
146
95
|
/** Tradier API base URL */
|
|
147
96
|
private readonly apiBaseUrl;
|
|
148
97
|
/** Tradier WebSocket URL */
|
|
149
98
|
private readonly wsUrl;
|
|
150
|
-
/** Whether to log verbose debug information */
|
|
151
|
-
private readonly verbose;
|
|
152
99
|
/**
|
|
153
100
|
* Creates a new TradierClient instance.
|
|
154
101
|
*
|
|
155
|
-
* @param
|
|
156
|
-
* @param options -
|
|
102
|
+
* @param options - Client configuration options
|
|
103
|
+
* @param options.authToken - Tradier API auth token (required)
|
|
157
104
|
* @param options.verbose - Whether to log verbose debug information (default: false)
|
|
158
105
|
*/
|
|
159
|
-
constructor(
|
|
160
|
-
verbose?: boolean;
|
|
161
|
-
});
|
|
106
|
+
constructor(options: TradierClientOptions);
|
|
162
107
|
/**
|
|
163
108
|
* Establishes a streaming connection to Tradier.
|
|
164
109
|
*
|
|
@@ -219,33 +164,6 @@ export declare class TradierClient {
|
|
|
219
164
|
* This method groups options by underlying and expiration to minimize API calls.
|
|
220
165
|
*/
|
|
221
166
|
fetchOpenInterest(occSymbols: string[]): Promise<void>;
|
|
222
|
-
/**
|
|
223
|
-
* Returns the cached option data for a symbol.
|
|
224
|
-
*
|
|
225
|
-
* @param occSymbol - OCC option symbol
|
|
226
|
-
* @returns Cached option data or undefined
|
|
227
|
-
*/
|
|
228
|
-
getOption(occSymbol: string): NormalizedOption | undefined;
|
|
229
|
-
/**
|
|
230
|
-
* Returns all cached options.
|
|
231
|
-
*
|
|
232
|
-
* @returns Map of OCC symbols to option data
|
|
233
|
-
*/
|
|
234
|
-
getAllOptions(): Map<string, NormalizedOption>;
|
|
235
|
-
/**
|
|
236
|
-
* Registers an event listener.
|
|
237
|
-
*
|
|
238
|
-
* @param event - Event type to listen for
|
|
239
|
-
* @param listener - Callback function
|
|
240
|
-
*/
|
|
241
|
-
on<T>(event: TradierClientEventType, listener: TradierEventListener<T>): this;
|
|
242
|
-
/**
|
|
243
|
-
* Removes an event listener.
|
|
244
|
-
*
|
|
245
|
-
* @param event - Event type
|
|
246
|
-
* @param listener - Callback function to remove
|
|
247
|
-
*/
|
|
248
|
-
off<T>(event: TradierClientEventType, listener: TradierEventListener<T>): this;
|
|
249
167
|
/**
|
|
250
168
|
* Creates a streaming session with Tradier API.
|
|
251
169
|
*/
|
|
@@ -304,108 +222,10 @@ export declare class TradierClient {
|
|
|
304
222
|
/**
|
|
305
223
|
* Updates option data from a timesale event.
|
|
306
224
|
* Timesale events include bid/ask at the time of the trade, enabling aggressor side detection.
|
|
307
|
-
*
|
|
308
|
-
* This is the primary method for calculating live open interest:
|
|
309
|
-
* - Aggressor side is determined by comparing trade price to NBBO
|
|
310
|
-
* - Buy aggressor (lifting ask) typically indicates new long positions → OI increases
|
|
311
|
-
* - Sell aggressor (hitting bid) typically indicates closing longs or new shorts → OI decreases
|
|
312
225
|
*/
|
|
313
226
|
private updateOptionFromTimesale;
|
|
314
|
-
/**
|
|
315
|
-
* Determines the aggressor side of a trade by comparing trade price to NBBO.
|
|
316
|
-
*
|
|
317
|
-
* @param tradePrice - The executed trade price
|
|
318
|
-
* @param bid - The bid price at time of trade
|
|
319
|
-
* @param ask - The ask price at time of trade
|
|
320
|
-
* @returns The aggressor side: 'buy' if lifting offer, 'sell' if hitting bid, 'unknown' if mid
|
|
321
|
-
*
|
|
322
|
-
* @remarks
|
|
323
|
-
* The aggressor is the party that initiated the trade by crossing the spread:
|
|
324
|
-
* - Buy aggressor: Buyer lifts the offer (trades at or above ask) → bullish intent
|
|
325
|
-
* - Sell aggressor: Seller hits the bid (trades at or below bid) → bearish intent
|
|
326
|
-
* - Unknown: Trade occurred mid-market (could be internalized, crossed, or negotiated)
|
|
327
|
-
*/
|
|
328
|
-
private determineAggressorSide;
|
|
329
|
-
/**
|
|
330
|
-
* Calculates the estimated open interest change from a single trade.
|
|
331
|
-
*
|
|
332
|
-
* @param aggressorSide - The aggressor side of the trade
|
|
333
|
-
* @param size - Number of contracts traded
|
|
334
|
-
* @param optionType - Whether this is a call or put
|
|
335
|
-
* @returns Estimated OI change (positive = OI increase, negative = OI decrease)
|
|
336
|
-
*
|
|
337
|
-
* @remarks
|
|
338
|
-
* This uses a simplified heuristic based on typical market behavior:
|
|
339
|
-
*
|
|
340
|
-
* For CALLS:
|
|
341
|
-
* - Buy aggressor (lifting offer) → typically bullish, opening new longs → +OI
|
|
342
|
-
* - Sell aggressor (hitting bid) → typically closing longs or bearish new shorts → -OI
|
|
343
|
-
*
|
|
344
|
-
* For PUTS:
|
|
345
|
-
* - Buy aggressor (lifting offer) → typically bearish/hedging, opening new longs → +OI
|
|
346
|
-
* - Sell aggressor (hitting bid) → typically closing longs → -OI
|
|
347
|
-
*
|
|
348
|
-
* Note: This is an estimate. Without knowing if trades are opening or closing,
|
|
349
|
-
* we use aggressor side as a proxy. SpotGamma and similar providers use
|
|
350
|
-
* more sophisticated models that may incorporate position sizing, strike
|
|
351
|
-
* selection patterns, and other heuristics.
|
|
352
|
-
*/
|
|
353
|
-
private calculateOIChangeFromTrade;
|
|
354
|
-
/**
|
|
355
|
-
* Calculates the live (intraday) open interest estimate for an option.
|
|
356
|
-
*
|
|
357
|
-
* @param occSymbol - OCC option symbol
|
|
358
|
-
* @returns Live OI estimate = base OI + cumulative estimated changes
|
|
359
|
-
*
|
|
360
|
-
* @remarks
|
|
361
|
-
* Live Open Interest = Base OI (from REST at t=0) + Cumulative OI Changes (from trades)
|
|
362
|
-
*
|
|
363
|
-
* This provides a real-time estimate of open interest that updates throughout
|
|
364
|
-
* the trading day as trades occur. The accuracy depends on:
|
|
365
|
-
* 1. The accuracy of aggressor side detection
|
|
366
|
-
* 2. The assumption that aggressors are typically opening new positions
|
|
367
|
-
*
|
|
368
|
-
* The official OI is only updated overnight by the OCC clearing house,
|
|
369
|
-
* so this estimate fills the gap during trading hours.
|
|
370
|
-
*/
|
|
371
|
-
private calculateLiveOpenInterest;
|
|
372
|
-
/**
|
|
373
|
-
* Returns the intraday trades for an option with aggressor classification.
|
|
374
|
-
*
|
|
375
|
-
* @param occSymbol - OCC option symbol
|
|
376
|
-
* @returns Array of intraday trades, or empty array if none
|
|
377
|
-
*/
|
|
378
|
-
getIntradayTrades(occSymbol: string): IntradayTrade[];
|
|
379
|
-
/**
|
|
380
|
-
* Returns summary statistics for intraday option flow.
|
|
381
|
-
*
|
|
382
|
-
* @param occSymbol - OCC option symbol
|
|
383
|
-
* @returns Object with buy/sell volume, net OI change, and trade count
|
|
384
|
-
*/
|
|
385
|
-
getFlowSummary(occSymbol: string): {
|
|
386
|
-
buyVolume: number;
|
|
387
|
-
sellVolume: number;
|
|
388
|
-
unknownVolume: number;
|
|
389
|
-
netOIChange: number;
|
|
390
|
-
tradeCount: number;
|
|
391
|
-
};
|
|
392
|
-
/**
|
|
393
|
-
* Resets intraday tracking data. Call this at market open or when re-fetching base OI.
|
|
394
|
-
*
|
|
395
|
-
* @param occSymbols - Optional specific symbols to reset. If not provided, resets all.
|
|
396
|
-
*/
|
|
397
|
-
resetIntradayData(occSymbols?: string[]): void;
|
|
398
227
|
/**
|
|
399
228
|
* Checks if a symbol is an OCC option symbol.
|
|
400
229
|
*/
|
|
401
|
-
private
|
|
402
|
-
/**
|
|
403
|
-
* Emits an event to all registered listeners.
|
|
404
|
-
*/
|
|
405
|
-
private emit;
|
|
406
|
-
/**
|
|
407
|
-
* Simple sleep utility.
|
|
408
|
-
*/
|
|
409
|
-
private sleep;
|
|
230
|
+
private isTradierOptionSymbol;
|
|
410
231
|
}
|
|
411
|
-
export {};
|