@adaptic/utils 0.1.44 → 0.1.45

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 +61 -153
  2. package/dist/index.cjs +5356 -60315
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.mjs +5356 -60054
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/test.js +361 -824
  7. package/dist/test.js.map +1 -1
  8. package/dist/types/adaptic.d.ts +2 -2
  9. package/dist/types/adaptic.d.ts.map +1 -1
  10. package/dist/types/alpaca-functions.d.ts +233 -0
  11. package/dist/types/alpaca-functions.d.ts.map +1 -0
  12. package/dist/types/alpaca-market-data-api.d.ts +9 -24
  13. package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
  14. package/dist/types/alpaca-trading-api.d.ts +12 -12
  15. package/dist/types/alpaca-trading-api.d.ts.map +1 -1
  16. package/dist/types/alphavantage.d.ts +1 -1
  17. package/dist/types/alphavantage.d.ts.map +1 -1
  18. package/dist/types/asset-allocation-algorithm.d.ts +1 -7
  19. package/dist/types/asset-allocation-algorithm.d.ts.map +1 -1
  20. package/dist/types/cache/stampede-protected-cache.d.ts.map +1 -1
  21. package/dist/types/crypto.d.ts +4 -4
  22. package/dist/types/crypto.d.ts.map +1 -1
  23. package/dist/types/display-manager.d.ts +1 -1
  24. package/dist/types/display-manager.d.ts.map +1 -1
  25. package/dist/types/examples/asset-allocation-example.d.ts +6 -7
  26. package/dist/types/examples/asset-allocation-example.d.ts.map +1 -1
  27. package/dist/types/format-tools.d.ts.map +1 -1
  28. package/dist/types/index.d.ts +55 -393
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/logging.d.ts +1 -1
  31. package/dist/types/logging.d.ts.map +1 -1
  32. package/dist/types/market-hours.d.ts.map +1 -1
  33. package/dist/types/market-time.d.ts +13 -75
  34. package/dist/types/market-time.d.ts.map +1 -1
  35. package/dist/types/metrics-calcs.d.ts.map +1 -1
  36. package/dist/types/misc-utils.d.ts +1 -4
  37. package/dist/types/misc-utils.d.ts.map +1 -1
  38. package/dist/types/performance-metrics.d.ts +6 -6
  39. package/dist/types/performance-metrics.d.ts.map +1 -1
  40. package/dist/types/polygon-indices.d.ts +3 -3
  41. package/dist/types/polygon-indices.d.ts.map +1 -1
  42. package/dist/types/polygon.d.ts +1 -1
  43. package/dist/types/polygon.d.ts.map +1 -1
  44. package/dist/types/price-utils.d.ts.map +1 -1
  45. package/dist/types/technical-analysis.d.ts +9 -9
  46. package/dist/types/technical-analysis.d.ts.map +1 -1
  47. package/dist/types/time-utils.d.ts.map +1 -1
  48. package/dist/types/types/adaptic-types.d.ts +1 -1
  49. package/dist/types/types/adaptic-types.d.ts.map +1 -1
  50. package/dist/types/types/alpaca-types.d.ts +89 -252
  51. package/dist/types/types/alpaca-types.d.ts.map +1 -1
  52. package/dist/types/types/alphavantage-types.d.ts +2 -2
  53. package/dist/types/types/asset-allocation-types.d.ts +11 -11
  54. package/dist/types/types/index.d.ts +8 -8
  55. package/dist/types/types/index.d.ts.map +1 -1
  56. package/dist/types/types/logging-types.d.ts +2 -2
  57. package/dist/types/types/logging-types.d.ts.map +1 -1
  58. package/dist/types/types/market-time-types.d.ts +4 -4
  59. package/dist/types/types/market-time-types.d.ts.map +1 -1
  60. package/dist/types/types/metrics-types.d.ts +4 -4
  61. package/dist/types/types/metrics-types.d.ts.map +1 -1
  62. package/dist/types/types/polygon-indices-types.d.ts +6 -6
  63. package/dist/types/types/polygon-types.d.ts +3 -3
  64. package/dist/types/types/ta-types.d.ts +3 -3
  65. package/package.json +6 -24
  66. package/dist/types/__tests__/alpaca-functions.test.d.ts +0 -2
  67. package/dist/types/__tests__/alpaca-functions.test.d.ts.map +0 -1
  68. package/dist/types/__tests__/api-endpoints.test.d.ts +0 -2
  69. package/dist/types/__tests__/api-endpoints.test.d.ts.map +0 -1
  70. package/dist/types/__tests__/asset-allocation.test.d.ts +0 -2
  71. package/dist/types/__tests__/asset-allocation.test.d.ts.map +0 -1
  72. package/dist/types/__tests__/auth-validator.test.d.ts +0 -2
  73. package/dist/types/__tests__/auth-validator.test.d.ts.map +0 -1
  74. package/dist/types/__tests__/cache.test.d.ts +0 -2
  75. package/dist/types/__tests__/cache.test.d.ts.map +0 -1
  76. package/dist/types/__tests__/errors.test.d.ts +0 -2
  77. package/dist/types/__tests__/errors.test.d.ts.map +0 -1
  78. package/dist/types/__tests__/financial-regression.test.d.ts +0 -2
  79. package/dist/types/__tests__/financial-regression.test.d.ts.map +0 -1
  80. package/dist/types/__tests__/format-tools.test.d.ts +0 -2
  81. package/dist/types/__tests__/format-tools.test.d.ts.map +0 -1
  82. package/dist/types/__tests__/http-keep-alive.test.d.ts +0 -2
  83. package/dist/types/__tests__/http-keep-alive.test.d.ts.map +0 -1
  84. package/dist/types/__tests__/http-timeout.test.d.ts +0 -2
  85. package/dist/types/__tests__/http-timeout.test.d.ts.map +0 -1
  86. package/dist/types/__tests__/logger.test.d.ts +0 -2
  87. package/dist/types/__tests__/logger.test.d.ts.map +0 -1
  88. package/dist/types/__tests__/market-time.test.d.ts +0 -2
  89. package/dist/types/__tests__/market-time.test.d.ts.map +0 -1
  90. package/dist/types/__tests__/misc-utils.test.d.ts +0 -2
  91. package/dist/types/__tests__/misc-utils.test.d.ts.map +0 -1
  92. package/dist/types/__tests__/paginator.test.d.ts +0 -2
  93. package/dist/types/__tests__/paginator.test.d.ts.map +0 -1
  94. package/dist/types/__tests__/performance-metrics.test.d.ts +0 -2
  95. package/dist/types/__tests__/performance-metrics.test.d.ts.map +0 -1
  96. package/dist/types/__tests__/polygon.test.d.ts +0 -2
  97. package/dist/types/__tests__/polygon.test.d.ts.map +0 -1
  98. package/dist/types/__tests__/price-utils.test.d.ts +0 -2
  99. package/dist/types/__tests__/price-utils.test.d.ts.map +0 -1
  100. package/dist/types/__tests__/property-based-financial.test.d.ts +0 -2
  101. package/dist/types/__tests__/property-based-financial.test.d.ts.map +0 -1
  102. package/dist/types/__tests__/rate-limiter.test.d.ts +0 -2
  103. package/dist/types/__tests__/rate-limiter.test.d.ts.map +0 -1
  104. package/dist/types/__tests__/schema-validation.test.d.ts +0 -2
  105. package/dist/types/__tests__/schema-validation.test.d.ts.map +0 -1
  106. package/dist/types/__tests__/technical-analysis.test.d.ts +0 -2
  107. package/dist/types/__tests__/technical-analysis.test.d.ts.map +0 -1
  108. package/dist/types/__tests__/time-utils.test.d.ts +0 -2
  109. package/dist/types/__tests__/time-utils.test.d.ts.map +0 -1
  110. package/dist/types/alpaca/client.d.ts +0 -95
  111. package/dist/types/alpaca/client.d.ts.map +0 -1
  112. package/dist/types/alpaca/crypto/data.d.ts +0 -281
  113. package/dist/types/alpaca/crypto/data.d.ts.map +0 -1
  114. package/dist/types/alpaca/crypto/index.d.ts +0 -75
  115. package/dist/types/alpaca/crypto/index.d.ts.map +0 -1
  116. package/dist/types/alpaca/crypto/orders.d.ts +0 -221
  117. package/dist/types/alpaca/crypto/orders.d.ts.map +0 -1
  118. package/dist/types/alpaca/index.d.ts +0 -205
  119. package/dist/types/alpaca/index.d.ts.map +0 -1
  120. package/dist/types/alpaca/legacy/account.d.ts +0 -34
  121. package/dist/types/alpaca/legacy/account.d.ts.map +0 -1
  122. package/dist/types/alpaca/legacy/assets.d.ts +0 -13
  123. package/dist/types/alpaca/legacy/assets.d.ts.map +0 -1
  124. package/dist/types/alpaca/legacy/auth.d.ts +0 -18
  125. package/dist/types/alpaca/legacy/auth.d.ts.map +0 -1
  126. package/dist/types/alpaca/legacy/index.d.ts +0 -15
  127. package/dist/types/alpaca/legacy/index.d.ts.map +0 -1
  128. package/dist/types/alpaca/legacy/market-data.d.ts +0 -32
  129. package/dist/types/alpaca/legacy/market-data.d.ts.map +0 -1
  130. package/dist/types/alpaca/legacy/orders.d.ts +0 -84
  131. package/dist/types/alpaca/legacy/orders.d.ts.map +0 -1
  132. package/dist/types/alpaca/legacy/positions.d.ts +0 -66
  133. package/dist/types/alpaca/legacy/positions.d.ts.map +0 -1
  134. package/dist/types/alpaca/legacy/utils.d.ts +0 -18
  135. package/dist/types/alpaca/legacy/utils.d.ts.map +0 -1
  136. package/dist/types/alpaca/market-data/bars.d.ts +0 -142
  137. package/dist/types/alpaca/market-data/bars.d.ts.map +0 -1
  138. package/dist/types/alpaca/market-data/index.d.ts +0 -13
  139. package/dist/types/alpaca/market-data/index.d.ts.map +0 -1
  140. package/dist/types/alpaca/market-data/news.d.ts +0 -87
  141. package/dist/types/alpaca/market-data/news.d.ts.map +0 -1
  142. package/dist/types/alpaca/market-data/quotes.d.ts +0 -85
  143. package/dist/types/alpaca/market-data/quotes.d.ts.map +0 -1
  144. package/dist/types/alpaca/market-data/trades.d.ts +0 -98
  145. package/dist/types/alpaca/market-data/trades.d.ts.map +0 -1
  146. package/dist/types/alpaca/options/contracts.d.ts +0 -279
  147. package/dist/types/alpaca/options/contracts.d.ts.map +0 -1
  148. package/dist/types/alpaca/options/data.d.ts +0 -126
  149. package/dist/types/alpaca/options/data.d.ts.map +0 -1
  150. package/dist/types/alpaca/options/index.d.ts +0 -17
  151. package/dist/types/alpaca/options/index.d.ts.map +0 -1
  152. package/dist/types/alpaca/options/orders.d.ts +0 -366
  153. package/dist/types/alpaca/options/orders.d.ts.map +0 -1
  154. package/dist/types/alpaca/options/strategies.d.ts +0 -224
  155. package/dist/types/alpaca/options/strategies.d.ts.map +0 -1
  156. package/dist/types/alpaca/streams/base-stream.d.ts +0 -143
  157. package/dist/types/alpaca/streams/base-stream.d.ts.map +0 -1
  158. package/dist/types/alpaca/streams/crypto-stream.d.ts +0 -173
  159. package/dist/types/alpaca/streams/crypto-stream.d.ts.map +0 -1
  160. package/dist/types/alpaca/streams/index.d.ts +0 -54
  161. package/dist/types/alpaca/streams/index.d.ts.map +0 -1
  162. package/dist/types/alpaca/streams/option-stream.d.ts +0 -167
  163. package/dist/types/alpaca/streams/option-stream.d.ts.map +0 -1
  164. package/dist/types/alpaca/streams/stock-stream.d.ts +0 -176
  165. package/dist/types/alpaca/streams/stock-stream.d.ts.map +0 -1
  166. package/dist/types/alpaca/streams/stream-manager.d.ts +0 -277
  167. package/dist/types/alpaca/streams/stream-manager.d.ts.map +0 -1
  168. package/dist/types/alpaca/streams/trading-stream.d.ts +0 -186
  169. package/dist/types/alpaca/streams/trading-stream.d.ts.map +0 -1
  170. package/dist/types/alpaca/streams.d.ts +0 -88
  171. package/dist/types/alpaca/streams.d.ts.map +0 -1
  172. package/dist/types/alpaca/test-imports.d.ts +0 -7
  173. package/dist/types/alpaca/test-imports.d.ts.map +0 -1
  174. package/dist/types/alpaca/trading/account.d.ts +0 -198
  175. package/dist/types/alpaca/trading/account.d.ts.map +0 -1
  176. package/dist/types/alpaca/trading/bracket-orders.d.ts +0 -162
  177. package/dist/types/alpaca/trading/bracket-orders.d.ts.map +0 -1
  178. package/dist/types/alpaca/trading/clock.d.ts +0 -99
  179. package/dist/types/alpaca/trading/clock.d.ts.map +0 -1
  180. package/dist/types/alpaca/trading/index.d.ts +0 -15
  181. package/dist/types/alpaca/trading/index.d.ts.map +0 -1
  182. package/dist/types/alpaca/trading/oco-orders.d.ts +0 -203
  183. package/dist/types/alpaca/trading/oco-orders.d.ts.map +0 -1
  184. package/dist/types/alpaca/trading/order-utils.d.ts +0 -404
  185. package/dist/types/alpaca/trading/order-utils.d.ts.map +0 -1
  186. package/dist/types/alpaca/trading/orders.d.ts +0 -199
  187. package/dist/types/alpaca/trading/orders.d.ts.map +0 -1
  188. package/dist/types/alpaca/trading/oto-orders.d.ts +0 -282
  189. package/dist/types/alpaca/trading/oto-orders.d.ts.map +0 -1
  190. package/dist/types/alpaca/trading/positions.d.ts +0 -389
  191. package/dist/types/alpaca/trading/positions.d.ts.map +0 -1
  192. package/dist/types/alpaca/trading/smart-orders.d.ts +0 -301
  193. package/dist/types/alpaca/trading/smart-orders.d.ts.map +0 -1
  194. package/dist/types/alpaca/trading/trailing-stops.d.ts +0 -240
  195. package/dist/types/alpaca/trading/trailing-stops.d.ts.map +0 -1
  196. package/dist/types/config/api-endpoints.d.ts +0 -94
  197. package/dist/types/config/api-endpoints.d.ts.map +0 -1
  198. package/dist/types/errors/index.d.ts +0 -130
  199. package/dist/types/errors/index.d.ts.map +0 -1
  200. package/dist/types/examples/rate-limiter-example.d.ts +0 -7
  201. package/dist/types/examples/rate-limiter-example.d.ts.map +0 -1
  202. package/dist/types/http-timeout.d.ts +0 -37
  203. package/dist/types/http-timeout.d.ts.map +0 -1
  204. package/dist/types/logger.d.ts +0 -56
  205. package/dist/types/logger.d.ts.map +0 -1
  206. package/dist/types/rate-limiter.d.ts +0 -171
  207. package/dist/types/rate-limiter.d.ts.map +0 -1
  208. package/dist/types/schemas/alpaca-schemas.d.ts +0 -779
  209. package/dist/types/schemas/alpaca-schemas.d.ts.map +0 -1
  210. package/dist/types/schemas/alphavantage-schemas.d.ts +0 -255
  211. package/dist/types/schemas/alphavantage-schemas.d.ts.map +0 -1
  212. package/dist/types/schemas/index.d.ts +0 -21
  213. package/dist/types/schemas/index.d.ts.map +0 -1
  214. package/dist/types/schemas/polygon-schemas.d.ts +0 -551
  215. package/dist/types/schemas/polygon-schemas.d.ts.map +0 -1
  216. package/dist/types/schemas/validate-response.d.ts +0 -88
  217. package/dist/types/schemas/validate-response.d.ts.map +0 -1
  218. package/dist/types/utils/auth-validator.d.ts +0 -32
  219. package/dist/types/utils/auth-validator.d.ts.map +0 -1
  220. package/dist/types/utils/http-keep-alive.d.ts +0 -110
  221. package/dist/types/utils/http-keep-alive.d.ts.map +0 -1
  222. package/dist/types/utils/paginator.d.ts +0 -154
  223. package/dist/types/utils/paginator.d.ts.map +0 -1
  224. package/dist/types/utils/retry.d.ts +0 -78
  225. package/dist/types/utils/retry.d.ts.map +0 -1
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install @adaptic/utils
17
17
  Import the functions from the library:
