@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.
- package/dist/index.cjs +48504 -341
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +48321 -341
- 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,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crypto Orders Module
|
|
3
|
+
* Create and manage cryptocurrency orders
|
|
4
|
+
* Crypto trading is available 24/7 on Alpaca
|
|
5
|
+
*/
|
|
6
|
+
import { AlpacaClient } from '../client';
|
|
7
|
+
import { AlpacaOrder, OrderSide, OrderType, TimeInForce } from '../../types/alpaca-types';
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when crypto order operations fail
|
|
10
|
+
*/
|
|
11
|
+
export declare class CryptoOrderError extends Error {
|
|
12
|
+
code: string;
|
|
13
|
+
symbol?: string | undefined;
|
|
14
|
+
details?: unknown | undefined;
|
|
15
|
+
constructor(message: string, code: string, symbol?: string | undefined, details?: unknown | undefined);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parameters for creating a crypto order
|
|
19
|
+
* Crypto trading is available 24/7
|
|
20
|
+
*/
|
|
21
|
+
export interface CryptoOrderParams {
|
|
22
|
+
/** Crypto pair symbol (e.g., 'BTC/USD', 'ETH/USD') */
|
|
23
|
+
symbol: string;
|
|
24
|
+
/** Quantity to trade (mutually exclusive with notional) */
|
|
25
|
+
qty?: number;
|
|
26
|
+
/** Dollar amount to trade (mutually exclusive with qty) */
|
|
27
|
+
notional?: number;
|
|
28
|
+
/** Order side: 'buy' or 'sell' */
|
|
29
|
+
side: OrderSide;
|
|
30
|
+
/** Order type: 'market', 'limit', 'stop', 'stop_limit' */
|
|
31
|
+
type: OrderType;
|
|
32
|
+
/** Limit price for limit/stop_limit orders */
|
|
33
|
+
limitPrice?: number;
|
|
34
|
+
/** Stop price for stop/stop_limit orders */
|
|
35
|
+
stopPrice?: number;
|
|
36
|
+
/** Time in force - typically 'gtc' for crypto */
|
|
37
|
+
timeInForce?: TimeInForce;
|
|
38
|
+
/** Optional client-specified order ID */
|
|
39
|
+
clientOrderId?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a crypto order
|
|
43
|
+
* Crypto trading is available 24/7 on Alpaca
|
|
44
|
+
*
|
|
45
|
+
* @param client - The AlpacaClient instance
|
|
46
|
+
* @param params - Crypto order parameters
|
|
47
|
+
* @returns The created order
|
|
48
|
+
* @throws CryptoOrderError if order creation fails
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Buy 0.5 BTC at market price
|
|
52
|
+
* const order = await createCryptoOrder(client, {
|
|
53
|
+
* symbol: 'BTC/USD',
|
|
54
|
+
* qty: 0.5,
|
|
55
|
+
* side: 'buy',
|
|
56
|
+
* type: 'market',
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Buy $100 worth of ETH
|
|
61
|
+
* const order = await createCryptoOrder(client, {
|
|
62
|
+
* symbol: 'ETH/USD',
|
|
63
|
+
* notional: 100,
|
|
64
|
+
* side: 'buy',
|
|
65
|
+
* type: 'market',
|
|
66
|
+
* });
|
|
67
|
+
*/
|
|
68
|
+
export declare function createCryptoOrder(client: AlpacaClient, params: CryptoOrderParams): Promise<AlpacaOrder>;
|
|
69
|
+
/**
|
|
70
|
+
* Create a crypto market order
|
|
71
|
+
* Executes immediately at the current market price
|
|
72
|
+
*
|
|
73
|
+
* @param client - The AlpacaClient instance
|
|
74
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
75
|
+
* @param side - Order side: 'buy' or 'sell'
|
|
76
|
+
* @param qty - Quantity to trade
|
|
77
|
+
* @returns The created order
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* const order = await createCryptoMarketOrder(client, 'BTC/USD', 'buy', 0.1);
|
|
81
|
+
*/
|
|
82
|
+
export declare function createCryptoMarketOrder(client: AlpacaClient, symbol: string, side: OrderSide, qty: number): Promise<AlpacaOrder>;
|
|
83
|
+
/**
|
|
84
|
+
* Create a crypto limit order
|
|
85
|
+
* Executes only at the specified price or better
|
|
86
|
+
*
|
|
87
|
+
* @param client - The AlpacaClient instance
|
|
88
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
89
|
+
* @param side - Order side: 'buy' or 'sell'
|
|
90
|
+
* @param qty - Quantity to trade
|
|
91
|
+
* @param limitPrice - Maximum (buy) or minimum (sell) price
|
|
92
|
+
* @returns The created order
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Buy 0.5 BTC at $40,000 or lower
|
|
96
|
+
* const order = await createCryptoLimitOrder(client, 'BTC/USD', 'buy', 0.5, 40000);
|
|
97
|
+
*/
|
|
98
|
+
export declare function createCryptoLimitOrder(client: AlpacaClient, symbol: string, side: OrderSide, qty: number, limitPrice: number): Promise<AlpacaOrder>;
|
|
99
|
+
/**
|
|
100
|
+
* Create a crypto stop order
|
|
101
|
+
* Becomes a market order when the stop price is reached
|
|
102
|
+
*
|
|
103
|
+
* @param client - The AlpacaClient instance
|
|
104
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
105
|
+
* @param side - Order side: 'buy' or 'sell'
|
|
106
|
+
* @param qty - Quantity to trade
|
|
107
|
+
* @param stopPrice - Price at which to trigger the order
|
|
108
|
+
* @returns The created order
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* // Sell 0.5 BTC if price drops to $35,000
|
|
112
|
+
* const order = await createCryptoStopOrder(client, 'BTC/USD', 'sell', 0.5, 35000);
|
|
113
|
+
*/
|
|
114
|
+
export declare function createCryptoStopOrder(client: AlpacaClient, symbol: string, side: OrderSide, qty: number, stopPrice: number): Promise<AlpacaOrder>;
|
|
115
|
+
/**
|
|
116
|
+
* Create a crypto stop-limit order
|
|
117
|
+
* Becomes a limit order when the stop price is reached
|
|
118
|
+
*
|
|
119
|
+
* @param client - The AlpacaClient instance
|
|
120
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
121
|
+
* @param side - Order side: 'buy' or 'sell'
|
|
122
|
+
* @param qty - Quantity to trade
|
|
123
|
+
* @param stopPrice - Price at which to trigger the limit order
|
|
124
|
+
* @param limitPrice - Limit price for the resulting order
|
|
125
|
+
* @returns The created order
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // Sell 0.5 BTC when price drops to $35,000, but not below $34,500
|
|
129
|
+
* const order = await createCryptoStopLimitOrder(client, 'BTC/USD', 'sell', 0.5, 35000, 34500);
|
|
130
|
+
*/
|
|
131
|
+
export declare function createCryptoStopLimitOrder(client: AlpacaClient, symbol: string, side: OrderSide, qty: number, stopPrice: number, limitPrice: number): Promise<AlpacaOrder>;
|
|
132
|
+
/**
|
|
133
|
+
* Buy crypto with a dollar amount (notional order)
|
|
134
|
+
* Allows purchasing crypto with a specific USD amount
|
|
135
|
+
*
|
|
136
|
+
* @param client - The AlpacaClient instance
|
|
137
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
138
|
+
* @param dollarAmount - Amount in USD to spend
|
|
139
|
+
* @returns The created order
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* // Buy $500 worth of Bitcoin
|
|
143
|
+
* const order = await buyCryptoNotional(client, 'BTC/USD', 500);
|
|
144
|
+
*/
|
|
145
|
+
export declare function buyCryptoNotional(client: AlpacaClient, symbol: string, dollarAmount: number): Promise<AlpacaOrder>;
|
|
146
|
+
/**
|
|
147
|
+
* Sell crypto for a dollar amount (notional order)
|
|
148
|
+
* Allows selling crypto for a specific USD amount
|
|
149
|
+
*
|
|
150
|
+
* @param client - The AlpacaClient instance
|
|
151
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
152
|
+
* @param dollarAmount - Amount in USD to receive
|
|
153
|
+
* @returns The created order
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Sell $200 worth of Ethereum
|
|
157
|
+
* const order = await sellCryptoNotional(client, 'ETH/USD', 200);
|
|
158
|
+
*/
|
|
159
|
+
export declare function sellCryptoNotional(client: AlpacaClient, symbol: string, dollarAmount: number): Promise<AlpacaOrder>;
|
|
160
|
+
/**
|
|
161
|
+
* Sell all of a crypto position
|
|
162
|
+
* Closes the entire position for the specified crypto pair
|
|
163
|
+
*
|
|
164
|
+
* @param client - The AlpacaClient instance
|
|
165
|
+
* @param symbol - Crypto pair symbol (e.g., 'BTC/USD')
|
|
166
|
+
* @returns The close order
|
|
167
|
+
* @throws CryptoOrderError if no position exists or close fails
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* const order = await sellAllCrypto(client, 'BTC/USD');
|
|
171
|
+
*/
|
|
172
|
+
export declare function sellAllCrypto(client: AlpacaClient, symbol: string): Promise<AlpacaOrder>;
|
|
173
|
+
/**
|
|
174
|
+
* Get all open crypto orders
|
|
175
|
+
*
|
|
176
|
+
* @param client - The AlpacaClient instance
|
|
177
|
+
* @param symbols - Optional array of crypto symbols to filter by
|
|
178
|
+
* @returns Array of open crypto orders
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* const orders = await getOpenCryptoOrders(client);
|
|
182
|
+
* const btcOrders = await getOpenCryptoOrders(client, ['BTC/USD']);
|
|
183
|
+
*/
|
|
184
|
+
export declare function getOpenCryptoOrders(client: AlpacaClient, symbols?: string[]): Promise<AlpacaOrder[]>;
|
|
185
|
+
/**
|
|
186
|
+
* Cancel all open crypto orders
|
|
187
|
+
*
|
|
188
|
+
* @param client - The AlpacaClient instance
|
|
189
|
+
* @param symbol - Optional specific crypto symbol to cancel orders for
|
|
190
|
+
* @returns Number of orders canceled
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* // Cancel all crypto orders
|
|
194
|
+
* const canceled = await cancelAllCryptoOrders(client);
|
|
195
|
+
*
|
|
196
|
+
* // Cancel only BTC orders
|
|
197
|
+
* const canceled = await cancelAllCryptoOrders(client, 'BTC/USD');
|
|
198
|
+
*/
|
|
199
|
+
export declare function cancelAllCryptoOrders(client: AlpacaClient, symbol?: string): Promise<number>;
|
|
200
|
+
/**
|
|
201
|
+
* Check if a symbol is a valid crypto pair
|
|
202
|
+
*
|
|
203
|
+
* @param symbol - Symbol to check
|
|
204
|
+
* @returns true if the symbol appears to be a crypto pair
|
|
205
|
+
*/
|
|
206
|
+
export declare function isCryptoPair(symbol: string): boolean;
|
|
207
|
+
declare const _default: {
|
|
208
|
+
createCryptoOrder: typeof createCryptoOrder;
|
|
209
|
+
createCryptoMarketOrder: typeof createCryptoMarketOrder;
|
|
210
|
+
createCryptoLimitOrder: typeof createCryptoLimitOrder;
|
|
211
|
+
createCryptoStopOrder: typeof createCryptoStopOrder;
|
|
212
|
+
createCryptoStopLimitOrder: typeof createCryptoStopLimitOrder;
|
|
213
|
+
buyCryptoNotional: typeof buyCryptoNotional;
|
|
214
|
+
sellCryptoNotional: typeof sellCryptoNotional;
|
|
215
|
+
sellAllCrypto: typeof sellAllCrypto;
|
|
216
|
+
getOpenCryptoOrders: typeof getOpenCryptoOrders;
|
|
217
|
+
cancelAllCryptoOrders: typeof cancelAllCryptoOrders;
|
|
218
|
+
isCryptoPair: typeof isCryptoPair;
|
|
219
|
+
};
|
|
220
|
+
export default _default;
|
|
221
|
+
//# sourceMappingURL=orders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orders.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/crypto/orders.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,OAAO,EACL,WAAW,EACX,SAAS,EACT,SAAS,EACT,WAAW,EAEZ,MAAM,0B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wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAGpD;;;;;;;;;;;;;;AAED,wBAYE"}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Alpaca Module
|
|
3
|
+
* Unified export of all Alpaca functionality using official SDK
|
|
4
|
+
*
|
|
5
|
+
* @module @adaptic/utils/alpaca
|
|
6
|
+
*/
|
|
7
|
+
export * from './client';
|
|
8
|
+
export * from './trading';
|
|
9
|
+
export { getLatestQuote, getLatestQuotes, getSpread, getSpreads, hasGoodLiquidity as hasStockLiquidity, QuoteError, type SpreadInfo, } from './market-data/quotes';
|
|
10
|
+
export { getBars, getLatestBars, getDailyPrices, getIntradayPrices, getPreviousClose, analyzeBars, getPriceRange, getAverageDailyVolume, hasSufficientVolume, BarError, type GetBarsParams, type BarAnalysis, } from './market-data/bars';
|
|
11
|
+
export { getLatestTrade, getLatestTrades, getHistoricalTrades, getCurrentPrice, getCurrentPrices, getTradeVolume, TradeError, type GetHistoricalTradesParams, } from './market-data/trades';
|
|
12
|
+
export { getNews, getLatestNews, searchNews, getNewsForSymbols, getSymbolSentiment, NewsError, type GetNewsParams, } from './market-data/news';
|
|
13
|
+
export { getOptionContracts, getOptionContract, getOptionChain, getExpirationDates, getStrikePrices, findATMOptions, getGroupedOptionChain, findOptionsByDelta, findNearestExpiration, parseOCCSymbol, buildOCCSymbol, isContractTradable, getDaysToExpiration, isExpiringWithin, type GetOptionChainParams, type ATMOptionsResult, type GroupedOptionChain, } from './options/contracts';
|
|
14
|
+
export { createOptionOrder, buyToOpen, sellToClose, sellToOpen, buyToClose, validateMultiLegOrder, createMultiLegOptionOrder, createVerticalSpread, createIronCondor, createStraddle, createStrangle, closeOptionPosition, closeAllOptionPositions, exerciseOption, isOptionOrderTerminal, isOptionOrderCancelable, type SingleLegOptionOrderParams, type CloseOptionPositionParams, type CloseAllOptionsResult, type ExerciseOptionParams, type MultiLegValidationResult, } from './options/orders';
|
|
15
|
+
export { buildOptionSymbol, createVerticalSpread as createVerticalSpreadAdvanced, createIronCondor as createIronCondorAdvanced, createStraddle as createStraddleAdvanced, createCoveredCall, rollOptionPosition, createStrangle as createStrangleAdvanced, createButterflySpread, OptionStrategyError, type VerticalSpreadParams, type IronCondorParams, type StraddleParams, type CoveredCallParams, type RollPositionParams, type StrangleParams, type ButterflySpreadParams, } from './options/strategies';
|
|
16
|
+
export { getOptionsChain, getLatestOptionsQuotes, getLatestOptionsTrades, getOptionsSnapshots, getHistoricalOptionsBars, approximateImpliedVolatility, calculateMoneyness, findATMStrikes, calculatePutCallRatio, extractGreeks, filterByExpiration, filterByStrike, filterByType, getOptionSpread, hasGoodLiquidity as hasOptionLiquidity, OptionsDataError, type OptionsFeed, type GetHistoricalOptionsBarsParams, } from './options/data';
|
|
17
|
+
export { CryptoOrderError, CryptoOrderParams, createCryptoOrder, createCryptoMarketOrder, createCryptoLimitOrder, createCryptoStopOrder, createCryptoStopLimitOrder, buyCryptoNotional, sellCryptoNotional, sellAllCrypto, getOpenCryptoOrders, cancelAllCryptoOrders, isCryptoPair, } from './crypto/orders';
|
|
18
|
+
export { CryptoDataError, CryptoTrade, CryptoQuote, GetCryptoBarsParams, CryptoSnapshot, getCryptoBars, getLatestCryptoTrades, getLatestCryptoQuotes, getCryptoPrice, getCryptoSpread, getCryptoSnapshots, getCryptoTrades, getCryptoDailyPrices, getCrypto24HourChange, getSupportedCryptoPairs, getCryptoPairsByQuote, isSupportedCryptoPair, getPopularCryptoPairs, BTC_PAIRS, USDT_PAIRS, USDC_PAIRS, USD_PAIRS, } from './crypto/data';
|
|
19
|
+
export * from './streams';
|
|
20
|
+
import { createAlpacaClient, AlpacaClient, AlpacaClientConfig, createClientFromEnv, clearClientCache } from './client';
|
|
21
|
+
import * as trading from './trading/orders';
|
|
22
|
+
import * as orderUtils from './trading/order-utils';
|
|
23
|
+
import * as bracketOrders from './trading/bracket-orders';
|
|
24
|
+
import * as ocoOrders from './trading/oco-orders';
|
|
25
|
+
import * as otoOrders from './trading/oto-orders';
|
|
26
|
+
import * as trailingStops from './trading/trailing-stops';
|
|
27
|
+
import * as smartOrders from './trading/smart-orders';
|
|
28
|
+
import * as positions from './trading/positions';
|
|
29
|
+
import * as account from './trading/account';
|
|
30
|
+
import * as quotes from './market-data/quotes';
|
|
31
|
+
import * as bars from './market-data/bars';
|
|
32
|
+
import * as trades from './market-data/trades';
|
|
33
|
+
import * as news from './market-data/news';
|
|
34
|
+
import * as optionContracts from './options/contracts';
|
|
35
|
+
import * as optionOrders from './options/orders';
|
|
36
|
+
import * as optionStrategies from './options/strategies';
|
|
37
|
+
import * as optionData from './options/data';
|
|
38
|
+
import * as cryptoOrders from './crypto/orders';
|
|
39
|
+
import * as cryptoData from './crypto/data';
|
|
40
|
+
import * as streams from './streams';
|
|
41
|
+
/**
|
|
42
|
+
* Alpaca namespace for convenient access to all functionality
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* import { alpaca } from '@adaptic/utils';
|
|
47
|
+
*
|
|
48
|
+
* // Create client
|
|
49
|
+
* const client = alpaca.createClient({
|
|
50
|
+
* apiKey: 'your-api-key',
|
|
51
|
+
* apiSecret: 'your-api-secret',
|
|
52
|
+
* accountType: 'PAPER',
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Use trading functions
|
|
56
|
+
* const order = await alpaca.orders.createOrder(client, { ... });
|
|
57
|
+
*
|
|
58
|
+
* // Use market data functions
|
|
59
|
+
* const quote = await alpaca.quotes.getLatestQuote(client, 'AAPL');
|
|
60
|
+
*
|
|
61
|
+
* // Use smart orders
|
|
62
|
+
* const bracket = await alpaca.smartOrders.createSmartOrder(client, { ... });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const alpaca: {
|
|
66
|
+
createClient: typeof createAlpacaClient;
|
|
67
|
+
createClientFromEnv: typeof createClientFromEnv;
|
|
68
|
+
clearClientCache: typeof clearClientCache;
|
|
69
|
+
orders: {
|
|
70
|
+
getOrdersBySymbol(client: AlpacaClient, symbol: string, params?: Omit<import("..").GetOrdersParams, "symbols">): Promise<import("..").AlpacaOrder[]>;
|
|
71
|
+
getOpenOrders(client: AlpacaClient, params?: Omit<import("..").GetOrdersParams, "status">): Promise<import("..").AlpacaOrder[]>;
|
|
72
|
+
getFilledOrders(client: AlpacaClient, params: orderUtils.GetFilledOrdersParams): Promise<import("..").AlpacaOrder[]>;
|
|
73
|
+
getOrderHistory(client: AlpacaClient, params?: orderUtils.GetOrderHistoryParams): Promise<orderUtils.OrderHistoryResult>;
|
|
74
|
+
getAllOrders(client: AlpacaClient, params?: orderUtils.GetAllOrdersParams): Promise<import("..").AlpacaOrder[]>;
|
|
75
|
+
waitForOrderFill(client: AlpacaClient, params: orderUtils.WaitForOrderFillParams): Promise<orderUtils.WaitForOrderFillResult>;
|
|
76
|
+
isOrderFillable(order: import("..").AlpacaOrder): boolean;
|
|
77
|
+
isOrderFilled(order: import("..").AlpacaOrder): boolean;
|
|
78
|
+
isOrderTerminal(order: import("..").AlpacaOrder): boolean;
|
|
79
|
+
isOrderOpen(order: import("..").AlpacaOrder): boolean;
|
|
80
|
+
calculateOrderValue(order: import("..").AlpacaOrder): number | null;
|
|
81
|
+
formatOrderSummary(order: import("..").AlpacaOrder): orderUtils.OrderSummary;
|
|
82
|
+
formatOrderForLog(order: import("..").AlpacaOrder): string;
|
|
83
|
+
roundPriceForAlpaca(price: number): string;
|
|
84
|
+
roundPriceForAlpacaNumber(price: number): number;
|
|
85
|
+
groupOrdersBySymbol(orders: import("..").AlpacaOrder[]): Map<string, import("..").AlpacaOrder[]>;
|
|
86
|
+
groupOrdersByStatus(orders: import("..").AlpacaOrder[]): Map<string, import("..").AlpacaOrder[]>;
|
|
87
|
+
calculateTotalFilledValue(orders: import("..").AlpacaOrder[]): number;
|
|
88
|
+
filterOrdersByDateRange(orders: import("..").AlpacaOrder[], startDate: Date, endDate: Date): import("..").AlpacaOrder[];
|
|
89
|
+
sortOrdersByDate(orders: import("..").AlpacaOrder[], direction?: "asc" | "desc"): import("..").AlpacaOrder[];
|
|
90
|
+
default: {
|
|
91
|
+
getOrdersBySymbol: typeof orderUtils.getOrdersBySymbol;
|
|
92
|
+
getOpenOrders: typeof orderUtils.getOpenOrders;
|
|
93
|
+
getFilledOrders: typeof orderUtils.getFilledOrders;
|
|
94
|
+
getOrderHistory: typeof orderUtils.getOrderHistory;
|
|
95
|
+
getAllOrders: typeof orderUtils.getAllOrders;
|
|
96
|
+
waitForOrderFill: typeof orderUtils.waitForOrderFill;
|
|
97
|
+
isOrderFillable: typeof orderUtils.isOrderFillable;
|
|
98
|
+
isOrderFilled: typeof orderUtils.isOrderFilled;
|
|
99
|
+
isOrderTerminal: typeof orderUtils.isOrderTerminal;
|
|
100
|
+
isOrderOpen: typeof orderUtils.isOrderOpen;
|
|
101
|
+
calculateOrderValue: typeof orderUtils.calculateOrderValue;
|
|
102
|
+
calculateTotalFilledValue: typeof orderUtils.calculateTotalFilledValue;
|
|
103
|
+
formatOrderSummary: typeof orderUtils.formatOrderSummary;
|
|
104
|
+
formatOrderForLog: typeof orderUtils.formatOrderForLog;
|
|
105
|
+
roundPriceForAlpaca: typeof orderUtils.roundPriceForAlpaca;
|
|
106
|
+
roundPriceForAlpacaNumber: typeof orderUtils.roundPriceForAlpacaNumber;
|
|
107
|
+
groupOrdersBySymbol: typeof orderUtils.groupOrdersBySymbol;
|
|
108
|
+
groupOrdersByStatus: typeof orderUtils.groupOrdersByStatus;
|
|
109
|
+
filterOrdersByDateRange: typeof orderUtils.filterOrdersByDateRange;
|
|
110
|
+
sortOrdersByDate: typeof orderUtils.sortOrdersByDate;
|
|
111
|
+
};
|
|
112
|
+
createOrder(client: AlpacaClient, params: import("..").CreateOrderParams): Promise<import("..").AlpacaOrder>;
|
|
113
|
+
getOrder(client: AlpacaClient, orderId: string): Promise<import("..").AlpacaOrder>;
|
|
114
|
+
getOrders(client: AlpacaClient, params?: import("..").GetOrdersParams): Promise<import("..").AlpacaOrder[]>;
|
|
115
|
+
cancelOrder(client: AlpacaClient, orderId: string): Promise<void>;
|
|
116
|
+
cancelAllOrders(client: AlpacaClient): Promise<trading.CancelAllOrdersResponse>;
|
|
117
|
+
replaceOrder(client: AlpacaClient, orderId: string, params: import("..").ReplaceOrderParams): Promise<import("..").AlpacaOrder>;
|
|
118
|
+
isOrderCancelable(status: import("..").OrderStatus): boolean;
|
|
119
|
+
getOrderByClientId(client: AlpacaClient, clientOrderId: string): Promise<import("..").AlpacaOrder>;
|
|
120
|
+
};
|
|
121
|
+
smartOrders: {
|
|
122
|
+
bracket: typeof bracketOrders;
|
|
123
|
+
oco: typeof ocoOrders;
|
|
124
|
+
oto: typeof otoOrders;
|
|
125
|
+
trailingStops: typeof trailingStops;
|
|
126
|
+
determineOrderType(params: smartOrders.SmartOrderParams): smartOrders.SmartOrderType;
|
|
127
|
+
createSmartOrder(client: AlpacaClient, params: smartOrders.SmartOrderParams): Promise<smartOrders.SmartOrderResult>;
|
|
128
|
+
createPercentageBracket(client: AlpacaClient, params: smartOrders.PercentageBracketParams): Promise<bracketOrders.BracketOrderResult>;
|
|
129
|
+
createRiskManagedPosition(client: AlpacaClient, params: smartOrders.RiskManagedPositionParams): Promise<bracketOrders.BracketOrderResult | otoOrders.OTOOrderResult>;
|
|
130
|
+
calculateRewardRiskRatio(entryPrice: number, takeProfitPrice: number, stopLossPrice: number, side: import("..").OrderSide): number;
|
|
131
|
+
calculatePositionSize(accountValue: number, riskPercent: number, entryPrice: number, stopPrice: number): number;
|
|
132
|
+
default: {
|
|
133
|
+
createSmartOrder: typeof smartOrders.createSmartOrder;
|
|
134
|
+
determineOrderType: typeof smartOrders.determineOrderType;
|
|
135
|
+
createPercentageBracket: typeof smartOrders.createPercentageBracket;
|
|
136
|
+
createRiskManagedPosition: typeof smartOrders.createRiskManagedPosition;
|
|
137
|
+
calculateRewardRiskRatio: typeof smartOrders.calculateRewardRiskRatio;
|
|
138
|
+
calculatePositionSize: typeof smartOrders.calculatePositionSize;
|
|
139
|
+
createBracketOrder: typeof bracketOrders.createBracketOrder;
|
|
140
|
+
createProtectiveBracket: typeof bracketOrders.createProtectiveBracket;
|
|
141
|
+
createExecutorFromTradingAPI: typeof bracketOrders.createExecutorFromTradingAPI;
|
|
142
|
+
createOCOOrder: typeof ocoOrders.createOCOOrder;
|
|
143
|
+
createOTOOrder: typeof otoOrders.createOTOOrder;
|
|
144
|
+
createTrailingStop: typeof trailingStops.createTrailingStop;
|
|
145
|
+
updateTrailingStop: typeof trailingStops.updateTrailingStop;
|
|
146
|
+
};
|
|
147
|
+
createBracketOrder(executor: bracketOrders.BracketOrderExecutor, params: bracketOrders.BracketOrderParams): Promise<bracketOrders.BracketOrderResult>;
|
|
148
|
+
createProtectiveBracket(executor: bracketOrders.BracketOrderExecutor, params: bracketOrders.ProtectiveBracketParams): Promise<bracketOrders.BracketOrderResult>;
|
|
149
|
+
createExecutorFromTradingAPI(api: {
|
|
150
|
+
makeRequest: (endpoint: string, method: string, body?: unknown) => Promise<import("..").AlpacaOrder>;
|
|
151
|
+
}): bracketOrders.BracketOrderExecutor;
|
|
152
|
+
createOCOOrder(client: AlpacaClient, params: ocoOrders.OCOOrderParams): Promise<ocoOrders.OCOOrderResult>;
|
|
153
|
+
cancelOCOOrder(client: AlpacaClient, parentOrderId: string): Promise<void>;
|
|
154
|
+
getOCOOrderStatus(client: AlpacaClient, parentOrderId: string): Promise<import("..").AlpacaOrder>;
|
|
155
|
+
protectLongPosition(client: AlpacaClient, symbol: string, qty: number, takeProfitPrice: number, stopLossPrice: number, stopLimitPrice?: number): Promise<ocoOrders.OCOOrderResult>;
|
|
156
|
+
protectShortPosition(client: AlpacaClient, symbol: string, qty: number, takeProfitPrice: number, stopLossPrice: number, stopLimitPrice?: number): Promise<ocoOrders.OCOOrderResult>;
|
|
157
|
+
createOTOOrder(client: AlpacaClient, params: otoOrders.OTOOrderParams): Promise<otoOrders.OTOOrderResult>;
|
|
158
|
+
cancelOTOOrder(client: AlpacaClient, parentOrderId: string): Promise<void>;
|
|
159
|
+
getOTOOrderStatus(client: AlpacaClient, parentOrderId: string): Promise<import("..").AlpacaOrder>;
|
|
160
|
+
buyWithStopLoss(client: AlpacaClient, symbol: string, qty: number, stopLossPrice: number, stopLimitPrice?: number): Promise<otoOrders.OTOOrderResult>;
|
|
161
|
+
buyWithTrailingStop(client: AlpacaClient, symbol: string, qty: number, trailPercent: number): Promise<otoOrders.OTOOrderResult>;
|
|
162
|
+
limitBuyWithTakeProfit(client: AlpacaClient, symbol: string, qty: number, entryPrice: number, takeProfitPrice: number): Promise<otoOrders.OTOOrderResult>;
|
|
163
|
+
shortWithStopLoss(client: AlpacaClient, symbol: string, qty: number, entryPrice: number, stopLossPrice: number): Promise<otoOrders.OTOOrderResult>;
|
|
164
|
+
entryWithPercentStopLoss(client: AlpacaClient, symbol: string, qty: number, entryPrice: number | null, stopLossPercent: number, side?: import("..").OrderSide): Promise<otoOrders.OTOOrderResult>;
|
|
165
|
+
createTrailingStop(client: AlpacaClient, params: trailingStops.TrailingStopParams): Promise<import("..").AlpacaOrder>;
|
|
166
|
+
updateTrailingStop(client: AlpacaClient, orderId: string, updates: {
|
|
167
|
+
trailPercent?: number;
|
|
168
|
+
trailPrice?: number;
|
|
169
|
+
}): Promise<import("..").AlpacaOrder>;
|
|
170
|
+
getTrailingStopHWM(client: AlpacaClient, orderId: string): Promise<trailingStops.TrailingStopHWMResult>;
|
|
171
|
+
cancelTrailingStop(client: AlpacaClient, orderId: string): Promise<void>;
|
|
172
|
+
createPortfolioTrailingStops(client: AlpacaClient, params: trailingStops.PortfolioTrailingStopParams): Promise<Map<string, import("..").AlpacaOrder>>;
|
|
173
|
+
getOpenTrailingStops(client: AlpacaClient, symbol?: string): Promise<import("..").AlpacaOrder[]>;
|
|
174
|
+
hasActiveTrailingStop(client: AlpacaClient, symbol: string): Promise<boolean>;
|
|
175
|
+
cancelTrailingStopsForSymbol(client: AlpacaClient, symbol: string): Promise<number>;
|
|
176
|
+
TrailingStopValidationError: typeof trailingStops.TrailingStopValidationError;
|
|
177
|
+
};
|
|
178
|
+
positions: typeof positions;
|
|
179
|
+
account: typeof account;
|
|
180
|
+
quotes: typeof quotes;
|
|
181
|
+
bars: typeof bars;
|
|
182
|
+
trades: typeof trades;
|
|
183
|
+
news: typeof news;
|
|
184
|
+
options: {
|
|
185
|
+
contracts: typeof optionContracts;
|
|
186
|
+
orders: typeof optionOrders;
|
|
187
|
+
strategies: typeof optionStrategies;
|
|
188
|
+
data: typeof optionData;
|
|
189
|
+
};
|
|
190
|
+
crypto: {
|
|
191
|
+
orders: typeof cryptoOrders;
|
|
192
|
+
data: typeof cryptoData;
|
|
193
|
+
};
|
|
194
|
+
streams: typeof streams;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Re-export type definitions for external use
|
|
198
|
+
*/
|
|
199
|
+
export type { AlpacaClient, AlpacaClientConfig };
|
|
200
|
+
export default alpaca;
|
|
201
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/alpaca/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,UAAU,CAAC;AAGzB,cAAc,WAAW,CAAC;AAG1B,OAAO,EAEL,cAAc,EACd,eAAe,EACf,SAAS,EACT,UAAU,EACV,gBAAgB,IAAI,iBAAiB,EACrC,UAAU,EAEV,KAAK,UAAU,GAChB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAEL,OAAO,EACP,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,QAAQ,EAER,KAAK,aAAa,EAClB,KAAK,WAAW,GACjB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EA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WAAW,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,SAAS,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAG7C,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,oBAAoB,CAAC;AAG3C,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,YAAY,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,gBAAgB,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,UAAU,MAAM,gBAAgB,CAAC;AAG7C,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,UAAU,MAAM,eAAe,CAAC;AAG5C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gEAyDk9L,CAAC;;;;;;;;;;;;;;;;;wBAA5nL,CAAC;sBAAwB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;CARnY,CAAC;AAEF;;GAEG;AACH,YAAY,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAEjD,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bars Module
|
|
3
|
+
* Historical and real-time OHLCV data using Alpaca SDK
|
|
4
|
+
*/
|
|
5
|
+
import { AlpacaClient } from '../client';
|
|
6
|
+
import { Bar, TimeFrame } from '../../types/alpaca-types';
|
|
7
|
+
/**
|
|
8
|
+
* Error thrown when bar operations fail
|
|
9
|
+
*/
|
|
10
|
+
export declare class BarError 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
|
+
* Parameters for fetching bars
|
|
18
|
+
*/
|
|
19
|
+
export interface GetBarsParams {
|
|
20
|
+
/** Symbols to fetch bars for */
|
|
21
|
+
symbols: string[];
|
|
22
|
+
/** Bar timeframe (e.g., '1Min', '5Min', '1Hour', '1Day') */
|
|
23
|
+
timeframe: TimeFrame;
|
|
24
|
+
/** Start date/time for the data range */
|
|
25
|
+
start?: Date | string;
|
|
26
|
+
/** End date/time for the data range */
|
|
27
|
+
end?: Date | string;
|
|
28
|
+
/** Maximum number of bars to return per symbol */
|
|
29
|
+
limit?: number;
|
|
30
|
+
/** Price adjustment type */
|
|
31
|
+
adjustment?: 'raw' | 'split' | 'dividend' | 'all';
|
|
32
|
+
/** Data feed (sip for premium, iex for free tier) */
|
|
33
|
+
feed?: 'sip' | 'iex';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Bar analysis summary
|
|
37
|
+
*/
|
|
38
|
+
export interface BarAnalysis {
|
|
39
|
+
/** Opening price of the period */
|
|
40
|
+
open: number;
|
|
41
|
+
/** Highest price during the period */
|
|
42
|
+
high: number;
|
|
43
|
+
/** Lowest price during the period */
|
|
44
|
+
low: number;
|
|
45
|
+
/** Closing price of the period */
|
|
46
|
+
close: number;
|
|
47
|
+
/** Total volume traded */
|
|
48
|
+
volume: number;
|
|
49
|
+
/** Volume-weighted average price */
|
|
50
|
+
vwap: number;
|
|
51
|
+
/** Price change (close - open) */
|
|
52
|
+
change: number;
|
|
53
|
+
/** Price change as percentage */
|
|
54
|
+
changePercent: number;
|
|
55
|
+
/** Number of bars analyzed */
|
|
56
|
+
barCount: number;
|
|
57
|
+
/** Total number of trades */
|
|
58
|
+
totalTrades: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get historical bars with automatic pagination
|
|
62
|
+
* @param client - AlpacaClient instance
|
|
63
|
+
* @param params - Parameters for fetching bars
|
|
64
|
+
* @returns Map of symbol to array of bars
|
|
65
|
+
*/
|
|
66
|
+
export declare function getBars(client: AlpacaClient, params: GetBarsParams): Promise<Map<string, Bar[]>>;
|
|
67
|
+
/**
|
|
68
|
+
* Get latest bars for symbols
|
|
69
|
+
* @param client - AlpacaClient instance
|
|
70
|
+
* @param symbols - Array of stock symbols
|
|
71
|
+
* @returns Map of symbol to latest bar
|
|
72
|
+
*/
|
|
73
|
+
export declare function getLatestBars(client: AlpacaClient, symbols: string[]): Promise<Map<string, Bar>>;
|
|
74
|
+
/**
|
|
75
|
+
* Get daily prices for a symbol
|
|
76
|
+
* @param client - AlpacaClient instance
|
|
77
|
+
* @param symbol - Stock symbol
|
|
78
|
+
* @param days - Number of days of history to fetch
|
|
79
|
+
* @returns Array of daily bars
|
|
80
|
+
*/
|
|
81
|
+
export declare function getDailyPrices(client: AlpacaClient, symbol: string, days: number): Promise<Bar[]>;
|
|
82
|
+
/**
|
|
83
|
+
* Get intraday prices for a symbol
|
|
84
|
+
* @param client - AlpacaClient instance
|
|
85
|
+
* @param symbol - Stock symbol
|
|
86
|
+
* @param timeframe - Bar timeframe
|
|
87
|
+
* @param start - Start date/time
|
|
88
|
+
* @param end - Optional end date/time (defaults to now)
|
|
89
|
+
* @returns Array of intraday bars
|
|
90
|
+
*/
|
|
91
|
+
export declare function getIntradayPrices(client: AlpacaClient, symbol: string, timeframe: TimeFrame, start: Date, end?: Date): Promise<Bar[]>;
|
|
92
|
+
/**
|
|
93
|
+
* Get previous close price for a symbol
|
|
94
|
+
* @param client - AlpacaClient instance
|
|
95
|
+
* @param symbol - Stock symbol
|
|
96
|
+
* @returns Previous close price
|
|
97
|
+
*/
|
|
98
|
+
export declare function getPreviousClose(client: AlpacaClient, symbol: string): Promise<number>;
|
|
99
|
+
/**
|
|
100
|
+
* Analyze bars and return summary statistics
|
|
101
|
+
* @param bars - Array of bars to analyze
|
|
102
|
+
* @returns Analysis summary with OHLCV stats and price change
|
|
103
|
+
*/
|
|
104
|
+
export declare function analyzeBars(bars: Bar[]): BarAnalysis;
|
|
105
|
+
/**
|
|
106
|
+
* Get price range statistics for a symbol over a period
|
|
107
|
+
* @param client - AlpacaClient instance
|
|
108
|
+
* @param symbol - Stock symbol
|
|
109
|
+
* @param days - Number of days to analyze
|
|
110
|
+
* @returns Analysis of the price range
|
|
111
|
+
*/
|
|
112
|
+
export declare function getPriceRange(client: AlpacaClient, symbol: string, days: number): Promise<BarAnalysis>;
|
|
113
|
+
/**
|
|
114
|
+
* Calculate average daily volume for a symbol
|
|
115
|
+
* @param client - AlpacaClient instance
|
|
116
|
+
* @param symbol - Stock symbol
|
|
117
|
+
* @param days - Number of days to average (default 20)
|
|
118
|
+
* @returns Average daily volume
|
|
119
|
+
*/
|
|
120
|
+
export declare function getAverageDailyVolume(client: AlpacaClient, symbol: string, days?: number): Promise<number>;
|
|
121
|
+
/**
|
|
122
|
+
* Check if a symbol has sufficient trading volume
|
|
123
|
+
* @param client - AlpacaClient instance
|
|
124
|
+
* @param symbol - Stock symbol
|
|
125
|
+
* @param minAvgVolume - Minimum average daily volume required (default 100,000)
|
|
126
|
+
* @param days - Number of days to check (default 20)
|
|
127
|
+
* @returns true if average volume meets minimum requirement
|
|
128
|
+
*/
|
|
129
|
+
export declare function hasSufficientVolume(client: AlpacaClient, symbol: string, minAvgVolume?: number, days?: number): Promise<boolean>;
|
|
130
|
+
declare const _default: {
|
|
131
|
+
getBars: typeof getBars;
|
|
132
|
+
getLatestBars: typeof getLatestBars;
|
|
133
|
+
getDailyPrices: typeof getDailyPrices;
|
|
134
|
+
getIntradayPrices: typeof getIntradayPrices;
|
|
135
|
+
getPreviousClose: typeof getPreviousClose;
|
|
136
|
+
analyzeBars: typeof analyzeBars;
|
|
137
|
+
getPriceRange: typeof getPriceRange;
|
|
138
|
+
getAverageDailyVolume: typeof getAverageDailyVolume;
|
|
139
|
+
hasSufficientVolume: typeof hasSufficientVolume;
|
|
140
|
+
};
|
|
141
|
+
export default _default;
|
|
142
|
+
//# sourceMappingURL=bars.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bars.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/market-data/bars.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAQ1D;;GAEG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAGxB,IAAI,EAAE,MAAM;IACZ,MAAM,CAAC,EAAE,MAAM;IACf,OAAO,CAAC,EAAE,OAAO;gBAHxB,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,YAAA,EACf,OAAO,CAAC,EAAE,OAAO,YAAA;CAK3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,gCAAgC;IAChC,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4DAA4D;IAC5D,SAAS,EAAE,SAAS,CAAC;IACrB,yCAAyC;IACzC,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IACtB,uCAAuC;IACvC,GAAG,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IACpB,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,UAAU,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,UAAU,GAAG,KAAK,CAAC;IAClD,qDAAqD;IACrD,IAAI,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAA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AAW,CAuDpD;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,CAAC,CAGtB;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,MAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CASjB;AAED;;;;;;;GAOG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,MAAM,EACd,YAAY,GAAE,MAAe,EAC7B,IAAI,GAAE,MAAW,GAChB,OAAO,CAAC,OAAO,CAAC,CAQlB;;;;;;;;;;;;AAED,wBAUE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Market Data Module
|
|
3
|
+
* Exports quotes, bars, trades, and news functionality for market data access
|
|
4
|
+
*/
|
|
5
|
+
export { getLatestQuote, getLatestQuotes, getSpread, getSpreads, hasGoodLiquidity, QuoteError, } from './quotes';
|
|
6
|
+
export type { SpreadInfo } from './quotes';
|
|
7
|
+
export { getBars, getLatestBars, getDailyPrices, getIntradayPrices, getPreviousClose, analyzeBars, getPriceRange, getAverageDailyVolume, hasSufficientVolume, BarError, } from './bars';
|
|
8
|
+
export type { GetBarsParams, BarAnalysis } from './bars';
|
|
9
|
+
export { getLatestTrade, getLatestTrades, getHistoricalTrades, getCurrentPrice, getCurrentPrices, getTradeVolume, TradeError, } from './trades';
|
|
10
|
+
export type { GetHistoricalTradesParams } from './trades';
|
|
11
|
+
export { getNews, getLatestNews, searchNews, getNewsForSymbols, getSymbolSentiment, NewsError, } from './news';
|
|
12
|
+
export type { GetNewsParams } from './news';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/market-data/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,cAAc,EACd,eAAe,EACf,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG3C,OAAO,EACL,OAAO,EACP,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,QAAQ,GACT,MAAM,QAAQ,CAAC;AAEhB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGzD,OAAO,EACL,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAG1D,OAAO,EACL,OAAO,EACP,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,GACV,MAAM,QAAQ,CAAC;AAEhB,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC"}
|