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