18
18
 
19
19
  ```typescript
20
- import { adaptic } from "@adaptic/utils";
20
+ import { adaptic } from '@adaptic/utils';
21
21
  ```
22
22
 
23
23
  ## Environment Variables
@@ -38,26 +38,18 @@ import { adaptic } from "@adaptic/utils";
38
38
  Asynchronously retrieves detailed information about a specific Alpaca trading account.
39
39
 
40
40
  **Parameters:**
41
-
42
41
  - `accountId: string` - The Alpaca account ID
43
42
 
44
43
  **Returns:**
45
-
46
44
  - `Promise<AccountDetails>` - Comprehensive account details including:
47
45
  ```typescript
48
46
  {
49
47
  id: string;
50
48
  account_number: string;
51
- status: "ONBOARDING" |
52
- "SUBMISSION_FAILED" |
53
- "SUBMITTED" |
54
- "ACCOUNT_UPDATED" |
55
- "APPROVAL_PENDING" |
56
- "ACTIVE" |
57
- "REJECTED";
49
+ status: 'ONBOARDING' | 'SUBMISSION_FAILED' | 'SUBMITTED' | 'ACCOUNT_UPDATED' | 'APPROVAL_PENDING' | 'ACTIVE' | 'REJECTED';
58
50
  currency: string;
59
51
  cash: string;
60
- portfolio_value: string; // deprecated, equivalent to equity
52
+ portfolio_value: string; // deprecated, equivalent to equity
61
53
  equity: string;
62
54
  buying_power: string;
63
55
  initial_margin: string;
@@ -71,10 +63,8 @@ Asynchronously retrieves detailed information about a specific Alpaca trading ac
71
63
  ```
