@barchart/portfolio-client-js 1.4.7 → 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.
@@ -1,963 +0,0 @@
1
- const version = require('./../../lib/index').version;
2
-
3
- const Currency = require('@barchart/common-js/lang/Currency');
4
- const Day = require('@barchart/common-js/lang/Day');
5
- const Decimal = require('@barchart/common-js/lang/Decimal');
6
- const Timezones = require('@barchart/common-js/lang/Timezones');
7
-
8
- const TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType');
9
- const ValuationType = require('@barchart/portfolio-api-common/lib/data/ValuationType');
10
-
11
- const JwtGateway = require('./../../lib/gateway/jwt/JwtGateway');
12
- const PortfolioGateway = require('./../../lib/gateway/PortfolioGateway');
13
-
14
- module.exports = (() => {
15
- 'use strict';
16
-
17
- var PageModel = function() {
18
- var that = this;
19
-
20
- that.gateway = null;
21
-
22
- that.user = ko.observable('d46fba70-21d3-413d-a1bc-a5a37d9de46c');
23
- that.userLegacy = ko.observable('00000000');
24
-
25
- that.connected = ko.observable(false);
26
- that.connecting = ko.observable(false);
27
-
28
- that.activeTemplate = ko.observable('disconnected-template');
29
- that.console = ko.observableArray([ ]);
30
-
31
- that.portfolio = ko.observable();
32
- that.position = ko.observable();
33
- that.transaction = ko.observable();
34
-
35
- that.clientVersion = ko.observable(version);
36
-
37
- var getPortfolios = function() {
38
- var action = 'portfolioGateway.readPortfolios()';
39
-
40
- that.gateway.readPortfolios(that.portfolio() || null)
41
- .then((data) => {
42
- writeConsoleText(action, true);
43
- writeConsoleObject(data);
44
- }).catch((e) => {
45
- writeConsoleText(action, true);
46
- writeConsoleObject(e);
47
-
48
- that.setConsoleMode();
49
- });
50
- };
51
- var createPortfolio = function () {
52
- var action = 'portfolioGateway.createPortfolio()';
53
-
54
- var portfolio = {
55
- name: `Random ${Math.random()}`,
56
- timezone: Timezones.AMERICA_NEW_YORK,
57
- dates: {
58
- create: Day.getToday(),
59
- cash: Day.getToday()
60
- },
61
- defaults: {
62
- currency: Currency.CAD,
63
- reinvest: true,
64
- valuation: ValuationType.AVERAGE_COST
65
- },
66
- miscellany: {
67
- testing: {
68
- nested: 'yes'
69
- }
70
- }
71
- };
72
-
73
- that.gateway.createPortfolio(portfolio)
74
- .then((data) => {
75
- writeConsoleText(action, true);
76
- writeConsoleObject(data);
77
- }).catch((e) => {
78
- writeConsoleText(action, true);
79
- writeConsoleObject(e);
80
-
81
- that.setConsoleMode();
82
- });
83
- };
84
- var updatePortfolio = function() {
85
- var action = 'portfolioGateway.updatePortfolio()';
86
-
87
- var portfolio = {
88
- name: `Random ${Math.random()}`,
89
- timezone: 'America/New_York',
90
- dates: {
91
- cash: Day.getToday()
92
- },
93
- defaults: {
94
- currency: 'CAD',
95
- reinvest: true,
96
- valuation: 'AVG'
97
- },
98
- data: {}
99
- };
100
-
101
- if (!that.portfolio()) {
102
- toastr.info('A "portfolio" is required.');
103
- return;
104
- }
105
-
106
- that.gateway.updatePortfolio(portfolio)
107
- .then((data) => {
108
- writeConsoleText(action, true);
109
- writeConsoleObject(data);
110
- }).catch((e) => {
111
- writeConsoleText(action, true);
112
- writeConsoleObject(e);
113
-
114
- that.setConsoleMode();
115
- });
116
- };
117
- var deletePortfolio = function() {
118
- var action = 'portfolioGateway.deletePortfolio()';
119
-
120
- if (!that.portfolio()) {
121
- toastr.info('A "portfolio" is required.');
122
- return;
123
- }
124
-
125
- that.gateway.deletePortfolio(that.portfolio())
126
- .then((data) => {
127
- writeConsoleText(action, true);
128
- writeConsoleObject(data);
129
- }).catch((e) => {
130
- writeConsoleText(action, true);
131
- writeConsoleObject(e);
132
-
133
- that.setConsoleMode();
134
- });
135
- };
136
- var getPositions = function() {
137
- var action = 'portfolioGateway.readPositions()';
138
-
139
- that.gateway.readPositions(that.portfolio() || null, that.position() || null, true)
140
- .then((data) => {
141
- writeConsoleText(action, true);
142
- writeConsoleObject(data);
143
- }).catch((e) => {
144
- writeConsoleText(action, true);
145
- writeConsoleObject(e);
146
-
147
- that.setConsoleMode();
148
- });
149
- };
150
- var readPositionSummaries = function() {
151
- var action = 'portfolioGateway.readPositionSummaries()';
152
-
153
- that.gateway.readPositionSummaries(that.portfolio() || null, that.position() || null, [ 'YEARLY', 'YTD' ], 1)
154
- .then((data) => {
155
- writeConsoleText(action, true);
156
- writeConsoleObject(data);
157
- }).catch((e) => {
158
- writeConsoleText(action, true);
159
- writeConsoleObject(e);
160
-
161
- that.setConsoleMode();
162
- });
163
- };
164
- var deletePosition = function() {
165
- var action = 'portfolioGateway.deletePosition()';
166
-
167
- if (!that.portfolio()) {
168
- toastr.info('A "portfolio" is required.');
169
- return;
170
- }
171
-
172
- if (!that.position()) {
173
- toastr.info('A "position" is required.');
174
- return;
175
- }
176
-
177
- that.gateway.deletePosition(that.portfolio(), that.position())
178
- .then((data) => {
179
- writeConsoleText(action, true);
180
- writeConsoleObject(data);
181
- }).catch((e) => {
182
- writeConsoleText(action, true);
183
- writeConsoleObject(e);
184
-
185
- that.setConsoleMode();
186
- });
187
- };
188
- var getTransactions = function() {
189
- var action = 'portfolioGateway.readTransactions()';
190
-
191
- var portfolio = that.portfolio();
192
- var position = that.position();
193
-
194
- if (!portfolio) {
195
- toastr.info('A "portfolio" is required.');
196
- return;
197
- }
198
-
199
- that.gateway.readTransactions(that.portfolio(), that.position() || null)
200
- .then((data) => {
201
- writeConsoleText(action, true);
202
- writeConsoleObject(data);
203
- }).catch((e) => {
204
- writeConsoleText(action, true);
205
- writeConsoleObject(e);
206
-
207
- that.setConsoleMode();
208
- });
209
- };
210
- var getTransactionsFormatted = function() {
211
- var action = 'portfolioGateway.readTransactionsFormatted()';
212
-
213
- var portfolio = that.portfolio();
214
- var position = that.position();
215
-
216
- if (!portfolio) {
217
- toastr.info('A "portfolio" is required.');
218
- return;
219
- }
220
-
221
- that.gateway.readTransactionsFormatted(that.portfolio(), that.position() || null)
222
- .then((data) => {
223
- writeConsoleText(action, true);
224
- writeConsoleObject(data);
225
- }).catch((e) => {
226
- writeConsoleText(action, true);
227
- writeConsoleObject(e);
228
-
229
- that.setConsoleMode();
230
- });
231
- };
232
- var createBuyTransaction = function() {
233
- var action = 'portfolioGateway.createTransaction()';
234
-
235
- if (!that.portfolio()) {
236
- toastr.info('A "portfolio" is required.');
237
- return;
238
- }
239
-
240
- var transaction = {
241
- portfolio: that.portfolio(),
242
- position: that.position() || null,
243
- type: TransactionType.BUY,
244
- instrument: {
245
- name: 'International Business Machines',
246
- currency: Currency.USD,
247
- symbol: {
248
- barchart: 'IBM',
249
- display: 'IBM'
250
- }
251
- },
252
- currency: Currency.CAD,
253
- date: Day.getToday(),
254
- price: Decimal.parse(5),
255
- quantity: Decimal.parse(100),
256
- fee: Decimal.ZERO
257
- };
258
-
259
- that.gateway.createTransaction(transaction)
260
- .then((data) => {
261
- writeConsoleText(action, true);
262
- writeConsoleObject(data);
263
-
264
- that.position(data.position);
265
- }).catch((e) => {
266
- writeConsoleText(action, true);
267
- writeConsoleObject(e);
268
-
269
- that.setConsoleMode();
270
- });
271
- };
272
- var createSellTransaction = function() {
273
- var action = 'portfolioGateway.createTransaction()';
274
-
275
- if (!that.portfolio()) {
276
- toastr.info('A "portfolio" is required.');
277
- return;
278
- }
279
-
280
- if (!that.position()) {
281
- toastr.info('A "position" is required.');
282
- return;
283
- }
284
-
285
- var transaction = {
286
- portfolio: that.portfolio(),
287
- position: that.position(),
288
- type: TransactionType.SELL,
289
- currency: Currency.CAD,
290
- date: Day.getToday(),
291
- price: Decimal.parse(5),
292
- quantity: Decimal.parse(100),
293
- fee: Decimal.ZERO
294
- };
295
-
296
- that.gateway.createTransaction(transaction)
297
- .then((data) => {
298
- writeConsoleText(action, true);
299
- writeConsoleObject(data);
300
- }).catch((e) => {
301
- writeConsoleText(action, true);
302
- writeConsoleObject(e);
303
-
304
- that.setConsoleMode();
305
- });
306
- };
307
- var createBuyShortTransaction = function() {
308
- var action = 'portfolioGateway.createTransaction()';
309
-
310
- if (!that.portfolio()) {
311
- toastr.info('A "portfolio" is required.');
312
- return;
313
- }
314
-
315
- var transaction = {
316
- portfolio: that.portfolio(),
317
- position: that.position() || null,
318
- type: TransactionType.BUY_SHORT,
319
- instrument: {
320
- name: 'International Business Machines',
321
- currency: Currency.USD,
322
- symbol: {
323
- barchart: 'IBM',
324
- display: 'IBM'
325
- }
326
- },
327
- currency: Currency.CAD,
328
- date: Day.getToday(),
329
- price: Decimal.parse(5),
330
- quantity: Decimal.parse(100),
331
- fee: Decimal.ZERO
332
- };
333
-
334
- that.gateway.createTransaction(transaction)
335
- .then((data) => {
336
- writeConsoleText(action, true);
337
- writeConsoleObject(data);
338
- }).catch((e) => {
339
- writeConsoleText(action, true);
340
- writeConsoleObject(e);
341
-
342
- that.setConsoleMode();
343
- });
344
- };
345
- var createSellShortTransaction = function() {
346
- var action = 'portfolioGateway.createTransaction()';
347
-
348
- if (!that.portfolio()) {
349
- toastr.info('A "portfolio" is required.');
350
- return;
351
- }
352
-
353
- if (!that.position()) {
354
- toastr.info('A "position" is required.');
355
- return;
356
- }
357
-
358
- var transaction = {
359
- portfolio: that.portfolio(),
360
- position: that.position(),
361
- type: TransactionType.SELL_SHORT,
362
- instrument: {
363
- name: 'International Business Machines',
364
- currency: Currency.USD,
365
- symbol: {
366
- barchart: 'IBM',
367
- display: 'IBM'
368
- }
369
- },
370
- currency: Currency.CAD,
371
- date: Day.getToday(),
372
- price: Decimal.parse(5),
373
- quantity: Decimal.parse(100),
374
- fee: Decimal.ZERO
375
- };
376
-
377
- that.gateway.createTransaction(transaction)
378
- .then((data) => {
379
- writeConsoleText(action, true);
380
- writeConsoleObject(data);
381
- }).catch((e) => {
382
- writeConsoleText(action, true);
383
- writeConsoleObject(e);
384
-
385
- that.setConsoleMode();
386
- });
387
- };
388
- var createDividendTransaction = function() {
389
- var action = 'portfolioGateway.createTransaction()';
390
-
391
- if (!that.portfolio()) {
392
- toastr.info('A "portfolio" is required.');
393
- return;
394
- }
395
-
396
- if (!that.position()) {
397
- toastr.info('A "position" is required.');
398
- return;
399
- }
400
-
401
- var transaction = {
402
- portfolio: that.portfolio(),
403
- position: that.position(),
404
- type: TransactionType.DIVIDEND,
405
- currency: Currency.CAD,
406
- date: Day.getToday(),
407
- price: Decimal.parse(5),
408
- quantity: Decimal.parse(100),
409
- rate: Decimal.parse(0.125),
410
- effective: Day.getToday(),
411
- fee: Decimal.ZERO
412
- };
413
-
414
- that.gateway.createTransaction(transaction)
415
- .then((data) => {
416
- writeConsoleText(action, true);
417
- writeConsoleObject(data);
418
- }).catch((e) => {
419
- writeConsoleText(action, true);
420
- writeConsoleObject(e);
421
-
422
- that.setConsoleMode();
423
- });
424
- };
425
- var createDividendReinvestTransaction = function() {
426
- var action = 'portfolioGateway.createTransaction()';
427
-
428
- if (!that.portfolio()) {
429
- toastr.info('A "portfolio" is required.');
430
- return;
431
- }
432
-
433
- if (!that.position()) {
434
- toastr.info('A "position" is required.');
435
- return;
436
- }
437
-
438
- var transaction = {
439
- portfolio: that.portfolio(),
440
- position: that.position(),
441
- type: TransactionType.DIVIDEND_REINVEST,
442
- currency: Currency.CAD,
443
- date: Day.getToday(),
444
- price: Decimal.parse(5),
445
- quantity: Decimal.parse(100),
446
- rate: Decimal.parse(0.125),
447
- effective: Day.getToday(),
448
- fee: Decimal.ZERO
449
- };
450
-
451
- that.gateway.createTransaction(transaction)
452
- .then((data) => {
453
- writeConsoleText(action, true);
454
- writeConsoleObject(data);
455
- }).catch((e) => {
456
- writeConsoleText(action, true);
457
- writeConsoleObject(e);
458
-
459
- that.setConsoleMode();
460
- });
461
- };
462
- var createDividendStockTransaction = function() {
463
- var action = 'portfolioGateway.createTransaction()';
464
-
465
- if (!that.portfolio()) {
466
- toastr.info('A "portfolio" is required.');
467
- return;
468
- }
469
-
470
- if (!that.position()) {
471
- toastr.info('A "position" is required.');
472
- return;
473
- }
474
-
475
- var transaction = {
476
- portfolio: that.portfolio(),
477
- position: that.position(),
478
- type: TransactionType.DIVIDEND_STOCK,
479
- currency: Currency.CAD,
480
- date: Day.getToday(),
481
- price: Decimal.parse(5),
482
- quantity: Decimal.parse(100),
483
- rate: Decimal.parse(0.125),
484
- effective: Day.getToday(),
485
- fee: Decimal.ZERO
486
- };
487
-
488
- that.gateway.createTransaction(transaction)
489
- .then((data) => {
490
- writeConsoleText(action, true);
491
- writeConsoleObject(data);
492
- }).catch((e) => {
493
- writeConsoleText(action, true);
494
- writeConsoleObject(e);
495
-
496
- that.setConsoleMode();
497
- });
498
- };
499
- var createDistributionCashTransaction = function() {
500
- var action = 'portfolioGateway.createTransaction()';
501
-
502
- if (!that.portfolio()) {
503
- toastr.info('A "portfolio" is required.');
504
- return;
505
- }
506
-
507
- if (!that.position()) {
508
- toastr.info('A "position" is required.');
509
- return;
510
- }
511
-
512
- var transaction = {
513
- portfolio: that.portfolio(),
514
- position: that.position(),
515
- type: TransactionType.DISTRIBUTION_CASH,
516
- currency: Currency.CAD,
517
- date: Day.getToday(),
518
- price: Decimal.parse(5),
519
- quantity: Decimal.parse(100),
520
- rate: Decimal.parse(0.125),
521
- effective: Day.getToday(),
522
- fee: Decimal.ZERO
523
- };
524
-
525
- that.gateway.createTransaction(transaction)
526
- .then((data) => {
527
- writeConsoleText(action, true);
528
- writeConsoleObject(data);
529
- }).catch((e) => {
530
- writeConsoleText(action, true);
531
- writeConsoleObject(e);
532
-
533
- that.setConsoleMode();
534
- });
535
- };
536
- var createDistributionFundTransaction = function() {
537
- var action = 'portfolioGateway.createTransaction()';
538
-
539
- if (!that.portfolio()) {
540
- toastr.info('A "portfolio" is required.');
541
- return;
542
- }
543
-
544
- if (!that.position()) {
545
- toastr.info('A "position" is required.');
546
- return;
547
- }
548
-
549
- var transaction = {
550
- portfolio: that.portfolio(),
551
- position: that.position(),
552
- type: TransactionType.DISTRIBUTION_FUND,
553
- currency: Currency.CAD,
554
- date: Day.getToday(),
555
- price: Decimal.parse(5),
556
- quantity: Decimal.parse(100),
557
- rate: Decimal.parse(0.125),
558
- effective: Day.getToday(),
559
- fee: Decimal.ZERO
560
- };
561
-
562
- that.gateway.createTransaction(transaction)
563
- .then((data) => {
564
- writeConsoleText(action, true);
565
- writeConsoleObject(data);
566
- }).catch((e) => {
567
- writeConsoleText(action, true);
568
- writeConsoleObject(e);
569
-
570
- that.setConsoleMode();
571
- });
572
- };
573
- var createSplitTransaction = function() {
574
- var action = 'portfolioGateway.createTransaction()';
575
-
576
- if (!that.portfolio()) {
577
- toastr.info('A "portfolio" is required.');
578
- return;
579
- }
580
-
581
- if (!that.position()) {
582
- toastr.info('A "position" is required.');
583
- return;
584
- }
585
-
586
- var transaction = {
587
- portfolio: that.portfolio(),
588
- position: that.position(),
589
- type: TransactionType.SPLIT,
590
- currency: Currency.CAD,
591
- date: Day.getToday(),
592
- numerator: Decimal.parse(3),
593
- denominator: Decimal.parse(1),
594
- effective: Day.getToday(),
595
- fee: Decimal.ZERO
596
- };
597
-
598
- that.gateway.createTransaction(transaction)
599
- .then((data) => {
600
- writeConsoleText(action, true);
601
- writeConsoleObject(data);
602
- }).catch((e) => {
603
- writeConsoleText(action, true);
604
- writeConsoleObject(e);
605
-
606
- that.setConsoleMode();
607
- });
608
- };
609
- var createFeeTransaction = function() {
610
- var action = 'portfolioGateway.createTransaction()';
611
-
612
- if (!that.portfolio()) {
613
- toastr.info('A "portfolio" is required.');
614
- return;
615
- }
616
-
617
- if (!that.position()) {
618
- toastr.info('A "position" is required.');
619
- return;
620
- }
621
-
622
- var transaction = {
623
- portfolio: that.portfolio(),
624
- position: that.position(),
625
- type: TransactionType.FEE,
626
- date: Day.getToday(),
627
- effective: Day.getToday(),
628
- fee: Decimal.ZERO
629
- };
630
-
631
- that.gateway.createTransaction(transaction)
632
- .then((data) => {
633
- writeConsoleText(action, true);
634
- writeConsoleObject(data);
635
- }).catch((e) => {
636
- writeConsoleText(action, true);
637
- writeConsoleObject(e);
638
-
639
- that.setConsoleMode();
640
- });
641
- };
642
- var createFeeUnitsTransaction = function() {
643
- var action = 'portfolioGateway.createTransaction()';
644
-
645
- if (!that.portfolio()) {
646
- toastr.info('A "portfolio" is required.');
647
- return;
648
- }
649
-
650
- if (!that.position()) {
651
- toastr.info('A "position" is required.');
652
- return;
653
- }
654
-
655
- var transaction = {
656
- portfolio: that.portfolio(),
657
- position: that.position(),
658
- type: TransactionType.FEE_UNITS,
659
- date: Day.getToday(),
660
- effective: Day.getToday(),
661
- fee: Decimal.ZERO,
662
- price: Decimal.parse(5)
663
- };
664
-
665
- that.gateway.createTransaction(transaction)
666
- .then((data) => {
667
- writeConsoleText(action, true);
668
- writeConsoleObject(data);
669
- }).catch((e) => {
670
- writeConsoleText(action, true);
671
- writeConsoleObject(e);
672
-
673
- that.setConsoleMode();
674
- });
675
- };
676
- var createDepositTransaction = function() {
677
- var action = 'portfolioGateway.createTransaction()';
678
-
679
- if (!that.portfolio()) {
680
- toastr.info('A "portfolio" is required.');
681
- return;
682
- }
683
-
684
- if (!that.position()) {
685
- toastr.info('A "position" is required.');
686
- return;
687
- }
688
-
689
- var transaction = {
690
- portfolio: that.portfolio(),
691
- position: that.position(),
692
- type: TransactionType.DEPOSIT,
693
- date: Day.getToday(),
694
- amount: Decimal.parse(5),
695
- fee: Decimal.ZERO
696
- };
697
-
698
- that.gateway.createTransaction(transaction)
699
- .then((data) => {
700
- writeConsoleText(action, true);
701
- writeConsoleObject(data);
702
- }).catch((e) => {
703
- writeConsoleText(action, true);
704
- writeConsoleObject(e);
705
-
706
- that.setConsoleMode();
707
- });
708
- };
709
- var createWithdrawalTransaction = function() {
710
- var action = 'portfolioGateway.createTransaction()';
711
-
712
- if (!that.portfolio()) {
713
- toastr.info('A "portfolio" is required.');
714
- return;
715
- }
716
-
717
- if (!that.position()) {
718
- toastr.info('A "position" is required.');
719
- return;
720
- }
721
-
722
- var transaction = {
723
- portfolio: that.portfolio(),
724
- position: that.position(),
725
- type: TransactionType.WITHDRAWAL,
726
- date: Day.getToday(),
727
- amount: Decimal.parse(5),
728
- fee: Decimal.ZERO
729
- };
730
-
731
- that.gateway.createTransaction(transaction)
732
- .then((data) => {
733
- writeConsoleText(action, true);
734
- writeConsoleObject(data);
735
- }).catch((e) => {
736
- writeConsoleText(action, true);
737
- writeConsoleObject(e);
738
-
739
- that.setConsoleMode();
740
- });
741
- };
742
- var createValuationTransaction = function() {
743
- var action = 'portfolioGateway.createTransaction()';
744
-
745
- if (!that.portfolio()) {
746
- toastr.info('A "portfolio" is required.');
747
- return;
748
- }
749
-
750
- if (!that.position()) {
751
- toastr.info('A "position" is required.');
752
- return;
753
- }
754
-
755
- var transaction = {
756
- portfolio: that.portfolio(),
757
- position: that.position(),
758
- type: TransactionType.VALUATION,
759
- date: Day.getToday(),
760
- value: Decimal.parse(5),
761
- fee: Decimal.ZERO
762
- };
763
-
764
- that.gateway.createTransaction(transaction)
765
- .then((data) => {
766
- writeConsoleText(action, true);
767
- writeConsoleObject(data);
768
- }).catch((e) => {
769
- writeConsoleText(action, true);
770
- writeConsoleObject(e);
771
-
772
- that.setConsoleMode();
773
- });
774
- };
775
- var createIncomeTransaction = function() {
776
- var action = 'portfolioGateway.createTransaction()';
777
-
778
- if (!that.portfolio()) {
779
- toastr.info('A "portfolio" is required.');
780
- return;
781
- }
782
-
783
- if (!that.position()) {
784
- toastr.info('A "position" is required.');
785
- return;
786
- }
787
-
788
- var transaction = {
789
- portfolio: that.portfolio(),
790
- position: that.position(),
791
- type: TransactionType.INCOME,
792
- date: Day.getToday(),
793
- income: Decimal.parse(5),
794
- fee: Decimal.ZERO
795
- };
796
-
797
- that.gateway.createTransaction(transaction)
798
- .then((data) => {
799
- writeConsoleText(action, true);
800
- writeConsoleObject(data);
801
- }).catch((e) => {
802
- writeConsoleText(action, true);
803
- writeConsoleObject(e);
804
-
805
- that.setConsoleMode();
806
- });
807
- };
808
- var deleteTransaction = function() {
809
- var action = 'portfolioGateway.deleteTransaction()';
810
-
811
- if (!that.portfolio()) {
812
- toastr.info('A "portfolio" is required.');
813
- return;
814
- }
815
-
816
- if (!that.position()) {
817
- toastr.info('A "position" is required.');
818
- return;
819
- }
820
-
821
- if (!that.transaction()) {
822
- toastr.info('A "transaction" is required.');
823
- return;
824
- }
825
-
826
- that.gateway.deleteTransaction(that.portfolio(), that.position(), that.transaction())
827
- .then((data) => {
828
- writeConsoleText(action, true);
829
- writeConsoleObject(data);
830
- }).catch((e) => {
831
- writeConsoleText(action, true);
832
- writeConsoleObject(e);
833
-
834
- that.setConsoleMode();
835
- });
836
- };
837
-
838
- that.modes = ko.observableArray([
839
- { text: 'Get Portfolios', action: getPortfolios },
840
- { text: 'Create Portfolio', action: createPortfolio },
841
- { text: 'Update Portfolio', action: updatePortfolio },
842
- { text: 'Delete Portfolio', action: deletePortfolio },
843
-
844
- { text: 'Get Positions', action: getPositions },
845
- { text: 'Get Positions Summaries', action: readPositionSummaries },
846
- { text: 'Delete Position', action: deletePosition },
847
-
848
- { text: 'Get Transactions', action: getTransactions },
849
- { text: 'Get Transactions (Formatted)', action: getTransactionsFormatted },
850
-
851
- { text: 'Create Buy Transaction', action: createBuyTransaction },
852
- { text: 'Create Sell Transaction', action: createSellTransaction },
853
- { text: 'Create BuyShort Transaction', action: createBuyShortTransaction },
854
- { text: 'Create SellShort Transaction', action: createSellShortTransaction },
855
- { text: 'Create Dividend Transaction', action: createDividendTransaction },
856
- { text: 'Create Dividend Reinvest Transaction', action: createDividendReinvestTransaction },
857
- { text: 'Create Dividend Stock Transaction', action: createDividendStockTransaction },
858
- { text: 'Create Distribution Cash Transaction', action: createDistributionCashTransaction },
859
- { text: 'Create Distribution Fund Transaction', action: createDistributionFundTransaction },
860
- { text: 'Create Split Transaction', action: createSplitTransaction },
861
- { text: 'Create Fee Transaction', action: createFeeTransaction },
862
- { text: 'Create Fee Units Transaction', action: createFeeUnitsTransaction },
863
- { text: 'Create Deposit Transaction', action: createDepositTransaction },
864
- { text: 'Create Withdrawal Transaction', action: createWithdrawalTransaction },
865
- { text: 'Create Valuation Transaction', action: createValuationTransaction },
866
- { text: 'Create Income Transaction', action: createIncomeTransaction },
867
-
868
- { text: 'Delete Transaction', action: deleteTransaction }
869
- ]);
870
-
871
- that.mode = ko.observable(that.modes()[0]);
872
-
873
-
874
- that.canConnect = ko.computed(function() {
875
- return !that.connecting() && !that.connected();
876
- });
877
- that.canDisconnect = ko.computed(function() {
878
- return that.connected();
879
- });
880
-
881
- var writeConsoleText = function(text, clear) {
882
- if (clear) {
883
- that.console.removeAll();
884
- }
885
-
886
- that.console.push(text);
887
- };
888
-
889
- var writeConsoleObject = function(data) {
890
- that.console.push(JSON.stringify(data, null, 2));
891
- };
892
-
893
- that.setConsoleMode = function() {
894
- that.activeTemplate('portfolio-console-template');
895
- };
896
-
897
- that.connect = function() {
898
- that.disconnect();
899
-
900
- if (!that.user() || !that.userLegacy()) {
901
- return;
902
- }
903
-
904
- that.connecting(true);
905
-
906
- PortfolioGateway.forDevelopment(JwtGateway.forDevelopmentClient(that.user(), that.userLegacy()))
907
- .then((gateway) => {
908
- that.gateway = gateway;
909
-
910
- that.connecting(false);
911
- that.connected(true);
912
-
913
- that.setConsoleMode();
914
-
915
- getPortfolios();
916
- });
917
- };
918
- that.disconnect = function() {
919
- if (that.gateway === null) {
920
- return;
921
- }
922
-
923
- if (that.gateway) {
924
- that.gateway.dispose();
925
- that.gateway = null;
926
- }
927
-
928
- that.console.removeAll();
929
-
930
- that.connecting(false);
931
- that.connected(false);
932
-
933
- that.activeTemplate('disconnected-template');
934
- };
935
-
936
- that.setMode = function(mode) {
937
- that.mode(mode);
938
-
939
- that.execute();
940
- };
941
- that.execute = function() {
942
- that.mode().action();
943
- };
944
-
945
- that.handleLoginKeypress = function(d, e) {
946
- var enterKey = e.keyCode === 13;
947
-
948
- if (enterKey) {
949
- that.connect();
950
- }
951
-
952
- return !enterKey;
953
- };
954
- };
955
-
956
- var pageModel;
957
-
958
- $(document).ready(function() {
959
- pageModel = new PageModel();
960
-
961
- ko.applyBindings(pageModel, $('body')[0]);
962
- });
963
- })();