snaptrade-typescript-sdk 1.0.3 → 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.
- package/.konfig/generate-id.txt +1 -0
- package/.konfigignore +2 -0
- package/README.md +57 -36
- package/api.ts +2190 -1889
- package/base.ts +2 -2
- package/common.ts +2 -2
- package/configuration.ts +2 -2
- package/dist/api.d.ts +1481 -1098
- package/dist/api.js +1679 -1833
- package/dist/api.js.map +1 -1
- package/dist/base.d.ts +2 -2
- package/dist/base.js +2 -2
- package/dist/common.d.ts +2 -2
- package/dist/common.js +3 -3
- package/dist/configuration.d.ts +2 -2
- package/dist/configuration.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +105 -0
- package/dist/index.test.js.map +1 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +13 -0
- package/dist/jest.config.js.map +1 -0
- package/git_push.sh +2 -2
- package/index.test.ts +70 -0
- package/index.ts +2 -2
- package/jest.config.ts +11 -0
- package/package.json +13 -8
- package/tsconfig.test.json +6 -0
- package/.openapi-generator/FILES +0 -12
- package/.openapi-generator/VERSION +0 -1
- package/.openapi-generator-ignore +0 -23
- package/.vscode/settings.json +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ba5c7e08-b43f-410b-a71b-d37e65071ba4
|
package/.konfigignore
ADDED
package/README.md
CHANGED
|
@@ -1,72 +1,92 @@
|
|
|
1
|
-
## snaptrade-typescript-sdk@
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
|
|
7
|
+
- Node.js
|
|
8
|
+
- Webpack
|
|
9
|
+
- Browserify
|
|
9
10
|
|
|
10
11
|
Language level
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
- ES5 - you must have a Promises/A+ library installed
|
|
14
|
+
- ES6
|
|
13
15
|
|
|
14
16
|
Module system
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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@
|
|
37
|
+
npm install snaptrade-typescript-sdk@2.0.0 --save
|
|
40
38
|
```
|
|
41
39
|
|
|
42
40
|
### Getting Started
|
|
43
41
|
|
|
44
42
|
```typescript
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const {
|
|
44
|
+
Configuration,
|
|
47
45
|
APIStatusApi,
|
|
48
46
|
AuthenticationApi,
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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.
|
|
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 =
|
|
86
|
+
const userId = getUserId();
|
|
67
87
|
const authenticationApiInst = new AuthenticationApi(config);
|
|
68
88
|
const { userSecret } = (
|
|
69
|
-
await authenticationApiInst.
|
|
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.
|
|
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 = (
|
|
88
|
-
.
|
|
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.
|
|
114
|
+
await authenticationApiInst.deleteSnapTradeUser(userId)
|
|
94
115
|
).data;
|
|
95
116
|
console.log("deleteResponse:", deleteResponse);
|
|
96
|
-
}
|
|
117
|
+
}
|
|
97
118
|
|
|
98
119
|
main();
|
|
99
120
|
```
|