snaptrade-typescript-sdk 4.0.0 → 5.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 -1
- package/README.md +2 -2
- package/common.ts +2 -2
- package/configuration.ts +1 -1
- package/dist/common.js +2 -2
- package/dist/configuration.js +1 -1
- package/dist/pagination/page-types.d.ts +27 -0
- package/dist/pagination/page-types.js +13 -0
- package/dist/pagination/page.d.ts +6 -1
- package/dist/pagination/page.js +3 -0
- package/dist/pagination/pageable.d.ts +8 -3
- package/dist/pagination/pageable.js +5 -6
- package/dist/pagination/paginate.d.ts +2 -2
- package/docs/AuthenticationApi.md +7 -7
- package/docs/OptionsApi.md +5 -5
- package/docs/PortfolioManagementApi.md +17 -17
- package/docs/ReferenceDataApi.md +2 -2
- package/docs/TradingApi.md +19 -19
- package/package.json +1 -1
- package/pagination/page-types.ts +34 -0
- package/pagination/page.ts +9 -1
- package/pagination/pageable.ts +16 -10
- package/pagination/paginate.ts +3 -2
- package/tsconfig.json +1 -0
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -175
package/.konfig/generate-id.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
8d97d665-66ac-4b6b-b534-28964884bb9b
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
## snaptrade-typescript-sdk@
|
|
1
|
+
## snaptrade-typescript-sdk@5.0.0
|
|
2
2
|
|
|
3
3
|
This library that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
|
|
4
4
|
|
|
@@ -28,7 +28,7 @@ npm run build
|
|
|
28
28
|
navigate to the folder of your consuming project and run the following command.
|
|
29
29
|
|
|
30
30
|
```
|
|
31
|
-
npm install snaptrade-typescript-sdk@
|
|
31
|
+
npm install snaptrade-typescript-sdk@5.0.0 --save
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
### Getting Started
|
package/common.ts
CHANGED
|
@@ -42,9 +42,9 @@ export const setApiKeyToObject = async function (object: any, keyParamName: stri
|
|
|
42
42
|
if (configuration && configuration.apiKey) {
|
|
43
43
|
if (typeof configuration.apiKey === "function")
|
|
44
44
|
object[keyParamName] = await configuration.apiKey(keyParamName);
|
|
45
|
-
if (typeof configuration.apiKey === "string")
|
|
45
|
+
else if (typeof configuration.apiKey === "string")
|
|
46
46
|
object[keyParamName] = configuration.apiKey;
|
|
47
|
-
if (typeof configuration.apiKey === "object") {
|
|
47
|
+
else if (typeof configuration.apiKey === "object") {
|
|
48
48
|
if (keyParamName in configuration.apiKey)
|
|
49
49
|
object[keyParamName] = configuration.apiKey[keyParamName];
|
|
50
50
|
} else
|
package/configuration.ts
CHANGED
|
@@ -109,7 +109,7 @@ export class Configuration {
|
|
|
109
109
|
this.accessToken = param.accessToken;
|
|
110
110
|
this.basePath = param.basePath;
|
|
111
111
|
this.baseOptions = param.baseOptions;
|
|
112
|
-
this.userAgent = param.userAgent === undefined ? "Konfig/
|
|
112
|
+
this.userAgent = param.userAgent === undefined ? "Konfig/5.0.0/typescript" : param.userAgent;
|
|
113
113
|
this.formDataCtor = param.formDataCtor;
|
|
114
114
|
}
|
|
115
115
|
|
package/dist/common.js
CHANGED
|
@@ -96,11 +96,11 @@ var setApiKeyToObject = function (object, keyParamName, configuration) {
|
|
|
96
96
|
return [4 /*yield*/, configuration.apiKey(keyParamName)];
|
|
97
97
|
case 1:
|
|
98
98
|
_a[_b] = _c.sent();
|
|
99
|
-
|
|
99
|
+
return [3 /*break*/, 3];
|
|
100
100
|
case 2:
|
|
101
101
|
if (typeof configuration.apiKey === "string")
|
|
102
102
|
object[keyParamName] = configuration.apiKey;
|
|
103
|
-
if (typeof configuration.apiKey === "object") {
|
|
103
|
+
else if (typeof configuration.apiKey === "object") {
|
|
104
104
|
if (keyParamName in configuration.apiKey)
|
|
105
105
|
object[keyParamName] = configuration.apiKey[keyParamName];
|
|
106
106
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -33,7 +33,7 @@ var Configuration = /** @class */ (function () {
|
|
|
33
33
|
this.accessToken = param.accessToken;
|
|
34
34
|
this.basePath = param.basePath;
|
|
35
35
|
this.baseOptions = param.baseOptions;
|
|
36
|
-
this.userAgent = param.userAgent === undefined ? "Konfig/
|
|
36
|
+
this.userAgent = param.userAgent === undefined ? "Konfig/5.0.0/typescript" : param.userAgent;
|
|
37
37
|
this.formDataCtor = param.formDataCtor;
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SnapTrade
|
|
3
|
+
* Connect brokerage accounts to your app for live positions and trading
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: 1.0.0
|
|
6
|
+
* Contact: api@snaptrade.com
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This file is auto generated by Konfig (https://konfigthis.com).
|
|
9
|
+
* https://konfigthis.com
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
import { Pageable, PageParametersBase } from "./pageable";
|
|
13
|
+
/**
|
|
14
|
+
* The set of parameters that appear in a paginated operation (requestBody or parameters)
|
|
15
|
+
*/
|
|
16
|
+
export type PageParameterProperties = {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
};
|
|
19
|
+
export type PageParameters = PageParametersBase<PageParameterProperties>;
|
|
20
|
+
/**
|
|
21
|
+
* The set of properties that appear in a paginated operation's response
|
|
22
|
+
*/
|
|
23
|
+
export interface PageInfo {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
export interface PageBase<Data extends PageInfo, Parameters extends PageParameters> extends Pageable<Data, Parameters> {
|
|
27
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SnapTrade
|
|
4
|
+
* Connect brokerage accounts to your app for live positions and trading
|
|
5
|
+
*
|
|
6
|
+
* The version of the OpenAPI document: 1.0.0
|
|
7
|
+
* Contact: api@snaptrade.com
|
|
8
|
+
*
|
|
9
|
+
* NOTE: This file is auto generated by Konfig (https://konfigthis.com).
|
|
10
|
+
* https://konfigthis.com
|
|
11
|
+
* Do not edit the class manually.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* https://konfigthis.com
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
|
-
import { Pageable, PageParametersBase } from "./pageable";
|
|
12
|
+
import { Pageable, PageParametersBase, PageRequest } from "./pageable";
|
|
13
13
|
/**
|
|
14
14
|
* The set of parameters that appear in a paginated operation (requestBody or parameters)
|
|
15
15
|
*/
|
|
@@ -24,6 +24,11 @@ export interface PageInfo {
|
|
|
24
24
|
[key: string]: any;
|
|
25
25
|
}
|
|
26
26
|
export declare class Page<Data extends PageInfo, Parameters extends PageParameters> extends Pageable<Data, Parameters> {
|
|
27
|
+
make(parameters: {
|
|
28
|
+
data: Data;
|
|
29
|
+
initialParameters: Parameters;
|
|
30
|
+
request: PageRequest<Data, Parameters>;
|
|
31
|
+
}): Pageable<Data, Parameters>;
|
|
27
32
|
protected get previousParameters(): PageParameterProperties | null;
|
|
28
33
|
protected get nextParameters(): PageParameterProperties | null;
|
|
29
34
|
hasPrevious(): boolean;
|
package/dist/pagination/page.js
CHANGED
|
@@ -33,6 +33,9 @@ var Page = /** @class */ (function (_super) {
|
|
|
33
33
|
function Page() {
|
|
34
34
|
return _super !== null && _super.apply(this, arguments) || this;
|
|
35
35
|
}
|
|
36
|
+
Page.prototype.make = function (parameters) {
|
|
37
|
+
throw new Error("Method not implemented.");
|
|
38
|
+
};
|
|
36
39
|
Object.defineProperty(Page.prototype, "previousParameters", {
|
|
37
40
|
get: function () {
|
|
38
41
|
throw Error("Stub");
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
import { AxiosPromise } from "axios";
|
|
13
|
-
import {
|
|
13
|
+
import { PageBase, PageInfo, PageParameterProperties, PageParameters } from "./page-types";
|
|
14
14
|
export type PageParametersBase<Parameters> = Parameters & {
|
|
15
15
|
requestBody?: Parameters;
|
|
16
16
|
};
|
|
@@ -19,8 +19,8 @@ export declare abstract class Pageable<Data extends PageInfo, Parameters extends
|
|
|
19
19
|
readonly data: Data;
|
|
20
20
|
protected readonly initialParameters: Parameters;
|
|
21
21
|
private readonly _request;
|
|
22
|
-
previous(): Promise<
|
|
23
|
-
next(): Promise<
|
|
22
|
+
previous(): Promise<PageBase<Data, Parameters>>;
|
|
23
|
+
next(): Promise<PageBase<Data, Parameters>>;
|
|
24
24
|
/**
|
|
25
25
|
* Generate minimal set of parameters needed to get the previous page
|
|
26
26
|
*/
|
|
@@ -50,4 +50,9 @@ export declare abstract class Pageable<Data extends PageInfo, Parameters extends
|
|
|
50
50
|
initialParameters: Parameters;
|
|
51
51
|
request: PageRequest<Data, Parameters>;
|
|
52
52
|
});
|
|
53
|
+
abstract make(parameters: {
|
|
54
|
+
data: Data;
|
|
55
|
+
initialParameters: Parameters;
|
|
56
|
+
request: PageRequest<Data, Parameters>;
|
|
57
|
+
}): Pageable<Data, Parameters>;
|
|
53
58
|
}
|
|
@@ -59,7 +59,6 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
59
59
|
};
|
|
60
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
61
|
exports.Pageable = void 0;
|
|
62
|
-
var Page_1 = require("./Page");
|
|
63
62
|
var Pageable = /** @class */ (function () {
|
|
64
63
|
function Pageable(_a) {
|
|
65
64
|
var data = _a.data, initialParameters = _a.initialParameters, request = _a.request;
|
|
@@ -74,9 +73,9 @@ var Pageable = /** @class */ (function () {
|
|
|
74
73
|
switch (_a.label) {
|
|
75
74
|
case 0:
|
|
76
75
|
if (!this.hasPrevious())
|
|
77
|
-
return [2 /*return*/,
|
|
76
|
+
return [2 /*return*/, this];
|
|
78
77
|
if (this.previousParameters === null)
|
|
79
|
-
return [2 /*return*/,
|
|
78
|
+
return [2 /*return*/, this];
|
|
80
79
|
return [4 /*yield*/, this.makeRequest(this.previousParameters)];
|
|
81
80
|
case 1:
|
|
82
81
|
response = _a.sent();
|
|
@@ -92,9 +91,9 @@ var Pageable = /** @class */ (function () {
|
|
|
92
91
|
switch (_a.label) {
|
|
93
92
|
case 0:
|
|
94
93
|
if (!this.hasNext())
|
|
95
|
-
return [2 /*return*/,
|
|
94
|
+
return [2 /*return*/, this];
|
|
96
95
|
if (this.nextParameters === null)
|
|
97
|
-
return [2 /*return*/,
|
|
96
|
+
return [2 /*return*/, this];
|
|
98
97
|
return [4 /*yield*/, this.makeRequest(this.nextParameters)];
|
|
99
98
|
case 1:
|
|
100
99
|
response = _a.sent();
|
|
@@ -117,7 +116,7 @@ var Pageable = /** @class */ (function () {
|
|
|
117
116
|
* Helper for creating new page
|
|
118
117
|
*/
|
|
119
118
|
Pageable.prototype.withData = function (data) {
|
|
120
|
-
return
|
|
119
|
+
return this.make({
|
|
121
120
|
data: data,
|
|
122
121
|
initialParameters: this.initialParameters,
|
|
123
122
|
request: this._request,
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* https://konfigthis.com
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
|
-
import { PageInfo, PageParameters
|
|
12
|
+
import { PageBase, PageInfo, PageParameters } from "./page-types";
|
|
13
13
|
import { PageRequest } from "./pageable";
|
|
14
14
|
export declare const paginate: <Data extends PageInfo, Parameters_1 extends PageParameters>({ request, initialParameters, }: {
|
|
15
15
|
request: PageRequest<Data, Parameters_1>;
|
|
16
16
|
initialParameters: Parameters_1;
|
|
17
|
-
}) => Promise<
|
|
17
|
+
}) => Promise<PageBase<Data, Parameters_1>>;
|
|
@@ -199,11 +199,11 @@ const response = await snaptrade.authentication.loginSnapTradeUser({
|
|
|
199
199
|
'userId': "John.doe@snaptrade.com",
|
|
200
200
|
'userSecret': "USERSECRET123",
|
|
201
201
|
'requestBody': {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
"broker": "ALPACA",
|
|
203
|
+
"immediate_redirect": true,
|
|
204
|
+
"custom_redirect": "https://passiv.com",
|
|
205
|
+
"reconnect": "8b5f262d-4bb9-365d-888a-202bd3b15fa1",
|
|
206
|
+
"connection_type": "read",
|
|
207
207
|
},
|
|
208
208
|
})
|
|
209
209
|
console.log(response)
|
|
@@ -264,8 +264,8 @@ const snaptrade = new Snaptrade({
|
|
|
264
264
|
|
|
265
265
|
const response = await snaptrade.authentication.registerSnapTradeUser({
|
|
266
266
|
'requestBody': {
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
"user_id": "snaptrade-user-123",
|
|
268
|
+
"rsa_public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQC7vbqajDw4o6gJy8UtmIbkcpnkO3Kwc4qsEnSZp/TR+fQi62F79RHWmwKOtFmwteURgLbj7D/WGuNLGOfa/2vse3G2eHnHl5CB8ruRX9fBl/KgwCVr2JaEuUm66bBQeP5XeBotdR4cvX38uPYivCDdPjJ1QWPdspTBKcxeFbccDw==",
|
|
269
269
|
},
|
|
270
270
|
})
|
|
271
271
|
console.log(response)
|
package/docs/OptionsApi.md
CHANGED
|
@@ -33,8 +33,8 @@ const response = await snaptrade.options.getOptionStrategy({
|
|
|
33
33
|
'userSecret': "USERSECRET123",
|
|
34
34
|
'accountId': "accountId_example",
|
|
35
35
|
'requestBody': {
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
"underlying_symbol_id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
37
|
+
"strategy_type": "CUSTOM",
|
|
38
38
|
},
|
|
39
39
|
})
|
|
40
40
|
console.log(response)
|
|
@@ -275,9 +275,9 @@ const response = await snaptrade.options.placeOptionStrategy({
|
|
|
275
275
|
'accountId': "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
276
276
|
'optionStrategyId': "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
277
277
|
'requestBody': {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
"order_type": "Limit",
|
|
279
|
+
"time_in_force": "DAY",
|
|
280
|
+
"price": 31.33,
|
|
281
281
|
},
|
|
282
282
|
})
|
|
283
283
|
console.log(response)
|
|
@@ -59,10 +59,10 @@ const snaptrade = new Snaptrade({
|
|
|
59
59
|
const response = await snaptrade.portfolioManagement.addPortfolioExcludedAsset({
|
|
60
60
|
'portfolioGroupId': "portfolioGroupId_example",
|
|
61
61
|
'requestBody': {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
"id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
63
|
+
"symbol": "VAB.TO",
|
|
64
|
+
"raw_symbol": "VAB",
|
|
65
|
+
"description": "VANGUARD CDN AGGREGATE BOND INDEX ETF",
|
|
66
66
|
},
|
|
67
67
|
})
|
|
68
68
|
console.log(response)
|
|
@@ -120,8 +120,8 @@ const response = await snaptrade.portfolioManagement.create({
|
|
|
120
120
|
'userId': "John.doe@snaptrade.com",
|
|
121
121
|
'userSecret': "USERSECRET123",
|
|
122
122
|
'requestBody': {
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
"id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
124
|
+
"name": "Combined Retirement Portfolio",
|
|
125
125
|
},
|
|
126
126
|
})
|
|
127
127
|
console.log(response)
|
|
@@ -1524,8 +1524,8 @@ const snaptrade = new Snaptrade({
|
|
|
1524
1524
|
const response = await snaptrade.portfolioManagement.savePortfolio({
|
|
1525
1525
|
'portfolioGroupId': "portfolioGroupId_example",
|
|
1526
1526
|
'requestBody': {
|
|
1527
|
-
|
|
1528
|
-
|
|
1527
|
+
"id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
1528
|
+
"name": "Combined Retirement Portfolio",
|
|
1529
1529
|
},
|
|
1530
1530
|
})
|
|
1531
1531
|
console.log(response)
|
|
@@ -1585,7 +1585,7 @@ const snaptrade = new Snaptrade({
|
|
|
1585
1585
|
const response = await snaptrade.portfolioManagement.searchPortfolioSymbols({
|
|
1586
1586
|
'portfolioGroupId': "portfolioGroupId_example",
|
|
1587
1587
|
'requestBody': {
|
|
1588
|
-
|
|
1588
|
+
"substring": "apple",
|
|
1589
1589
|
},
|
|
1590
1590
|
})
|
|
1591
1591
|
console.log(response)
|
|
@@ -1644,10 +1644,10 @@ const response = await snaptrade.portfolioManagement.setPortfolioTargets({
|
|
|
1644
1644
|
'portfolioGroupId': "portfolioGroupId_example",
|
|
1645
1645
|
'requestBody': [
|
|
1646
1646
|
{
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1647
|
+
"id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
1648
|
+
"percent": 90,
|
|
1649
|
+
"is_supported": true,
|
|
1650
|
+
"is_excluded": true,
|
|
1651
1651
|
}
|
|
1652
1652
|
],
|
|
1653
1653
|
})
|
|
@@ -1819,10 +1819,10 @@ const response = await snaptrade.portfolioManagement.updatePortfolioTargetById({
|
|
|
1819
1819
|
'portfolioGroupId': "portfolioGroupId_example",
|
|
1820
1820
|
'targetAssetId': "targetAssetId_example",
|
|
1821
1821
|
'requestBody': {
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1822
|
+
"id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
1823
|
+
"percent": 90,
|
|
1824
|
+
"is_supported": true,
|
|
1825
|
+
"is_excluded": true,
|
|
1826
1826
|
},
|
|
1827
1827
|
})
|
|
1828
1828
|
console.log(response)
|
package/docs/ReferenceDataApi.md
CHANGED
|
@@ -238,7 +238,7 @@ const snaptrade = new Snaptrade({
|
|
|
238
238
|
|
|
239
239
|
const response = await snaptrade.referenceData.getSymbols({
|
|
240
240
|
'requestBody': {
|
|
241
|
-
|
|
241
|
+
"substring": "apple",
|
|
242
242
|
},
|
|
243
243
|
})
|
|
244
244
|
console.log(response)
|
|
@@ -554,7 +554,7 @@ const response = await snaptrade.referenceData.symbolSearchUserAccount({
|
|
|
554
554
|
'userSecret': "USERSECRET123",
|
|
555
555
|
'accountId': "accountId_example",
|
|
556
556
|
'requestBody': {
|
|
557
|
-
|
|
557
|
+
"substring": "apple",
|
|
558
558
|
},
|
|
559
559
|
})
|
|
560
560
|
console.log(response)
|
package/docs/TradingApi.md
CHANGED
|
@@ -210,13 +210,13 @@ const response = await snaptrade.trading.getOrderImpact({
|
|
|
210
210
|
'userId': "John.doe@snaptrade.com",
|
|
211
211
|
'userSecret': "USERSECRET123",
|
|
212
212
|
'requestBody': {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
"account_id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
214
|
+
"action": "BUY",
|
|
215
|
+
"order_type": "Limit",
|
|
216
|
+
"price": 31.33,
|
|
217
|
+
"stop": 31.33,
|
|
218
|
+
"time_in_force": "Day",
|
|
219
|
+
"universal_symbol_id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
220
220
|
},
|
|
221
221
|
})
|
|
222
222
|
console.log(response)
|
|
@@ -341,11 +341,11 @@ const response = await snaptrade.trading.modifyCalculatedTradeById({
|
|
|
341
341
|
'calculatedTradeId': "calculatedTradeId_example",
|
|
342
342
|
'tradeId': "tradeId_example",
|
|
343
343
|
'requestBody': {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
344
|
+
"id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
345
|
+
"action": "BUY",
|
|
346
|
+
"units": 6,
|
|
347
|
+
"price": 24.81,
|
|
348
|
+
"sequence": 1,
|
|
349
349
|
},
|
|
350
350
|
})
|
|
351
351
|
console.log(response)
|
|
@@ -460,13 +460,13 @@ const response = await snaptrade.trading.placeForceOrder({
|
|
|
460
460
|
'userId': "John.doe@snaptrade.com",
|
|
461
461
|
'userSecret': "USERSECRET123",
|
|
462
462
|
'requestBody': {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
463
|
+
"account_id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
464
|
+
"action": "BUY",
|
|
465
|
+
"order_type": "Limit",
|
|
466
|
+
"price": 31.33,
|
|
467
|
+
"stop": 31.33,
|
|
468
|
+
"time_in_force": "Day",
|
|
469
|
+
"universal_symbol_id": "2bcd7cc3-e922-4976-bce1-9858296801c3",
|
|
470
470
|
},
|
|
471
471
|
})
|
|
472
472
|
console.log(response)
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SnapTrade
|
|
3
|
+
* Connect brokerage accounts to your app for live positions and trading
|
|
4
|
+
*
|
|
5
|
+
* The version of the OpenAPI document: 1.0.0
|
|
6
|
+
* Contact: api@snaptrade.com
|
|
7
|
+
*
|
|
8
|
+
* NOTE: This file is auto generated by Konfig (https://konfigthis.com).
|
|
9
|
+
* https://konfigthis.com
|
|
10
|
+
* Do not edit the class manually.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Pageable, PageParametersBase } from "./pageable";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The set of parameters that appear in a paginated operation (requestBody or parameters)
|
|
17
|
+
*/
|
|
18
|
+
export type PageParameterProperties = {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type PageParameters = PageParametersBase<PageParameterProperties>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The set of properties that appear in a paginated operation's response
|
|
26
|
+
*/
|
|
27
|
+
export interface PageInfo {
|
|
28
|
+
[key: string]: any
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface PageBase<
|
|
32
|
+
Data extends PageInfo,
|
|
33
|
+
Parameters extends PageParameters
|
|
34
|
+
> extends Pageable<Data, Parameters> {}
|
package/pagination/page.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { Pageable, PageParametersBase } from "./pageable";
|
|
13
|
+
import { Pageable, PageParametersBase, PageRequest } from "./pageable";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* The set of parameters that appear in a paginated operation (requestBody or parameters)
|
|
@@ -32,6 +32,14 @@ export class Page<
|
|
|
32
32
|
Data extends PageInfo,
|
|
33
33
|
Parameters extends PageParameters
|
|
34
34
|
> extends Pageable<Data, Parameters> {
|
|
35
|
+
make(parameters: {
|
|
36
|
+
data: Data;
|
|
37
|
+
initialParameters: Parameters;
|
|
38
|
+
request: PageRequest<Data, Parameters>;
|
|
39
|
+
}): Pageable<Data, Parameters> {
|
|
40
|
+
throw new Error("Method not implemented.");
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
protected get previousParameters(): PageParameterProperties | null {
|
|
36
44
|
throw Error("Stub")
|
|
37
45
|
}
|
package/pagination/pageable.ts
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
import { AxiosPromise } from "axios";
|
|
14
14
|
import {
|
|
15
|
-
|
|
15
|
+
PageBase,
|
|
16
16
|
PageInfo,
|
|
17
17
|
PageParameterProperties,
|
|
18
18
|
PageParameters,
|
|
19
|
-
} from "./
|
|
19
|
+
} from "./page-types";
|
|
20
20
|
|
|
21
21
|
export type PageParametersBase<Parameters> = Parameters & {
|
|
22
22
|
requestBody?: Parameters;
|
|
@@ -33,15 +33,15 @@ export abstract class Pageable<
|
|
|
33
33
|
readonly data: Data;
|
|
34
34
|
protected readonly initialParameters: Parameters;
|
|
35
35
|
private readonly _request: PageRequest<Data, Parameters>;
|
|
36
|
-
async previous(): Promise<
|
|
37
|
-
if (!this.hasPrevious()) return
|
|
38
|
-
if (this.previousParameters === null) return
|
|
36
|
+
async previous(): Promise<PageBase<Data, Parameters>> {
|
|
37
|
+
if (!this.hasPrevious()) return this;
|
|
38
|
+
if (this.previousParameters === null) return this;
|
|
39
39
|
const response = await this.makeRequest(this.previousParameters);
|
|
40
40
|
return this.withData(response.data);
|
|
41
41
|
}
|
|
42
|
-
async next(): Promise<
|
|
43
|
-
if (!this.hasNext()) return
|
|
44
|
-
if (this.nextParameters === null) return
|
|
42
|
+
async next(): Promise<PageBase<Data, Parameters>> {
|
|
43
|
+
if (!this.hasNext()) return this;
|
|
44
|
+
if (this.nextParameters === null) return this;
|
|
45
45
|
const response = await this.makeRequest(this.nextParameters);
|
|
46
46
|
return this.withData(response.data);
|
|
47
47
|
}
|
|
@@ -83,8 +83,8 @@ export abstract class Pageable<
|
|
|
83
83
|
/**
|
|
84
84
|
* Helper for creating new page
|
|
85
85
|
*/
|
|
86
|
-
private withData(data: Data):
|
|
87
|
-
return
|
|
86
|
+
private withData(data: Data): PageBase<Data, Parameters> {
|
|
87
|
+
return this.make({
|
|
88
88
|
data,
|
|
89
89
|
initialParameters: this.initialParameters,
|
|
90
90
|
request: this._request,
|
|
@@ -104,4 +104,10 @@ export abstract class Pageable<
|
|
|
104
104
|
this._request = request;
|
|
105
105
|
this.initialParameters = initialParameters;
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
abstract make(parameters: {
|
|
109
|
+
data: Data;
|
|
110
|
+
initialParameters: Parameters;
|
|
111
|
+
request: PageRequest<Data, Parameters>;
|
|
112
|
+
}): Pageable<Data, Parameters>;
|
|
107
113
|
}
|
package/pagination/paginate.ts
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* Do not edit the class manually.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { PageInfo, PageParameters
|
|
13
|
+
import { PageBase, PageInfo, PageParameters } from "./page-types";
|
|
14
|
+
import { Page } from "./page";
|
|
14
15
|
import { PageRequest } from "./pageable";
|
|
15
16
|
|
|
16
17
|
export const paginate = <
|
|
@@ -22,7 +23,7 @@ export const paginate = <
|
|
|
22
23
|
}: {
|
|
23
24
|
request: PageRequest<Data, Parameters>;
|
|
24
25
|
initialParameters: Parameters;
|
|
25
|
-
}): Promise<
|
|
26
|
+
}): Promise<PageBase<Data, Parameters>> => {
|
|
26
27
|
return new Promise(async (resolve, reject) => {
|
|
27
28
|
try {
|
|
28
29
|
const data = await request(initialParameters);
|
package/tsconfig.json
CHANGED
package/dist/index.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.test.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var index_1 = require("./index");
|
|
40
|
-
function uuid() {
|
|
41
|
-
var d = new Date().getTime(); //Timestamp
|
|
42
|
-
var d2 = (typeof performance !== "undefined" &&
|
|
43
|
-
performance.now &&
|
|
44
|
-
performance.now() * 1000) ||
|
|
45
|
-
0; //Time in microseconds since page-load or 0 if unsupported
|
|
46
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
47
|
-
var r = Math.random() * 16; //random number between 0 and 16
|
|
48
|
-
if (d > 0) {
|
|
49
|
-
//Use timestamp until depleted
|
|
50
|
-
r = (d + r) % 16 | 0;
|
|
51
|
-
d = Math.floor(d / 16);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
//Use microseconds since page-load if supported
|
|
55
|
-
r = (d2 + r) % 16 | 0;
|
|
56
|
-
d2 = Math.floor(d2 / 16);
|
|
57
|
-
}
|
|
58
|
-
return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
it("getting started", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
62
|
-
var snaptrade, status, userId, userSecret, data, holdings, deleteResponse;
|
|
63
|
-
return __generator(this, function (_a) {
|
|
64
|
-
switch (_a.label) {
|
|
65
|
-
case 0:
|
|
66
|
-
snaptrade = new index_1.Snaptrade({
|
|
67
|
-
consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
|
|
68
|
-
clientId: process.env.SNAPTRADE_CLIENT_ID,
|
|
69
|
-
});
|
|
70
|
-
return [4 /*yield*/, snaptrade.apiStatus.check()];
|
|
71
|
-
case 1:
|
|
72
|
-
status = _a.sent();
|
|
73
|
-
console.log("status:", status.data);
|
|
74
|
-
userId = uuid();
|
|
75
|
-
return [4 /*yield*/, snaptrade.authentication.registerSnapTradeUser({
|
|
76
|
-
requestBody: {
|
|
77
|
-
userId: userId,
|
|
78
|
-
},
|
|
79
|
-
})];
|
|
80
|
-
case 2:
|
|
81
|
-
userSecret = (_a.sent()).data.userSecret;
|
|
82
|
-
// Note: A user secret is only generated once. It's required to access
|
|
83
|
-
// resources for certain endpoints.
|
|
84
|
-
console.log("userSecret:", userSecret);
|
|
85
|
-
return [4 /*yield*/, snaptrade.authentication.loginSnapTradeUser({ userId: userId, userSecret: userSecret })];
|
|
86
|
-
case 3:
|
|
87
|
-
data = (_a.sent()).data;
|
|
88
|
-
if (!("redirectURI" in data))
|
|
89
|
-
throw Error("Should have gotten redirect URI");
|
|
90
|
-
console.log("redirectURI:", data.redirectURI);
|
|
91
|
-
return [4 /*yield*/, snaptrade.accountInformation.getAllUserHoldings({
|
|
92
|
-
userId: userId,
|
|
93
|
-
userSecret: userSecret,
|
|
94
|
-
})];
|
|
95
|
-
case 4:
|
|
96
|
-
holdings = (_a.sent()).data;
|
|
97
|
-
console.log("holdings:", holdings);
|
|
98
|
-
return [4 /*yield*/, snaptrade.authentication.deleteSnapTradeUser({ userId: userId })];
|
|
99
|
-
case 5:
|
|
100
|
-
deleteResponse = (_a.sent()).data;
|
|
101
|
-
console.log("deleteResponse:", deleteResponse);
|
|
102
|
-
return [2 /*return*/];
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}); });
|
|
106
|
-
it("getUserAccountBalance", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
|
-
var snaptrade, userId, userSecret, accounts, response;
|
|
108
|
-
return __generator(this, function (_a) {
|
|
109
|
-
switch (_a.label) {
|
|
110
|
-
case 0:
|
|
111
|
-
snaptrade = new index_1.Snaptrade({
|
|
112
|
-
consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
|
|
113
|
-
clientId: process.env.SNAPTRADE_CLIENT_ID,
|
|
114
|
-
});
|
|
115
|
-
userId = process.env.SNAPTRADE_TEST_USER_ID;
|
|
116
|
-
userSecret = process.env.SNAPTRADE_TEST_USER_SECRET;
|
|
117
|
-
return [4 /*yield*/, snaptrade.accountInformation.listUserAccounts({
|
|
118
|
-
userId: userId,
|
|
119
|
-
userSecret: userSecret,
|
|
120
|
-
})];
|
|
121
|
-
case 1:
|
|
122
|
-
accounts = _a.sent();
|
|
123
|
-
console.log(accounts.data);
|
|
124
|
-
return [4 /*yield*/, snaptrade.accountInformation.getUserAccountBalance({
|
|
125
|
-
accountId: accounts.data[0].id,
|
|
126
|
-
userId: userId,
|
|
127
|
-
userSecret: userSecret,
|
|
128
|
-
})];
|
|
129
|
-
case 2:
|
|
130
|
-
response = _a.sent();
|
|
131
|
-
console.log(response.data);
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}); });
|
|
136
|
-
it.skip("getOptionsChain", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
137
|
-
var snaptrade, userId, userSecret, accounts, accountId, symbols, symbol, response;
|
|
138
|
-
return __generator(this, function (_a) {
|
|
139
|
-
switch (_a.label) {
|
|
140
|
-
case 0:
|
|
141
|
-
snaptrade = new index_1.Snaptrade({
|
|
142
|
-
consumerKey: process.env.SNAPTRADE_CONSUMER_KEY,
|
|
143
|
-
clientId: process.env.SNAPTRADE_CLIENT_ID,
|
|
144
|
-
});
|
|
145
|
-
userId = process.env.SNAPTRADE_TEST_USER_ID;
|
|
146
|
-
userSecret = process.env.SNAPTRADE_TEST_USER_SECRET;
|
|
147
|
-
return [4 /*yield*/, snaptrade.accountInformation.listUserAccounts({
|
|
148
|
-
userId: userId,
|
|
149
|
-
userSecret: userSecret,
|
|
150
|
-
})];
|
|
151
|
-
case 1:
|
|
152
|
-
accounts = _a.sent();
|
|
153
|
-
console.log(accounts.data);
|
|
154
|
-
accountId = accounts.data[0].id;
|
|
155
|
-
return [4 /*yield*/, snaptrade.referenceData.getSymbols({
|
|
156
|
-
requestBody: { substring: "apple" },
|
|
157
|
-
})];
|
|
158
|
-
case 2:
|
|
159
|
-
symbols = _a.sent();
|
|
160
|
-
console.log(symbols);
|
|
161
|
-
symbol = symbols.data[0].id;
|
|
162
|
-
console.log(symbol);
|
|
163
|
-
return [4 /*yield*/, snaptrade.options.getOptionsChain({
|
|
164
|
-
accountId: accountId,
|
|
165
|
-
userId: userId,
|
|
166
|
-
userSecret: userSecret,
|
|
167
|
-
symbol: symbol,
|
|
168
|
-
})];
|
|
169
|
-
case 3:
|
|
170
|
-
response = _a.sent();
|
|
171
|
-
console.log(response.data);
|
|
172
|
-
return [2 /*return*/];
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}); });
|