@barchart/portfolio-client-js 1.1.4 → 1.1.7

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.
@@ -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,68 @@
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: Barchart.Day.getToday(),
67
+ cash: Barchart.Day.getToday()
68
+ },
69
+ defaults: {
70
+ currency: 'CAD',
71
+ reinvest: true,
72
+ valuation: 'AVG'
73
+ },
74
+ data: {}
75
+ };
76
+
77
+ that.gateway.createPortfolio(portfolio)
78
+ .then((data) => {
79
+ writeConsoleText(action, true);
80
+ writeConsoleObject(data);
81
+ }).catch((e) => {
82
+ writeConsoleText(action, true);
83
+ writeConsoleObject(e);
84
+
85
+ that.setConsoleMode();
86
+ });
87
+ };
88
+ var updatePortfolio = function() {
89
+ var action = 'portfolioGateway.updatePortfolio()';
90
+
91
+ var portfolio = {
92
+ name: `Random ${Math.random()}`,
93
+ timezone: 'America/New_York',
94
+ dates: {
95
+ cash: Barchart.Day.getToday()
96
+ },
97
+ defaults: {
98
+ currency: 'CAD',
99
+ reinvest: true,
100
+ valuation: 'AVG'
101
+ },
102
+ data: {}
103
+ };
104
+
105
+ if (!that.portfolio()) {
106
+ toastr.info('A "portfolio" is required.');
107
+ return;
108
+ }
109
+
110
+ that.gateway.updatePortfolio(that.portfolio(), portfolio)
111
+ .then((data) => {
112
+ writeConsoleText(action, true);
113
+ writeConsoleObject(data);
114
+ }).catch((e) => {
115
+ writeConsoleText(action, true);
116
+ writeConsoleObject(e);
117
+
55
118
  that.setConsoleMode();
56
119
  });
57
120
  };
@@ -92,7 +155,7 @@
92
155
  });
93
156
  };
94
157
  var getTransactionsFormatted = function() {
95
- var action = 'portfolioGateway.getTransactionsReport()';
158
+ var action = 'portfolioGateway.readTransactionsFormatted()';
96
159
 
97
160
  var portfolio = that.portfolio();
98
161
  var position = that.position();
@@ -116,6 +179,8 @@
116
179
 
117
180
  that.modes = ko.observableArray([
118
181
  { text: 'Get Portfolios', action: getPortfolios },
182
+ { text: 'Create Portfolio', action: createPortfolio },
183
+ { text: 'Update Portfolio', action: updatePortfolio },
119
184
  { text: 'Get Positions', action: getPositions },
120
185
  { text: 'Get Transactions', action: getTransactions },
121
186
  { text: 'Get Transactions (Formatted)', action: getTransactionsFormatted }
@@ -150,13 +215,13 @@
150
215
  that.connect = function() {
151
216
  that.disconnect();
152
217
 
153
- if (!that.user()) {
218
+ if (!that.user() || !that.userLegacy()) {
154
219
  return;
155
220
  }
156
221
 
157
222
  that.connecting(true);
158
223
 
159
- Barchart.Portfolio.PortfolioGateway.forDevelopment(Barchart.Portfolio.JwtGateway.forDevelopmentClient(that.user()))
224
+ Barchart.Portfolio.PortfolioGateway.forDevelopment(Barchart.Portfolio.JwtGateway.forDevelopmentClient(that.user(), that.userLegacy()))
160
225
  .then((gateway) => {
161
226
  that.gateway = gateway;
162
227
 
@@ -206,8 +271,10 @@
206
271
  };
207
272
  };
208
273
 
274
+ var pageModel
275
+
209
276
  $(document).ready(function() {
210
- var pageModel = new PageModel();
277
+ pageModel = new PageModel();
211
278
 
212
279
  ko.applyBindings(pageModel, $('body')[0]);
213
280
  });
@@ -221,6 +288,10 @@
221
288
  <label class="pull-left">User</label>
222
289
  <input class="form-control" data-bind="textInput: user" type="text" placeholder="User">
223
290
  </div>
291
+ <div class="form-group" data-bind="css: { 'has-error': user().length === 0 }, event: { keypress: handleLoginKeypress }">
292
+ <label class="pull-left">Legacy User</label>
293
+ <input class="form-control" data-bind="textInput: userLegacy" type="text" placeholder="Legacy User">
294
+ </div>
224
295
  <div class="form-group buttons">
225
296
  <button class="form-control btn btn-primary" type="button" data-bind="click: connect, enable: canConnect">Connect</button>
226
297
  </div>