72
64
 
73
65
  **Example:**
74
-
75
66
  ```typescript
76
- const accountDetails =
77
- await adaptic.alpaca.fetchAccountDetails("your-account-id");
67
+ const accountDetails = await adaptic.alpaca.fetchAccountDetails('your-account-id');
78
68
  console.log(`Account equity: ${accountDetails.equity}`);
79
69
  ```
80
70
 
@@ -83,7 +73,6 @@ console.log(`Account equity: ${accountDetails.equity}`);
83
73
  Asynchronously retrieves historical portfolio data including equity and profit/loss information from either the Adaptic backend or directly from an Alpaca account.
84
74
 
85
75
  **Parameters:**
86
-
87
76
  - `FetchPortfolioHistoryProps`:
88
77
  ```typescript
89
78
  {
@@ -106,7 +95,6 @@ Asynchronously retrieves historical portfolio data including equity and profit/l
106
95
  ```
107
96
 
108
97
  **Returns:**
109
-
110
98
  - `Promise<PortfolioHistoryResponse>`:
111
99
  ```typescript
112
100
  {
@@ -122,25 +110,24 @@ Asynchronously retrieves historical portfolio data including equity and profit/l
122
110
  ```
123
111
 
124
112
  **Example:**
125
-
126
113
  ```typescript
127
114
  // Using accountId
128
115
  const history = await adaptic.alpaca.fetchPortfolioHistory({
129
- accountId: "your-account-id",
116
+ accountId: 'your-account-id',
130
117
  params: {
131
- period: "1M",
132
- timeframe: "1D",
133
- },
118
+ period: '1M',
119
+ timeframe: '1D'
120
+ }
134
121
  });
135
122
 
136
123
  // Using direct Alpaca account object
137
124
  const history = await adaptic.alpaca.fetchPortfolioHistory({
138
125
  alpacaAccount: yourAlpacaAccount,
139
126
  params: {
140
- start: "2025-01-01T00:00:00Z",
141
- end: "2025-01-31T00:00:00Z",
142
- timeframe: "1D",
143
- },
127
+ start: '2025-01-01T00:00:00Z',
128
+ end: '2025-01-31T00:00:00Z',
129
+ timeframe: '1D'
130
+ }
144
131
  });
145
132
  ```
