snaptrade-typescript-sdk 9.0.197 → 9.0.199
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 +43 -215
- package/dist/api.d.ts +0 -1
- package/dist/api.js +0 -1
- package/dist/browser.js +1 -1
- package/dist/client.d.ts +1 -2
- package/dist/client.js +0 -1
- package/dist/configuration.js +1 -1
- package/dist/models/balance.d.ts +1 -1
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.js +2 -0
- package/dist/models/trade-detection-cancel-subscription-response.d.ts +14 -0
- package/dist/models/trade-detection-cancel-subscription-response.js +2 -0
- package/dist/models/trade-detection-subscription.d.ts +26 -0
- package/dist/models/trade-detection-subscription.js +2 -0
- package/dist/operationParameterMap.js +0 -64
- package/package.json +1 -1
- package/dist/api/experimental-endpoints-api-generated.d.ts +0 -300
- package/dist/api/experimental-endpoints-api-generated.js +0 -441
- package/dist/api/experimental-endpoints-api.d.ts +0 -4
- package/dist/api/experimental-endpoints-api.js +0 -22
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
|
-
[](https://www.npmjs.com/package/snaptrade-typescript-sdk/v/9.0.199)
|
|
10
10
|
[](https://snaptrade.com/)
|
|
11
11
|
|
|
12
12
|
</div>
|
|
@@ -47,10 +47,6 @@ Connect brokerage accounts to your app for live positions and trading
|
|
|
47
47
|
* [`snaptrade.connections.removeBrokerageAuthorization`](#snaptradeconnectionsremovebrokerageauthorization)
|
|
48
48
|
* [`snaptrade.connections.returnRates`](#snaptradeconnectionsreturnrates)
|
|
49
49
|
* [`snaptrade.connections.sessionEvents`](#snaptradeconnectionssessionevents)
|
|
50
|
-
* [`snaptrade.experimentalEndpoints.getUserAccountOrderDetailV2`](#snaptradeexperimentalendpointsgetuseraccountorderdetailv2)
|
|
51
|
-
* [`snaptrade.experimentalEndpoints.getUserAccountOrdersV2`](#snaptradeexperimentalendpointsgetuseraccountordersv2)
|
|
52
|
-
* [`snaptrade.experimentalEndpoints.getUserAccountRecentOrdersV2`](#snaptradeexperimentalendpointsgetuseraccountrecentordersv2)
|
|
53
|
-
* [`snaptrade.experimentalEndpoints.syncBrokerageAuthorizationTransactions`](#snaptradeexperimentalendpointssyncbrokerageauthorizationtransactions)
|
|
54
50
|
* [`snaptrade.options.listOptionHoldings`](#snaptradeoptionslistoptionholdings)
|
|
55
51
|
* [`snaptrade.referenceData.getCurrencyExchangeRatePair`](#snaptradereferencedatagetcurrencyexchangeratepair)
|
|
56
52
|
* [`snaptrade.referenceData.getPartnerInfo`](#snaptradereferencedatagetpartnerinfo)
|
|
@@ -122,6 +118,8 @@ yarn add snaptrade-typescript-sdk
|
|
|
122
118
|
|
|
123
119
|
```typescript
|
|
124
120
|
const { Snaptrade } = require("snaptrade-typescript-sdk");
|
|
121
|
+
const { randomUUID } = require("crypto");
|
|
122
|
+
const readline = require("readline");
|
|
125
123
|
|
|
126
124
|
async function main() {
|
|
127
125
|
// 1) Initialize a client with your clientID and consumerKey.
|
|
@@ -135,32 +133,51 @@ async function main() {
|
|
|
135
133
|
console.log("status:", status.data);
|
|
136
134
|
|
|
137
135
|
// 3) Create a new user on SnapTrade
|
|
138
|
-
const userId =
|
|
139
|
-
const
|
|
136
|
+
const userId = randomUUID();
|
|
137
|
+
const registerResponse = (
|
|
140
138
|
await snaptrade.authentication.registerSnapTradeUser({
|
|
141
139
|
userId,
|
|
142
140
|
})
|
|
143
141
|
).data;
|
|
142
|
+
console.log("registerResponse:", registerResponse);
|
|
144
143
|
|
|
145
144
|
// Note: A user secret is only generated once. It's required to access
|
|
146
145
|
// resources for certain endpoints.
|
|
147
|
-
|
|
146
|
+
const userSecret = registerResponse.userSecret;
|
|
148
147
|
|
|
149
148
|
// 4) Get a redirect URI. Users will need this to connect
|
|
150
|
-
|
|
149
|
+
// their brokerage to the SnapTrade server.
|
|
150
|
+
const redirectURI = (
|
|
151
151
|
await snaptrade.authentication.loginSnapTradeUser({ userId, userSecret })
|
|
152
152
|
).data;
|
|
153
|
-
|
|
154
|
-
console.log("redirectURI:", data.redirectURI);
|
|
153
|
+
console.log("redirectURI:", redirectURI);
|
|
155
154
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
await waitForEnter(
|
|
156
|
+
"Open the link in your browser. When done logging in, press Enter to continue..."
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// 5) Get a list of connections
|
|
160
|
+
const connections = (
|
|
161
|
+
await snaptrade.connections.listBrokerageAuthorizations({
|
|
159
162
|
userId,
|
|
160
163
|
userSecret,
|
|
161
164
|
})
|
|
162
165
|
).data;
|
|
163
|
-
console.log("
|
|
166
|
+
console.log("connections:", connections);
|
|
167
|
+
|
|
168
|
+
// 6) Get a list of accounts for the first connection, if available
|
|
169
|
+
if (!Array.isArray(connections) || connections.length === 0) {
|
|
170
|
+
console.log("No brokerage connections found for the user.");
|
|
171
|
+
} else {
|
|
172
|
+
const accounts = (
|
|
173
|
+
await snaptrade.connections.listBrokerageAuthorizationAccounts({
|
|
174
|
+
authorizationId: connections[0].id,
|
|
175
|
+
userId,
|
|
176
|
+
userSecret,
|
|
177
|
+
})
|
|
178
|
+
).data;
|
|
179
|
+
console.log("accounts:", accounts);
|
|
180
|
+
}
|
|
164
181
|
|
|
165
182
|
// 6) Deleting a user
|
|
166
183
|
const deleteResponse = (
|
|
@@ -169,26 +186,17 @@ async function main() {
|
|
|
169
186
|
console.log("deleteResponse:", deleteResponse);
|
|
170
187
|
}
|
|
171
188
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
//Use timestamp until depleted
|
|
184
|
-
r = (d + r) % 16 | 0;
|
|
185
|
-
d = Math.floor(d / 16);
|
|
186
|
-
} else {
|
|
187
|
-
//Use microseconds since page-load if supported
|
|
188
|
-
r = (d2 + r) % 16 | 0;
|
|
189
|
-
d2 = Math.floor(d2 / 16);
|
|
190
|
-
}
|
|
191
|
-
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
189
|
+
function waitForEnter(prompt) {
|
|
190
|
+
const rl = readline.createInterface({
|
|
191
|
+
input: process.stdin,
|
|
192
|
+
output: process.stdout,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return new Promise((resolve) => {
|
|
196
|
+
rl.question(prompt, () => {
|
|
197
|
+
rl.close();
|
|
198
|
+
resolve();
|
|
199
|
+
});
|
|
192
200
|
});
|
|
193
201
|
}
|
|
194
202
|
|
|
@@ -1399,186 +1407,6 @@ Optional comma separated list of session IDs used to filter the request on speci
|
|
|
1399
1407
|
---
|
|
1400
1408
|
|
|
1401
1409
|
|
|
1402
|
-
### `snaptrade.experimentalEndpoints.getUserAccountOrderDetailV2`<a id="snaptradeexperimentalendpointsgetuseraccountorderdetailv2"></a>
|
|
1403
|
-
|
|
1404
|
-
Returns the detail of a single order using the brokerage order ID provided as a path parameter.
|
|
1405
|
-
|
|
1406
|
-
The V2 order response format includes all legs of the order in the `legs` list field.
|
|
1407
|
-
If the order is single legged, `legs` will be a list of one leg.
|
|
1408
|
-
|
|
1409
|
-
This endpoint is always realtime and does not rely on cached data.
|
|
1410
|
-
|
|
1411
|
-
This endpoint only returns orders placed through SnapTrade. In other words, orders placed outside of the SnapTrade network are not returned by this endpoint.
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
#### 🛠️ Usage<a id="🛠️-usage"></a>
|
|
1415
|
-
|
|
1416
|
-
```typescript
|
|
1417
|
-
const getUserAccountOrderDetailV2Response =
|
|
1418
|
-
await snaptrade.experimentalEndpoints.getUserAccountOrderDetailV2({
|
|
1419
|
-
accountId: "917c8734-8470-4a3e-a18f-57c3f2ee6631",
|
|
1420
|
-
brokerageOrderId: "66a033fa-da74-4fcf-b527-feefdec9257e",
|
|
1421
|
-
userId: "snaptrade-user-123",
|
|
1422
|
-
userSecret: "adf2aa34-8219-40f7-a6b3-60156985cc61",
|
|
1423
|
-
});
|
|
1424
|
-
```
|
|
1425
|
-
|
|
1426
|
-
#### ⚙️ Parameters<a id="⚙️-parameters"></a>
|
|
1427
|
-
|
|
1428
|
-
##### accountId: `string`<a id="accountid-string"></a>
|
|
1429
|
-
|
|
1430
|
-
##### brokerageOrderId: `string`<a id="brokerageorderid-string"></a>
|
|
1431
|
-
|
|
1432
|
-
##### userId: `string`<a id="userid-string"></a>
|
|
1433
|
-
|
|
1434
|
-
##### userSecret: `string`<a id="usersecret-string"></a>
|
|
1435
|
-
|
|
1436
|
-
#### 🔄 Return<a id="🔄-return"></a>
|
|
1437
|
-
|
|
1438
|
-
[AccountOrderRecordV2](./models/account-order-record-v2.ts)
|
|
1439
|
-
|
|
1440
|
-
#### 🌐 Endpoint<a id="🌐-endpoint"></a>
|
|
1441
|
-
|
|
1442
|
-
`/accounts/{accountId}/orders/details/v2/{brokerageOrderId}` `GET`
|
|
1443
|
-
|
|
1444
|
-
[🔙 **Back to Table of Contents**](#table-of-contents)
|
|
1445
|
-
|
|
1446
|
-
---
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
### `snaptrade.experimentalEndpoints.getUserAccountOrdersV2`<a id="snaptradeexperimentalendpointsgetuseraccountordersv2"></a>
|
|
1450
|
-
|
|
1451
|
-
Returns a list of recent orders in the specified account.
|
|
1452
|
-
|
|
1453
|
-
The V2 order response format will include all legs of each order in the `legs` list field. If the order is single legged, `legs` will be a list of one leg.
|
|
1454
|
-
|
|
1455
|
-
If the connection has become disabled, it can no longer access the latest data from the brokerage, but will continue to return the last available cached state. Please see [this guide](/docs/fix-broken-connections) on how to fix a disabled connection.
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
#### 🛠️ Usage<a id="🛠️-usage"></a>
|
|
1459
|
-
|
|
1460
|
-
```typescript
|
|
1461
|
-
const getUserAccountOrdersV2Response =
|
|
1462
|
-
await snaptrade.experimentalEndpoints.getUserAccountOrdersV2({
|
|
1463
|
-
userId: "snaptrade-user-123",
|
|
1464
|
-
userSecret: "adf2aa34-8219-40f7-a6b3-60156985cc61",
|
|
1465
|
-
state: "all",
|
|
1466
|
-
days: 30,
|
|
1467
|
-
accountId: "917c8734-8470-4a3e-a18f-57c3f2ee6631",
|
|
1468
|
-
});
|
|
1469
|
-
```
|
|
1470
|
-
|
|
1471
|
-
#### ⚙️ Parameters<a id="⚙️-parameters"></a>
|
|
1472
|
-
|
|
1473
|
-
##### userId: `string`<a id="userid-string"></a>
|
|
1474
|
-
|
|
1475
|
-
##### userSecret: `string`<a id="usersecret-string"></a>
|
|
1476
|
-
|
|
1477
|
-
##### accountId: `string`<a id="accountid-string"></a>
|
|
1478
|
-
|
|
1479
|
-
##### state: `'all' | 'open' | 'executed'`<a id="state-all--open--executed"></a>
|
|
1480
|
-
|
|
1481
|
-
defaults value is set to \"all\"
|
|
1482
|
-
|
|
1483
|
-
##### days: `number`<a id="days-number"></a>
|
|
1484
|
-
|
|
1485
|
-
Number of days in the past to fetch the most recent orders. Defaults to the last 30 days if no value is passed in. Values greater than 90 will be capped at 90.
|
|
1486
|
-
|
|
1487
|
-
#### 🔄 Return<a id="🔄-return"></a>
|
|
1488
|
-
|
|
1489
|
-
[AccountOrdersV2Response](./models/account-orders-v2-response.ts)
|
|
1490
|
-
|
|
1491
|
-
#### 🌐 Endpoint<a id="🌐-endpoint"></a>
|
|
1492
|
-
|
|
1493
|
-
`/accounts/{accountId}/orders/v2` `GET`
|
|
1494
|
-
|
|
1495
|
-
[🔙 **Back to Table of Contents**](#table-of-contents)
|
|
1496
|
-
|
|
1497
|
-
---
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
### `snaptrade.experimentalEndpoints.getUserAccountRecentOrdersV2`<a id="snaptradeexperimentalendpointsgetuseraccountrecentordersv2"></a>
|
|
1501
|
-
|
|
1502
|
-
A lightweight endpoint that returns a list of orders executed in the last 24 hours in the specified account using the V2 order format.
|
|
1503
|
-
This endpoint is realtime and can be used to quickly check if account state has recently changed due to an execution, or check status of recently placed orders.
|
|
1504
|
-
Differs from /orders in that it is realtime, and only checks the last 24 hours as opposed to the last 30 days.
|
|
1505
|
-
By default only returns executed orders, but that can be changed by setting *only_executed* to false.
|
|
1506
|
-
**Because of the cost of realtime requests, 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)**
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
#### 🛠️ Usage<a id="🛠️-usage"></a>
|
|
1510
|
-
|
|
1511
|
-
```typescript
|
|
1512
|
-
const getUserAccountRecentOrdersV2Response =
|
|
1513
|
-
await snaptrade.experimentalEndpoints.getUserAccountRecentOrdersV2({
|
|
1514
|
-
userId: "snaptrade-user-123",
|
|
1515
|
-
userSecret: "adf2aa34-8219-40f7-a6b3-60156985cc61",
|
|
1516
|
-
accountId: "917c8734-8470-4a3e-a18f-57c3f2ee6631",
|
|
1517
|
-
});
|
|
1518
|
-
```
|
|
1519
|
-
|
|
1520
|
-
#### ⚙️ Parameters<a id="⚙️-parameters"></a>
|
|
1521
|
-
|
|
1522
|
-
##### userId: `string`<a id="userid-string"></a>
|
|
1523
|
-
|
|
1524
|
-
##### userSecret: `string`<a id="usersecret-string"></a>
|
|
1525
|
-
|
|
1526
|
-
##### accountId: `string`<a id="accountid-string"></a>
|
|
1527
|
-
|
|
1528
|
-
##### onlyExecuted: `boolean`<a id="onlyexecuted-boolean"></a>
|
|
1529
|
-
|
|
1530
|
-
Defaults to true. Indicates if request should fetch only executed orders. Set to false to retrieve non executed orders as well
|
|
1531
|
-
|
|
1532
|
-
#### 🔄 Return<a id="🔄-return"></a>
|
|
1533
|
-
|
|
1534
|
-
[AccountOrdersV2Response](./models/account-orders-v2-response.ts)
|
|
1535
|
-
|
|
1536
|
-
#### 🌐 Endpoint<a id="🌐-endpoint"></a>
|
|
1537
|
-
|
|
1538
|
-
`/accounts/{accountId}/recentOrders/v2` `GET`
|
|
1539
|
-
|
|
1540
|
-
[🔙 **Back to Table of Contents**](#table-of-contents)
|
|
1541
|
-
|
|
1542
|
-
---
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
### `snaptrade.experimentalEndpoints.syncBrokerageAuthorizationTransactions`<a id="snaptradeexperimentalendpointssyncbrokerageauthorizationtransactions"></a>
|
|
1546
|
-
|
|
1547
|
-
Trigger a transactions sync for all accounts under this connection. Updates will be queued asynchronously. Transactions are not updated intra-day, but calling this endpoint can ensure that the previous day's transactions have been synced. For more information on sync behaviour, see: https://docs.snaptrade.com/docs/syncing
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
#### 🛠️ Usage<a id="🛠️-usage"></a>
|
|
1551
|
-
|
|
1552
|
-
```typescript
|
|
1553
|
-
const syncBrokerageAuthorizationTransactionsResponse =
|
|
1554
|
-
await snaptrade.experimentalEndpoints.syncBrokerageAuthorizationTransactions({
|
|
1555
|
-
authorizationId: "87b24961-b51e-4db8-9226-f198f6518a89",
|
|
1556
|
-
userId: "snaptrade-user-123",
|
|
1557
|
-
userSecret: "adf2aa34-8219-40f7-a6b3-60156985cc61",
|
|
1558
|
-
});
|
|
1559
|
-
```
|
|
1560
|
-
|
|
1561
|
-
#### ⚙️ Parameters<a id="⚙️-parameters"></a>
|
|
1562
|
-
|
|
1563
|
-
##### authorizationId: `string`<a id="authorizationid-string"></a>
|
|
1564
|
-
|
|
1565
|
-
##### userId: `string`<a id="userid-string"></a>
|
|
1566
|
-
|
|
1567
|
-
##### userSecret: `string`<a id="usersecret-string"></a>
|
|
1568
|
-
|
|
1569
|
-
#### 🔄 Return<a id="🔄-return"></a>
|
|
1570
|
-
|
|
1571
|
-
[BrokerageAuthorizationTransactionsSyncConfirmation](./models/brokerage-authorization-transactions-sync-confirmation.ts)
|
|
1572
|
-
|
|
1573
|
-
#### 🌐 Endpoint<a id="🌐-endpoint"></a>
|
|
1574
|
-
|
|
1575
|
-
`/authorizations/{authorizationId}/transactions/sync` `POST`
|
|
1576
|
-
|
|
1577
|
-
[🔙 **Back to Table of Contents**](#table-of-contents)
|
|
1578
|
-
|
|
1579
|
-
---
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
1410
|
### `snaptrade.options.listOptionHoldings`<a id="snaptradeoptionslistoptionholdings"></a>
|
|
1583
1411
|
|
|
1584
1412
|
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).
|
package/dist/api.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './api/account-information-api';
|
|
|
2
2
|
export * from './api/api-status-api';
|
|
3
3
|
export * from './api/authentication-api';
|
|
4
4
|
export * from './api/connections-api';
|
|
5
|
-
export * from './api/experimental-endpoints-api';
|
|
6
5
|
export * from './api/options-api';
|
|
7
6
|
export * from './api/reference-data-api';
|
|
8
7
|
export * from './api/trading-api';
|
package/dist/api.js
CHANGED
|
@@ -30,7 +30,6 @@ __exportStar(require("./api/account-information-api"), exports);
|
|
|
30
30
|
__exportStar(require("./api/api-status-api"), exports);
|
|
31
31
|
__exportStar(require("./api/authentication-api"), exports);
|
|
32
32
|
__exportStar(require("./api/connections-api"), exports);
|
|
33
|
-
__exportStar(require("./api/experimental-endpoints-api"), exports);
|
|
34
33
|
__exportStar(require("./api/options-api"), exports);
|
|
35
34
|
__exportStar(require("./api/reference-data-api"), exports);
|
|
36
35
|
__exportStar(require("./api/trading-api"), exports);
|