snaptrade-typescript-sdk 11.0.0-canary.0 → 11.0.0

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 CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Connect brokerage accounts to your app for live positions and trading
8
8
 
9
- [![npm](https://img.shields.io/badge/npm-v11.0.0--canary.0-blue)](https://www.npmjs.com/package/snaptrade-typescript-sdk/v/11.0.0-canary.0)
9
+ [![npm](https://img.shields.io/badge/npm-v11.0.0-blue)](https://www.npmjs.com/package/snaptrade-typescript-sdk/v/11.0.0)
10
10
  [![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](https://snaptrade.com/)
11
11
 
12
12
  </div>
@@ -124,7 +124,10 @@ yarn add snaptrade-typescript-sdk
124
124
  ## Getting Started<a id="getting-started"></a>
125
125
 
126
126
  ```typescript
127
+ // Commercial API key example: registers a SnapTrade user and uses userId/userSecret.
127
128
  const { Snaptrade, SnaptradeAuth } = require("snaptrade-typescript-sdk");
129
+ const { randomUUID } = require("crypto");
130
+ const readline = require("readline");
128
131
 
129
132
  async function main() {
130
133
  // 1) Initialize a client with your clientID and consumerKey.
@@ -140,32 +143,51 @@ async function main() {
140
143
  console.log("status:", status.data);
141
144
 
142
145
  // 3) Create a new user on SnapTrade
143
- const userId = uuid();
144
- const { userSecret } = (
146
+ const userId = randomUUID();
147
+ const registerResponse = (
145
148
  await snaptrade.authentication.registerSnapTradeUser({
146
149
  userId,
147
150
  })
148
151
  ).data;
152
+ console.log("registerResponse:", registerResponse);
149
153
 
150
154
  // Note: A user secret is only generated once. It's required to access
151
155
  // resources for certain endpoints.
152
- console.log("userSecret:", userSecret);
156
+ const userSecret = registerResponse.userSecret;
153
157
 
154
158
  // 4) Get a redirect URI. Users will need this to connect
155
- const data = (
159
+ // their brokerage to the SnapTrade server.
160
+ const redirectURI = (
156
161
  await snaptrade.authentication.loginSnapTradeUser({ userId, userSecret })
157
162
  ).data;
158
- if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
159
- console.log("redirectURI:", data.redirectURI);
163
+ console.log("redirectURI:", redirectURI);
160
164
 
161
- // 5) Obtaining account holdings data
162
- const holdings = (
163
- await snaptrade.accountInformation.getAllUserHoldings({
165
+ await waitForEnter(
166
+ "Open the link in your browser. When done logging in, press Enter to continue..."
167
+ );
168
+
169
+ // 5) Get a list of connections
170
+ const connections = (
171
+ await snaptrade.connections.listBrokerageAuthorizations({
164
172
  userId,
165
173
  userSecret,
166
174
  })
167
175
  ).data;
168
- console.log("holdings:", holdings);
176
+ console.log("connections:", connections);
177
+
178
+ // 6) Get a list of accounts for the first connection, if available
179
+ if (!Array.isArray(connections) || connections.length === 0) {
180
+ console.log("No brokerage connections found for the user.");
181
+ } else {
182
+ const accounts = (
183
+ await snaptrade.connections.listBrokerageAuthorizationAccounts({
184
+ authorizationId: connections[0].id,
185
+ userId,
186
+ userSecret,
187
+ })
188
+ ).data;
189
+ console.log("accounts:", accounts);
190
+ }
169
191
 
170
192
  // 6) Deleting a user
171
193
  const deleteResponse = (
@@ -174,26 +196,17 @@ async function main() {
174
196
  console.log("deleteResponse:", deleteResponse);
175
197
  }
176
198
 
177
- // Should be replaced with function to get user ID
178
- function getUserId() {
179
- var d = new Date().getTime(); //Timestamp
180
- var d2 =
181
- (typeof performance !== "undefined" &&
182
- performance.now &&
183
- performance.now() * 1000) ||
184
- 0; //Time in microseconds since page-load or 0 if unsupported
185
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
186
- var r = Math.random() * 16; //random number between 0 and 16
187
- if (d > 0) {
188
- //Use timestamp until depleted
189
- r = (d + r) % 16 | 0;
190
- d = Math.floor(d / 16);
191
- } else {
192
- //Use microseconds since page-load if supported
193
- r = (d2 + r) % 16 | 0;
194
- d2 = Math.floor(d2 / 16);
195
- }
196
- return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
199
+ function waitForEnter(prompt) {
200
+ const rl = readline.createInterface({
201
+ input: process.stdin,
202
+ output: process.stdout,
203
+ });
204
+
205
+ return new Promise((resolve) => {
206
+ rl.question(prompt, () => {
207
+ rl.close();
208
+ resolve();
209
+ });
197
210
  });
198
211
  }
199
212
 
@@ -689,13 +702,10 @@ const getUserHoldingsResponse =
689
702
 
690
703
 
691
704
  ### `snaptrade.accountInformation.listUserAccounts`<a id="snaptradeaccountinformationlistuseraccounts"></a>
692
- ![Deprecated](https://img.shields.io/badge/deprecated-yellow)
693
-
694
- **Deprecated, please use the [list accounts for a connection endpoint](/reference/Connections/Connections_listBrokerageAuthorizationAccounts) instead.**
695
705
 
696
706
  Returns all brokerage accounts across all connections known to SnapTrade for the authenticated user.
697
707
 
698
- This endpoint returns Daily data regardless of the customer's plan. Daily data is cached and refreshed once a day. Exact refresh timing may vary by brokerage. To get real-time data on Pay as you Go / Real-time, use the connection-scoped endpoint linked above. Customers on Pay as you Go / Daily can force a refresh with the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization).
708
+ This endpoint returns Daily data regardless of the customer's plan. Daily data is cached and refreshed once a day, which makes this endpoint fast and well-suited to listing accounts across all of a user's connections in a single call. Exact refresh timing may vary by brokerage. To get real-time data on Pay as you Go / Real-time, use the [list accounts for a connection endpoint](/reference/Connections/Connections_listBrokerageAuthorizationAccounts). Customers on Pay as you Go / Daily can force a refresh with the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization).
699
709
 
700
710
 
701
711
  #### 🛠️ Usage<a id="🛠️-usage"></a>
@@ -1124,7 +1134,7 @@ Trigger a holdings update for all accounts under this connection. Updates will b
1124
1134
  This endpoint will also trigger a transaction sync for the past day if one has not yet occurred.
1125
1135
 
1126
1136
  **Because of the cost of refreshing a connection, each call to this endpoint incurs an additional charge. You can find the exact cost for your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing)**
1127
- **Please note this endpoint is disabled for Personal and Pay as you Go Real-time plans. Real-time plans do not benefit from this feature since data is refreshed when calls are made**
1137
+ **Please note this endpoint is disabled for Real-time plans (Personal and Pay as you go) unless the connection is delayed. Real-time connections do not benefit from this feature since data is refreshed when calls are made. Refer to the `data_freshness_mode` field on a connection to determine this.**
1128
1138
 
1129
1139
 
1130
1140
  #### 🛠️ Usage<a id="🛠️-usage"></a>
@@ -1223,6 +1233,8 @@ Returns a list of session events associated with a user.
1223
1233
  ```typescript
1224
1234
  const sessionEventsResponse = await snaptrade.connections.sessionEvents({
1225
1235
  partnerClientId: "SNAPTRADETEST",
1236
+ userId:
1237
+ "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2",
1226
1238
  sessionId:
1227
1239
  "917c8734-8470-4a3e-a18f-57c3f2ee6631,65e839a3-9103-4cfb-9b72-2071ef80c5f2",
1228
1240
  });
@@ -1232,6 +1244,10 @@ const sessionEventsResponse = await snaptrade.connections.sessionEvents({
1232
1244
 
1233
1245
  ##### partnerClientId: `string`<a id="partnerclientid-string"></a>
1234
1246
 
1247
+ ##### userId: `string`<a id="userid-string"></a>
1248
+
1249
+ Optional comma separated list of user IDs used to filter the request on specific users
1250
+
1235
1251
  ##### sessionId: `string`<a id="sessionid-string"></a>
1236
1252
 
1237
1253
  Optional comma separated list of session IDs used to filter the request on specific users
@@ -1292,6 +1308,7 @@ This endpoint requires `userId` and `userSecret` in addition to the partner sign
1292
1308
  const addSubscriptionResponse =
1293
1309
  await snaptrade.experimentalEndpoints.addSubscription({
1294
1310
  account_id: "917c8734-8470-4a3e-a18f-57c3f2ee6631",
1311
+ check_interval_seconds: 300,
1295
1312
  });
1296
1313
  ```
1297
1314
 
@@ -1301,6 +1318,10 @@ const addSubscriptionResponse =
1301
1318
 
1302
1319
  Unique identifier for the connected brokerage account. This is the UUID used to reference the account in SnapTrade.
1303
1320
 
1321
+ ##### check_interval_seconds: `number`<a id="check_interval_seconds-number"></a>
1322
+
1323
+ How often the subscribed account should be checked for new trades. Must match an active Trade Detection plan.
1324
+
1304
1325
  #### 🔄 Return<a id="🔄-return"></a>
1305
1326
 
1306
1327
  [TradeDetectionSubscription](./models/trade-detection-subscription.ts)
@@ -1502,7 +1523,7 @@ const listSubscriptionsResponse =
1502
1523
 
1503
1524
  Returns a list of option positions in the specified account. For stock/ETF/crypto/mutual fund positions, please use the [positions endpoint](/reference/Account%20Information/AccountInformation_getUserAccountPositions).
1504
1525
 
1505
- This endpoint is deprecatd. Consider using the newer [unified positions endpoint](/reference/Account%20Information/AccountInformation_getAllAccountPositions). This will allow you to get both equity and option positions in a single call, as well as additional asset classes such as futures.
1526
+ This endpoint is deprecated. Consider using the newer [unified positions endpoint](/reference/Account%20Information/AccountInformation_getAllAccountPositions). This will allow you to get both equity and option positions in a single call, as well as additional asset classes such as futures.
1506
1527
 
1507
1528
  Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see if you have real-time data access:
1508
1529
  - If you do, this endpoint returns real-time data.
@@ -2284,8 +2305,9 @@ Number of shares for the order. This can be a decimal for fractional orders. Mus
2284
2305
 
2285
2306
  ### `snaptrade.trading.placeComplexOrder`<a id="snaptradetradingplacecomplexorder"></a>
2286
2307
 
2287
- Places a complex conditional order (OCO, OTO, or OTOCO). Disabled by default — contact support to enable.
2308
+ Places a complex conditional order (OCO, OTO, or OTOCO).
2288
2309
  Only supported on certain brokerages.
2310
+ Please refer to the [brokerage trading support page](https://support.snaptrade.com/brokerages) for details on which brokerages support complex orders and which types they support.
2289
2311
 
2290
2312
  - **OCO** (One Cancels the Other): Two peer orders; when one fills the other is cancelled.
2291
2313
  - **OTO** (One Triggers the Other): A trigger order that, when filled, activates a conditional order.
@@ -2313,7 +2335,7 @@ const placeComplexOrderResponse = await snaptrade.trading.placeComplexOrder({
2313
2335
  stop: 29.5,
2314
2336
  },
2315
2337
  ],
2316
- client_order_id: "my-order-123",
2338
+ client_order_id: "550e8400-e29b-41d4-a716-446655440000",
2317
2339
  });
2318
2340
  ```
2319
2341
 
@@ -2331,9 +2353,7 @@ The orders that make up the complex order. Required counts and roles per type: -
2331
2353
 
2332
2354
  The ID of the account to execute the trade on.
2333
2355
 
2334
- ##### client_order_id: `string`<a id="client_order_id-string"></a>
2335
-
2336
- An optional client-provided identifier for this complex order. Passed through to the brokerage and returned in the response.
2356
+ ##### client_order_id: [`string`](./models/model-string.ts)<a id="client_order_id-stringmodelsmodel-stringts"></a>
2337
2357
 
2338
2358
  #### 🔄 Return<a id="🔄-return"></a>
2339
2359
 
@@ -2445,9 +2465,11 @@ const placeForceOrderResponse = await snaptrade.trading.placeForceOrder({
2445
2465
  order_type: "Market",
2446
2466
  time_in_force: "Day",
2447
2467
  trading_session: "REGULAR",
2468
+ expiry_date: "2026-08-21T23:27:55.027Z",
2448
2469
  price: 31.33,
2449
2470
  stop: 31.33,
2450
2471
  units: 10.5,
2472
+ client_order_id: "550e8400-e29b-41d4-a716-446655440000",
2451
2473
  });
2452
2474
  ```
2453
2475
 
@@ -2465,9 +2487,9 @@ The action describes the intent or side of a trade. This is either `BUY` or `SEL
2465
2487
 
2466
2488
  The type of order to place. - For `Limit` and `StopLimit` orders, the `price` field is required. - For `Stop` and `StopLimit` orders, the `stop` field is required.
2467
2489
 
2468
- ##### time_in_force: [`TimeInForceStrict`](./models/time-in-force-strict.ts)<a id="time_in_force-timeinforcestrictmodelstime-in-force-strictts"></a>
2490
+ ##### time_in_force: [`ManualTradePlaceTimeInForceStrict`](./models/manual-trade-place-time-in-force-strict.ts)<a id="time_in_force-manualtradeplacetimeinforcestrictmodelsmanual-trade-place-time-in-force-strictts"></a>
2469
2491
 
2470
- The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. Here are the supported values: - `Day` - Day. The order is valid only for the trading day on which it is placed. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled.
2492
+ The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. Here are the supported values: - `Day` - Day. The order is valid only for the trading day on which it is placed. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until `expiry_date`, which is required. Not available for market orders. GTD orders are only available on certain brokerages. Visit https://support.snaptrade.com/brokerages for brokerage support.
2471
2493
 
2472
2494
  ##### universal_symbol_id: [`string`](./models/model-string.ts)<a id="universal_symbol_id-stringmodelsmodel-stringts"></a>
2473
2495
 
@@ -2481,6 +2503,10 @@ The security\\\'s trading ticker symbol. If \\\'symbol\\\' is provided, then \\\
2481
2503
 
2482
2504
  The trading session for the order. This field indicates which market session the order will be placed in. This is only available for certain brokerages. Defaults to REGULAR. Here are the supported values: - `REGULAR` - Regular trading hours. - `EXTENDED` - Extended trading hours.
2483
2505
 
2506
+ ##### expiry_date: `string`<a id="expiry_date-string"></a>
2507
+
2508
+ Timestamp in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format indicating when the order expires. Required when `time_in_force` is `GTD`. Include a timezone offset or `Z` for UTC; if no timezone is provided, UTC is assumed. GTD orders are only available on certain brokerages. Visit https://support.snaptrade.com/brokerages for brokerage support.
2509
+
2484
2510
  ##### price: `number`<a id="price-number"></a>
2485
2511
 
2486
2512
  The limit price for `Limit` and `StopLimit` orders.
@@ -2495,6 +2521,8 @@ For Equity orders, this represents the number of shares for the order. This can
2495
2521
 
2496
2522
  ##### notional_value: [`ManualTradeFormNotionalValue`](./models/manual-trade-form-notional-value.ts)<a id="notional_value-manualtradeformnotionalvaluemodelsmanual-trade-form-notional-valuets"></a>
2497
2523
 
2524
+ ##### client_order_id: [`string`](./models/model-string.ts)<a id="client_order_id-stringmodelsmodel-stringts"></a>
2525
+
2498
2526
  #### 🔄 Return<a id="🔄-return"></a>
2499
2527
 
2500
2528
  [AccountOrderRecord](./models/account-order-record.ts)