146
133
 
@@ -149,7 +136,6 @@ const history = await adaptic.alpaca.fetchPortfolioHistory({
149
136
  Asynchronously fetches all current open positions for an Alpaca trading account.
150
137
 
151
138
  **Parameters:**
152
-
153
139
  - `auth: AlpacaAuth` - Authentication details:
154
140
  ```typescript
155
141
  {
@@ -160,7 +146,6 @@ Asynchronously fetches all current open positions for an Alpaca trading account.
160
146
  ```
161
147
 
162
148
  **Returns:**
163
-
164
149
  - `Promise<Position[]>` - Array of positions with the following type:
165
150
  ```typescript
166
151
  {
@@ -172,7 +157,7 @@ Asynchronously fetches all current open positions for an Alpaca trading account.
172
157
  qty: string;
173
158
  qty_available: string;
174
159
  avg_entry_price: string;
175
- side: "long" | "short";
160
+ side: 'long' | 'short';
176
161
  market_value: string;
177
162
  cost_basis: string;
178
163
  unrealized_pl: string;
@@ -186,17 +171,16 @@ Asynchronously fetches all current open positions for an Alpaca trading account.
186
171
  ```
187
172
 
188
173
  **Example:**
189
-
190
174
  ```typescript
191
175
  // Using adapticAccountId
192
176
  const positions = await adaptic.position.fetchAll({
193
- adapticAccountId: "your-account-id",
177
+ adapticAccountId: 'your-account-id'
194
178
  });
195
179
 
196
180
  // Using direct API keys
197
181
  const positions = await adaptic.position.fetchAll({
198
- alpacaApiKey: "your-api-key",
199
- alpacaApiSecret: "your-api-secret",
182
+ alpacaApiKey: 'your-api-key',
183
+ alpacaApiSecret: 'your-api-secret'
200
184
  });
201
185
  ```
202
186
 
@@ -205,19 +189,16 @@ const positions = await adaptic.position.fetchAll({
205
189
  Asynchronously fetches a specific position for an Alpaca trading account.
206
190
 
207
191
  **Parameters:**
208
-
209
192
  - `symbolOrAssetId: string` - The symbol or asset ID to fetch the position for
210
193
  - `auth: AlpacaAuth` - Authentication details (same as above)
211
194
 
212
195
  **Returns:**
213
-
214
196
  - `Promise<Position>` - Single position details with the same type as in `fetchAll`
215
197
 
216
198
  **Example:**
217
-
218
199
  ```typescript
219
- const position = await adaptic.position.fetch("AAPL", {
220
- adapticAccountId: "your-account-id",
200
+ const position = await adaptic.position.fetch('AAPL', {
201
+ adapticAccountId: 'your-account-id'
221
202
  });
222
203
  ```
223
204
 
@@ -226,7 +207,6 @@ const position = await adaptic.position.fetch("AAPL", {
226
207
  Closes a specific position in an Alpaca trading account.
227
208
 
228
209
  **Parameters:**
229
-
230
210
  - `symbolOrAssetId: string` - The symbol or asset ID of the position to close
231
211
  - `auth: AlpacaAuth` - Authentication details (same as above)
232
212
  - `params?: ClosePositionParams` - Optional closing parameters:
@@ -238,27 +218,21 @@ Closes a specific position in an Alpaca trading account.
238
218
  ```
239
219
 
240
220
  **Returns:**
241
-
242
221
  - `Promise<Order>` - The order created to close the position
243
222
 
244
223
  **Example:**
245
-
246
224
  ```typescript
247
225
  // Close entire position
248
- const order = await adaptic.position.close("AAPL", {
249
- adapticAccountId: "your-account-id",
226
+ const order = await adaptic.position.close('AAPL', {
227
+ adapticAccountId: 'your-account-id'
250
228
  });
251
229
 
252
230
  // Close 50% of position
253
- const order = await adaptic.position.close(
254
- "AAPL",
255
- {
256
- adapticAccountId: "your-account-id",
257
- },
258
- {
259
- percentage: 50,
260
- },
261
- );
231
+ const order = await adaptic.position.close('AAPL', {
232
+ adapticAccountId: 'your-account-id'
233
+ }, {
234
+ percentage: 50
235
+ });
262
236
  ```
263
237
 
264
238
  ### `adaptic.position.closeAll(auth: AlpacaAuth, params?: CloseAllPositionsParams): Promise<Array<{ symbol: string; status: number; body?: Order }>>`
@@ -266,7 +240,6 @@ const order = await adaptic.position.close(
266
240
  Closes all positions in an Alpaca trading account.
267
241
 
268
242
  **Parameters:**
269
-
270
243
  - `auth: AlpacaAuth` - Authentication details (same as above)
271
244
  - `params?: CloseAllPositionsParams` - Optional parameters:
272
245
  ```typescript
@@ -276,29 +249,24 @@ Closes all positions in an Alpaca trading account.
276
249
  ```
277
250
 
278
251
  **Returns:**
279
-
280
252
  - `Promise<Array<{ symbol: string; status: number; body?: Order }>>` - Status of each position closure attempt:
281
253
  - `symbol: string` - The symbol of the position
282
254
  - `status: number` - HTTP status code for the attempt
283
255
  - `body?: Order` - The order created to close the position (if successful)
284
256
 
285
257
  **Example:**
286
-
287
258
  ```typescript
288
259
  // Close all positions
289
260
  const results = await adaptic.position.closeAll({
290
- adapticAccountId: "your-account-id",
261
+ adapticAccountId: 'your-account-id'
291
262
  });
292
263
 
293
264
  // Close all positions and cancel pending orders
294
- const results = await adaptic.position.closeAll(
295
- {
296
- adapticAccountId: "your-account-id",
297
- },
298
- {
299
- cancelOrders: true,
300
- },
301
- );
265
+ const results = await adaptic.position.closeAll({
266
+ adapticAccountId: 'your-account-id'
267
+ }, {
268
+ cancelOrders: true
269
+ });
302
270
  ```
303
271
 
304
272
  ### `createOrder(params: CreateOrderParams): Promise<Order>`
@@ -306,7 +274,6 @@ const results = await adaptic.position.closeAll(
306
274
  Creates a new order for trading.
307
275
 
308
276
  **Parameters:**
309
-
310
277
  - `params: CreateOrderParams`:
311
278
  ```typescript
312
279
  {
@@ -338,7 +305,6 @@ Creates a new order for trading.
338
305
  ```
339
306
 
340
307
  **Returns:**
341
-
342
308
  - `Promise<Order>` - Created order details with full order type information
343
309
 
344
310
  ## Crypto Functions
@@ -348,7 +314,6 @@ Creates a new order for trading.
348
314
  Fetches historical bar data for crypto trading pairs.
349
315
 
350
316
  **Parameters:**
351
-
352
317
  - `params: CryptoBarsParams`:
353
318
  ```typescript
354
319
  {
@@ -363,7 +328,6 @@ Fetches historical bar data for crypto trading pairs.
363
328
  ```
364
329
 
365
330
  **Returns:**
366
-
367
331
  - `Promise<CryptoBarsResponse>`:
368
332
  ```typescript
369
333
  {
@@ -376,12 +340,12 @@ Fetches historical bar data for crypto trading pairs.
376
340
  where `CryptoBar` is:
377
341
  ```typescript
378
342
  {
379
- t: number; // timestamp
380
- o: number; // open
381
- h: number; // high
382
- l: number; // low
383
- c: number; // close
384
- v: number; // volume
343
+ t: number; // timestamp
344
+ o: number; // open
345
+ h: number; // high
346
+ l: number; // low
347
+ c: number; // close
348
+ v: number; // volume
385
349
  }
386
350
  ```
387
351
 
@@ -392,12 +356,10 @@ Fetches historical bar data for crypto trading pairs.
392
356
  Fetches historical price data from Polygon.io.
393
357
 
394
358
  **Parameters:**
395
-
396
359
  - `symbol: string` - The trading symbol
397
360
  - `params: object` - Query parameters for the data fetch
398
361
 
399
362
  **Returns:**
400
-
401
363
  - `Promise<PolygonPriceData[]>`:
402
364
  ```typescript
403
365
  {
@@ -409,8 +371,7 @@ Fetches historical price data from Polygon.io.
409
371
  close: number;
410
372
  vol: number;
411
373
  vwap: number;
412
- }
413
- [];
374
+ }[]
414
375
  ```
415
376
 
416
377
  ## Performance Metrics
@@ -420,12 +381,10 @@ Fetches historical price data from Polygon.io.
420
381
  Calculates beta and related statistics for a portfolio against a benchmark.
421
382
 
422
383
  **Parameters:**
423
-
424
384
  - `returns: number[]` - Array of portfolio returns
425
385
  - `benchmarkReturns: number[]` - Array of benchmark returns
426
386
 
427
387
  **Returns:**
428
-
429
388
  - `CalculateBetaResult`:
430
389
  ```typescript
431
390
  {
@@ -442,11 +401,9 @@ Calculates beta and related statistics for a portfolio against a benchmark.
442
401
  Calculates the maximum drawdown from peak for a series of portfolio values.
443
402
 
444
403
  **Parameters:**
445
-
446
404
  - `portfolioValues: number[]` - Array of portfolio values over time
447
405
 
448
406
  **Returns:**
449
-
450
407
  - `number` - Maximum drawdown as a decimal (e.g., 0.25 for 25% drawdown)
451
408
 
452
409
  ### `calculateDailyReturns(portfolioValues: number[]): number[]`
@@ -454,11 +411,9 @@ Calculates the maximum drawdown from peak for a series of portfolio values.
454
411
  Computes daily returns from a series of portfolio values.
455
412
 
456
413
  **Parameters:**
457
-
458
414
  - `portfolioValues: number[]` - Array of portfolio values
459
415
 
460
416
  **Returns:**
461
-
462
417
  - `number[]` - Array of daily returns as decimals
463
418
 
464
419
  ## News Functions
@@ -468,7 +423,6 @@ Computes daily returns from a series of portfolio values.
468
423
  Fetches financial news articles.
469
424
 
470
425
  **Parameters:**
471
-
472
426
  - `params: NewsParams`:
473
427
  ```typescript
474
428
  {
@@ -482,7 +436,6 @@ Fetches financial news articles.
482
436
  ```
483
437
 
484
438
  **Returns:**
485
-
486
439
  - `Promise<NewsResponse>`:
487
440
  ```typescript
488
441
  {
@@ -515,8 +468,8 @@ The following types are used throughout the market time utilities:
515
468
  ```typescript
516
469
  type Period = "1D" | "3D" | "1W" | "1M" | "3M" | "6M" | "1Y" | "YTD";
517
470
  type Timeframe = "1Min" | "5Min" | "15Min" | "1H" | "1D";
518
- type IntradayReporting = "market_hours" | "extended_hours" | "continuous";
519
- type OutputFormat = "iso" | "unix-seconds" | "unix-ms";
471
+ type IntradayReporting = 'market_hours' | 'extended_hours' | 'continuous';
472
+ type OutputFormat = 'iso' | 'unix-seconds' | 'unix-ms';
520
473
 
521
474
  interface MarketTimeParams {
522
475
  period?: Period;
@@ -550,7 +503,6 @@ interface MarketOpenCloseResult {
550
503
  Creates a utility for market time-related operations.
551
504
 
552
505
  **Parameters:**
553
-
554
506
  - `timezone?: string` - Optional timezone (default: 'America/New_York')
555
507
  - `intraday_reporting?: IntradayReporting` - Optional intraday reporting mode:
556
508
  - `'market_hours'` - Regular market hours (9:30 AM - 4:00 PM ET)
@@ -558,7 +510,6 @@ Creates a utility for market time-related operations.
558
510
  - `'continuous'` - All day, 24/7
559
511
 
560
512
  **Returns:**
561
-
562
513
  - `MarketTimeUtil` - Market time utility object
563
514
 
564
515
  ### `getMarketOpenClose(options?: MarketOpenCloseOptions): MarketOpenCloseResult`
@@ -566,30 +517,26 @@ Creates a utility for market time-related operations.
566
517
  Gets market open/close times for both regular and extended hours for a given date.
567
518
 
568
519
  **Parameters:**
569
-
570
520
  - `options?: MarketOpenCloseOptions` - Optional parameters:
571
521
  - `date?: Date` - The date to check (default: current date)
572
522
 
573
523
  **Returns:**
574
-
575
524
  - `MarketOpenCloseResult`:
576
525
  ```typescript
577
526
  {
578
- marketOpen: boolean; // Whether the market is open on this date
579
- open: Date | null; // Regular market hours open time
580
- close: Date | null; // Regular market hours close time
581
- openExt: Date | null; // Extended hours open time
582
- closeExt: Date | null; // Extended hours close time
527
+ marketOpen: boolean; // Whether the market is open on this date
528
+ open: Date | null; // Regular market hours open time
529
+ close: Date | null; // Regular market hours close time
530
+ openExt: Date | null; // Extended hours open time
531
+ closeExt: Date | null; // Extended hours close time
583
532
  }
584
533
  ```
585
534
 
586
535
  **Example:**
587
-
588
536
  ```typescript
589
- const { marketOpen, open, close, openExt, closeExt } =
590
- adaptic.time.getMarketOpenClose({
591
- date: new Date("2024-12-24"),
592
- });
537
+ const { marketOpen, open, close, openExt, closeExt } = adaptic.time.getMarketOpenClose({
538
+ date: new Date('2024-12-24')
539
+ });
593
540
  ```
594
541
 
595
542
  ### `getMarketStatus(options?: { date?: Date }): MarketStatus`
@@ -597,32 +544,25 @@ const { marketOpen, open, close, openExt, closeExt } =
597
544
  Gets the current market status and detailed information about market periods.
598
545
 
599
546
  **Parameters:**
600
-
601
547
  - `options?: object` - Optional parameters:
602
548
  - `date?: Date` - The date to check (default: current date)
603
549
 
604
550
  **Returns:**
605
-
606
551
  - `MarketStatus`:
607
552
  ```typescript
608
553
  {
609
- time: Date; // Current time
610
- timeString: string; // Formatted time string
611
- status: "closed" | "extended hours" | "open"; // Current market status
612
- nextStatus: "closed" | "extended hours" | "open"; // Next market status
613
- marketPeriod: "preMarket" |
614
- "earlyMarket" |
615
- "regularMarket" |
616
- "afterMarket" |
617
- "closed"; // Detailed market period
618
- nextStatusTime: Date; // Time when next status begins
619
- nextStatusTimeDifference: number; // Milliseconds until next status
620
- nextStatusTimeString: string; // Formatted next status time
554
+ time: Date; // Current time
555
+ timeString: string; // Formatted time string
556
+ status: "closed" | "extended hours" | "open"; // Current market status
557
+ nextStatus: "closed" | "extended hours" | "open"; // Next market status
558
+ marketPeriod: "preMarket" | "earlyMarket" | "regularMarket" | "afterMarket" | "closed"; // Detailed market period
559
+ nextStatusTime: Date; // Time when next status begins
560
+ nextStatusTimeDifference: number; // Milliseconds until next status
561
+ nextStatusTimeString: string; // Formatted next status time
621
562
  }
622
563
  ```
623
564
 
624
565
  The `marketPeriod` field indicates the specific trading period:
625
-
626
566
  - `preMarket`: 4:00 AM - 9:30 AM ET
627
567
  - `earlyMarket`: 9:30 AM - 10:00 AM ET
628
568
  - `regularMarket`: 10:00 AM - Market Close (typically 4:00 PM ET)
@@ -630,7 +570,6 @@ The `marketPeriod` field indicates the specific trading period:
630
570
  - `closed`: Outside of all trading hours
631
571
 
632
572
  **Example:**
633
-
634
573
  ```typescript
635
574
  const status = adaptic.time.getMarketStatus();
636
575
  console.log(`Current market period: ${status.marketPeriod}`);
@@ -641,11 +580,9 @@ console.log(`Current market period: ${status.marketPeriod}`);
641
580
  Converts a date to Unix timestamp.
642
581
 
643
582
  **Parameters:**
644
-
645
583
  - `date: Date` - The date to convert
646
584
 
647
585
  **Returns:**
648
-
649
586
  - `number` - Unix timestamp
650
587
 
651
588
  ### `getTimeAgo(date: Date): string`
@@ -653,11 +590,9 @@ Converts a date to Unix timestamp.
653
590
  Returns a human-readable time difference from now.
654
591
 
655
592
  **Parameters:**
656
-
657
593
  - `date: Date` - The date to calculate from
658
594
 
659
595
  **Returns:**
660
-
661
596
  - `string` - Human-readable time difference (e.g., '1 minute ago')
662
597
 
663
598
  ### `normalizeDate(date: Date): string`
@@ -665,11 +600,9 @@ Returns a human-readable time difference from now.
665
600
  Standardizes a date to a consistent format.
666
601
 
667
602
  **Parameters:**
668
-
669
603
  - `date: Date` - The date to standardize
670
604
 
671
605
  **Returns:**
672
-
673
606
  - `string` - Standardized date string (e.g., '2024-11-09')
674
607
 
675
608
  ### `getDateInNY(time: number | string | { year: number; month: number; day: number }): Date`
@@ -677,11 +610,9 @@ Standardizes a date to a consistent format.
677
610
  Returns the current date in New York timezone.
678
611
 
679
612
  **Parameters:**
680
-
681
613
  - `time: number | string | { year: number; month: number; day: number }` - The time or date to convert
682
614
 
683
615
  **Returns:**
684
-
685
616
  - `Date` - Date in New York timezone
686
617
 
687
618
  ### `getStartAndEndTimestamps(params: MarketTimeParams = {}): PeriodDates`
@@ -689,11 +620,9 @@ Returns the current date in New York timezone.
689
620
  Generates start and end timestamps for a given period.
690
621
 
691
622
  **Parameters:**
692
-
693
623
  - `params: MarketTimeParams` - Optional parameters for the period
694
624
 
695
625
  **Returns:**
696
-
697
626
  - `PeriodDates` - Start and end timestamps for the period
698
627
 
699
628
  ### `getStartAndEndDates(params: MarketTimeParams = {}): { start: Date; end: Date }`
@@ -701,11 +630,9 @@ Generates start and end timestamps for a given period.
701
630
  Gets the start and end dates for a given period.
702
631
 
703
632
  **Parameters:**
704
-
705
633
  - `params: MarketTimeParams` - Optional parameters for the period
706
634
 
707
635
  **Returns:**
708
-
709
636
  - `{ start: Date; end: Date }` - Start and end dates for the period
710
637
 
711
638
  ### `getLastTradingDateYYYYMMDD(): string`
@@ -713,7 +640,6 @@ Gets the start and end dates for a given period.
713
640
  Gets the last trading date in YYYY-MM-DD format.
714
641
 
715
642
  **Returns:**
716
-
717
643
  - `string` - Last trading date in YYYY-MM-DD format
718
644
 
719
645
  ### `getLastFullTradingDate(currentDate?: Date): { date: Date; YYYYMMDD: string }`
@@ -721,11 +647,9 @@ Gets the last trading date in YYYY-MM-DD format.
721
647
  Gets the last full trading date, considering market hours and holidays.
722
648
 
723
649
  **Parameters:**
724
-
725
650
  - `currentDate?: Date` - Optional reference date (defaults to current date)
726
651
 
727
652
  **Returns:**
728
-
729
653
  - Object containing:
730
654
  - `date: Date` - The last full trading date
731
655
  - `YYYYMMDD: string` - The date formatted as YYYY-MM-DD
@@ -735,26 +659,21 @@ Gets the last full trading date, considering market hours and holidays.
735
659
  Gets the next market day from a reference date.
736
660
 
737
661
  **Parameters:**
738
-
739
662
  - `referenceDate?: Date` - Optional reference date (defaults to current date)
740
663
 
741
664
  **Returns:**
742
-
743
665
  - Object containing:
744
666
  - `date: Date` - The next market day (start of day in NY time)
745
667
  - `yyyymmdd: string` - The date formatted as YYYY-MM-DD
746
668
  - `dateISOString: string` - Full ISO date string
747
669
 
748
670
  **Example:**
749
-
750
671
  ```typescript
751
672
  const nextMarketDay = adaptic.time.getNextMarketDay();
752
673
  console.log(`Next market day: ${nextMarketDay.yyyymmdd}`);
753
674
 
754
675
  // With reference date
755
- const nextMarketDay = adaptic.time.getNextMarketDay({
756
- referenceDate: new Date("2025-01-01"),
757
- });
676
+ const nextMarketDay = adaptic.time.getNextMarketDay({ referenceDate: new Date('2025-01-01') });
758
677
  ```
759
678
 
760
679
  ### `currentTimeET(): Date`
@@ -762,7 +681,6 @@ const nextMarketDay = adaptic.time.getNextMarketDay({
762
681
  Gets the current time in Eastern Time.
763
682
 
764
683
  **Returns:**
765
-
766
684
  - `Date` - Current time in Eastern Time
767
685
 
768
686
  ## Formatting Utilities
@@ -772,11 +690,9 @@ Gets the current time in Eastern Time.
772
690
  Capitalizes the first letter of a string.
773
691
 
774
692
  **Parameters:**
775
-
776
693
  - `string: string` - The string to capitalize
777
694
 
778
695
  **Returns:**
779
-
780
696
  - `string` - Capitalized string
781
697
 
782
698
  ### `formatEnum(enumValue: any): string`
@@ -784,11 +700,9 @@ Capitalizes the first letter of a string.
784
700
  Formats an enum value for display.
785
701
 
786
702
  **Parameters:**
787
-
788
703
  - `enumValue: any` - The enum value to format
789
704
 
790
705
  **Returns:**
791
-
792
706
  - `string` - Formatted enum value
793
707
 
794
708
  ### `formatCurrency(value: number): string`
@@ -796,11 +710,9 @@ Formats an enum value for display.
796
710
  Formats a number as currency.
797
711
 
798
712
  **Parameters:**
799
-
800
713
  - `value: number` - The number to format
801
714
 
802
715
  **Returns:**
803
-
804
716
  - `string` - Formatted currency string
805
717
 
806
718
  ### `formatPercentage(value: number): string`
@@ -808,11 +720,9 @@ Formats a number as currency.
808
720
  Formats a number as a percentage.
809
721
 
810
722
  **Parameters:**
811
-
812
723
  - `value: number` - The number to format
813
724
 
814
725
  **Returns:**
815
-
816
726
  - `string` - Formatted percentage string
817
727
 
818
728
  ## Misc utilities
@@ -822,7 +732,6 @@ Formats a number as a percentage.
822
732
  Debug logging utility that respects environment debug flags.
823
733
 
824
734
  **Parameters:**
825
-
826
735
  - `message: string` - The log message
827
736
  - `data?: unknown` - Optional data to log
828
737
  - `type: LogType` - Optional log type (default: 'info')
@@ -832,12 +741,10 @@ Debug logging utility that respects environment debug flags.
832
741
  Fetches data from a URL with retry logic.
833
742
 
834
743
  **Parameters:**
835
-
836
744
  - `url: string` - The URL to fetch
837
745
  - `options: RequestInit` - Optional fetch options
838
746
 
839
747
  **Returns:**
840
-
841
748
  - `Promise<Response>` - Fetched response
842
749
 
843
750
  ## Alpaca API Utilities
@@ -851,7 +758,7 @@ The `fetchNews` function retrieves news articles for specified symbols from the
851
758
  #### Usage
852
759
 
853
760
  ```typescript
854
- import { fetchNews } from "./alpaca";
761
+ import { fetchNews } from './alpaca';
855
762
 
856
763
  // Example: Fetch news for a single symbol or multiple symbols (comma-separated)
857
764
  const symbols = "AAPL,MSFT,GOOG"; // For multiple symbols, use a comma-separated string
@@ -867,7 +774,7 @@ const symbols = "AAPL,MSFT,GOOG"; // For multiple symbols, use a comma-separated
867
774
  start: new Date(Date.now() - 24 * 60 * 60 * 1000), // Default: last 24 hours
868
775
  end: new Date(),
869
776
  limit: 10,
870
- sort: "desc",
777
+ sort: 'desc',
871
778
  });
872
779
  console.log(newsData.news);
873
780
 
@@ -876,13 +783,14 @@ const symbols = "AAPL,MSFT,GOOG"; // For multiple symbols, use a comma-separated
876
783
  start: new Date(Date.now() - 24 * 60 * 60 * 1000),
877
784
  end: new Date(),
878
785
  limit: 10,
879
- sort: "desc",
786
+ sort: 'desc',
880
787
  });
881
788
  console.log(newsDataEnv.news);
882
789
 
883
790
  // Pagination
884
791
  // fetchNews automatically fetches all pages if a next_page_token is provided by the API.
885
792
  // The final returned result contains all aggregated news articles along with a `nextPageToken` (if any remain).
793
+
886
794
  } catch (error) {
887
795
  console.error(`Error fetching news: ${error}`);
888
796
  }