@adaptic/utils 0.0.383 → 0.1.1

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.
Files changed (75) hide show
  1. package/dist/index.cjs +48504 -341
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.mjs +48321 -341
  4. package/dist/index.mjs.map +1 -1
  5. package/dist/types/alpaca/client.d.ts +95 -0
  6. package/dist/types/alpaca/client.d.ts.map +1 -0
  7. package/dist/types/alpaca/crypto/data.d.ts +281 -0
  8. package/dist/types/alpaca/crypto/data.d.ts.map +1 -0
  9. package/dist/types/alpaca/crypto/index.d.ts +75 -0
  10. package/dist/types/alpaca/crypto/index.d.ts.map +1 -0
  11. package/dist/types/alpaca/crypto/orders.d.ts +221 -0
  12. package/dist/types/alpaca/crypto/orders.d.ts.map +1 -0
  13. package/dist/types/alpaca/index.d.ts +201 -0
  14. package/dist/types/alpaca/index.d.ts.map +1 -0
  15. package/dist/types/alpaca/market-data/bars.d.ts +142 -0
  16. package/dist/types/alpaca/market-data/bars.d.ts.map +1 -0
  17. package/dist/types/alpaca/market-data/index.d.ts +13 -0
  18. package/dist/types/alpaca/market-data/index.d.ts.map +1 -0
  19. package/dist/types/alpaca/market-data/news.d.ts +87 -0
  20. package/dist/types/alpaca/market-data/news.d.ts.map +1 -0
  21. package/dist/types/alpaca/market-data/quotes.d.ts +85 -0
  22. package/dist/types/alpaca/market-data/quotes.d.ts.map +1 -0
  23. package/dist/types/alpaca/market-data/trades.d.ts +98 -0
  24. package/dist/types/alpaca/market-data/trades.d.ts.map +1 -0
  25. package/dist/types/alpaca/options/contracts.d.ts +279 -0
  26. package/dist/types/alpaca/options/contracts.d.ts.map +1 -0
  27. package/dist/types/alpaca/options/data.d.ts +126 -0
  28. package/dist/types/alpaca/options/data.d.ts.map +1 -0
  29. package/dist/types/alpaca/options/index.d.ts +17 -0
  30. package/dist/types/alpaca/options/index.d.ts.map +1 -0
  31. package/dist/types/alpaca/options/orders.d.ts +366 -0
  32. package/dist/types/alpaca/options/orders.d.ts.map +1 -0
  33. package/dist/types/alpaca/options/strategies.d.ts +224 -0
  34. package/dist/types/alpaca/options/strategies.d.ts.map +1 -0
  35. package/dist/types/alpaca/streams/base-stream.d.ts +143 -0
  36. package/dist/types/alpaca/streams/base-stream.d.ts.map +1 -0
  37. package/dist/types/alpaca/streams/crypto-stream.d.ts +173 -0
  38. package/dist/types/alpaca/streams/crypto-stream.d.ts.map +1 -0
  39. package/dist/types/alpaca/streams/index.d.ts +54 -0
  40. package/dist/types/alpaca/streams/index.d.ts.map +1 -0
  41. package/dist/types/alpaca/streams/option-stream.d.ts +167 -0
  42. package/dist/types/alpaca/streams/option-stream.d.ts.map +1 -0
  43. package/dist/types/alpaca/streams/stock-stream.d.ts +176 -0
  44. package/dist/types/alpaca/streams/stock-stream.d.ts.map +1 -0
  45. package/dist/types/alpaca/streams/stream-manager.d.ts +277 -0
  46. package/dist/types/alpaca/streams/stream-manager.d.ts.map +1 -0
  47. package/dist/types/alpaca/streams/trading-stream.d.ts +186 -0
  48. package/dist/types/alpaca/streams/trading-stream.d.ts.map +1 -0
  49. package/dist/types/alpaca/streams.d.ts +88 -0
  50. package/dist/types/alpaca/streams.d.ts.map +1 -0
  51. package/dist/types/alpaca/test-imports.d.ts +7 -0
  52. package/dist/types/alpaca/test-imports.d.ts.map +1 -0
  53. package/dist/types/alpaca/trading/account.d.ts +198 -0
  54. package/dist/types/alpaca/trading/account.d.ts.map +1 -0
  55. package/dist/types/alpaca/trading/bracket-orders.d.ts +162 -0
  56. package/dist/types/alpaca/trading/bracket-orders.d.ts.map +1 -0
  57. package/dist/types/alpaca/trading/index.d.ts +13 -0
  58. package/dist/types/alpaca/trading/index.d.ts.map +1 -0
  59. package/dist/types/alpaca/trading/oco-orders.d.ts +203 -0
  60. package/dist/types/alpaca/trading/oco-orders.d.ts.map +1 -0
  61. package/dist/types/alpaca/trading/order-utils.d.ts +404 -0
  62. package/dist/types/alpaca/trading/order-utils.d.ts.map +1 -0
  63. package/dist/types/alpaca/trading/orders.d.ts +199 -0
  64. package/dist/types/alpaca/trading/orders.d.ts.map +1 -0
  65. package/dist/types/alpaca/trading/oto-orders.d.ts +282 -0
  66. package/dist/types/alpaca/trading/oto-orders.d.ts.map +1 -0
  67. package/dist/types/alpaca/trading/positions.d.ts +389 -0
  68. package/dist/types/alpaca/trading/positions.d.ts.map +1 -0
  69. package/dist/types/alpaca/trading/smart-orders.d.ts +301 -0
  70. package/dist/types/alpaca/trading/smart-orders.d.ts.map +1 -0
  71. package/dist/types/alpaca/trading/trailing-stops.d.ts +240 -0
  72. package/dist/types/alpaca/trading/trailing-stops.d.ts.map +1 -0
  73. package/dist/types/index.d.ts +353 -6
  74. package/dist/types/index.d.ts.map +1 -1
  75. package/package.json +4 -4
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Options Market Data Module
3
+ * Quotes, bars, and analytics for options using Alpaca SDK
4
+ */
5
+ import { AlpacaClient } from '../client';
6
+ import { OptionQuote, OptionTrade, OptionBar, OptionSnapshot, OptionGreeks, OptionsChainParams, OptionsChainResponse, TimeFrame } from '../../types/alpaca-types';
7
+ /**
8
+ * Error class for options data operations
9
+ */
10
+ export declare class OptionsDataError extends Error {
11
+ code: string;
12
+ symbol?: string | undefined;
13
+ details?: unknown | undefined;
14
+ constructor(message: string, code: string, symbol?: string | undefined, details?: unknown | undefined);
15
+ }
16
+ /**
17
+ * Options data feed type
18
+ */
19
+ export type OptionsFeed = 'opra' | 'indicative';
20
+ /**
21
+ * Get options chain with snapshots for an underlying symbol
22
+ * Returns option contracts with their latest quotes, trades, and Greeks
23
+ */
24
+ export declare function getOptionsChain(client: AlpacaClient, params: OptionsChainParams): Promise<OptionsChainResponse>;
25
+ /**
26
+ * Get latest option quotes for multiple symbols
27
+ */
28
+ export declare function getLatestOptionsQuotes(client: AlpacaClient, symbols: string[]): Promise<Map<string, OptionQuote>>;
29
+ /**
30
+ * Get latest option trades for multiple symbols
31
+ */
32
+ export declare function getLatestOptionsTrades(client: AlpacaClient, symbols: string[]): Promise<Map<string, OptionTrade>>;
33
+ /**
34
+ * Get option snapshots with Greeks for multiple symbols
35
+ */
36
+ export declare function getOptionsSnapshots(client: AlpacaClient, symbols: string[]): Promise<Map<string, OptionSnapshot>>;
37
+ /**
38
+ * Parameters for historical options bars request
39
+ */
40
+ export interface GetHistoricalOptionsBarsParams {
41
+ /** Option contract symbols */
42
+ symbols: string[];
43
+ /** Bar timeframe (e.g., '1Min', '1Hour', '1Day') */
44
+ timeframe: TimeFrame;
45
+ /** Start date/time */
46
+ start?: Date;
47
+ /** End date/time */
48
+ end?: Date;
49
+ /** Maximum number of bars to return */
50
+ limit?: number;
51
+ }
52
+ /**
53
+ * Get historical option bars (OHLCV data)
54
+ */
55
+ export declare function getHistoricalOptionsBars(client: AlpacaClient, params: GetHistoricalOptionsBarsParams): Promise<Map<string, OptionBar[]>>;
56
+ /**
57
+ * Calculate implied volatility from option price (simplified approximation)
58
+ * For production use, consider using a proper Black-Scholes solver
59
+ */
60
+ export declare function approximateImpliedVolatility(optionPrice: number, underlyingPrice: number, strike: number, daysToExpiration: number, riskFreeRate?: number, isCall?: boolean): number;
61
+ /**
62
+ * Calculate option moneyness
63
+ */
64
+ export declare function calculateMoneyness(underlyingPrice: number, strike: number, isCall: boolean): 'ITM' | 'ATM' | 'OTM';
65
+ /**
66
+ * Find ATM (at-the-money) strikes from an options chain
67
+ */
68
+ export declare function findATMStrikes(snapshots: Map<string, OptionSnapshot>, underlyingPrice: number): {
69
+ callSymbol: string | null;
70
+ putSymbol: string | null;
71
+ strike: number;
72
+ };
73
+ /**
74
+ * Calculate put/call ratio from options chain
75
+ */
76
+ export declare function calculatePutCallRatio(snapshots: Map<string, OptionSnapshot>): {
77
+ volumeRatio: number;
78
+ openInterestRatio: number;
79
+ };
80
+ /**
81
+ * Get option Greeks from a snapshot
82
+ */
83
+ export declare function extractGreeks(snapshot: OptionSnapshot): OptionGreeks | null;
84
+ /**
85
+ * Filter options chain by expiration date range
86
+ */
87
+ export declare function filterByExpiration(snapshots: Map<string, OptionSnapshot>, minDays: number, maxDays: number): Map<string, OptionSnapshot>;
88
+ /**
89
+ * Filter options chain by strike price range
90
+ */
91
+ export declare function filterByStrike(snapshots: Map<string, OptionSnapshot>, minStrike: number, maxStrike: number): Map<string, OptionSnapshot>;
92
+ /**
93
+ * Filter options chain by option type
94
+ */
95
+ export declare function filterByType(snapshots: Map<string, OptionSnapshot>, type: 'call' | 'put'): Map<string, OptionSnapshot>;
96
+ /**
97
+ * Get the bid-ask spread for an option
98
+ */
99
+ export declare function getOptionSpread(quote: OptionQuote): {
100
+ spread: number;
101
+ spreadPercent: number;
102
+ midPrice: number;
103
+ };
104
+ /**
105
+ * Check if an option has sufficient liquidity
106
+ */
107
+ export declare function hasGoodLiquidity(snapshot: OptionSnapshot, maxSpreadPercent?: number, minOpenInterest?: number): boolean;
108
+ declare const _default: {
109
+ getOptionsChain: typeof getOptionsChain;
110
+ getLatestOptionsQuotes: typeof getLatestOptionsQuotes;
111
+ getLatestOptionsTrades: typeof getLatestOptionsTrades;
112
+ getOptionsSnapshots: typeof getOptionsSnapshots;
113
+ getHistoricalOptionsBars: typeof getHistoricalOptionsBars;
114
+ approximateImpliedVolatility: typeof approximateImpliedVolatility;
115
+ calculateMoneyness: typeof calculateMoneyness;
116
+ findATMStrikes: typeof findATMStrikes;
117
+ calculatePutCallRatio: typeof calculatePutCallRatio;
118
+ extractGreeks: typeof extractGreeks;
119
+ filterByExpiration: typeof filterByExpiration;
120
+ filterByStrike: typeof filterByStrike;
121
+ filterByType: typeof filterByType;
122
+ getOptionSpread: typeof getOptionSpread;
123
+ hasGoodLiquidity: typeof hasGoodLiquidity;
124
+ };
125
+ export default _default;
126
+ //# sourceMappingURL=data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/options/data.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,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M,EAAE,cAAc,CAAC,EACtC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GACd,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAuB7B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,EACtC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAgB7B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,EACtC,IAAI,EAAE,MAAM,GAAG,KAAK,GACnB,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAW7B;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG;IACnD,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAMA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,cAAc,EACxB,gBAAgB,GAAE,MAAW,EAC7B,eAAe,GAAE,MAAY,GAC5B,OAAO,CAeT;;;;;;;;;;;;;;;;;;AAED,wBAgBE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Options Trading Module
3
+ * Provides functionality for options contracts, orders, strategies, and market data
4
+ */
5
+ export { getOptionContracts, getOptionContract, getOptionChain, getExpirationDates, getStrikePrices, findATMOptions, getGroupedOptionChain, findOptionsByDelta, findNearestExpiration, parseOCCSymbol, buildOCCSymbol, isContractTradable, getDaysToExpiration, isExpiringWithin, } from './contracts';
6
+ export type { GetOptionChainParams, ATMOptionsResult, GroupedOptionChain, } from './contracts';
7
+ export { default as contracts } from './contracts';
8
+ export { createOptionOrder, buyToOpen, sellToClose, sellToOpen, buyToClose, validateMultiLegOrder, createMultiLegOptionOrder, createVerticalSpread, createIronCondor, createStraddle, createStrangle, closeOptionPosition, closeAllOptionPositions, exerciseOption, isOptionOrderTerminal, isOptionOrderCancelable, } from './orders';
9
+ export type { SingleLegOptionOrderParams, CloseOptionPositionParams, CloseAllOptionsResult, ExerciseOptionParams, MultiLegValidationResult, } from './orders';
10
+ export { default as orders } from './orders';
11
+ export { buildOptionSymbol, createVerticalSpread as createVerticalSpreadAdvanced, createIronCondor as createIronCondorAdvanced, createStraddle as createStraddleAdvanced, createCoveredCall, rollOptionPosition, createStrangle as createStrangleAdvanced, createButterflySpread, OptionStrategyError, } from './strategies';
12
+ export type { VerticalSpreadParams, IronCondorParams, StraddleParams, CoveredCallParams, RollPositionParams, StrangleParams, ButterflySpreadParams, } from './strategies';
13
+ export { default as strategies } from './strategies';
14
+ export { getOptionsChain, getLatestOptionsQuotes, getLatestOptionsTrades, getOptionsSnapshots, getHistoricalOptionsBars, approximateImpliedVolatility, calculateMoneyness, findATMStrikes, calculatePutCallRatio, extractGreeks, filterByExpiration, filterByStrike, filterByType, getOptionSpread, hasGoodLiquidity, OptionsDataError, } from './data';
15
+ export type { OptionsFeed, GetHistoricalOptionsBarsParams, } from './data';
16
+ export { default as data } from './data';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/options/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAEL,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,qBAAqB,EAGrB,cAAc,EACd,cAAc,EACd,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO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Module
3
+ * Create and manage option orders
4
+ */
5
+ import { AlpacaClient } from '../client';
6
+ import { AlpacaOrder, PositionIntent, TimeInForce, CreateMultiLegOrderParams, OrderStatus } from '../../types/alpaca-types';
7
+ /**
8
+ * Parameters for creating a single-leg option order
9
+ */
10
+ export interface SingleLegOptionOrderParams {
11
+ /** Option contract symbol (e.g., AAPL230120C00150000) */
12
+ symbol: string;
13
+ /** Number of contracts to trade */
14
+ qty: number;
15
+ /** Order side: buy or sell */
16
+ side: 'buy' | 'sell';
17
+ /** Order type: market or limit */
18
+ type: 'market' | 'limit';
19
+ /** Limit price for limit orders (price per share, not per contract) */
20
+ limitPrice?: number;
21
+ /** Position intent: indicates opening or closing a position */
22
+ positionIntent: PositionIntent;
23
+ /** Time in force: day, gtc, ioc, fok, opg, cls */
24
+ timeInForce?: TimeInForce;
25
+ /** Optional client order ID for tracking */
26
+ clientOrderId?: string;
27
+ }
28
+ /**
29
+ * Parameters for closing an option position
30
+ */
31
+ export interface CloseOptionPositionParams {
32
+ /** Specific quantity to close (defaults to full position) */
33
+ qty?: number;
34
+ /** Limit price for limit order close */
35
+ limitPrice?: number;
36
+ /** Time in force for the close order */
37
+ timeInForce?: TimeInForce;
38
+ }
39
+ /**
40
+ * Result of closing all option positions
41
+ */
42
+ export interface CloseAllOptionsResult {
43
+ /** Orders created for closing positions */
44
+ orders: AlpacaOrder[];
45
+ /** Positions that failed to close */
46
+ failed: {
47
+ symbol: string;
48
+ error: string;
49
+ }[];
50
+ /** Total number of positions processed */
51
+ totalProcessed: number;
52
+ }
53
+ /**
54
+ * Parameters for exercising an option
55
+ */
56
+ export interface ExerciseOptionParams {
57
+ /** Option contract symbol */
58
+ symbol: string;
59
+ /** Number of contracts to exercise (defaults to full position) */
60
+ qty?: number;
61
+ }
62
+ /**
63
+ * Multi-leg order validation result
64
+ */
65
+ export interface MultiLegValidationResult {
66
+ /** Whether the order is valid */
67
+ isValid: boolean;
68
+ /** Validation errors if any */
69
+ errors: string[];
70
+ /** Validation warnings if any */
71
+ warnings: string[];
72
+ }
73
+ /**
74
+ * Create a single-leg option order
75
+ *
76
+ * @param client - The AlpacaClient instance
77
+ * @param params - Order parameters
78
+ * @returns The created order
79
+ * @throws Error if order creation fails
80
+ *
81
+ * @example
82
+ * // Buy to open 5 call contracts
83
+ * const order = await createOptionOrder(client, {
84
+ * symbol: 'AAPL230120C00150000',
85
+ * qty: 5,
86
+ * side: 'buy',
87
+ * type: 'limit',
88
+ * limitPrice: 2.50,
89
+ * positionIntent: 'buy_to_open',
90
+ * timeInForce: 'day',
91
+ * });
92
+ *
93
+ * @example
94
+ * // Sell to close with market order
95
+ * const order = await createOptionOrder(client, {
96
+ * symbol: 'AAPL230120C00150000',
97
+ * qty: 5,
98
+ * side: 'sell',
99
+ * type: 'market',
100
+ * positionIntent: 'sell_to_close',
101
+ * });
102
+ */
103
+ export declare function createOptionOrder(client: AlpacaClient, params: SingleLegOptionOrderParams): Promise<AlpacaOrder>;
104
+ /**
105
+ * Buy to open option contracts
106
+ *
107
+ * @param client - The AlpacaClient instance
108
+ * @param symbol - Option contract symbol
109
+ * @param qty - Number of contracts
110
+ * @param limitPrice - Optional limit price (market order if not provided)
111
+ * @param timeInForce - Time in force (default: day)
112
+ * @returns The created order
113
+ *
114
+ * @example
115
+ * const order = await buyToOpen(client, 'AAPL230120C00150000', 5, 2.50);
116
+ */
117
+ export declare function buyToOpen(client: AlpacaClient, symbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
118
+ /**
119
+ * Sell to close option contracts
120
+ *
121
+ * @param client - The AlpacaClient instance
122
+ * @param symbol - Option contract symbol
123
+ * @param qty - Number of contracts
124
+ * @param limitPrice - Optional limit price (market order if not provided)
125
+ * @param timeInForce - Time in force (default: day)
126
+ * @returns The created order
127
+ *
128
+ * @example
129
+ * const order = await sellToClose(client, 'AAPL230120C00150000', 5, 3.00);
130
+ */
131
+ export declare function sellToClose(client: AlpacaClient, symbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
132
+ /**
133
+ * Sell to open option contracts (short selling options)
134
+ *
135
+ * @param client - The AlpacaClient instance
136
+ * @param symbol - Option contract symbol
137
+ * @param qty - Number of contracts
138
+ * @param limitPrice - Optional limit price (market order if not provided)
139
+ * @param timeInForce - Time in force (default: day)
140
+ * @returns The created order
141
+ *
142
+ * @example
143
+ * const order = await sellToOpen(client, 'AAPL230120P00140000', 5, 1.50);
144
+ */
145
+ export declare function sellToOpen(client: AlpacaClient, symbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
146
+ /**
147
+ * Buy to close option contracts (closing short options)
148
+ *
149
+ * @param client - The AlpacaClient instance
150
+ * @param symbol - Option contract symbol
151
+ * @param qty - Number of contracts
152
+ * @param limitPrice - Optional limit price (market order if not provided)
153
+ * @param timeInForce - Time in force (default: day)
154
+ * @returns The created order
155
+ *
156
+ * @example
157
+ * const order = await buyToClose(client, 'AAPL230120P00140000', 5, 0.50);
158
+ */
159
+ export declare function buyToClose(client: AlpacaClient, symbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
160
+ /**
161
+ * Validate multi-leg order parameters
162
+ *
163
+ * @param params - Multi-leg order parameters
164
+ * @returns Validation result with errors and warnings
165
+ */
166
+ export declare function validateMultiLegOrder(params: CreateMultiLegOrderParams): MultiLegValidationResult;
167
+ /**
168
+ * Create a multi-leg option order (spreads, straddles, etc.)
169
+ *
170
+ * @param client - The AlpacaClient instance
171
+ * @param params - Multi-leg order parameters
172
+ * @returns The created order
173
+ * @throws Error if validation fails or order creation fails
174
+ *
175
+ * @example
176
+ * // Create a vertical call spread
177
+ * const order = await createMultiLegOptionOrder(client, {
178
+ * order_class: 'mleg',
179
+ * qty: '1',
180
+ * type: 'limit',
181
+ * limit_price: '1.50',
182
+ * time_in_force: 'day',
183
+ * legs: [
184
+ * {
185
+ * symbol: 'AAPL230120C00150000',
186
+ * ratio_qty: '1',
187
+ * side: 'buy',
188
+ * position_intent: 'buy_to_open',
189
+ * },
190
+ * {
191
+ * symbol: 'AAPL230120C00155000',
192
+ * ratio_qty: '1',
193
+ * side: 'sell',
194
+ * position_intent: 'sell_to_open',
195
+ * },
196
+ * ],
197
+ * });
198
+ */
199
+ export declare function createMultiLegOptionOrder(client: AlpacaClient, params: CreateMultiLegOrderParams): Promise<AlpacaOrder>;
200
+ /**
201
+ * Create a vertical spread (bull call spread or bear put spread)
202
+ *
203
+ * @param client - The AlpacaClient instance
204
+ * @param longSymbol - Symbol of the long leg
205
+ * @param shortSymbol - Symbol of the short leg
206
+ * @param qty - Number of spreads
207
+ * @param limitPrice - Net debit or credit for the spread
208
+ * @param timeInForce - Time in force (default: day)
209
+ * @returns The created order
210
+ *
211
+ * @example
212
+ * // Bull call spread: buy lower strike call, sell higher strike call
213
+ * const order = await createVerticalSpread(
214
+ * client,
215
+ * 'AAPL230120C00150000', // Long leg
216
+ * 'AAPL230120C00155000', // Short leg
217
+ * 5,
218
+ * 1.50 // Net debit
219
+ * );
220
+ */
221
+ export declare function createVerticalSpread(client: AlpacaClient, longSymbol: string, shortSymbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
222
+ /**
223
+ * Create an iron condor spread
224
+ *
225
+ * @param client - The AlpacaClient instance
226
+ * @param putLongSymbol - Lower strike put (buy)
227
+ * @param putShortSymbol - Higher strike put (sell)
228
+ * @param callShortSymbol - Lower strike call (sell)
229
+ * @param callLongSymbol - Higher strike call (buy)
230
+ * @param qty - Number of iron condors
231
+ * @param limitPrice - Net credit for the iron condor
232
+ * @param timeInForce - Time in force (default: day)
233
+ * @returns The created order
234
+ *
235
+ * @example
236
+ * const order = await createIronCondor(
237
+ * client,
238
+ * 'AAPL230120P00140000', // Buy put
239
+ * 'AAPL230120P00145000', // Sell put
240
+ * 'AAPL230120C00155000', // Sell call
241
+ * 'AAPL230120C00160000', // Buy call
242
+ * 5,
243
+ * 2.00 // Net credit
244
+ * );
245
+ */
246
+ export declare function createIronCondor(client: AlpacaClient, putLongSymbol: string, putShortSymbol: string, callShortSymbol: string, callLongSymbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
247
+ /**
248
+ * Create a straddle (buy both call and put at same strike)
249
+ *
250
+ * @param client - The AlpacaClient instance
251
+ * @param callSymbol - Call option symbol
252
+ * @param putSymbol - Put option symbol
253
+ * @param qty - Number of straddles
254
+ * @param limitPrice - Net debit for the straddle
255
+ * @param timeInForce - Time in force (default: day)
256
+ * @returns The created order
257
+ *
258
+ * @example
259
+ * const order = await createStraddle(
260
+ * client,
261
+ * 'AAPL230120C00150000',
262
+ * 'AAPL230120P00150000',
263
+ * 5,
264
+ * 6.00 // Net debit
265
+ * );
266
+ */
267
+ export declare function createStraddle(client: AlpacaClient, callSymbol: string, putSymbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
268
+ /**
269
+ * Create a strangle (buy OTM call and OTM put at different strikes)
270
+ *
271
+ * @param client - The AlpacaClient instance
272
+ * @param callSymbol - OTM call option symbol
273
+ * @param putSymbol - OTM put option symbol
274
+ * @param qty - Number of strangles
275
+ * @param limitPrice - Net debit for the strangle
276
+ * @param timeInForce - Time in force (default: day)
277
+ * @returns The created order
278
+ */
279
+ export declare function createStrangle(client: AlpacaClient, callSymbol: string, putSymbol: string, qty: number, limitPrice?: number, timeInForce?: TimeInForce): Promise<AlpacaOrder>;
280
+ /**
281
+ * Close an option position
282
+ *
283
+ * @param client - The AlpacaClient instance
284
+ * @param symbol - Option contract symbol
285
+ * @param options - Optional close parameters
286
+ * @returns The close order
287
+ * @throws Error if position not found or close fails
288
+ *
289
+ * @example
290
+ * // Close entire position with market order
291
+ * const order = await closeOptionPosition(client, 'AAPL230120C00150000');
292
+ *
293
+ * @example
294
+ * // Close partial position with limit order
295
+ * const order = await closeOptionPosition(client, 'AAPL230120C00150000', {
296
+ * qty: 2,
297
+ * limitPrice: 3.00,
298
+ * });
299
+ */
300
+ export declare function closeOptionPosition(client: AlpacaClient, symbol: string, options?: CloseOptionPositionParams): Promise<AlpacaOrder>;
301
+ /**
302
+ * Close all option positions
303
+ *
304
+ * @param client - The AlpacaClient instance
305
+ * @returns Result containing orders and any failures
306
+ *
307
+ * @example
308
+ * const result = await closeAllOptionPositions(client);
309
+ * console.log(`Closed ${result.orders.length} positions`);
310
+ * if (result.failed.length > 0) {
311
+ * console.log(`Failed to close: ${result.failed.map(f => f.symbol).join(', ')}`);
312
+ * }
313
+ */
314
+ export declare function closeAllOptionPositions(client: AlpacaClient): Promise<CloseAllOptionsResult>;
315
+ /**
316
+ * Exercise an option contract
317
+ * Note: Exercise is only available for American-style options before expiration
318
+ *
319
+ * @param client - The AlpacaClient instance
320
+ * @param symbol - Option contract symbol
321
+ * @param qty - Number of contracts to exercise (defaults to full position)
322
+ * @throws Error if exercise fails
323
+ *
324
+ * @example
325
+ * // Exercise all contracts in position
326
+ * await exerciseOption(client, 'AAPL230120C00150000');
327
+ *
328
+ * @example
329
+ * // Exercise specific quantity
330
+ * await exerciseOption(client, 'AAPL230120C00150000', 5);
331
+ */
332
+ export declare function exerciseOption(client: AlpacaClient, symbol: string, qty?: number): Promise<void>;
333
+ /**
334
+ * Check if an option order is in a terminal state
335
+ *
336
+ * @param status - The order status
337
+ * @returns True if the order is in a terminal state
338
+ */
339
+ export declare function isOptionOrderTerminal(status: OrderStatus): boolean;
340
+ /**
341
+ * Check if an option order can be canceled
342
+ *
343
+ * @param status - The order status
344
+ * @returns True if the order can be canceled
345
+ */
346
+ export declare function isOptionOrderCancelable(status: OrderStatus): boolean;
347
+ declare const _default: {
348
+ createOptionOrder: typeof createOptionOrder;
349
+ buyToOpen: typeof buyToOpen;
350
+ sellToClose: typeof sellToClose;
351
+ sellToOpen: typeof sellToOpen;
352
+ buyToClose: typeof buyToClose;
353
+ validateMultiLegOrder: typeof validateMultiLegOrder;
354
+ createMultiLegOptionOrder: typeof createMultiLegOptionOrder;
355
+ createVerticalSpread: typeof createVerticalSpread;
356
+ createIronCondor: typeof createIronCondor;
357
+ createStraddle: typeof createStraddle;
358
+ createStrangle: typeof createStrangle;
359
+ closeOptionPosition: typeof closeOptionPosition;
360
+ closeAllOptionPositions: typeof closeAllOptionPositions;
361
+ exerciseOption: typeof exerciseOption;
362
+ isOptionOrderTerminal: typeof isOptionOrderTerminal;
363
+ isOptionOrderCancelable: typeof isOptionOrderCancelable;
364
+ };
365
+ export default _default;
366
+ //# sourceMappingURL=orders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/options/orders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EACL,WAAW,EAEX,cAAc,EACd,WAAW,EACX,yBAAyB,EAEzB,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAelC;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,yDAAyD;IACzD,MAAM,EAAE,MAAM,CAAC;IACf,mCAAmC;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,kCAAkC;IAClC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,uEAAuE;IACvE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,cAAc,EAAE,cAAc,CAAC;IAC/B,kDAAkD;IAClD,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,4CAA4C;IAC5C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,6DAA6D;IAC7D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wCAAwC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,WAAW,CAAC,EAAE,WAAW,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