@barchart/portfolio-client-js 1.1.4 → 1.1.5
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/example/example.html +68 -4
- package/example/example.js +1722 -179
- package/lib/gateway/PortfolioGateway.js +86 -1
- package/lib/gateway/jwt/JwtGateway.js +9 -7
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/example/example.html
CHANGED
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
that.gateway = null;
|
|
29
29
|
|
|
30
30
|
that.user = ko.observable('22e59613-d393-4069-814c-f0b5a3e4b31e');
|
|
31
|
+
that.userLegacy = ko.observable('16399446');
|
|
31
32
|
|
|
32
33
|
that.connected = ko.observable(false);
|
|
33
34
|
that.connecting = ko.observable(false);
|
|
@@ -52,6 +53,61 @@
|
|
|
52
53
|
writeConsoleText(action, true);
|
|
53
54
|
writeConsoleObject(e);
|
|
54
55
|
|
|
56
|
+
that.setConsoleMode();
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
var createPortfolio = function () {
|
|
60
|
+
var action = 'portfolioGateway.createPortfolio()';
|
|
61
|
+
|
|
62
|
+
var portfolio = {
|
|
63
|
+
name: `Random ${Math.random()}`,
|
|
64
|
+
timezone: 'America/New_York',
|
|
65
|
+
dates: {
|
|
66
|
+
create: '2018-02-28',
|
|
67
|
+
cash: '2018-02-28'
|
|
68
|
+
},
|
|
69
|
+
defaults: {
|
|
70
|
+
currency: 'CAD',
|
|
71
|
+
reinvest: true,
|
|
72
|
+
valuation: 'AVG'
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
that.gateway.createPortfolio(portfolio)
|
|
77
|
+
.then((data) => {
|
|
78
|
+
writeConsoleText(action, true);
|
|
79
|
+
writeConsoleObject(data);
|
|
80
|
+
}).catch((e) => {
|
|
81
|
+
writeConsoleText(action, true);
|
|
82
|
+
writeConsoleObject(e);
|
|
83
|
+
|
|
84
|
+
that.setConsoleMode();
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
var updatePortfolio = function() {
|
|
88
|
+
var action = 'portfolioGateway.createPortfolio()';
|
|
89
|
+
|
|
90
|
+
var portfolio = {
|
|
91
|
+
name: `Random ${Math.random()}`,
|
|
92
|
+
timezone: 'America/New_York',
|
|
93
|
+
dates: {
|
|
94
|
+
cash: '2018-02-28'
|
|
95
|
+
},
|
|
96
|
+
defaults: {
|
|
97
|
+
currency: 'CAD',
|
|
98
|
+
reinvest: true,
|
|
99
|
+
valuation: 'AVG'
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
that.gateway.updatePortfolio(that.portfolio(), portfolio)
|
|
104
|
+
.then((data) => {
|
|
105
|
+
writeConsoleText(action, true);
|
|
106
|
+
writeConsoleObject(data);
|
|
107
|
+
}).catch((e) => {
|
|
108
|
+
writeConsoleText(action, true);
|
|
109
|
+
writeConsoleObject(e);
|
|
110
|
+
|
|
55
111
|
that.setConsoleMode();
|
|
56
112
|
});
|
|
57
113
|
};
|
|
@@ -92,7 +148,7 @@
|
|
|
92
148
|
});
|
|
93
149
|
};
|
|
94
150
|
var getTransactionsFormatted = function() {
|
|
95
|
-
var action = 'portfolioGateway.
|
|
151
|
+
var action = 'portfolioGateway.readTransactionsFormatted()';
|
|
96
152
|
|
|
97
153
|
var portfolio = that.portfolio();
|
|
98
154
|
var position = that.position();
|
|
@@ -116,6 +172,8 @@
|
|
|
116
172
|
|
|
117
173
|
that.modes = ko.observableArray([
|
|
118
174
|
{ text: 'Get Portfolios', action: getPortfolios },
|
|
175
|
+
{ text: 'Create Portfolio', action: createPortfolio },
|
|
176
|
+
{ text: 'Update Portfolio', action: updatePortfolio },
|
|
119
177
|
{ text: 'Get Positions', action: getPositions },
|
|
120
178
|
{ text: 'Get Transactions', action: getTransactions },
|
|
121
179
|
{ text: 'Get Transactions (Formatted)', action: getTransactionsFormatted }
|
|
@@ -150,13 +208,13 @@
|
|
|
150
208
|
that.connect = function() {
|
|
151
209
|
that.disconnect();
|
|
152
210
|
|
|
153
|
-
if (!that.user()) {
|
|
211
|
+
if (!that.user() || !that.userLegacy()) {
|
|
154
212
|
return;
|
|
155
213
|
}
|
|
156
214
|
|
|
157
215
|
that.connecting(true);
|
|
158
216
|
|
|
159
|
-
Barchart.Portfolio.PortfolioGateway.forDevelopment(Barchart.Portfolio.JwtGateway.forDevelopmentClient(that.user()))
|
|
217
|
+
Barchart.Portfolio.PortfolioGateway.forDevelopment(Barchart.Portfolio.JwtGateway.forDevelopmentClient(that.user(), that.userLegacy()))
|
|
160
218
|
.then((gateway) => {
|
|
161
219
|
that.gateway = gateway;
|
|
162
220
|
|
|
@@ -206,8 +264,10 @@
|
|
|
206
264
|
};
|
|
207
265
|
};
|
|
208
266
|
|
|
267
|
+
var pageModel
|
|
268
|
+
|
|
209
269
|
$(document).ready(function() {
|
|
210
|
-
|
|
270
|
+
pageModel = new PageModel();
|
|
211
271
|
|
|
212
272
|
ko.applyBindings(pageModel, $('body')[0]);
|
|
213
273
|
});
|
|
@@ -221,6 +281,10 @@
|
|
|
221
281
|
<label class="pull-left">User</label>
|
|
222
282
|
<input class="form-control" data-bind="textInput: user" type="text" placeholder="User">
|
|
223
283
|
</div>
|
|
284
|
+
<div class="form-group" data-bind="css: { 'has-error': user().length === 0 }, event: { keypress: handleLoginKeypress }">
|
|
285
|
+
<label class="pull-left">Legacy User</label>
|
|
286
|
+
<input class="form-control" data-bind="textInput: userLegacy" type="text" placeholder="Legacy User">
|
|
287
|
+
</div>
|
|
224
288
|
<div class="form-group buttons">
|
|
225
289
|
<button class="form-control btn btn-primary" type="button" data-bind="click: connect, enable: canConnect">Connect</button>
|
|
226
290
|
</div>
|