snaptrade-typescript-sdk 8.18.0 → 8.20.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.
Files changed (306) hide show
  1. package/README.md +147 -147
  2. package/dist/api/account-information-api-generated.d.ts +525 -0
  3. package/dist/api/account-information-api-generated.js +765 -0
  4. package/dist/api/account-information-api.d.ts +4 -526
  5. package/dist/api/account-information-api.js +22 -1049
  6. package/dist/api/api-status-api-generated.d.ts +69 -0
  7. package/dist/api/api-status-api-generated.js +131 -0
  8. package/dist/api/api-status-api.d.ts +4 -70
  9. package/dist/api/api-status-api.js +22 -203
  10. package/dist/api/authentication-api-generated.d.ts +266 -0
  11. package/dist/api/authentication-api-generated.js +461 -0
  12. package/dist/api/authentication-api.d.ts +4 -267
  13. package/dist/api/authentication-api.js +22 -661
  14. package/dist/api/connections-api-generated.d.ts +274 -0
  15. package/dist/api/connections-api-generated.js +411 -0
  16. package/dist/api/connections-api.d.ts +4 -275
  17. package/dist/api/connections-api.js +22 -583
  18. package/dist/api/error-logs-api-generated.d.ts +93 -0
  19. package/dist/api/error-logs-api-generated.js +152 -0
  20. package/dist/api/error-logs-api.d.ts +4 -94
  21. package/dist/api/error-logs-api.js +22 -240
  22. package/dist/api/options-api-generated.d.ts +368 -0
  23. package/dist/api/options-api-generated.js +530 -0
  24. package/dist/api/options-api.d.ts +4 -369
  25. package/dist/api/options-api.js +22 -730
  26. package/dist/api/reference-data-api-generated.d.ts +467 -0
  27. package/dist/api/reference-data-api-generated.js +872 -0
  28. package/dist/api/reference-data-api.d.ts +4 -468
  29. package/dist/api/reference-data-api.js +22 -1246
  30. package/dist/api/trading-api-generated.d.ts +402 -0
  31. package/dist/api/trading-api-generated.js +613 -0
  32. package/dist/api/trading-api.d.ts +4 -403
  33. package/dist/api/trading-api.js +22 -841
  34. package/dist/api/transactions-and-reporting-api-generated.d.ts +217 -0
  35. package/dist/api/transactions-and-reporting-api-generated.js +287 -0
  36. package/dist/api/transactions-and-reporting-api.d.ts +4 -218
  37. package/dist/api/transactions-and-reporting-api.js +22 -403
  38. package/dist/api.d.ts +19 -19
  39. package/dist/api.js +37 -37
  40. package/dist/base.d.ts +54 -54
  41. package/dist/base.js +60 -81
  42. package/dist/client-custom.d.ts +4 -4
  43. package/dist/client-custom.js +7 -9
  44. package/dist/client.d.ts +25 -25
  45. package/dist/client.js +32 -50
  46. package/dist/common.d.ts +67 -67
  47. package/dist/common.js +177 -236
  48. package/dist/configuration.d.ts +99 -99
  49. package/dist/configuration.js +53 -55
  50. package/dist/error.d.ts +56 -0
  51. package/dist/error.js +104 -0
  52. package/dist/index.d.ts +15 -14
  53. package/dist/index.js +33 -32
  54. package/dist/jest.config.d.ts +3 -3
  55. package/dist/jest.config.js +13 -13
  56. package/dist/models/account-holdings-account.d.ts +53 -53
  57. package/dist/models/account-holdings-account.js +14 -14
  58. package/dist/models/account-holdings.d.ts +46 -46
  59. package/dist/models/account-holdings.js +14 -14
  60. package/dist/models/account-order-record-status.d.ts +16 -16
  61. package/dist/models/account-order-record-status.js +14 -14
  62. package/dist/models/account-order-record.d.ts +132 -132
  63. package/dist/models/account-order-record.js +14 -14
  64. package/dist/models/account-simple.d.ts +43 -43
  65. package/dist/models/account-simple.js +14 -14
  66. package/dist/models/account-sync-status.d.ts +24 -24
  67. package/dist/models/account-sync-status.js +14 -14
  68. package/dist/models/account.d.ts +82 -82
  69. package/dist/models/account.js +14 -14
  70. package/dist/models/action.d.ts +16 -16
  71. package/dist/models/action.js +14 -14
  72. package/dist/models/authentication-login-snap-trade-user200-response.d.ts +17 -17
  73. package/dist/models/authentication-login-snap-trade-user200-response.js +14 -14
  74. package/dist/models/balance.d.ts +31 -31
  75. package/dist/models/balance.js +14 -14
  76. package/dist/models/brokerage-authorization-type-read-only-brokerage.d.ts +36 -36
  77. package/dist/models/brokerage-authorization-type-read-only-brokerage.js +14 -14
  78. package/dist/models/brokerage-authorization-type-read-only.d.ts +46 -46
  79. package/dist/models/brokerage-authorization-type-read-only.js +14 -14
  80. package/dist/models/brokerage-authorization-type.d.ts +26 -26
  81. package/dist/models/brokerage-authorization-type.js +14 -14
  82. package/dist/models/brokerage-authorization.d.ts +75 -75
  83. package/dist/models/brokerage-authorization.js +14 -14
  84. package/dist/models/brokerage-symbol.d.ts +50 -50
  85. package/dist/models/brokerage-symbol.js +14 -14
  86. package/dist/models/brokerage-type.d.ts +30 -30
  87. package/dist/models/brokerage-type.js +14 -14
  88. package/dist/models/brokerage.d.ts +127 -127
  89. package/dist/models/brokerage.js +14 -14
  90. package/dist/models/calculated-trade.d.ts +31 -31
  91. package/dist/models/calculated-trade.js +14 -14
  92. package/dist/models/cash-restriction.d.ts +50 -50
  93. package/dist/models/cash-restriction.js +14 -14
  94. package/dist/models/connections-session-events200-response-inner.d.ts +16 -16
  95. package/dist/models/connections-session-events200-response-inner.js +14 -14
  96. package/dist/models/currency.d.ts +36 -36
  97. package/dist/models/currency.js +14 -14
  98. package/dist/models/delete-user-response.d.ts +30 -30
  99. package/dist/models/delete-user-response.js +14 -14
  100. package/dist/models/dividend-at-date.d.ts +36 -36
  101. package/dist/models/dividend-at-date.js +14 -14
  102. package/dist/models/encrypted-response-encrypted-message-data.d.ts +36 -36
  103. package/dist/models/encrypted-response-encrypted-message-data.js +14 -14
  104. package/dist/models/encrypted-response.d.ts +30 -30
  105. package/dist/models/encrypted-response.js +14 -14
  106. package/dist/models/exchange-rate-pairs.d.ts +37 -37
  107. package/dist/models/exchange-rate-pairs.js +14 -14
  108. package/dist/models/exchange.d.ts +66 -66
  109. package/dist/models/exchange.js +14 -14
  110. package/dist/models/excluded-asset.d.ts +25 -25
  111. package/dist/models/excluded-asset.js +14 -14
  112. package/dist/models/index.d.ts +108 -108
  113. package/dist/models/index.js +124 -124
  114. package/dist/models/jwt.d.ts +24 -24
  115. package/dist/models/jwt.js +14 -14
  116. package/dist/models/login-redirect-uri.d.ts +29 -29
  117. package/dist/models/login-redirect-uri.js +14 -14
  118. package/dist/models/manual-trade-and-impact.d.ts +38 -38
  119. package/dist/models/manual-trade-and-impact.js +14 -14
  120. package/dist/models/manual-trade-balance.d.ts +38 -38
  121. package/dist/models/manual-trade-balance.js +14 -14
  122. package/dist/models/manual-trade-form.d.ts +68 -68
  123. package/dist/models/manual-trade-form.js +14 -14
  124. package/dist/models/manual-trade-symbol.d.ts +55 -55
  125. package/dist/models/manual-trade-symbol.js +14 -14
  126. package/dist/models/manual-trade.d.ts +70 -70
  127. package/dist/models/manual-trade.js +14 -14
  128. package/dist/models/model-asset-class-details.d.ts +32 -32
  129. package/dist/models/model-asset-class-details.js +14 -14
  130. package/dist/models/model-asset-class-target.d.ts +25 -25
  131. package/dist/models/model-asset-class-target.js +14 -14
  132. package/dist/models/model-asset-class.d.ts +30 -30
  133. package/dist/models/model-asset-class.js +14 -14
  134. package/dist/models/model-portfolio-asset-class.d.ts +31 -31
  135. package/dist/models/model-portfolio-asset-class.js +14 -14
  136. package/dist/models/model-portfolio-details.d.ts +39 -39
  137. package/dist/models/model-portfolio-details.js +14 -14
  138. package/dist/models/model-portfolio-security.d.ts +31 -31
  139. package/dist/models/model-portfolio-security.js +14 -14
  140. package/dist/models/model-portfolio.d.ts +38 -38
  141. package/dist/models/model-portfolio.js +14 -14
  142. package/dist/models/model400-failed-request-response.d.ts +30 -30
  143. package/dist/models/model400-failed-request-response.js +14 -14
  144. package/dist/models/model401-failed-request-response.d.ts +30 -30
  145. package/dist/models/model401-failed-request-response.js +14 -14
  146. package/dist/models/model403-failed-request-response.d.ts +30 -30
  147. package/dist/models/model403-failed-request-response.js +14 -14
  148. package/dist/models/model404-failed-request-response.d.ts +30 -30
  149. package/dist/models/model404-failed-request-response.js +14 -14
  150. package/dist/models/monthly-dividends.d.ts +31 -31
  151. package/dist/models/monthly-dividends.js +14 -14
  152. package/dist/models/net-contributions.d.ts +36 -36
  153. package/dist/models/net-contributions.js +14 -14
  154. package/dist/models/net-dividend.d.ts +37 -37
  155. package/dist/models/net-dividend.js +14 -14
  156. package/dist/models/option-chain-inner-chain-per-root-inner-chain-per-strike-price-inner.d.ts +36 -36
  157. package/dist/models/option-chain-inner-chain-per-root-inner-chain-per-strike-price-inner.js +14 -14
  158. package/dist/models/option-chain-inner-chain-per-root-inner.d.ts +37 -37
  159. package/dist/models/option-chain-inner-chain-per-root-inner.js +14 -14
  160. package/dist/models/option-chain-inner.d.ts +49 -49
  161. package/dist/models/option-chain-inner.js +14 -14
  162. package/dist/models/option-leg.d.ts +38 -38
  163. package/dist/models/option-leg.js +14 -14
  164. package/dist/models/option-strategy-legs-inner.d.ts +41 -41
  165. package/dist/models/option-strategy-legs-inner.js +14 -14
  166. package/dist/models/option-strategy.d.ts +50 -50
  167. package/dist/models/option-strategy.js +14 -14
  168. package/dist/models/options-get-option-strategy-request.d.ts +38 -38
  169. package/dist/models/options-get-option-strategy-request.js +14 -14
  170. package/dist/models/options-holdings.d.ts +56 -56
  171. package/dist/models/options-holdings.js +14 -14
  172. package/dist/models/options-place-option-strategy-request.d.ts +38 -38
  173. package/dist/models/options-place-option-strategy-request.js +14 -14
  174. package/dist/models/options-position.d.ts +62 -62
  175. package/dist/models/options-position.js +14 -14
  176. package/dist/models/options-symbol.d.ts +85 -85
  177. package/dist/models/options-symbol.js +14 -14
  178. package/dist/models/order-type.d.ts +16 -16
  179. package/dist/models/order-type.js +14 -14
  180. package/dist/models/partner-data.d.ts +91 -91
  181. package/dist/models/partner-data.js +14 -14
  182. package/dist/models/past-value.d.ts +36 -36
  183. package/dist/models/past-value.js +14 -14
  184. package/dist/models/performance-custom.d.ts +137 -137
  185. package/dist/models/performance-custom.js +14 -14
  186. package/dist/models/portfolio-group-info.d.ts +92 -92
  187. package/dist/models/portfolio-group-info.js +14 -14
  188. package/dist/models/portfolio-group-position.d.ts +37 -37
  189. package/dist/models/portfolio-group-position.js +14 -14
  190. package/dist/models/portfolio-group-settings.d.ts +49 -49
  191. package/dist/models/portfolio-group-settings.js +14 -14
  192. package/dist/models/portfolio-group.d.ts +30 -30
  193. package/dist/models/portfolio-group.js +14 -14
  194. package/dist/models/position-symbol.d.ts +55 -55
  195. package/dist/models/position-symbol.js +14 -14
  196. package/dist/models/position.d.ts +55 -55
  197. package/dist/models/position.js +14 -14
  198. package/dist/models/redirect-tokenand-pin.d.ts +30 -30
  199. package/dist/models/redirect-tokenand-pin.js +14 -14
  200. package/dist/models/security-type.d.ts +42 -42
  201. package/dist/models/security-type.js +14 -14
  202. package/dist/models/session-event.d.ts +62 -62
  203. package/dist/models/session-event.js +14 -14
  204. package/dist/models/snap-trade-apidisclaimer-accept-status.d.ts +30 -30
  205. package/dist/models/snap-trade-apidisclaimer-accept-status.js +14 -14
  206. package/dist/models/snap-trade-holdings-account-account-id.d.ts +75 -75
  207. package/dist/models/snap-trade-holdings-account-account-id.js +14 -14
  208. package/dist/models/snap-trade-holdings-account.d.ts +70 -70
  209. package/dist/models/snap-trade-holdings-account.js +14 -14
  210. package/dist/models/snap-trade-holdings-total-value.d.ts +30 -30
  211. package/dist/models/snap-trade-holdings-total-value.js +14 -14
  212. package/dist/models/snap-trade-login-user-request-body.d.ts +49 -49
  213. package/dist/models/snap-trade-login-user-request-body.js +14 -14
  214. package/dist/models/snap-trade-register-user-request-body.d.ts +29 -29
  215. package/dist/models/snap-trade-register-user-request-body.js +14 -14
  216. package/dist/models/status.d.ts +36 -36
  217. package/dist/models/status.js +14 -14
  218. package/dist/models/strategy-impact-legs-inner.d.ts +60 -60
  219. package/dist/models/strategy-impact-legs-inner.js +14 -14
  220. package/dist/models/strategy-impact.d.ts +85 -85
  221. package/dist/models/strategy-impact.js +14 -14
  222. package/dist/models/strategy-order-place-orders-inner-legs-inner.d.ts +60 -60
  223. package/dist/models/strategy-order-place-orders-inner-legs-inner.js +14 -14
  224. package/dist/models/strategy-order-place-orders-inner.d.ts +277 -277
  225. package/dist/models/strategy-order-place-orders-inner.js +14 -14
  226. package/dist/models/strategy-order-place.d.ts +31 -31
  227. package/dist/models/strategy-order-place.js +14 -14
  228. package/dist/models/strategy-order-record.d.ts +89 -89
  229. package/dist/models/strategy-order-record.js +14 -14
  230. package/dist/models/strategy-quotes-greek.d.ts +48 -48
  231. package/dist/models/strategy-quotes-greek.js +14 -14
  232. package/dist/models/strategy-quotes.d.ts +56 -56
  233. package/dist/models/strategy-quotes.js +14 -14
  234. package/dist/models/sub-period-return-rate.d.ts +36 -36
  235. package/dist/models/sub-period-return-rate.js +14 -14
  236. package/dist/models/symbol-query.d.ts +23 -23
  237. package/dist/models/symbol-query.js +14 -14
  238. package/dist/models/symbol.d.ts +63 -63
  239. package/dist/models/symbol.js +14 -14
  240. package/dist/models/symbols-quotes-inner.d.ts +54 -54
  241. package/dist/models/symbols-quotes-inner.js +14 -14
  242. package/dist/models/target-asset.d.ts +57 -57
  243. package/dist/models/target-asset.js +14 -14
  244. package/dist/models/time-in-force.d.ts +16 -16
  245. package/dist/models/time-in-force.js +14 -14
  246. package/dist/models/trade-execution-status.d.ts +80 -80
  247. package/dist/models/trade-execution-status.js +14 -14
  248. package/dist/models/trade-impact.d.ts +50 -50
  249. package/dist/models/trade-impact.js +14 -14
  250. package/dist/models/trade.d.ts +71 -71
  251. package/dist/models/trade.js +14 -14
  252. package/dist/models/trading-cancel-user-account-order-request.d.ts +23 -23
  253. package/dist/models/trading-cancel-user-account-order-request.js +14 -14
  254. package/dist/models/trading-place-ocoorder-request.d.ts +29 -29
  255. package/dist/models/trading-place-ocoorder-request.js +14 -14
  256. package/dist/models/transactions-status.d.ts +29 -29
  257. package/dist/models/transactions-status.js +14 -14
  258. package/dist/models/underlying-symbol.d.ts +63 -63
  259. package/dist/models/underlying-symbol.js +14 -14
  260. package/dist/models/universal-activity.d.ts +118 -118
  261. package/dist/models/universal-activity.js +14 -14
  262. package/dist/models/universal-symbol-ticker.d.ts +69 -69
  263. package/dist/models/universal-symbol-ticker.js +14 -14
  264. package/dist/models/universal-symbol.d.ts +69 -69
  265. package/dist/models/universal-symbol.js +14 -14
  266. package/dist/models/user-error-log.d.ts +54 -54
  267. package/dist/models/user-error-log.js +14 -14
  268. package/dist/models/user-idand-secret.d.ts +30 -30
  269. package/dist/models/user-idand-secret.js +14 -14
  270. package/dist/models/user-settings.d.ts +79 -79
  271. package/dist/models/user-settings.js +14 -14
  272. package/dist/models/usexchange.d.ts +72 -72
  273. package/dist/models/usexchange.js +14 -14
  274. package/dist/pagination/page-types.d.ts +26 -26
  275. package/dist/pagination/page-types.js +12 -12
  276. package/dist/pagination/page.d.ts +35 -35
  277. package/dist/pagination/page.js +32 -60
  278. package/dist/pagination/pageable.d.ts +57 -57
  279. package/dist/pagination/pageable.js +70 -126
  280. package/dist/pagination/paginate.d.ts +16 -16
  281. package/dist/pagination/paginate.js +39 -77
  282. package/dist/requestAfterHook.d.ts +8 -8
  283. package/dist/requestAfterHook.js +45 -45
  284. package/dist/requestBeforeHook.d.ts +9 -9
  285. package/dist/requestBeforeHook.js +8 -8
  286. package/dist/requestBeforeUrlHook.d.ts +7 -0
  287. package/dist/requestBeforeUrlHook.js +5 -0
  288. package/package.json +42 -42
  289. package/dist/api/account-information-api-custom.d.ts +0 -3
  290. package/dist/api/account-information-api-custom.js +0 -27
  291. package/dist/api/api-status-api-custom.d.ts +0 -3
  292. package/dist/api/api-status-api-custom.js +0 -27
  293. package/dist/api/authentication-api-custom.d.ts +0 -3
  294. package/dist/api/authentication-api-custom.js +0 -27
  295. package/dist/api/connections-api-custom.d.ts +0 -3
  296. package/dist/api/connections-api-custom.js +0 -27
  297. package/dist/api/error-logs-api-custom.d.ts +0 -3
  298. package/dist/api/error-logs-api-custom.js +0 -27
  299. package/dist/api/options-api-custom.d.ts +0 -3
  300. package/dist/api/options-api-custom.js +0 -27
  301. package/dist/api/reference-data-api-custom.d.ts +0 -3
  302. package/dist/api/reference-data-api-custom.js +0 -27
  303. package/dist/api/trading-api-custom.d.ts +0 -3
  304. package/dist/api/trading-api-custom.js +0 -27
  305. package/dist/api/transactions-and-reporting-api-custom.d.ts +0 -3
  306. package/dist/api/transactions-and-reporting-api-custom.js +0 -27
