@adaptic/utils 0.0.99

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 (238) hide show
  1. package/README.md +916 -0
  2. package/dist/index.cjs +71971 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.mjs +71677 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/dist/test.js +7799 -0
  7. package/dist/test.js.map +1 -0
  8. package/dist/types/__tests__/alpaca-functions.test.d.ts +2 -0
  9. package/dist/types/__tests__/alpaca-functions.test.d.ts.map +1 -0
  10. package/dist/types/__tests__/api-endpoints.test.d.ts +2 -0
  11. package/dist/types/__tests__/api-endpoints.test.d.ts.map +1 -0
  12. package/dist/types/__tests__/asset-allocation.test.d.ts +2 -0
  13. package/dist/types/__tests__/asset-allocation.test.d.ts.map +1 -0
  14. package/dist/types/__tests__/auth-validator.test.d.ts +2 -0
  15. package/dist/types/__tests__/auth-validator.test.d.ts.map +1 -0
  16. package/dist/types/__tests__/cache.test.d.ts +2 -0
  17. package/dist/types/__tests__/cache.test.d.ts.map +1 -0
  18. package/dist/types/__tests__/errors.test.d.ts +2 -0
  19. package/dist/types/__tests__/errors.test.d.ts.map +1 -0
  20. package/dist/types/__tests__/financial-regression.test.d.ts +2 -0
  21. package/dist/types/__tests__/financial-regression.test.d.ts.map +1 -0
  22. package/dist/types/__tests__/format-tools.test.d.ts +2 -0
  23. package/dist/types/__tests__/format-tools.test.d.ts.map +1 -0
  24. package/dist/types/__tests__/http-keep-alive.test.d.ts +2 -0
  25. package/dist/types/__tests__/http-keep-alive.test.d.ts.map +1 -0
  26. package/dist/types/__tests__/http-timeout.test.d.ts +2 -0
  27. package/dist/types/__tests__/http-timeout.test.d.ts.map +1 -0
  28. package/dist/types/__tests__/logger.test.d.ts +2 -0
  29. package/dist/types/__tests__/logger.test.d.ts.map +1 -0
  30. package/dist/types/__tests__/market-time.test.d.ts +2 -0
  31. package/dist/types/__tests__/market-time.test.d.ts.map +1 -0
  32. package/dist/types/__tests__/misc-utils.test.d.ts +2 -0
  33. package/dist/types/__tests__/misc-utils.test.d.ts.map +1 -0
  34. package/dist/types/__tests__/paginator.test.d.ts +2 -0
  35. package/dist/types/__tests__/paginator.test.d.ts.map +1 -0
  36. package/dist/types/__tests__/performance-metrics.test.d.ts +2 -0
  37. package/dist/types/__tests__/performance-metrics.test.d.ts.map +1 -0
  38. package/dist/types/__tests__/polygon.test.d.ts +2 -0
  39. package/dist/types/__tests__/polygon.test.d.ts.map +1 -0
  40. package/dist/types/__tests__/price-utils.test.d.ts +2 -0
  41. package/dist/types/__tests__/price-utils.test.d.ts.map +1 -0
  42. package/dist/types/__tests__/property-based-financial.test.d.ts +2 -0
  43. package/dist/types/__tests__/property-based-financial.test.d.ts.map +1 -0
  44. package/dist/types/__tests__/rate-limiter.test.d.ts +2 -0
  45. package/dist/types/__tests__/rate-limiter.test.d.ts.map +1 -0
  46. package/dist/types/__tests__/schema-validation.test.d.ts +2 -0
  47. package/dist/types/__tests__/schema-validation.test.d.ts.map +1 -0
  48. package/dist/types/__tests__/technical-analysis.test.d.ts +2 -0
  49. package/dist/types/__tests__/technical-analysis.test.d.ts.map +1 -0
  50. package/dist/types/__tests__/time-utils.test.d.ts +2 -0
  51. package/dist/types/__tests__/time-utils.test.d.ts.map +1 -0
  52. package/dist/types/adaptic.d.ts +52 -0
  53. package/dist/types/adaptic.d.ts.map +1 -0
  54. package/dist/types/alpaca/client.d.ts +95 -0
  55. package/dist/types/alpaca/client.d.ts.map +1 -0
  56. package/dist/types/alpaca/crypto/data.d.ts +281 -0
  57. package/dist/types/alpaca/crypto/data.d.ts.map +1 -0
  58. package/dist/types/alpaca/crypto/index.d.ts +75 -0
  59. package/dist/types/alpaca/crypto/index.d.ts.map +1 -0
  60. package/dist/types/alpaca/crypto/orders.d.ts +221 -0
  61. package/dist/types/alpaca/crypto/orders.d.ts.map +1 -0
  62. package/dist/types/alpaca/index.d.ts +205 -0
  63. package/dist/types/alpaca/index.d.ts.map +1 -0
  64. package/dist/types/alpaca/legacy/account.d.ts +34 -0
  65. package/dist/types/alpaca/legacy/account.d.ts.map +1 -0
  66. package/dist/types/alpaca/legacy/assets.d.ts +13 -0
  67. package/dist/types/alpaca/legacy/assets.d.ts.map +1 -0
  68. package/dist/types/alpaca/legacy/auth.d.ts +18 -0
  69. package/dist/types/alpaca/legacy/auth.d.ts.map +1 -0
  70. package/dist/types/alpaca/legacy/index.d.ts +15 -0
  71. package/dist/types/alpaca/legacy/index.d.ts.map +1 -0
  72. package/dist/types/alpaca/legacy/market-data.d.ts +32 -0
  73. package/dist/types/alpaca/legacy/market-data.d.ts.map +1 -0
  74. package/dist/types/alpaca/legacy/orders.d.ts +84 -0
  75. package/dist/types/alpaca/legacy/orders.d.ts.map +1 -0
  76. package/dist/types/alpaca/legacy/positions.d.ts +66 -0
  77. package/dist/types/alpaca/legacy/positions.d.ts.map +1 -0
  78. package/dist/types/alpaca/legacy/utils.d.ts +18 -0
  79. package/dist/types/alpaca/legacy/utils.d.ts.map +1 -0
  80. package/dist/types/alpaca/market-data/bars.d.ts +142 -0
  81. package/dist/types/alpaca/market-data/bars.d.ts.map +1 -0
  82. package/dist/types/alpaca/market-data/index.d.ts +13 -0
  83. package/dist/types/alpaca/market-data/index.d.ts.map +1 -0
  84. package/dist/types/alpaca/market-data/news.d.ts +87 -0
  85. package/dist/types/alpaca/market-data/news.d.ts.map +1 -0
  86. package/dist/types/alpaca/market-data/quotes.d.ts +85 -0
  87. package/dist/types/alpaca/market-data/quotes.d.ts.map +1 -0
  88. package/dist/types/alpaca/market-data/trades.d.ts +98 -0
  89. package/dist/types/alpaca/market-data/trades.d.ts.map +1 -0
  90. package/dist/types/alpaca/options/contracts.d.ts +279 -0
  91. package/dist/types/alpaca/options/contracts.d.ts.map +1 -0
  92. package/dist/types/alpaca/options/data.d.ts +126 -0
  93. package/dist/types/alpaca/options/data.d.ts.map +1 -0
  94. package/dist/types/alpaca/options/index.d.ts +17 -0
  95. package/dist/types/alpaca/options/index.d.ts.map +1 -0
  96. package/dist/types/alpaca/options/orders.d.ts +366 -0
  97. package/dist/types/alpaca/options/orders.d.ts.map +1 -0
  98. package/dist/types/alpaca/options/strategies.d.ts +224 -0
  99. package/dist/types/alpaca/options/strategies.d.ts.map +1 -0
  100. package/dist/types/alpaca/streams/base-stream.d.ts +143 -0
  101. package/dist/types/alpaca/streams/base-stream.d.ts.map +1 -0
  102. package/dist/types/alpaca/streams/crypto-stream.d.ts +173 -0
  103. package/dist/types/alpaca/streams/crypto-stream.d.ts.map +1 -0
  104. package/dist/types/alpaca/streams/index.d.ts +54 -0
  105. package/dist/types/alpaca/streams/index.d.ts.map +1 -0
  106. package/dist/types/alpaca/streams/option-stream.d.ts +167 -0
  107. package/dist/types/alpaca/streams/option-stream.d.ts.map +1 -0
  108. package/dist/types/alpaca/streams/stock-stream.d.ts +176 -0
  109. package/dist/types/alpaca/streams/stock-stream.d.ts.map +1 -0
  110. package/dist/types/alpaca/streams/stream-manager.d.ts +277 -0
  111. package/dist/types/alpaca/streams/stream-manager.d.ts.map +1 -0
  112. package/dist/types/alpaca/streams/trading-stream.d.ts +186 -0
  113. package/dist/types/alpaca/streams/trading-stream.d.ts.map +1 -0
  114. package/dist/types/alpaca/streams.d.ts +88 -0
  115. package/dist/types/alpaca/streams.d.ts.map +1 -0
  116. package/dist/types/alpaca/test-imports.d.ts +7 -0
  117. package/dist/types/alpaca/test-imports.d.ts.map +1 -0
  118. package/dist/types/alpaca/trading/account.d.ts +198 -0
  119. package/dist/types/alpaca/trading/account.d.ts.map +1 -0
  120. package/dist/types/alpaca/trading/bracket-orders.d.ts +162 -0
  121. package/dist/types/alpaca/trading/bracket-orders.d.ts.map +1 -0
  122. package/dist/types/alpaca/trading/clock.d.ts +99 -0
  123. package/dist/types/alpaca/trading/clock.d.ts.map +1 -0
  124. package/dist/types/alpaca/trading/index.d.ts +15 -0
  125. package/dist/types/alpaca/trading/index.d.ts.map +1 -0
  126. package/dist/types/alpaca/trading/oco-orders.d.ts +203 -0
  127. package/dist/types/alpaca/trading/oco-orders.d.ts.map +1 -0
  128. package/dist/types/alpaca/trading/order-utils.d.ts +404 -0
  129. package/dist/types/alpaca/trading/order-utils.d.ts.map +1 -0
  130. package/dist/types/alpaca/trading/orders.d.ts +199 -0
  131. package/dist/types/alpaca/trading/orders.d.ts.map +1 -0
  132. package/dist/types/alpaca/trading/oto-orders.d.ts +282 -0
  133. package/dist/types/alpaca/trading/oto-orders.d.ts.map +1 -0
  134. package/dist/types/alpaca/trading/positions.d.ts +389 -0
  135. package/dist/types/alpaca/trading/positions.d.ts.map +1 -0
  136. package/dist/types/alpaca/trading/smart-orders.d.ts +301 -0
  137. package/dist/types/alpaca/trading/smart-orders.d.ts.map +1 -0
  138. package/dist/types/alpaca/trading/trailing-stops.d.ts +240 -0
  139. package/dist/types/alpaca/trading/trailing-stops.d.ts.map +1 -0
  140. package/dist/types/alpaca-market-data-api.d.ts +386 -0
  141. package/dist/types/alpaca-market-data-api.d.ts.map +1 -0
  142. package/dist/types/alpaca-trading-api.d.ts +315 -0
  143. package/dist/types/alpaca-trading-api.d.ts.map +1 -0
  144. package/dist/types/alphavantage.d.ts +44 -0
  145. package/dist/types/alphavantage.d.ts.map +1 -0
  146. package/dist/types/asset-allocation-algorithm.d.ts +143 -0
  147. package/dist/types/asset-allocation-algorithm.d.ts.map +1 -0
  148. package/dist/types/cache/stampede-protected-cache.d.ts +565 -0
  149. package/dist/types/cache/stampede-protected-cache.d.ts.map +1 -0
  150. package/dist/types/config/api-endpoints.d.ts +94 -0
  151. package/dist/types/config/api-endpoints.d.ts.map +1 -0
  152. package/dist/types/crypto.d.ts +76 -0
  153. package/dist/types/crypto.d.ts.map +1 -0
  154. package/dist/types/display-manager.d.ts +24 -0
  155. package/dist/types/display-manager.d.ts.map +1 -0
  156. package/dist/types/errors/index.d.ts +130 -0
  157. package/dist/types/errors/index.d.ts.map +1 -0
  158. package/dist/types/examples/asset-allocation-example.d.ts +36 -0
  159. package/dist/types/examples/asset-allocation-example.d.ts.map +1 -0
  160. package/dist/types/examples/rate-limiter-example.d.ts +7 -0
  161. package/dist/types/examples/rate-limiter-example.d.ts.map +1 -0
  162. package/dist/types/format-tools.d.ts +54 -0
  163. package/dist/types/format-tools.d.ts.map +1 -0
  164. package/dist/types/http-timeout.d.ts +37 -0
  165. package/dist/types/http-timeout.d.ts.map +1 -0
  166. package/dist/types/index.d.ts +766 -0
  167. package/dist/types/index.d.ts.map +1 -0
  168. package/dist/types/logger.d.ts +56 -0
  169. package/dist/types/logger.d.ts.map +1 -0
  170. package/dist/types/logging.d.ts +12 -0
  171. package/dist/types/logging.d.ts.map +1 -0
  172. package/dist/types/market-hours.d.ts +24 -0
  173. package/dist/types/market-hours.d.ts.map +1 -0
  174. package/dist/types/market-time.d.ts +246 -0
  175. package/dist/types/market-time.d.ts.map +1 -0
  176. package/dist/types/metrics-calcs.d.ts +6 -0
  177. package/dist/types/metrics-calcs.d.ts.map +1 -0
  178. package/dist/types/misc-utils.d.ts +52 -0
  179. package/dist/types/misc-utils.d.ts.map +1 -0
  180. package/dist/types/performance-metrics.d.ts +88 -0
  181. package/dist/types/performance-metrics.d.ts.map +1 -0
  182. package/dist/types/polygon-indices.d.ts +85 -0
  183. package/dist/types/polygon-indices.d.ts.map +1 -0
  184. package/dist/types/polygon.d.ts +126 -0
  185. package/dist/types/polygon.d.ts.map +1 -0
  186. package/dist/types/price-utils.d.ts +26 -0
  187. package/dist/types/price-utils.d.ts.map +1 -0
  188. package/dist/types/rate-limiter.d.ts +171 -0
  189. package/dist/types/rate-limiter.d.ts.map +1 -0
  190. package/dist/types/schemas/alpaca-schemas.d.ts +779 -0
  191. package/dist/types/schemas/alpaca-schemas.d.ts.map +1 -0
  192. package/dist/types/schemas/alphavantage-schemas.d.ts +255 -0
  193. package/dist/types/schemas/alphavantage-schemas.d.ts.map +1 -0
  194. package/dist/types/schemas/index.d.ts +21 -0
  195. package/dist/types/schemas/index.d.ts.map +1 -0
  196. package/dist/types/schemas/polygon-schemas.d.ts +551 -0
  197. package/dist/types/schemas/polygon-schemas.d.ts.map +1 -0
  198. package/dist/types/schemas/validate-response.d.ts +88 -0
  199. package/dist/types/schemas/validate-response.d.ts.map +1 -0
  200. package/dist/types/technical-analysis.d.ts +90 -0
  201. package/dist/types/technical-analysis.d.ts.map +1 -0
  202. package/dist/types/test.d.ts +2 -0
  203. package/dist/types/test.d.ts.map +1 -0
  204. package/dist/types/testing/options-ws.d.ts +2 -0
  205. package/dist/types/testing/options-ws.d.ts.map +1 -0
  206. package/dist/types/time-utils.d.ts +17 -0
  207. package/dist/types/time-utils.d.ts.map +1 -0
  208. package/dist/types/types/adaptic-types.d.ts +11 -0
  209. package/dist/types/types/adaptic-types.d.ts.map +1 -0
  210. package/dist/types/types/alpaca-types.d.ts +1165 -0
  211. package/dist/types/types/alpaca-types.d.ts.map +1 -0
  212. package/dist/types/types/alphavantage-types.d.ts +66 -0
  213. package/dist/types/types/alphavantage-types.d.ts.map +1 -0
  214. package/dist/types/types/asset-allocation-types.d.ts +328 -0
  215. package/dist/types/types/asset-allocation-types.d.ts.map +1 -0
  216. package/dist/types/types/index.d.ts +21 -0
  217. package/dist/types/types/index.d.ts.map +1 -0
  218. package/dist/types/types/logging-types.d.ts +10 -0
  219. package/dist/types/types/logging-types.d.ts.map +1 -0
  220. package/dist/types/types/market-time-types.d.ts +59 -0
  221. package/dist/types/types/market-time-types.d.ts.map +1 -0
  222. package/dist/types/types/metrics-types.d.ts +33 -0
  223. package/dist/types/types/metrics-types.d.ts.map +1 -0
  224. package/dist/types/types/polygon-indices-types.d.ts +190 -0
  225. package/dist/types/types/polygon-indices-types.d.ts.map +1 -0
  226. package/dist/types/types/polygon-types.d.ts +204 -0
  227. package/dist/types/types/polygon-types.d.ts.map +1 -0
  228. package/dist/types/types/ta-types.d.ts +89 -0
  229. package/dist/types/types/ta-types.d.ts.map +1 -0
  230. package/dist/types/utils/auth-validator.d.ts +32 -0
  231. package/dist/types/utils/auth-validator.d.ts.map +1 -0
  232. package/dist/types/utils/http-keep-alive.d.ts +110 -0
  233. package/dist/types/utils/http-keep-alive.d.ts.map +1 -0
  234. package/dist/types/utils/paginator.d.ts +154 -0
  235. package/dist/types/utils/paginator.d.ts.map +1 -0
  236. package/dist/types/utils/retry.d.ts +78 -0
  237. package/dist/types/utils/retry.d.ts.map +1 -0
  238. package/package.json +78 -0
