snaptrade-typescript-sdk 1.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/.openapi-generator/FILES +12 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/.vscode/settings.json +3 -0
- package/README.md +99 -0
- package/api.ts +11331 -0
- package/base.ts +71 -0
- package/common.ts +181 -0
- package/configuration.ts +107 -0
- package/dist/api.d.ts +7076 -0
- package/dist/api.js +9345 -0
- package/dist/api.js.map +1 -0
- package/dist/base.d.ts +55 -0
- package/dist/base.js +83 -0
- package/dist/base.js.map +1 -0
- package/dist/common.d.ts +65 -0
- package/dist/common.js +281 -0
- package/dist/common.js.map +1 -0
- package/dist/configuration.d.ts +85 -0
- package/dist/configuration.js +50 -0
- package/dist/configuration.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/git_push.sh +57 -0
- package/index.ts +18 -0
- package/package.json +31 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
6.2.1
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# OpenAPI Generator Ignore
|
|
2
|
+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
|
|
3
|
+
|
|
4
|
+
# Use this file to prevent files from being overwritten by the generator.
|
|
5
|
+
# The patterns follow closely to .gitignore or .dockerignore.
|
|
6
|
+
|
|
7
|
+
# As an example, the C# client generator defines ApiClient.cs.
|
|
8
|
+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
|
|
9
|
+
#ApiClient.cs
|
|
10
|
+
|
|
11
|
+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
|
|
12
|
+
#foo/*/qux
|
|
13
|
+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
|
|
14
|
+
|
|
15
|
+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
|
|
16
|
+
#foo/**/qux
|
|
17
|
+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
|
|
18
|
+
|
|
19
|
+
# You can also negate patterns with an exclamation (!).
|
|
20
|
+
# For example, you can ignore all files in a docs folder with the file extension .md:
|
|
21
|
+
#docs/*.md
|
|
22
|
+
# Then explicitly reverse the ignore rule for a single file:
|
|
23
|
+
#!docs/README.md
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
## snaptrade-typescript-sdk@1.0.0
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
Environment
|
|
6
|
+
* Node.js
|
|
7
|
+
* Webpack
|
|
8
|
+
* Browserify
|
|
9
|
+
|
|
10
|
+
Language level
|
|
11
|
+
* ES5 - you must have a Promises/A+ library installed
|
|
12
|
+
* ES6
|
|
13
|
+
|
|
14
|
+
Module system
|
|
15
|
+
* CommonJS
|
|
16
|
+
* ES6 module system
|
|
17
|
+
|
|
18
|
+
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
|
+
|
|
20
|
+
### Building
|
|
21
|
+
|
|
22
|
+
To build and compile the typescript sources to javascript use:
|
|
23
|
+
```
|
|
24
|
+
npm install
|
|
25
|
+
npm run build
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Publishing
|
|
29
|
+
|
|
30
|
+
First build the package then run ```npm publish```
|
|
31
|
+
|
|
32
|
+
### Consuming
|
|
33
|
+
|
|
34
|
+
navigate to the folder of your consuming project and run one of the following commands.
|
|
35
|
+
|
|
36
|
+
_published:_
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
npm install snaptrade-typescript-sdk@1.0.0 --save
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Getting Started
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import {
|
|
46
|
+
AccountInformationApi,
|
|
47
|
+
APIStatusApi,
|
|
48
|
+
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
|
+
});
|
|
58
|
+
|
|
59
|
+
const main = async () => {
|
|
60
|
+
// 2) Check that the client is able to make a request to the API server.
|
|
61
|
+
const apiStatusApiInst = new APIStatusApi(config);
|
|
62
|
+
const status = await apiStatusApiInst.rootGet();
|
|
63
|
+
console.log("status:", status.data);
|
|
64
|
+
|
|
65
|
+
// 3) Create a new user on SnapTrade
|
|
66
|
+
const userId = v4();
|
|
67
|
+
const authenticationApiInst = new AuthenticationApi(config);
|
|
68
|
+
const { userSecret } = (
|
|
69
|
+
await authenticationApiInst.snapTradeRegisterUserPost({
|
|
70
|
+
userId,
|
|
71
|
+
})
|
|
72
|
+
).data;
|
|
73
|
+
|
|
74
|
+
// Note: A user secret is only generated once. It's required to access
|
|
75
|
+
// resources for certain endpoints.
|
|
76
|
+
console.log("userSecret:", userSecret);
|
|
77
|
+
|
|
78
|
+
// 4) Get a redirect URI. Users will need this to connect
|
|
79
|
+
const data = (
|
|
80
|
+
await authenticationApiInst.snapTradeLoginPost(userId, userSecret)
|
|
81
|
+
).data;
|
|
82
|
+
if (!("redirectURI" in data)) throw Error("Should have gotten redirect URI");
|
|
83
|
+
console.log("redirectURI:", data.redirectURI);
|
|
84
|
+
|
|
85
|
+
// 5) Obtaining account holdings data
|
|
86
|
+
const accountInformationApi = new AccountInformationApi(config);
|
|
87
|
+
const holdings = (await accountInformationApi.holdingsGet(userId, userSecret))
|
|
88
|
+
.data;
|
|
89
|
+
console.log("holdings:", holdings);
|
|
90
|
+
|
|
91
|
+
// 6) Deleting a user
|
|
92
|
+
const deleteResponse = (
|
|
93
|
+
await authenticationApiInst.snapTradeDeleteUserDelete(userId)
|
|
94
|
+
).data;
|
|
95
|
+
console.log("deleteResponse:", deleteResponse);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
main();
|
|
99
|
+
```
|