snaptrade-typescript-sdk 1.0.1 → 2.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.
@@ -0,0 +1 @@
1
+ ba5c7e08-b43f-410b-a71b-d37e65071ba4
package/.konfigignore ADDED
@@ -0,0 +1,2 @@
1
+ index.test.ts
2
+ README.md
package/README.md CHANGED
@@ -1,72 +1,92 @@
1
- ## snaptrade-typescript-sdk@1.0.1
1
+ ## snaptrade-typescript-sdk@2.0.0
2
2
 
3
3
  This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
4
4
 
5
5
  Environment
6
- * Node.js
7
- * Webpack
8
- * Browserify
6
+
7
+ - Node.js
8
+ - Webpack
9
+ - Browserify
9
10
 
10
11
  Language level
11
- * ES5 - you must have a Promises/A+ library installed
12
- * ES6
12
+
13
+ - ES5 - you must have a Promises/A+ library installed
14
+ - ES6
13
15
 
14
16
  Module system
15
- * CommonJS
16
- * ES6 module system
17
+
18
+ - CommonJS
19
+ - ES6 module system
17
20
 
18
21
  It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
19
22
 
20
23
  ### Building
21
24
 
22
25
  To build and compile the typescript sources to javascript use:
26
+
23
27
  ```
24
28
  npm install
25
29
  npm run build
26
30
  ```
27
31
 
28
- ### Publishing
29
-
30
- First build the package then run ```npm publish```
31
-
32
32
  ### Consuming
33
33
 
34
- navigate to the folder of your consuming project and run one of the following commands.
35
-
36
- _published:_
34
+ navigate to the folder of your consuming project and run the following command.
37
35
 
38
36
  ```
39
- npm install snaptrade-typescript-sdk@1.0.1 --save
37
+ npm install snaptrade-typescript-sdk@2.0.0 --save
40
38
  ```
41
39
 
42
40
  ### Getting Started
43
41
 
44
42
  ```typescript
45
- import {
46
- AccountInformationApi,
43
+ const {
44
+ Configuration,
47
45
  APIStatusApi,
48
46
  AuthenticationApi,
49
- Configuration,
50
- } from "snaptrade-typescript-sdk";
51
- import { v4 } from "uuid";
52
-
53
- // 1) Initialize a configuration with your clientID and consumerKey.
54
- const config = new Configuration({
55
- clientId: "YOUR_CLIENT_ID",
56
- consumerKey: "YOUR_CONSUMER_KEY",
57
- });
47
+ AccountInformationApi,
48
+ } = require("snaptrade-typescript-sdk");
49
+
50
+ // Should be replaced with function to get user ID
51
+ function getUserId() {
52
+ var d = new Date().getTime(); //Timestamp
53
+ var d2 =
54
+ (typeof performance !== "undefined" &&
55
+ performance.now &&
56
+ performance.now() * 1000) ||
57
+ 0; //Time in microseconds since page-load or 0 if unsupported
58
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
59
+ var r = Math.random() * 16; //random number between 0 and 16
60
+ if (d > 0) {
61
+ //Use timestamp until depleted
62
+ r = (d + r) % 16 | 0;
63
+ d = Math.floor(d / 16);
64
+ } else {
65
+ //Use microseconds since page-load if supported
66
+ r = (d2 + r) % 16 | 0;
67
+ d2 = Math.floor(d2 / 16);
68
+ }
69
+ return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
70
+ });
71
+ }
72
+
73
+ async function main() {
74
+ // 1) Initialize a configuration with your clientID and consumerKey.
75
+ const config = new Configuration({
76
+ consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
77
+ clientId: process.env.SNAPTRADE_CLIENT_ID,
78
+ });
58
79
 
59
- const main = async () => {
60
80
  // 2) Check that the client is able to make a request to the API server.
61
81
  const apiStatusApiInst = new APIStatusApi(config);
62
- const status = await apiStatusApiInst.rootGet();
82
+ const status = await apiStatusApiInst.check();
63
83
  console.log("status:", status.data);
64
84
 
65
85
  // 3) Create a new user on SnapTrade
66
- const userId = v4();
86
+ const userId = getUserId();
67
87
  const authenticationApiInst = new AuthenticationApi(config);
68
88
  const { userSecret } = (
69
- await authenticationApiInst.snapTradeRegisterUserPost({
89
+ await authenticationApiInst.registerSnapTradeUser({
70
90
  userId,
71
91
  })
72
92
  ).data;
@@ -77,23 +97,24 @@ const main = async () => {
77
97
 
78
98
  // 4) Get a redirect URI. Users will need this to connect
79
99
  const data = (
80
- await authenticationApiInst.snapTradeLoginPost(userId, userSecret)
100
+ await authenticationApiInst.loginSnapTradeUser(userId, userSecret)
81
101
  ).data;
82
102
  if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
83
103
  console.log("redirectURI:", data.redirectURI);
84
104
 
85
105
  // 5) Obtaining account holdings data
86
106
  const accountInformationApi = new AccountInformationApi(config);
87
- const holdings = (await accountInformationApi.holdingsGet(userId, userSecret))
88
- .data;
107
+ const holdings = (
108
+ await accountInformationApi.getAllUserHoldings(userId, userSecret)
109
+ ).data;
89
110
  console.log("holdings:", holdings);
90
111
 
91
112
  // 6) Deleting a user
92
113
  const deleteResponse = (
93
- await authenticationApiInst.snapTradeDeleteUserDelete(userId)
114
+ await authenticationApiInst.deleteSnapTradeUser(userId)
94
115
  ).data;
95
116
  console.log("deleteResponse:", deleteResponse);
96
- };
117
+ }
97
118
 
98
119
  main();
99
120
  ```