@@ -0,0 +1,315 @@
1
+ import { AlpacaAccountDetails, AlpacaCredentials, AlpacaPosition, AssetClass, GetOptionContractsParams, GetOrdersParams, OptionAccountActivity, OptionContract, OptionContractsResponse, AlpacaOrder, OrderLeg, TradeUpdate, ExerciseOptionResponse } from "./types/alpaca-types";
2
+ /**
3
+ Websocket example
4
+ const alpacaAPI = createAlpacaTradingAPI(credentials); // type AlpacaCredentials
5
+ alpacaAPI.onTradeUpdate((update: TradeUpdate) => {
6
+ this.log(`Received trade update: event ${update.event} for an order to ${update.order.side} ${update.order.qty} of ${update.order.symbol}`);
7
+ });
8
+ alpacaAPI.connectWebsocket(); // necessary to connect to the WebSocket
9
+ */
10
+ export declare class AlpacaTradingAPI {
11
+ static new(credentials: AlpacaCredentials): AlpacaTradingAPI;
12
+ static getInstance(credentials: AlpacaCredentials): AlpacaTradingAPI;
13
+ private ws;
14
+ private headers;
15
+ private tradeUpdateCallback;
16
+ private credentials;
17
+ private apiBaseUrl;
18
+ private wsUrl;
19
+ private authenticated;
20
+ private connecting;
21
+ private reconnectDelay;
22
+ private reconnectTimeout;
23
+ private messageHandlers;
24
+ private debugLogging;
25
+ /**
26
+ * Constructor for AlpacaTradingAPI
27
+ * @param credentials - Alpaca credentials,
28
+ * accountName: string; // The account identifier used inthis.logs and tracking
29
+ * apiKey: string; // Alpaca API key
30
+ * apiSecret: string; // Alpaca API secret
31
+ * type: AlpacaAccountType;
32
+ * orderType: AlpacaOrderType;
33
+ * @param options - Optional options
34
+ * debugLogging: boolean; // Whether to log messages of type 'debug'
35
+ */
36
+ constructor(credentials: AlpacaCredentials, options?: {
37
+ debugLogging?: boolean;
38
+ });
39
+ private log;
40
+ /**
41
+ * Round a price to the nearest 2 decimal places for Alpaca, or 4 decimal places for prices less than $1
42
+ * @param price - The price to round
43
+ * @returns The rounded price
44
+ */
45
+ private roundPriceForAlpaca;
46
+ private handleAuthMessage;
47
+ private handleListenMessage;
48
+ private handleTradeUpdate;
49
+ private handleMessage;
50
+ connectWebsocket(): void;
51
+ private authenticate;
52
+ private subscribeToTradeUpdates;
53
+ private makeRequest;
54
+ getPositions(assetClass?: AssetClass): Promise<AlpacaPosition[]>;
55
+ /**
56
+ * Get all orders
57
+ * @param params (GetOrdersParams) - optional parameters to filter the orders
58
+ * - status: 'open' | 'closed' | 'all'
59
+ * - limit: number
60
+ * - after: string
61
+ * - until: string
62
+ * - direction: 'asc' | 'desc'
63
+ * - nested: boolean
64
+ * - symbols: string[], an array of all the symbols
65
+ * - side: 'buy' | 'sell'
66
+ * @returns all orders
67
+ */
68
+ getOrders(params?: GetOrdersParams): Promise<AlpacaOrder[]>;
69
+ getAccountDetails(): Promise<AlpacaAccountDetails>;
70
+ /**
71
+ * Create a trailing stop order
72
+ * @param symbol (string) - the symbol of the order
73
+ * @param qty (number) - the quantity of the order
74
+ * @param side (string) - the side of the order
75
+ * @param trailPercent100 (number) - the trail percent of the order (scale 100, i.e. 0.5 = 0.5%)
76
+ * @param position_intent (string) - the position intent of the order
77
+ */
78
+ createTrailingStop(symbol: string, qty: number, side: "buy" | "sell", trailPercent100: number, position_intent: "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close"): Promise<void>;
79
+ /**
80
+ * Create a market order
81
+ * @param symbol (string) - the symbol of the order
82
+ * @param qty (number) - the quantity of the order
83
+ * @param side (string) - the side of the order
84
+ * @param position_intent (string) - the position intent of the order. Important for knowing if a position needs a trailing stop.
85
+ */
86
+ createMarketOrder(symbol: string, qty: number, side: "buy" | "sell", position_intent: "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close", client_order_id?: string): Promise<AlpacaOrder>;
87
+ /**
88
+ * Get the current trail percent for a symbol, assuming that it has an open position and a trailing stop order to close it. Because this relies on an orders request for one symbol, you can't do it too often.
89
+ * @param symbol (string) - the symbol of the order
90
+ * @returns the current trail percent
91
+ */
92
+ getCurrentTrailPercent(symbol: string): Promise<number | null>;
93
+ /**
94
+ * Update the trail percent for a trailing stop order
95
+ * @param symbol (string) - the symbol of the order
96
+ * @param trailPercent100 (number) - the trail percent of the order (scale 100, i.e. 0.5 = 0.5%)
97
+ */
98
+ updateTrailingStop(symbol: string, trailPercent100: number): Promise<void>;
99
+ /**
100
+ * Cancel all open orders
101
+ */
102
+ cancelAllOrders(): Promise<void>;
103
+ /**
104
+ * Cancel a specific order by its ID
105
+ * @param orderId The id of the order to cancel
106
+ * @throws Error if the order is not cancelable (status 422) or if the order doesn't exist
107
+ * @returns Promise that resolves when the order is successfully canceled
108
+ */
109
+ cancelOrder(orderId: string): Promise<void>;
110
+ /**
111
+ * Create a limit order
112
+ * @param symbol (string) - the symbol of the order
113
+ * @param qty (number) - the quantity of the order
114
+ * @param side (string) - the side of the order
115
+ * @param limitPrice (number) - the limit price of the order
116
+ * @param position_intent (string) - the position intent of the order
117
+ * @param extended_hours (boolean) - whether the order is in extended hours
118
+ * @param client_order_id (string) - the client order id of the order
119
+ */
120
+ createLimitOrder(symbol: string, qty: number, side: "buy" | "sell", limitPrice: number, position_intent: "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close", extended_hours?: boolean, client_order_id?: string): Promise<AlpacaOrder>;
121
+ /**
122
+ * Close all equities positions
123
+ * @param options (object) - the options for closing the positions
124
+ * - cancel_orders (boolean) - whether to cancel related orders
125
+ * - useLimitOrders (boolean) - whether to use limit orders to close the positions
126
+ */
127
+ closeAllPositions(options?: {
128
+ cancel_orders: boolean;
129
+ useLimitOrders: boolean;
130
+ }): Promise<void>;
131
+ /**
132
+ * Close all equities positions using limit orders during extended hours trading
133
+ * @param cancelOrders Whether to cancel related orders (default: true)
134
+ * @returns Promise that resolves when all positions are closed
135
+ */
136
+ closeAllPositionsAfterHours(): Promise<void>;
137
+ onTradeUpdate(callback: (update: TradeUpdate) => void): void;
138
+ /**
139
+ * Get portfolio history for the account
140
+ * @param params Parameters for the portfolio history request
141
+ * @returns Portfolio history data
142
+ */
143
+ getPortfolioHistory(params: {
144
+ timeframe?: "1Min" | "5Min" | "15Min" | "1H" | "1D";
145
+ period?: string;
146
+ extended_hours?: boolean;
147
+ date_end?: string;
148
+ }): Promise<{
149
+ timestamp: number[];
150
+ equity: number[];
151
+ profit_loss: number[];
152
+ profit_loss_pct: number[];
153
+ base_value: number;
154
+ timeframe: string;
155
+ }>;
156
+ /**
157
+ * Get option contracts based on specified parameters
158
+ * @param params Parameters to filter option contracts
159
+ * @returns Option contracts matching the criteria
160
+ */
161
+ getOptionContracts(params: GetOptionContractsParams): Promise<OptionContractsResponse>;
162
+ /**
163
+ * Get a specific option contract by symbol or ID
164
+ * @param symbolOrId The symbol or ID of the option contract
165
+ * @returns The option contract details
166
+ */
167
+ getOptionContract(symbolOrId: string): Promise<OptionContract>;
168
+ /**
169
+ * Create a simple option order (market or limit)
170
+ * @param symbol Option contract symbol
171
+ * @param qty Quantity of contracts (must be a whole number)
172
+ * @param side Buy or sell
173
+ * @param position_intent Position intent (buy_to_open, buy_to_close, sell_to_open, sell_to_close)
174
+ * @param type Order type (market or limit)
175
+ * @param limitPrice Limit price (required for limit orders)
176
+ * @returns The created order
177
+ */
178
+ createOptionOrder(symbol: string, qty: number, side: "buy" | "sell", position_intent: "buy_to_open" | "buy_to_close" | "sell_to_open" | "sell_to_close", type: "market" | "limit", limitPrice?: number): Promise<AlpacaOrder>;
179
+ /**
180
+ * Create a multi-leg option order
181
+ * @param legs Array of order legs
182
+ * @param qty Quantity of the multi-leg order (must be a whole number)
183
+ * @param type Order type (market or limit)
184
+ * @param limitPrice Limit price (required for limit orders)
185
+ * @returns The created multi-leg order
186
+ */
187
+ createMultiLegOptionOrder(legs: OrderLeg[], qty: number, type: "market" | "limit", limitPrice?: number): Promise<AlpacaOrder>;
188
+ /**
189
+ * Exercise an option contract
190
+ * @param symbolOrContractId The symbol or ID of the option contract to exercise
191
+ * @returns Response from the exercise request
192
+ */
193
+ exerciseOption(symbolOrContractId: string): Promise<ExerciseOptionResponse>;
194
+ /**
195
+ * Get option positions
196
+ * @returns Array of option positions
197
+ */
198
+ getOptionPositions(): Promise<AlpacaPosition[]>;
199
+ getOptionsOpenSpreadTrades(): Promise<void>;
200
+ /**
201
+ * Get option account activities (exercises, assignments, expirations)
202
+ * @param activityType Type of option activity to filter by
203
+ * @param date Date to filter activities (YYYY-MM-DD format)
204
+ * @returns Array of option account activities
205
+ */
206
+ getOptionActivities(activityType?: "OPEXC" | "OPASN" | "OPEXP", date?: string): Promise<OptionAccountActivity[]>;
207
+ /**
208
+ * Create a long call spread (buy lower strike call, sell higher strike call)
209
+ * @param lowerStrikeCallSymbol Symbol of the lower strike call option
210
+ * @param higherStrikeCallSymbol Symbol of the higher strike call option
211
+ * @param qty Quantity of spreads to create (must be a whole number)
212
+ * @param limitPrice Limit price for the spread
213
+ * @returns The created multi-leg order
214
+ */
215
+ createLongCallSpread(lowerStrikeCallSymbol: string, higherStrikeCallSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
216
+ /**
217
+ * Create a long put spread (buy higher strike put, sell lower strike put)
218
+ * @param higherStrikePutSymbol Symbol of the higher strike put option
219
+ * @param lowerStrikePutSymbol Symbol of the lower strike put option
220
+ * @param qty Quantity of spreads to create (must be a whole number)
221
+ * @param limitPrice Limit price for the spread
222
+ * @returns The created multi-leg order
223
+ */
224
+ createLongPutSpread(higherStrikePutSymbol: string, lowerStrikePutSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
225
+ /**
226
+ * Create an iron condor (sell call spread and put spread)
227
+ * @param longPutSymbol Symbol of the lower strike put (long)
228
+ * @param shortPutSymbol Symbol of the higher strike put (short)
229
+ * @param shortCallSymbol Symbol of the lower strike call (short)
230
+ * @param longCallSymbol Symbol of the higher strike call (long)
231
+ * @param qty Quantity of iron condors to create (must be a whole number)
232
+ * @param limitPrice Limit price for the iron condor (credit)
233
+ * @returns The created multi-leg order
234
+ */
235
+ createIronCondor(longPutSymbol: string, shortPutSymbol: string, shortCallSymbol: string, longCallSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
236
+ /**
237
+ * Create a covered call (sell call option against owned stock)
238
+ * @param stockSymbol Symbol of the underlying stock
239
+ * @param callOptionSymbol Symbol of the call option to sell
240
+ * @param qty Quantity of covered calls to create (must be a whole number)
241
+ * @param limitPrice Limit price for the call option
242
+ * @returns The created order
243
+ */
244
+ createCoveredCall(stockSymbol: string, callOptionSymbol: string, qty: number, limitPrice: number): Promise<AlpacaOrder>;
245
+ /**
246
+ * Roll an option position to a new expiration or strike
247
+ * @param currentOptionSymbol Symbol of the current option position
248
+ * @param newOptionSymbol Symbol of the new option to roll to
249
+ * @param qty Quantity of options to roll (must be a whole number)
250
+ * @param currentPositionSide Side of the current position ('buy' or 'sell')
251
+ * @param limitPrice Net limit price for the roll
252
+ * @returns The created multi-leg order
253
+ */
254
+ rollOptionPosition(currentOptionSymbol: string, newOptionSymbol: string, qty: number, currentPositionSide: "buy" | "sell", limitPrice: number): Promise<AlpacaOrder>;
255
+ /**
256
+ * Get option chain for a specific underlying symbol and expiration date
257
+ * @param underlyingSymbol The underlying stock symbol
258
+ * @param expirationDate The expiration date (YYYY-MM-DD format)
259
+ * @returns Option contracts for the specified symbol and expiration date
260
+ */
261
+ getOptionChain(underlyingSymbol: string, expirationDate: string): Promise<OptionContract[]>;
262
+ /**
263
+ * Get all available expiration dates for a specific underlying symbol
264
+ * @param underlyingSymbol The underlying stock symbol
265
+ * @returns Array of available expiration dates
266
+ */
267
+ getOptionExpirationDates(underlyingSymbol: string): Promise<string[]>;
268
+ /**
269
+ * Get the current options trading level for the account
270
+ * @returns The options trading level (0-3)
271
+ */
272
+ getOptionsTradingLevel(): Promise<number>;
273
+ /**
274
+ * Check if the account has options trading enabled
275
+ * @returns Boolean indicating if options trading is enabled
276
+ */
277
+ isOptionsEnabled(): Promise<boolean>;
278
+ /**
279
+ * Close all option positions
280
+ * @param cancelOrders Whether to cancel related orders (default: true)
281
+ * @returns Response from the close positions request
282
+ */
283
+ closeAllOptionPositions(cancelOrders?: boolean): Promise<void>;
284
+ /**
285
+ * Close a specific option position
286
+ * @param symbol The option contract symbol
287
+ * @param qty Optional quantity to close (defaults to entire position)
288
+ * @returns The created order
289
+ */
290
+ closeOptionPosition(symbol: string, qty?: number): Promise<AlpacaOrder>;
291
+ /**
292
+ * Create a complete equities trade with optional stop loss and take profit
293
+ * @param params Trade parameters including symbol, qty, side, and optional referencePrice
294
+ * @param options Trade options including order type, extended hours, stop loss, and take profit settings
295
+ * @returns The created order
296
+ */
297
+ createEquitiesTrade(params: {
298
+ symbol: string;
299
+ qty: number;
300
+ side: "buy" | "sell";
301
+ referencePrice?: number;
302
+ }, options?: {
303
+ type?: "market" | "limit";
304
+ limitPrice?: number;
305
+ extendedHours?: boolean;
306
+ useStopLoss?: boolean;
307
+ stopPrice?: number;
308
+ stopPercent100?: number;
309
+ useTakeProfit?: boolean;
310
+ takeProfitPrice?: number;
311
+ takeProfitPercent100?: number;
312
+ clientOrderId?: string;
313
+ }): Promise<AlpacaOrder>;
314
+ }
315
+ //# sourceMappingURL=alpaca-trading-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alpaca-trading-api.d.ts","sourceRoot":"","sources":["../../src/alpaca-trading-api.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,uBAAuB,EACvB,WAAW,EACX,QAAQ,EACR,WAAW,EAMX,sBAAsB,EACvB,MAAM,sBAAsB,CAAC;AAW9B;;;;;;;EAOE;AAEF,qBA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M,EACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,cAAc,EAAE,CAAC;IAiC5B;;;;OAIG;IACG,wBAAwB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAsC3E;;;OAGG;IACG,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC;IAO/C;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAiB1C;;;;OAIG;IACG,uBAAuB,CAAC,YAAY,GAAE,OAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAkD1E;;;;;OAKG;IACG,mBAAmB,CACvB,MAAM,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACX,OAAO,CAAC,WAAW,CAAC;IAkCvB;;;;;OAKG;IACG,mBAAmB,CACvB,MAAM,EAAE;QACN,MAAM,EAAE,MAAM,CAAC;QACf,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;QACrB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,EACD,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;QAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,GACA,OAAO,CAAC,WAAW,CAAC;CA4LxB"}
@@ -0,0 +1,44 @@
1
+ /**********************************************************************************
2
+ * AlphaVantage calls
3
+ **********************************************************************************/
4
+ import { AlphaVantageQuoteResponse, AVNewsArticle } from "./types";
5
+ /**
6
+ * Fetches the current quote for a given ticker symbol.
7
+ * @param {string} ticker - The ticker symbol to fetch the quote for.
8
+ * @param {Object} [options] - Optional parameters.
9
+ * @param {string} [options.apiKey] - The API key to use for the request.
10
+ * @returns {Promise<AlphaVantageQuoteResponse>} The current quote response.
11
+ */
12
+ export declare const fetchQuote: (ticker: string, options?: {
13
+ apiKey?: string;
14
+ }) => Promise<AlphaVantageQuoteResponse>;
15
+ /**
16
+ * Converts a Date object to a string in the format YYYYMMDDTHHMM.
17
+ * @param {Date} date - The date to convert.
18
+ * @returns {string} The formatted date string.
19
+ */
20
+ export declare function convertDateToYYYYMMDDTHHMM(date: Date): string;
21
+ /**
22
+ * Converts a string in the format YYYYMMDDTHHMMSS to a Date object.
23
+ * @param {string} dateString - The date string to convert.
24
+ * @returns {Date} The corresponding Date object.
25
+ */
26
+ export declare function convertYYYYMMDDTHHMMSSToDate(dateString: string): Date;
27
+ /**
28
+ * Fetches news articles from AlphaVantage for a given ticker symbol. Performs filtering as the API endpoint doesn't respect the parameters.
29
+ * @param {string} ticker - The ticker symbol to fetch news for.
30
+ * @param {Object} [options] - Optional parameters.
31
+ * @param {Date} [options.start] - The start date for fetching news.
32
+ * @param {Date} [options.end] - The end date for fetching news.
33
+ * @param {number} [options.limit] - The maximum number of news articles to fetch.
34
+ * @param {string} [options.apiKey] - The API key to use for the request.
35
+ * @returns {Promise<AVNewsArticle[]>} The fetched news articles.
36
+ */
37
+ export declare const fetchTickerNews: (ticker: string, options?: {
38
+ start?: Date;
39
+ end?: Date;
40
+ limit?: number;
41
+ apiKey?: string;
42
+ sort?: "LATEST" | "EARLIEST" | "RELEVANCE";
43
+ }) => Promise<AVNewsArticle[]>;
44
+ //# sourceMappingURL=alphavantage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"alphavantage.d.ts","sourceRoot":"","sources":["../../src/alphavantage.ts"],"names":[],"mappings":"AAAA;;oFAEoF;AAEpF,OAAO,EACL,yBAAyB,EAEzB,aAAa,EACd,MAAM,SAAS,CAAC;AAwBjB;;;;;;GAMG;AAEH,eAAO,MAAM,UAAU,GACrB,QAAQ,MAAM,EACd,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,KAC5B,OAAO,CAAC,yBAAyB,CA0BnC,CAAC;AAEF;;;;GAIG;AAEH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAU7D;AAED;;;;GAIG;AAEH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CASrE;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,GAC1B,QAAQ,MAAM,EACd,UAAS;IACP,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,WAAW,CAAC;CAM5C,KACA,OAAO,CAAC,aAAa,EAAE,CA6EzB,CAAC"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Intelligent Asset Allocation Algorithm
3
+ *
4
+ * Determines optimal asset allocation across multiple asset classes based on:
5
+ * - User risk profile
6
+ * - Market conditions
7
+ * - Account size
8
+ * - User preferences
9
+ * - Modern Portfolio Theory principles
10
+ * - Risk-adjusted returns
11
+ * - Diversification optimization
12
+ */
13
+ import { RiskProfile, AllocationInput, AllocationRecommendation, AllocationStrategyConfig, DefaultRiskProfile } from "./types/asset-allocation-types";
14
+ /**
15
+ * Asset Allocation Engine
16
+ *
17
+ * Implements sophisticated portfolio optimization using:
18
+ * - Mean-variance optimization
19
+ * - Risk parity approach
20
+ * - Black-Litterman model influences
21
+ * - Correlation-based diversification
22
+ * - Dynamic risk adjustment
23
+ */
24
+ export declare class AssetAllocationEngine {
25
+ private config;
26
+ private readonly defaultConfig;
27
+ /**
28
+ * Default risk profiles with typical asset class allocations
29
+ */
30
+ private readonly defaultRiskProfiles;
31
+ constructor(config?: AllocationStrategyConfig);
32
+ /**
33
+ * Get default risk profile characteristics
34
+ * @param profile - The risk profile to retrieve
35
+ * @returns The default risk profile characteristics or undefined if not found
36
+ */
37
+ getDefaultRiskProfile(profile: RiskProfile): DefaultRiskProfile | undefined;
38
+ /**
39
+ * Generate optimal asset allocation recommendation
40
+ */
41
+ generateAllocation(input: AllocationInput): Promise<AllocationRecommendation>;
42
+ /**
43
+ * Infer risk profile from account characteristics
44
+ */
45
+ private inferRiskProfile;
46
+ /**
47
+ * Assess current market condition
48
+ */
49
+ private assessMarketCondition;
50
+ /**
51
+ * Get base allocations from risk profile
52
+ */
53
+ private getBaseAllocations;
54
+ /**
55
+ * Adjust allocations based on market conditions
56
+ */
57
+ private adjustForMarketConditions;
58
+ /**
59
+ * Scale allocation for a specific asset class
60
+ */
61
+ private scaleAllocation;
62
+ /**
63
+ * Normalize allocations to sum to 1.0
64
+ */
65
+ private normalizeAllocations;
66
+ /**
67
+ * Apply user constraints and preferences
68
+ */
69
+ private applyConstraints;
70
+ /**
71
+ * Optimize allocations using specified objective
72
+ */
73
+ private optimizeAllocations;
74
+ /**
75
+ * Maximize Sharpe ratio allocation
76
+ */
77
+ private maximizeSharpeRatio;
78
+ /**
79
+ * Minimize portfolio risk
80
+ */
81
+ private minimizeRisk;
82
+ /**
83
+ * Maximize expected return
84
+ */
85
+ private maximizeReturn;
86
+ /**
87
+ * Risk parity allocation (equal risk contribution)
88
+ */
89
+ private riskParityAllocation;
90
+ /**
91
+ * Maximize diversification
92
+ */
93
+ private maximizeDiversification;
94
+ /**
95
+ * Calculate comprehensive portfolio metrics
96
+ */
97
+ private calculatePortfolioMetrics;
98
+ /**
99
+ * Perform comprehensive risk analysis
100
+ */
101
+ private performRiskAnalysis;
102
+ /**
103
+ * Calculate diversification metrics
104
+ */
105
+ private calculateDiversification;
106
+ /**
107
+ * Generate rebalancing actions
108
+ */
109
+ private generateRebalancingActions;
110
+ /**
111
+ * Build detailed asset allocations
112
+ */
113
+ private buildAssetAllocations;
114
+ /**
115
+ * Generate rationale for asset allocation
116
+ */
117
+ private generateAllocationRationale;
118
+ /**
119
+ * Calculate next rebalancing date
120
+ */
121
+ private calculateNextRebalancingDate;
122
+ /**
123
+ * Get methodology description
124
+ */
125
+ private getMethodologyDescription;
126
+ /**
127
+ * Generate warnings based on allocation
128
+ */
129
+ private generateWarnings;
130
+ /**
131
+ * Generate unique recommendation ID
132
+ */
133
+ private generateRecommendationId;
134
+ }
135
+ /**
136
+ * Convenience function to generate allocation with default settings
137
+ */
138
+ export declare function generateOptimalAllocation(input: AllocationInput, config?: Partial<AllocationStrategyConfig>): Promise<AllocationRecommendation>;
139
+ /**
140
+ * Convenience function to get default risk profile characteristics
141
+ */
142
+ export declare function getDefaultRiskProfile(profile: RiskProfile): DefaultRiskProfile | undefined;
143
+ //# sourceMappingURL=asset-allocation-algorithm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-allocation-algorithm.d.ts","sourceRoot":"","sources":["../../src/asset-allocation-algorithm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAEL,WAAW,EAEX,eAAe,EACf,wBAAwB,EAMxB,wBAAwB,EAMxB,kBAAkB,EAEnB,MAAM,gCAAgC,CAAC;AAExC;;;;;;;;;GASG;AACH,qBAAa,qBAAqB;IAkH9B,OAAO,CAAC,MAAM;IAjHhB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAQ5B;IAEF;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAiG/B;gBAGK,MAAM,GAAE,wBAAyD;IAK3E;;;;OAIG;IACI,qBAAqB,CAC1B,OAAO,EAAE,WAAW,GACnB,kBAAkB,GAAG,SAAS;IAIjC;;OAEG;IACU,kBAAkB,CAC7B,KAAK,EAAE,eAAe,GACrB,OAAO,CAAC,wBAAwB,CAAC;IA6FpC;;OAEG;IACH,OAAO,CAAC,gBAAgB;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