snaptrade-typescript-sdk 1.0.3 → 2.0.1

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
+ d4383e74-ba60-4145-8f92-fbb08b91c38f
package/.konfigignore ADDED
@@ -0,0 +1,2 @@
1
+ index.test.ts
2
+ README.md
package/README.md CHANGED
@@ -1,72 +1,69 @@
1
- ## snaptrade-typescript-sdk@1.0.3
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.3 --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";
47
+ AccountInformationApi,
48
+ } = require("snaptrade-typescript-sdk");
52
49
 
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
- });
50
+ async function main() {
51
+ // 1) Initialize a configuration with your clientID and consumerKey.
52
+ const config = new Configuration({
53
+ consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
54
+ clientId: process.env.SNAPTRADE_CLIENT_ID,
55
+ });
58
56
 
59
- const main = async () => {
60
57
  // 2) Check that the client is able to make a request to the API server.
61
58
  const apiStatusApiInst = new APIStatusApi(config);
62
- const status = await apiStatusApiInst.rootGet();
59
+ const status = await apiStatusApiInst.check();
63
60
  console.log("status:", status.data);
64
61
 
65
62
  // 3) Create a new user on SnapTrade
66
- const userId = v4();
63
+ const userId = getUserId();
67
64
  const authenticationApiInst = new AuthenticationApi(config);
68
65
  const { userSecret } = (
69
- await authenticationApiInst.snapTradeRegisterUserPost({
66
+ await authenticationApiInst.registerSnapTradeUser({
70
67
  userId,
71
68
  })
72
69
  ).data;
@@ -77,23 +74,47 @@ const main = async () => {
77
74
 
78
75
  // 4) Get a redirect URI. Users will need this to connect
79
76
  const data = (
80
- await authenticationApiInst.snapTradeLoginPost(userId, userSecret)
77
+ await authenticationApiInst.loginSnapTradeUser(userId, userSecret)
81
78
  ).data;
82
79
  if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
83
80
  console.log("redirectURI:", data.redirectURI);
84
81
 
85
82
  // 5) Obtaining account holdings data
86
83
  const accountInformationApi = new AccountInformationApi(config);
87
- const holdings = (await accountInformationApi.holdingsGet(userId, userSecret))
88
- .data;
84
+ const holdings = (
85
+ await accountInformationApi.getAllUserHoldings(userId, userSecret)
86
+ ).data;
89
87
  console.log("holdings:", holdings);
90
88
 
91
89
  // 6) Deleting a user
92
90
  const deleteResponse = (
93
- await authenticationApiInst.snapTradeDeleteUserDelete(userId)
91
+ await authenticationApiInst.deleteSnapTradeUser(userId)
94
92
  ).data;
95
93
  console.log("deleteResponse:", deleteResponse);
96
- };
94
+ }
95
+
96
+ // Should be replaced with function to get user ID
97
+ function getUserId() {
98
+ var d = new Date().getTime(); //Timestamp
99
+ var d2 =
100
+ (typeof performance !== "undefined" &&
101
+ performance.now &&
102
+ performance.now() * 1000) ||
103
+ 0; //Time in microseconds since page-load or 0 if unsupported
104
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
105
+ var r = Math.random() * 16; //random number between 0 and 16
106
+ if (d > 0) {
107
+ //Use timestamp until depleted
108
+ r = (d + r) % 16 | 0;
109
+ d = Math.floor(d / 16);
110
+ } else {
111
+ //Use microseconds since page-load if supported
112
+ r = (d2 + r) % 16 | 0;
113
+ d2 = Math.floor(d2 / 16);
114
+ }
115
+ return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
116
+ });
117
+ }
97
118
 
98
119
  main();
99
120
  ```