@adaptic/utils 0.0.382 → 0.0.900

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 (225) hide show
  1. package/README.md +153 -61
  2. package/dist/index.cjs +60090 -5244
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +59829 -5244
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/test.js +733 -383
  7. package/dist/test.js.map +1 -1
  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 +2 -2
  53. package/dist/types/adaptic.d.ts.map +1 -1
  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 +12 -10
  141. package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
  142. package/dist/types/alpaca-trading-api.d.ts +12 -12
  143. package/dist/types/alpaca-trading-api.d.ts.map +1 -1
  144. package/dist/types/alphavantage.d.ts +1 -1
  145. package/dist/types/alphavantage.d.ts.map +1 -1
  146. package/dist/types/asset-allocation-algorithm.d.ts +7 -1
  147. package/dist/types/asset-allocation-algorithm.d.ts.map +1 -1
  148. package/dist/types/cache/stampede-protected-cache.d.ts.map +1 -1
  149. package/dist/types/config/api-endpoints.d.ts +94 -0
  150. package/dist/types/config/api-endpoints.d.ts.map +1 -0
  151. package/dist/types/crypto.d.ts +2 -2
  152. package/dist/types/crypto.d.ts.map +1 -1
  153. package/dist/types/display-manager.d.ts +1 -1
  154. package/dist/types/display-manager.d.ts.map +1 -1
  155. package/dist/types/errors/index.d.ts +130 -0
  156. package/dist/types/errors/index.d.ts.map +1 -0
  157. package/dist/types/examples/asset-allocation-example.d.ts +7 -6
  158. package/dist/types/examples/asset-allocation-example.d.ts.map +1 -1
  159. package/dist/types/examples/rate-limiter-example.d.ts +7 -0
  160. package/dist/types/examples/rate-limiter-example.d.ts.map +1 -0
  161. package/dist/types/format-tools.d.ts.map +1 -1
  162. package/dist/types/http-timeout.d.ts +37 -0
  163. package/dist/types/http-timeout.d.ts.map +1 -0
  164. package/dist/types/index.d.ts +393 -55
  165. package/dist/types/index.d.ts.map +1 -1
  166. package/dist/types/logger.d.ts +56 -0
  167. package/dist/types/logger.d.ts.map +1 -0
  168. package/dist/types/logging.d.ts +1 -1
  169. package/dist/types/logging.d.ts.map +1 -1
  170. package/dist/types/market-hours.d.ts.map +1 -1
  171. package/dist/types/market-time.d.ts +75 -13
  172. package/dist/types/market-time.d.ts.map +1 -1
  173. package/dist/types/metrics-calcs.d.ts.map +1 -1
  174. package/dist/types/misc-utils.d.ts +4 -1
  175. package/dist/types/misc-utils.d.ts.map +1 -1
  176. package/dist/types/performance-metrics.d.ts +4 -4
  177. package/dist/types/performance-metrics.d.ts.map +1 -1
  178. package/dist/types/polygon-indices.d.ts +3 -3
  179. package/dist/types/polygon-indices.d.ts.map +1 -1
  180. package/dist/types/polygon.d.ts +1 -1
  181. package/dist/types/polygon.d.ts.map +1 -1
  182. package/dist/types/price-utils.d.ts.map +1 -1
  183. package/dist/types/rate-limiter.d.ts +171 -0
  184. package/dist/types/rate-limiter.d.ts.map +1 -0
  185. package/dist/types/schemas/alpaca-schemas.d.ts +779 -0
  186. package/dist/types/schemas/alpaca-schemas.d.ts.map +1 -0
  187. package/dist/types/schemas/alphavantage-schemas.d.ts +255 -0
  188. package/dist/types/schemas/alphavantage-schemas.d.ts.map +1 -0
  189. package/dist/types/schemas/index.d.ts +21 -0
  190. package/dist/types/schemas/index.d.ts.map +1 -0
  191. package/dist/types/schemas/polygon-schemas.d.ts +551 -0
  192. package/dist/types/schemas/polygon-schemas.d.ts.map +1 -0
  193. package/dist/types/schemas/validate-response.d.ts +88 -0
  194. package/dist/types/schemas/validate-response.d.ts.map +1 -0
  195. package/dist/types/technical-analysis.d.ts +9 -9
  196. package/dist/types/technical-analysis.d.ts.map +1 -1
  197. package/dist/types/time-utils.d.ts.map +1 -1
  198. package/dist/types/types/adaptic-types.d.ts +1 -1
  199. package/dist/types/types/adaptic-types.d.ts.map +1 -1
  200. package/dist/types/types/alpaca-types.d.ts +172 -98
  201. package/dist/types/types/alpaca-types.d.ts.map +1 -1
  202. package/dist/types/types/alphavantage-types.d.ts +2 -2
  203. package/dist/types/types/asset-allocation-types.d.ts +11 -11
  204. package/dist/types/types/index.d.ts +8 -8
  205. package/dist/types/types/index.d.ts.map +1 -1
  206. package/dist/types/types/logging-types.d.ts +2 -2
  207. package/dist/types/types/logging-types.d.ts.map +1 -1
  208. package/dist/types/types/market-time-types.d.ts +4 -4
  209. package/dist/types/types/market-time-types.d.ts.map +1 -1
  210. package/dist/types/types/metrics-types.d.ts +3 -3
  211. package/dist/types/types/metrics-types.d.ts.map +1 -1
  212. package/dist/types/types/polygon-indices-types.d.ts +6 -6
  213. package/dist/types/types/polygon-types.d.ts +3 -3
  214. package/dist/types/types/ta-types.d.ts +3 -3
  215. package/dist/types/utils/auth-validator.d.ts +32 -0
  216. package/dist/types/utils/auth-validator.d.ts.map +1 -0
  217. package/dist/types/utils/http-keep-alive.d.ts +110 -0
  218. package/dist/types/utils/http-keep-alive.d.ts.map +1 -0
  219. package/dist/types/utils/paginator.d.ts +154 -0
  220. package/dist/types/utils/paginator.d.ts.map +1 -0
  221. package/dist/types/utils/retry.d.ts +78 -0
  222. package/dist/types/utils/retry.d.ts.map +1 -0
  223. package/package.json +25 -5
  224. package/dist/types/alpaca-functions.d.ts +0 -233
  225. package/dist/types/alpaca-functions.d.ts.map +0 -1
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Alpaca WebSocket Streams Module
3
+ * Real-time market data and trade update streams
4
+ *
5
+ * NOTE: This is a placeholder module. Full streaming support requires
6
+ * additional implementation for WebSocket connection management.
7
+ *
8
+ * @module @adaptic/utils/alpaca/streams
9
+ */
10
+ import { AlpacaClient } from "./client";
11
+ /**
12
+ * Stream manager interface for managing WebSocket connections
13
+ */
14
+ export interface StreamManager {
15
+ /** Connect to trading updates stream */
16
+ connectTradingStream: () => Promise<void>;
17
+ /** Connect to market data stream */
18
+ connectDataStream: () => Promise<void>;
19
+ /** Disconnect all streams */
20
+ disconnect: () => void;
21
+ /** Subscribe to trade updates for specific symbols */
22
+ subscribeToTrades: (symbols: string[]) => void;
23
+ /** Subscribe to quote updates for specific symbols */
24
+ subscribeToQuotes: (symbols: string[]) => void;
25
+ /** Subscribe to bar updates for specific symbols */
26
+ subscribeToBars: (symbols: string[]) => void;
27
+ /** Unsubscribe from symbols */
28
+ unsubscribe: (symbols: string[]) => void;
29
+ }
30
+ /**
31
+ * Stream event types
32
+ */
33
+ export type StreamEventType = "trade" | "quote" | "bar" | "trade_update" | "error" | "connected" | "disconnected";
34
+ /**
35
+ * Stream event handler
36
+ */
37
+ export type StreamEventHandler<T = unknown> = (event: T) => void;
38
+ /**
39
+ * Configuration for stream manager
40
+ */
41
+ export interface StreamManagerConfig {
42
+ /** Client for authentication */
43
+ client: AlpacaClient;
44
+ /** Handler for trade events */
45
+ onTrade?: StreamEventHandler;
46
+ /** Handler for quote events */
47
+ onQuote?: StreamEventHandler;
48
+ /** Handler for bar events */
49
+ onBar?: StreamEventHandler;
50
+ /** Handler for trade update events (order fills, etc.) */
51
+ onTradeUpdate?: StreamEventHandler;
52
+ /** Handler for errors */
53
+ onError?: StreamEventHandler<Error>;
54
+ /** Handler for connection events */
55
+ onConnected?: StreamEventHandler<void>;
56
+ /** Handler for disconnection events */
57
+ onDisconnected?: StreamEventHandler<void>;
58
+ }
59
+ /**
60
+ * Create a stream manager for real-time data
61
+ *
62
+ * NOTE: This is a placeholder implementation. Full streaming support
63
+ * requires WebSocket connection management which is available through
64
+ * the Alpaca SDK's built-in streaming capabilities.
65
+ *
66
+ * @param config - Stream manager configuration
67
+ * @returns A stream manager instance
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const client = createAlpacaClient({ ... });
72
+ * const streamManager = createStreamManager({
73
+ * client,
74
+ * onTrade: (trade) => console.log('Trade:', trade),
75
+ * onQuote: (quote) => console.log('Quote:', quote),
76
+ * onError: (error) => console.error('Stream error:', error),
77
+ * });
78
+ *
79
+ * await streamManager.connectDataStream();
80
+ * streamManager.subscribeToTrades(['AAPL', 'GOOGL']);
81
+ * ```
82
+ */
83
+ export declare function createStreamManager(_config: StreamManagerConfig): StreamManager;
84
+ declare const _default: {
85
+ createStreamManager: typeof createStreamManager;
86
+ };
87
+ export default _default;
88
+ //# sourceMappingURL=streams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../../src/alpaca/streams.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,oBAAoB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,oCAAoC;IACpC,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,6BAA6B;IAC7B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,sDAAsD;IACtD,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC/C,sDAAsD;IACtD,iBAAiB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC/C,oDAAoD;IACpD,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC7C,+BAA+B;IAC/B,WAAW,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB,OAAO,GACP,OAAO,GACP,KAAK,GACL,cAAc,GACd,OAAO,GACP,WAAW,GACX,cAAc,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,gCAAgC;IAChC,MAAM,EAAE,YAAY,CAAC;IACrB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,+BAA+B;IAC/B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,6BAA6B;IAC7B,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAC3B,0DAA0D;IAC1D,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC,yBAAyB;IACzB,OAAO,CAAC,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACpC,oCAAoC;IACpC,WAAW,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;IACvC,uCAAuC;IACvC,cAAc,CAAC,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,mBAAmB,GAC3B,aAAa,CAoCf;;;;AAED,wBAEE"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Test imports file
3
+ * Verifies that all Alpaca module exports compile correctly
4
+ */
5
+ declare const testTypes: () => Promise<void>;
6
+ export { testTypes };
7
+ //# sourceMappingURL=test-imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-imports.d.ts","sourceRoot":"","sources":["../../../src/alpaca/test-imports.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqGH,QAAA,MAAM,SAAS,qBAuBd,CAAC;AAGF,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Account Management Module
3
+ * Handles account details, configuration, and portfolio history
4
+ */
5
+ import { AlpacaClient } from "../client";
6
+ import { AlpacaAccountDetails, AccountConfiguration, PortfolioHistoryParams, PortfolioHistoryResponse } from "../../types/alpaca-types";
7
+ /**
8
+ * Trading eligibility status for an account
9
+ */
10
+ export interface TradingEligibility {
11
+ canTrade: boolean;
12
+ reasons: string[];
13
+ buyingPower: number;
14
+ dayTradeCount: number;
15
+ isPatternDayTrader: boolean;
16
+ }
17
+ /**
18
+ * Buying power breakdown across different asset classes
19
+ */
20
+ export interface BuyingPowerBreakdown {
21
+ cash: number;
22
+ equity: number;
23
+ dayTradingBuyingPower: number;
24
+ regtBuyingPower: number;
25
+ optionsBuyingPower: number;
26
+ cryptoBuyingPower: number;
27
+ }
28
+ /**
29
+ * Pattern Day Trader (PDT) status information
30
+ */
31
+ export interface PDTStatus {
32
+ isPatternDayTrader: boolean;
33
+ dayTradeCount: number;
34
+ dayTradesRemaining: number;
35
+ canDayTrade: boolean;
36
+ }
37
+ /**
38
+ * Daily return information
39
+ */
40
+ export interface DailyReturn {
41
+ date: Date;
42
+ equity: number;
43
+ profitLoss: number;
44
+ profitLossPct: number;
45
+ dailyReturn: number;
46
+ }
47
+ /**
48
+ * Period performance metrics
49
+ */
50
+ export interface PeriodPerformance {
51
+ startDate: Date;
52
+ endDate: Date;
53
+ startingEquity: number;
54
+ endingEquity: number;
55
+ totalReturn: number;
56
+ totalReturnPct: number;
57
+ averageDailyReturn: number;
58
+ maxDrawdown: number;
59
+ maxDrawdownPct: number;
60
+ sharpeRatio: number | null;
61
+ volatility: number;
62
+ winningDays: number;
63
+ losingDays: number;
64
+ winRate: number;
65
+ }
66
+ /**
67
+ * Equity curve data point
68
+ */
69
+ export interface EquityCurvePoint {
70
+ timestamp: Date;
71
+ equity: number;
72
+ profitLoss: number;
73
+ profitLossPct: number;
74
+ cumulativeReturn: number;
75
+ }
76
+ /**
77
+ * Get account details from Alpaca
78
+ * @param client - AlpacaClient instance
79
+ * @returns Promise resolving to account details
80
+ */
81
+ export declare function getAccountDetails(client: AlpacaClient): Promise<AlpacaAccountDetails>;
82
+ /**
83
+ * Get account configuration from Alpaca
84
+ * @param client - AlpacaClient instance
85
+ * @returns Promise resolving to account configuration
86
+ */
87
+ export declare function getAccountConfiguration(client: AlpacaClient): Promise<AccountConfiguration>;
88
+ /**
89
+ * Update account configuration on Alpaca
90
+ * @param client - AlpacaClient instance
91
+ * @param config - Partial configuration to update
92
+ * @returns Promise resolving to updated account configuration
93
+ */
94
+ export declare function updateAccountConfiguration(client: AlpacaClient, config: Partial<AccountConfiguration>): Promise<AccountConfiguration>;
95
+ /**
96
+ * Get portfolio history from Alpaca
97
+ * @param client - AlpacaClient instance
98
+ * @param params - Parameters for portfolio history request
99
+ * @returns Promise resolving to portfolio history response
100
+ */
101
+ export declare function getPortfolioHistory(client: AlpacaClient, params: PortfolioHistoryParams): Promise<PortfolioHistoryResponse>;
102
+ /**
103
+ * Check if account is eligible for trading
104
+ * @param client - AlpacaClient instance
105
+ * @returns Promise resolving to trading eligibility status
106
+ */
107
+ export declare function checkTradingEligibility(client: AlpacaClient): Promise<TradingEligibility>;
108
+ /**
109
+ * Get buying power breakdown for different asset classes
110
+ * @param client - AlpacaClient instance
111
+ * @returns Promise resolving to buying power breakdown
112
+ */
113
+ export declare function getBuyingPower(client: AlpacaClient): Promise<BuyingPowerBreakdown>;
114
+ /**
115
+ * Get options trading level for the account
116
+ * @param client - AlpacaClient instance
117
+ * @returns Promise resolving to options trading level (0-3)
118
+ */
119
+ export declare function getOptionsTradingLevel(client: AlpacaClient): Promise<0 | 1 | 2 | 3>;
120
+ /**
121
+ * Get Pattern Day Trader (PDT) status
122
+ * @param client - AlpacaClient instance
123
+ * @returns Promise resolving to PDT status
124
+ */
125
+ export declare function getPDTStatus(client: AlpacaClient): Promise<PDTStatus>;
126
+ /**
127
+ * Get daily returns from portfolio history
128
+ * @param client - AlpacaClient instance
129
+ * @param period - Period to fetch (e.g., '1W', '1M', '3M', '1A')
130
+ * @returns Promise resolving to array of daily returns
131
+ */
132
+ export declare function getDailyReturns(client: AlpacaClient, period?: string): Promise<DailyReturn[]>;
133
+ /**
134
+ * Calculate period performance metrics
135
+ * @param client - AlpacaClient instance
136
+ * @param period - Period to analyze (e.g., '1W', '1M', '3M', '1A')
137
+ * @returns Promise resolving to period performance metrics
138
+ */
139
+ export declare function calculatePeriodPerformance(client: AlpacaClient, period?: string): Promise<PeriodPerformance>;
140
+ /**
141
+ * Get equity curve data
142
+ * @param client - AlpacaClient instance
143
+ * @param params - Portfolio history parameters
144
+ * @returns Promise resolving to equity curve data points
145
+ */
146
+ export declare function getEquityCurve(client: AlpacaClient, params?: PortfolioHistoryParams): Promise<EquityCurvePoint[]>;
147
+ /**
148
+ * Get account equity and cash summary
149
+ * @param client - AlpacaClient instance
150
+ * @returns Promise resolving to account summary
151
+ */
152
+ export declare function getAccountSummary(client: AlpacaClient): Promise<{
153
+ equity: number;
154
+ cash: number;
155
+ portfolioValue: number;
156
+ longMarketValue: number;
157
+ shortMarketValue: number;
158
+ lastEquity: number;
159
+ todayProfitLoss: number;
160
+ todayProfitLossPct: number;
161
+ }>;
162
+ /**
163
+ * Check if account is a margin account
164
+ * @param client - AlpacaClient instance
165
+ * @returns Promise resolving to boolean indicating margin status
166
+ */
167
+ export declare function isMarginAccount(client: AlpacaClient): Promise<boolean>;
168
+ /**
169
+ * Get margin information for the account
170
+ * @param client - AlpacaClient instance
171
+ * @returns Promise resolving to margin information
172
+ */
173
+ export declare function getMarginInfo(client: AlpacaClient): Promise<{
174
+ multiplier: string;
175
+ initialMargin: number;
176
+ maintenanceMargin: number;
177
+ lastMaintenanceMargin: number;
178
+ sma: number;
179
+ marginCallAmount: number;
180
+ }>;
181
+ declare const _default: {
182
+ getAccountDetails: typeof getAccountDetails;
183
+ getAccountConfiguration: typeof getAccountConfiguration;
184
+ updateAccountConfiguration: typeof updateAccountConfiguration;
185
+ getPortfolioHistory: typeof getPortfolioHistory;
186
+ checkTradingEligibility: typeof checkTradingEligibility;
187
+ getBuyingPower: typeof getBuyingPower;
188
+ getOptionsTradingLevel: typeof getOptionsTradingLevel;
189
+ getPDTStatus: typeof getPDTStatus;
190
+ getDailyReturns: typeof getDailyReturns;
191
+ calculatePeriodPerformance: typeof calculatePeriodPerformance;
192
+ getEquityCurve: typeof getEquityCurve;
193
+ getAccountSummary: typeof getAccountSummary;
194
+ isMarginAccount: typeof isMarginAccount;
195
+ getMarginInfo: typeof getMarginInfo;
196
+ };
197
+ export default _default;
198
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/trading/account.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,0BAA0B,CAAC;AASlC;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE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AAM,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB5E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC,CA+BD;;;;;;;;;;;;;;;;;AAED,wBAeE"}
@@ -0,0 +1,162 @@
1
+ import { AlpacaOrder, OrderSide, TimeInForce, CreateOrderParams } from "../../types/alpaca-types";
2
+ /**
3
+ * Interface for the Alpaca client/API that can execute bracket orders.
4
+ * This can be implemented by AlpacaTradingAPI or a future AlpacaClient class.
5
+ */
6
+ export interface BracketOrderExecutor {
7
+ /** Execute an order request and return the created order */
8
+ createOrder(params: CreateOrderParams): Promise<AlpacaOrder>;
9
+ }
10
+ /**
11
+ * Parameters for creating a bracket order.
12
+ */
13
+ export interface BracketOrderParams {
14
+ /** Stock symbol */
15
+ symbol: string;
16
+ /** Number of shares */
17
+ qty: number;
18
+ /** Order side: buy or sell */
19
+ side: OrderSide;
20
+ /** Entry order type: market for immediate, limit for price-specific */
21
+ type: "market" | "limit";
22
+ /** Limit price for entry (required if type is 'limit') */
23
+ limitPrice?: number;
24
+ /** Take profit configuration */
25
+ takeProfit: {
26
+ /** Price at which to take profit */
27
+ limitPrice: number;
28
+ };
29
+ /** Stop loss configuration */
30
+ stopLoss: {
31
+ /** Price at which to trigger stop */
32
+ stopPrice: number;
33
+ /** Optional limit price for stop-limit (if omitted, uses market stop) */
34
+ limitPrice?: number;
35
+ };
36
+ /** Time in force: 'day' expires at market close, 'gtc' good till canceled */
37
+ timeInForce?: TimeInForce;
38
+ /** Enable extended hours trading */
39
+ extendedHours?: boolean;
40
+ /** Client-specified order ID for tracking */
41
+ clientOrderId?: string;
42
+ }
43
+ /**
44
+ * Result of a bracket order submission.
45
+ */
46
+ export interface BracketOrderResult {
47
+ /** The parent/entry order */
48
+ entryOrder: AlpacaOrder;
49
+ /** The take profit leg */
50
+ takeProfitLeg: AlpacaOrder | null;
51
+ /** The stop loss leg */
52
+ stopLossLeg: AlpacaOrder | null;
53
+ /** All legs combined */
54
+ allOrders: AlpacaOrder[];
55
+ }
56
+ /**
57
+ * Create a bracket order (entry + take profit + stop loss).
58
+ *
59
+ * A bracket order ensures that when the entry fills:
60
+ * - A take profit limit order is placed
61
+ * - A stop loss order is placed
62
+ * - If either TP or SL fills, the other is automatically canceled (OCO behavior)
63
+ *
64
+ * @param executor - The order executor (AlpacaTradingAPI or AlpacaClient)
65
+ * @param params - The bracket order parameters
66
+ * @returns The bracket order result containing entry and leg orders
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const api = AlpacaTradingAPI.new(credentials);
71
+ * const result = await createBracketOrder(
72
+ * { createOrder: (p) => api.makeRequest('/orders', 'POST', p) },
73
+ * {
74
+ * symbol: 'AAPL',
75
+ * qty: 100,
76
+ * side: 'buy',
77
+ * type: 'limit',
78
+ * limitPrice: 150.00,
79
+ * takeProfit: { limitPrice: 160.00 },
80
+ * stopLoss: { stopPrice: 145.00 },
81
+ * timeInForce: 'gtc',
82
+ * }
83
+ * );
84
+ * ```
85
+ */
86
+ export declare function createBracketOrder(executor: BracketOrderExecutor, params: BracketOrderParams): Promise<BracketOrderResult>;
87
+ /**
88
+ * Parameters for creating a protective bracket on an existing position.
89
+ */
90
+ export interface ProtectiveBracketParams {
91
+ /** Stock symbol */
92
+ symbol: string;
93
+ /** Number of shares to protect */
94
+ qty: number;
95
+ /** Side is always 'sell' to close a long position */
96
+ side: "sell";
97
+ /** Take profit configuration */
98
+ takeProfit: {
99
+ /** Price at which to take profit */
100
+ limitPrice: number;
101
+ };
102
+ /** Stop loss configuration */
103
+ stopLoss: {
104
+ /** Price at which to trigger stop */
105
+ stopPrice: number;
106
+ /** Optional limit price for stop-limit */
107
+ limitPrice?: number;
108
+ };
109
+ /** Time in force: 'day' expires at market close, 'gtc' good till canceled */
110
+ timeInForce?: TimeInForce;
111
+ }
112
+ /**
113
+ * Create a bracket order for an existing position (protective bracket).
114
+ * Useful for adding stop loss and take profit to a position that was entered without them.
115
+ *
116
+ * Note: This creates an OCO (One-Cancels-Other) order rather than a full bracket
117
+ * because we already have the position - we just need the exit legs.
118
+ *
119
+ * @param executor - The order executor (AlpacaTradingAPI or AlpacaClient)
120
+ * @param params - The protective bracket parameters
121
+ * @returns The bracket order result
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * // Add protection to an existing long position
126
+ * const result = await createProtectiveBracket(
127
+ * executor,
128
+ * {
129
+ * symbol: 'AAPL',
130
+ * qty: 100,
131
+ * side: 'sell',
132
+ * takeProfit: { limitPrice: 160.00 },
133
+ * stopLoss: { stopPrice: 145.00 },
134
+ * timeInForce: 'gtc',
135
+ * }
136
+ * );
137
+ * ```
138
+ */
139
+ export declare function createProtectiveBracket(executor: BracketOrderExecutor, params: ProtectiveBracketParams): Promise<BracketOrderResult>;
140
+ /**
141
+ * Creates an adapter to use AlpacaTradingAPI as a BracketOrderExecutor.
142
+ *
143
+ * @param api - Instance of AlpacaTradingAPI
144
+ * @returns BracketOrderExecutor compatible with bracket order functions
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const api = AlpacaTradingAPI.new(credentials);
149
+ * const executor = createExecutorFromTradingAPI(api);
150
+ * const result = await createBracketOrder(executor, params);
151
+ * ```
152
+ */
153
+ export declare function createExecutorFromTradingAPI(api: {
154
+ makeRequest: (endpoint: string, method: string, body?: unknown) => Promise<AlpacaOrder>;
155
+ }): BracketOrderExecutor;
156
+ declare const _default: {
157
+ createBracketOrder: typeof createBracketOrder;
158
+ createProtectiveBracket: typeof createProtectiveBracket;
159
+ createExecutorFromTradingAPI: typeof createExecutorFromTradingAPI;
160
+ };
161
+ export default _default;
162
+ //# sourceMappingURL=bracket-orders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bracket-orders.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/trading/bracket-orders.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,WAAW,EACX,SAAS,EACT,WAAW,EACX,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAYlC;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,IAAI,EAAE,SAAS,CAAC;IAChB,uEAAuE;IACvE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC;IACzB,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,UAAU,EAAE;QACV,oCAAoC;QACpC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,8BAA8B;IAC9B,QAAQ,EAAE;QACR,qCAAqC;QACrC,SAAS,EAAE,MAAM,CAAC;QAClB,yEAAyE;QACzE,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,6EAA6E;IAC7E,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oCAAoC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,6CAA6C;IAC7C,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,UAAU,EAAE,WAAW,CAAC;IACxB,0BAA0B;IAC1B,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,wBAAwB;IACxB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAC;IAChC,wBAAwB;IACxB,SAAS,EAAE,WAAW,EAAE,CAAC;CAC1B;AAoED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CA+F7B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,gCAAgC;IAChC,UAAU,EAAE;QACV,oCAAoC;QACpC,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,8BAA8B;IAC9B,QAAQ,EAAE;QACR,qCAAqC;QACrC,SAAS,EAAE,MAAM,CAAC;QAClB,0CAA0C;QAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,6EAA6E;IAC7E,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,oBAAoB,EAC9B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,kBAAkB,CAAC,CAsF7B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE;IAChD,WAAW,EAAE,CACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,OAAO,KACX,OAAO,CAAC,WAAW,CAAC,CAAC;CAC3B,GAAG,oBAAoB,CAMvB;;;;;;AAED,wBAIE"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Market Clock and Calendar Module
3
+ * Provides access to market hours (clock) and trading calendar via the Alpaca API
4
+ */
5
+ import { AlpacaClient } from "../client";
6
+ /**
7
+ * Alpaca market clock representing the current market status and next session times.
8
+ * Corresponds to the response from GET /v2/clock.
9
+ */
10
+ export interface AlpacaClock {
11
+ /** ISO 8601 timestamp of the current server time */
12
+ timestamp: string;
13
+ /** Whether the market is currently open for trading */
14
+ is_open: boolean;
15
+ /** ISO 8601 timestamp of the next market open */
16
+ next_open: string;
17
+ /** ISO 8601 timestamp of the next market close */
18
+ next_close: string;
19
+ }
20
+ /**
21
+ * A single trading day entry from the Alpaca market calendar.
22
+ * Corresponds to one element in the response from GET /v2/calendar.
23
+ */
24
+ export interface AlpacaCalendarDay {
25
+ /** The date in YYYY-MM-DD format */
26
+ date: string;
27
+ /** The market open time in HH:MM format (US Eastern) */
28
+ open: string;
29
+ /** The market close time in HH:MM format (US Eastern) */
30
+ close: string;
31
+ /** The settlement date in YYYY-MM-DD format */
32
+ settlement_date: string;
33
+ }
34
+ /**
35
+ * Options for fetching the Alpaca market calendar.
36
+ */
37
+ export interface GetAlpacaCalendarOptions {
38
+ /** Start date for the calendar range (inclusive). Defaults to today if omitted. */
39
+ start?: Date;
40
+ /** End date for the calendar range (inclusive). Defaults to today if omitted. */
41
+ end?: Date;
42
+ }
43
+ /**
44
+ * Fetches the current market clock from Alpaca (GET /v2/clock).
45
+ *
46
+ * Returns the current server time, whether the market is open, and the next
47
+ * open/close timestamps. Useful for determining whether trading is currently
48
+ * possible before placing orders.
49
+ *
50
+ * @param client - An initialized AlpacaClient instance
51
+ * @returns Promise resolving to the current market clock status
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * const clock = await getAlpacaClock(client);
56
+ * if (clock.is_open) {
57
+ * console.log('Market is open, next close:', clock.next_close);
58
+ * } else {
59
+ * console.log('Market closed, next open:', clock.next_open);
60
+ * }
61
+ * ```
62
+ *
63
+ * @throws {Error} If the Alpaca API request fails
64
+ */
65
+ export declare function getAlpacaClock(client: AlpacaClient): Promise<AlpacaClock>;
66
+ /**
67
+ * Fetches the market trading calendar from Alpaca (GET /v2/calendar).
68
+ *
69
+ * Returns the scheduled open and close times for each trading day within the
70
+ * requested date range. The calendar accounts for market holidays and early
71
+ * closures. Dates default to today when omitted.
72
+ *
73
+ * @param client - An initialized AlpacaClient instance
74
+ * @param options - Optional start/end dates for the calendar range
75
+ * @returns Promise resolving to an array of trading calendar days
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * // Fetch the next 5 trading days
80
+ * const today = new Date();
81
+ * const nextWeek = new Date(today);
82
+ * nextWeek.setDate(today.getDate() + 7);
83
+ *
84
+ * const calendar = await getAlpacaCalendar(client, {
85
+ * start: today,
86
+ * end: nextWeek,
87
+ * });
88
+ * console.log('Trading days this week:', calendar.length);
89
+ * ```
90
+ *
91
+ * @throws {Error} If the Alpaca API request fails
92
+ */
93
+ export declare function getAlpacaCalendar(client: AlpacaClient, options?: GetAlpacaCalendarOptions): Promise<AlpacaCalendarDay[]>;
94
+ declare const _default: {
95
+ getAlpacaClock: typeof getAlpacaClock;
96
+ getAlpacaCalendar: typeof getAlpacaCalendar;
97
+ };
98
+ export default _default;
99
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/trading/clock.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAQzC;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,oCAAoC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,mFAAmF;IACnF,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,iFAAiF;IACjF,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAeD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,WAAW,CAAC,CAetB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE,wBAAwB,GACjC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAwB9B;;;;;AAED,wBAGE"}
@@ -0,0 +1,15 @@
1
+ export { createBracketOrder, createProtectiveBracket, createExecutorFromTradingAPI, BracketOrderParams, BracketOrderResult, BracketOrderExecutor, ProtectiveBracketParams, } from "./bracket-orders";
2
+ export { default as bracketOrders } from "./bracket-orders";
3
+ export { getAccountDetails, getAccountConfiguration, updateAccountConfiguration, getPortfolioHistory, checkTradingEligibility, getBuyingPower, getOptionsTradingLevel, getPDTStatus, getDailyReturns, calculatePeriodPerformance, getEquityCurve, getAccountSummary, isMarginAccount, getMarginInfo, TradingEligibility, BuyingPowerBreakdown, PDTStatus, DailyReturn, PeriodPerformance, EquityCurvePoint, } from "./account";
4
+ export { default as account } from "./account";
5
+ export { getOrdersBySymbol, getOpenOrders as getOpenOrdersQuery, getFilledOrders, getOrderHistory, getAllOrders, waitForOrderFill, isOrderFillable, isOrderFilled, isOrderTerminal as isOrderTerminalStatus, isOrderOpen, calculateOrderValue, calculateTotalFilledValue, formatOrderSummary, formatOrderForLog, roundPriceForAlpaca, roundPriceForAlpacaNumber, groupOrdersBySymbol, groupOrdersByStatus, filterOrdersByDateRange, sortOrdersByDate, GetAllOrdersParams, GetFilledOrdersParams, GetOrderHistoryParams, OrderHistoryResult, WaitForOrderFillParams, WaitForOrderFillResult, OrderSummary, } from "./order-utils";
6
+ export { default as orderUtils } from "./order-utils";
7
+ export { createTrailingStop, updateTrailingStop, getTrailingStopHWM, cancelTrailingStop, createPortfolioTrailingStops, getOpenTrailingStops, hasActiveTrailingStop, cancelTrailingStopsForSymbol, TrailingStopParams, TrailingStopHWMResult, PortfolioTrailingStopParams, TrailingStopValidationError, } from "./trailing-stops";
8
+ export { default as trailingStops } from "./trailing-stops";
9
+ export { createOCOOrder, cancelOCOOrder, getOCOOrderStatus, protectLongPosition, protectShortPosition, OCOOrderParams, OCOOrderResult, } from "./oco-orders";
10
+ export { default as ocoOrders } from "./oco-orders";
11
+ export { createOTOOrder, cancelOTOOrder, getOTOOrderStatus, buyWithStopLoss, buyWithTrailingStop, limitBuyWithTakeProfit, shortWithStopLoss, entryWithPercentStopLoss, OTOOrderParams, OTOOrderResult, DependentOrderConfig, DependentOrderType, } from "./oto-orders";
12
+ export { default as otoOrders } from "./oto-orders";
13
+ export { getAlpacaClock, getAlpacaCalendar, type AlpacaClock, type AlpacaCalendarDay, type GetAlpacaCalendarOptions, } from "./clock";
14
+ export { default as clock } from "./clock";
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/alpaca/trading/index.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,kBAAkB,EAClB,uBAAuB,EACvB,4BAA4B,EAC5B,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAG5D,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,0BAA0B,EAC1B,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,sBAAsB,EACtB,YAAY,EACZ,eAAe,EACf,0BAA0B,EAC1B,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EAC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