package/README.md CHANGED
@@ -1,147 +1,147 @@
1
- # snaptrade-typescript-sdk@8.18.0
2
-
3
- Connect brokerage accounts to your app for live positions and trading
4
- ## Installing
5
-
6
- ### npm
7
- ```
8
- npm install snaptrade-typescript-sdk --save
9
- ```
10
-
11
- ### yarn
12
- ```
13
- yarn add snaptrade-typescript-sdk
14
- ```
15
-
16
- **Important note: this library is can be used in both the client-side or server-side, but using it
17
- in client-side browser code is not recommended as you would expose security credentials.**
18
-
19
-
20
-
21
- ## Getting Started
22
-
23
- ```typescript
24
- const { Snaptrade } = require("snaptrade-typescript-sdk");
25
-
26
- async function main() {
27
- // 1) Initialize a client with your clientID and consumerKey.
28
- const snaptrade = new Snaptrade({
29
- consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
30
- clientId: process.env.SNAPTRADE_CLIENT_ID,
31
- });
32
-
33
- // 2) Check that the client is able to make a request to the API server.
34
- const status = await snaptrade.apiStatus.check();
35
- console.log("status:", status.data);
36
-
37
- // 3) Create a new user on SnapTrade
38
- const userId = uuid();
39
- const { userSecret } = (
40
- await snaptrade.authentication.registerSnapTradeUser({
41
- userId,
42
- })
43
- ).data;
44
-
45
- // Note: A user secret is only generated once. It's required to access
46
- // resources for certain endpoints.
47
- console.log("userSecret:", userSecret);
48
-
49
- // 4) Get a redirect URI. Users will need this to connect
50
- const data = (
51
- await snaptrade.authentication.loginSnapTradeUser({ userId, userSecret })
52
- ).data;
53
- if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
54
- console.log("redirectURI:", data.redirectURI);
55
-
56
- // 5) Obtaining account holdings data
57
- const holdings = (
58
- await snaptrade.accountInformation.getAllUserHoldings({
59
- userId,
60
- userSecret,
61
- })
62
- ).data;
63
- console.log("holdings:", holdings);
64
-
65
- // 6) Deleting a user
66
- const deleteResponse = (
67
- await snaptrade.authentication.deleteSnapTradeUser({ userId })
68
- ).data;
69
- console.log("deleteResponse:", deleteResponse);
70
- }
71
-
72
- // Should be replaced with function to get user ID
73
- function getUserId() {
74
- var d = new Date().getTime(); //Timestamp
75
- var d2 =
76
- (typeof performance !== "undefined" &&
77
- performance.now &&
78
- performance.now() * 1000) ||
79
- 0; //Time in microseconds since page-load or 0 if unsupported
80
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
81
- var r = Math.random() * 16; //random number between 0 and 16
82
- if (d > 0) {
83
- //Use timestamp until depleted
84
- r = (d + r) % 16 | 0;
85
- d = Math.floor(d / 16);
86
- } else {
87
- //Use microseconds since page-load if supported
88
- r = (d2 + r) % 16 | 0;
89
- d2 = Math.floor(d2 / 16);
90
- }
91
- return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
92
- });
93
- }
94
-
95
- main();
96
- ```
97
-
98
- ## Documentation for API Endpoints
99
-
100
- All URIs are relative to *https://api.snaptrade.com/api/v1*
101
-
102
- Class | Method | HTTP request | Description
103
- ------------ | ------------- | ------------- | -------------
104
- *AccountInformationApi* | [**getAllUserHoldings**](docs/AccountInformationApi.md#getAllUserHoldings) | **GET** /holdings | List all accounts for the user, plus balances and positions for each account.
105
- *AccountInformationApi* | [**getUserAccountBalance**](docs/AccountInformationApi.md#getUserAccountBalance) | **GET** /accounts/{accountId}/balances | Get all cash balances of an investment account
106
- *AccountInformationApi* | [**getUserAccountDetails**](docs/AccountInformationApi.md#getUserAccountDetails) | **GET** /accounts/{accountId} | Return details of a specific investment account
107
- *AccountInformationApi* | [**getUserAccountOrders**](docs/AccountInformationApi.md#getUserAccountOrders) | **GET** /accounts/{accountId}/orders | Get all history of orders placed in account
108
- *AccountInformationApi* | [**getUserAccountPositions**](docs/AccountInformationApi.md#getUserAccountPositions) | **GET** /accounts/{accountId}/positions | Get all positions of an investment account
109
- *AccountInformationApi* | [**getUserHoldings**](docs/AccountInformationApi.md#getUserHoldings) | **GET** /accounts/{accountId}/holdings | List balances, positions and orders for the specified account.
110
- *AccountInformationApi* | [**listUserAccounts**](docs/AccountInformationApi.md#listUserAccounts) | **GET** /accounts | List all investment accounts for the user
111
- *AccountInformationApi* | [**updateUserAccount**](docs/AccountInformationApi.md#updateUserAccount) | **PUT** /accounts/{accountId} | Update details of an investment account
112
- *ApiStatusApi* | [**check**](docs/ApiStatusApi.md#check) | **GET** / | Get API Status
113
- *AuthenticationApi* | [**deleteSnapTradeUser**](docs/AuthenticationApi.md#deleteSnapTradeUser) | **DELETE** /snapTrade/deleteUser | Delete user from SnapTrade, disabling all brokerage authorizations and permanently deleting all data associated with the user
114
- *AuthenticationApi* | [**getUserJWT**](docs/AuthenticationApi.md#getUserJWT) | **GET** /snapTrade/encryptedJWT | Obtains an encrypted JWT tokens that should be decrypted on a user\'s local device
115
- *AuthenticationApi* | [**listSnapTradeUsers**](docs/AuthenticationApi.md#listSnapTradeUsers) | **GET** /snapTrade/listUsers | Get a list of all SnapTrade users you\'ve registered on our platform
116
- *AuthenticationApi* | [**loginSnapTradeUser**](docs/AuthenticationApi.md#loginSnapTradeUser) | **POST** /snapTrade/login | Generate a redirect URI to securely login a user to the SnapTrade Connection Portal
117
- *AuthenticationApi* | [**registerSnapTradeUser**](docs/AuthenticationApi.md#registerSnapTradeUser) | **POST** /snapTrade/registerUser | Register user with SnapTrade in order to create secure brokerage authorizations
118
- *ConnectionsApi* | [**detailBrokerageAuthorization**](docs/ConnectionsApi.md#detailBrokerageAuthorization) | **GET** /authorizations/{authorizationId} | Get detail of a specific brokerage authorizations for the user
119
- *ConnectionsApi* | [**listBrokerageAuthorizations**](docs/ConnectionsApi.md#listBrokerageAuthorizations) | **GET** /authorizations | List all brokerage authorizations for the user
120
- *ConnectionsApi* | [**removeBrokerageAuthorization**](docs/ConnectionsApi.md#removeBrokerageAuthorization) | **DELETE** /authorizations/{authorizationId} | Remove a brokerage authorization.
121
- *ConnectionsApi* | [**sessionEvents**](docs/ConnectionsApi.md#sessionEvents) | **GET** /sessionEvents | List all session events for the partner
122
- *ErrorLogsApi* | [**listUserErrors**](docs/ErrorLogsApi.md#listUserErrors) | **GET** /snapTrade/listUserErrors | Retrieve error logs on behalf of your SnapTrade users
123
- *OptionsApi* | [**getOptionStrategy**](docs/OptionsApi.md#getOptionStrategy) | **POST** /accounts/{accountId}/optionStrategy | Creates an option strategy object that will be used to place an option strategy order
124
- *OptionsApi* | [**getOptionsChain**](docs/OptionsApi.md#getOptionsChain) | **GET** /accounts/{accountId}/optionsChain | Get the options chain
125
- *OptionsApi* | [**getOptionsStrategyQuote**](docs/OptionsApi.md#getOptionsStrategyQuote) | **GET** /accounts/{accountId}/optionStrategy/{optionStrategyId} | Get latest market data of option strategy
126
- *OptionsApi* | [**listOptionHoldings**](docs/OptionsApi.md#listOptionHoldings) | **GET** /accounts/{accountId}/options | Get the options holdings in the account
127
- *OptionsApi* | [**placeOptionStrategy**](docs/OptionsApi.md#placeOptionStrategy) | **POST** /accounts/{accountId}/optionStrategy/{optionStrategyId}/execute | Place an option strategy order on the brokerage
128
- *ReferenceDataApi* | [**getCurrencyExchangeRatePair**](docs/ReferenceDataApi.md#getCurrencyExchangeRatePair) | **GET** /currencies/rates/{currencyPair} | Return the exchange rate of a currency pair
129
- *ReferenceDataApi* | [**getPartnerInfo**](docs/ReferenceDataApi.md#getPartnerInfo) | **GET** /snapTrade/partners | Get metadata related to Snaptrade partner
130
- *ReferenceDataApi* | [**getSecurityTypes**](docs/ReferenceDataApi.md#getSecurityTypes) | **GET** /securityTypes | List of all security types.
131
- *ReferenceDataApi* | [**getStockExchanges**](docs/ReferenceDataApi.md#getStockExchanges) | **GET** /exchanges | Return list of stock exchanges on Passiv and their suffixes
132
- *ReferenceDataApi* | [**getSymbols**](docs/ReferenceDataApi.md#getSymbols) | **POST** /symbols | Search for symbols
133
- *ReferenceDataApi* | [**getSymbolsByTicker**](docs/ReferenceDataApi.md#getSymbolsByTicker) | **GET** /symbols/{ticker} | Get details of a symbol by the ticker
134
- *ReferenceDataApi* | [**listAllBrokerageAuthorizationType**](docs/ReferenceDataApi.md#listAllBrokerageAuthorizationType) | **GET** /brokerageAuthorizationTypes | List of all brokerage authorization types
135
- *ReferenceDataApi* | [**listAllBrokerages**](docs/ReferenceDataApi.md#listAllBrokerages) | **GET** /brokerages | List of all brokerages.
136
- *ReferenceDataApi* | [**listAllCurrencies**](docs/ReferenceDataApi.md#listAllCurrencies) | **GET** /currencies | List of all supported currencies
137
- *ReferenceDataApi* | [**listAllCurrenciesRates**](docs/ReferenceDataApi.md#listAllCurrenciesRates) | **GET** /currencies/rates | Return the exchange rates of all supported currencies
138
- *ReferenceDataApi* | [**symbolSearchUserAccount**](docs/ReferenceDataApi.md#symbolSearchUserAccount) | **POST** /accounts/{accountId}/symbols | Search for symbols that are supported by a brokerage account using a substring
139
- *TradingApi* | [**cancelUserAccountOrder**](docs/TradingApi.md#cancelUserAccountOrder) | **POST** /accounts/{accountId}/orders/cancel | Cancel open order in account
140
- *TradingApi* | [**getOrderImpact**](docs/TradingApi.md#getOrderImpact) | **POST** /trade/impact | Check impact of trades on account.
141
- *TradingApi* | [**getUserAccountQuotes**](docs/TradingApi.md#getUserAccountQuotes) | **GET** /accounts/{accountId}/quotes | Get symbol quotes
142
- *TradingApi* | [**placeForceOrder**](docs/TradingApi.md#placeForceOrder) | **POST** /trade/place | Place a trade with NO validation.
143
- *TradingApi* | [**placeOCOOrder**](docs/TradingApi.md#placeOCOOrder) | **POST** /trade/oco | Place a OCO (One Cancels Other) order
144
- *TradingApi* | [**placeOrder**](docs/TradingApi.md#placeOrder) | **POST** /trade/{tradeId} | Place order
145
- *TransactionsAndReportingApi* | [**getActivities**](docs/TransactionsAndReportingApi.md#getActivities) | **GET** /activities | Get transaction history for a user
146
- *TransactionsAndReportingApi* | [**getReportingCustomRange**](docs/TransactionsAndReportingApi.md#getReportingCustomRange) | **GET** /performance/custom | Get performance information for a specific timeframe
147
-
1
+ # snaptrade-typescript-sdk@8.20.0
2
+
3
+ Connect brokerage accounts to your app for live positions and trading
4
+ ## Installing
5
+
6
+ ### npm
7
+ ```
8
+ npm install snaptrade-typescript-sdk --save
9
+ ```
10
+
11
+ ### yarn
12
+ ```
13
+ yarn add snaptrade-typescript-sdk
14
+ ```
15
+
16
+ **Important note: this library can be used in both the client-side or server-side, but using it
17
+ in client-side browser code is not recommended as you would expose security credentials.**
18
+
19
+
20
+
21
+ ## Getting Started
22
+
23
+ ```typescript
24
+ const { Snaptrade } = require("snaptrade-typescript-sdk");
25
+
26
+ async function main() {
27
+ // 1) Initialize a client with your clientID and consumerKey.
28
+ const snaptrade = new Snaptrade({
29
+ consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
30
+ clientId: process.env.SNAPTRADE_CLIENT_ID,
31
+ });
32
+
33
+ // 2) Check that the client is able to make a request to the API server.
34
+ const status = await snaptrade.apiStatus.check();
35
+ console.log("status:", status.data);
36
+
37
+ // 3) Create a new user on SnapTrade
38
+ const userId = uuid();
39
+ const { userSecret } = (
40
+ await snaptrade.authentication.registerSnapTradeUser({
41
+ userId,
42
+ })
43
+ ).data;
44
+
45
+ // Note: A user secret is only generated once. It's required to access
46
+ // resources for certain endpoints.
47
+ console.log("userSecret:", userSecret);
48
+
49
+ // 4) Get a redirect URI. Users will need this to connect
50
+ const data = (
51
+ await snaptrade.authentication.loginSnapTradeUser({ userId, userSecret })
52
+ ).data;
53
+ if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
54
+ console.log("redirectURI:", data.redirectURI);
55
+
56
+ // 5) Obtaining account holdings data
57
+ const holdings = (
58
+ await snaptrade.accountInformation.getAllUserHoldings({
59
+ userId,
60
+ userSecret,
61
+ })
62
+ ).data;
63
+ console.log("holdings:", holdings);
64
+
65
+ // 6) Deleting a user
66
+ const deleteResponse = (
67
+ await snaptrade.authentication.deleteSnapTradeUser({ userId })
68
+ ).data;
69
+ console.log("deleteResponse:", deleteResponse);
70
+ }
71
+
72
+ // Should be replaced with function to get user ID
73
+ function getUserId() {
74
+ var d = new Date().getTime(); //Timestamp
75
+ var d2 =
76
+ (typeof performance !== "undefined" &&
77
+ performance.now &&
78
+ performance.now() * 1000) ||
79
+ 0; //Time in microseconds since page-load or 0 if unsupported
80
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
81
+ var r = Math.random() * 16; //random number between 0 and 16
82
+ if (d > 0) {
83
+ //Use timestamp until depleted
84
+ r = (d + r) % 16 | 0;
85
+ d = Math.floor(d / 16);
86
+ } else {
87
+ //Use microseconds since page-load if supported
88
+ r = (d2 + r) % 16 | 0;
89
+ d2 = Math.floor(d2 / 16);
90
+ }
91
+ return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
92
+ });
93
+ }
94
+
95
+ main();
96
+ ```
97
+
98
+ ## Documentation for API Endpoints
99
+
100
+ All URIs are relative to *https://api.snaptrade.com/api/v1*
101
+
102
+ Class | Method | HTTP request | Description
103
+ ------------ | ------------- | ------------- | -------------
104
+ *AccountInformationApi* | [**getAllUserHoldings**](docs/AccountInformationApi.md#getAllUserHoldings) | **GET** /holdings | List all accounts for the user, plus balances and positions for each account.
105
+ *AccountInformationApi* | [**getUserAccountBalance**](docs/AccountInformationApi.md#getUserAccountBalance) | **GET** /accounts/{accountId}/balances | Get all cash balances of an investment account
106
+ *AccountInformationApi* | [**getUserAccountDetails**](docs/AccountInformationApi.md#getUserAccountDetails) | **GET** /accounts/{accountId} | Return details of a specific investment account
107
+ *AccountInformationApi* | [**getUserAccountOrders**](docs/AccountInformationApi.md#getUserAccountOrders) | **GET** /accounts/{accountId}/orders | Get all history of orders placed in account
108
+ *AccountInformationApi* | [**getUserAccountPositions**](docs/AccountInformationApi.md#getUserAccountPositions) | **GET** /accounts/{accountId}/positions | Get all positions of an investment account
109
+ *AccountInformationApi* | [**getUserHoldings**](docs/AccountInformationApi.md#getUserHoldings) | **GET** /accounts/{accountId}/holdings | List balances, positions and orders for the specified account.
110
+ *AccountInformationApi* | [**listUserAccounts**](docs/AccountInformationApi.md#listUserAccounts) | **GET** /accounts | List all investment accounts for the user
111
+ *AccountInformationApi* | [**updateUserAccount**](docs/AccountInformationApi.md#updateUserAccount) | **PUT** /accounts/{accountId} | Update details of an investment account
112
+ *ApiStatusApi* | [**check**](docs/ApiStatusApi.md#check) | **GET** / | Get API Status
113
+ *AuthenticationApi* | [**deleteSnapTradeUser**](docs/AuthenticationApi.md#deleteSnapTradeUser) | **DELETE** /snapTrade/deleteUser | Delete user from SnapTrade, disabling all brokerage authorizations and permanently deleting all data associated with the user
114
+ *AuthenticationApi* | [**getUserJWT**](docs/AuthenticationApi.md#getUserJWT) | **GET** /snapTrade/encryptedJWT | Obtains an encrypted JWT tokens that should be decrypted on a user\'s local device
115
+ *AuthenticationApi* | [**listSnapTradeUsers**](docs/AuthenticationApi.md#listSnapTradeUsers) | **GET** /snapTrade/listUsers | Get a list of all SnapTrade users you\'ve registered on our platform
116
+ *AuthenticationApi* | [**loginSnapTradeUser**](docs/AuthenticationApi.md#loginSnapTradeUser) | **POST** /snapTrade/login | Generate a redirect URI to securely login a user to the SnapTrade Connection Portal
117
+ *AuthenticationApi* | [**registerSnapTradeUser**](docs/AuthenticationApi.md#registerSnapTradeUser) | **POST** /snapTrade/registerUser | Register user with SnapTrade in order to create secure brokerage authorizations
118
+ *ConnectionsApi* | [**detailBrokerageAuthorization**](docs/ConnectionsApi.md#detailBrokerageAuthorization) | **GET** /authorizations/{authorizationId} | Get detail of a specific brokerage authorizations for the user
119
+ *ConnectionsApi* | [**listBrokerageAuthorizations**](docs/ConnectionsApi.md#listBrokerageAuthorizations) | **GET** /authorizations | List all brokerage authorizations for the user
120
+ *ConnectionsApi* | [**removeBrokerageAuthorization**](docs/ConnectionsApi.md#removeBrokerageAuthorization) | **DELETE** /authorizations/{authorizationId} | Remove a brokerage authorization.
121
+ *ConnectionsApi* | [**sessionEvents**](docs/ConnectionsApi.md#sessionEvents) | **GET** /sessionEvents | List all session events for the partner
122
+ *ErrorLogsApi* | [**listUserErrors**](docs/ErrorLogsApi.md#listUserErrors) | **GET** /snapTrade/listUserErrors | Retrieve error logs on behalf of your SnapTrade users
123
+ *OptionsApi* | [**getOptionStrategy**](docs/OptionsApi.md#getOptionStrategy) | **POST** /accounts/{accountId}/optionStrategy | Creates an option strategy object that will be used to place an option strategy order
124
+ *OptionsApi* | [**getOptionsChain**](docs/OptionsApi.md#getOptionsChain) | **GET** /accounts/{accountId}/optionsChain | Get the options chain
125
+ *OptionsApi* | [**getOptionsStrategyQuote**](docs/OptionsApi.md#getOptionsStrategyQuote) | **GET** /accounts/{accountId}/optionStrategy/{optionStrategyId} | Get latest market data of option strategy
126
+ *OptionsApi* | [**listOptionHoldings**](docs/OptionsApi.md#listOptionHoldings) | **GET** /accounts/{accountId}/options | Get the options holdings in the account
127
+ *OptionsApi* | [**placeOptionStrategy**](docs/OptionsApi.md#placeOptionStrategy) | **POST** /accounts/{accountId}/optionStrategy/{optionStrategyId}/execute | Place an option strategy order on the brokerage
128
+ *ReferenceDataApi* | [**getCurrencyExchangeRatePair**](docs/ReferenceDataApi.md#getCurrencyExchangeRatePair) | **GET** /currencies/rates/{currencyPair} | Return the exchange rate of a currency pair
129
+ *ReferenceDataApi* | [**getPartnerInfo**](docs/ReferenceDataApi.md#getPartnerInfo) | **GET** /snapTrade/partners | Get metadata related to Snaptrade partner
130
+ *ReferenceDataApi* | [**getSecurityTypes**](docs/ReferenceDataApi.md#getSecurityTypes) | **GET** /securityTypes | List of all security types.
131
+ *ReferenceDataApi* | [**getStockExchanges**](docs/ReferenceDataApi.md#getStockExchanges) | **GET** /exchanges | Return list of stock exchanges on Passiv and their suffixes
132
+ *ReferenceDataApi* | [**getSymbols**](docs/ReferenceDataApi.md#getSymbols) | **POST** /symbols | Search for symbols
133
+ *ReferenceDataApi* | [**getSymbolsByTicker**](docs/ReferenceDataApi.md#getSymbolsByTicker) | **GET** /symbols/{ticker} | Get details of a symbol by the ticker
134
+ *ReferenceDataApi* | [**listAllBrokerageAuthorizationType**](docs/ReferenceDataApi.md#listAllBrokerageAuthorizationType) | **GET** /brokerageAuthorizationTypes | List of all brokerage authorization types
135
+ *ReferenceDataApi* | [**listAllBrokerages**](docs/ReferenceDataApi.md#listAllBrokerages) | **GET** /brokerages | List of all brokerages.
136
+ *ReferenceDataApi* | [**listAllCurrencies**](docs/ReferenceDataApi.md#listAllCurrencies) | **GET** /currencies | List of all supported currencies
137
+ *ReferenceDataApi* | [**listAllCurrenciesRates**](docs/ReferenceDataApi.md#listAllCurrenciesRates) | **GET** /currencies/rates | Return the exchange rates of all supported currencies
138
+ *ReferenceDataApi* | [**symbolSearchUserAccount**](docs/ReferenceDataApi.md#symbolSearchUserAccount) | **POST** /accounts/{accountId}/symbols | Search for symbols that are supported by a brokerage account using a substring
139
+ *TradingApi* | [**cancelUserAccountOrder**](docs/TradingApi.md#cancelUserAccountOrder) | **POST** /accounts/{accountId}/orders/cancel | Cancel open order in account
140
+ *TradingApi* | [**getOrderImpact**](docs/TradingApi.md#getOrderImpact) | **POST** /trade/impact | Check impact of trades on account.
141
+ *TradingApi* | [**getUserAccountQuotes**](docs/TradingApi.md#getUserAccountQuotes) | **GET** /accounts/{accountId}/quotes | Get symbol quotes
142
+ *TradingApi* | [**placeForceOrder**](docs/TradingApi.md#placeForceOrder) | **POST** /trade/place | Place a trade with NO validation.
143
+ *TradingApi* | [**placeOCOOrder**](docs/TradingApi.md#placeOCOOrder) | **POST** /trade/oco | Place a OCO (One Cancels Other) order
144
+ *TradingApi* | [**placeOrder**](docs/TradingApi.md#placeOrder) | **POST** /trade/{tradeId} | Place order
145
+ *TransactionsAndReportingApi* | [**getActivities**](docs/TransactionsAndReportingApi.md#getActivities) | **GET** /activities | Get transaction history for a user
146
+ *TransactionsAndReportingApi* | [**getReportingCustomRange**](docs/TransactionsAndReportingApi.md#getReportingCustomRange) | **GET** /performance/custom | Get performance information for a specific timeframe
147
+