@barchart/portfolio-api-common 1.11.7 → 1.11.8
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.
|
@@ -129,7 +129,7 @@ module.exports = (() => {
|
|
|
129
129
|
f.open = t.snapshot.open;
|
|
130
130
|
f.transaction = t.transaction;
|
|
131
131
|
|
|
132
|
-
f.raw.open = f.open
|
|
132
|
+
f.raw.open = getRawForDecimal(f.open);
|
|
133
133
|
};
|
|
134
134
|
|
|
135
135
|
const averageCostFormatter = (t, f) => {
|
|
@@ -152,9 +152,9 @@ module.exports = (() => {
|
|
|
152
152
|
f.price = t.trade.price;
|
|
153
153
|
f.fee = t.fee;
|
|
154
154
|
f.total = t.amount;
|
|
155
|
-
f.raw.total = f.total
|
|
156
|
-
f.raw.price = f.price
|
|
157
|
-
f.raw.boughtSold = f.boughtSold
|
|
155
|
+
f.raw.total = getRawForDecimal(f.total);
|
|
156
|
+
f.raw.price = getRawForDecimal(f.price);
|
|
157
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
const dividendFormatter = (t, f) => {
|
|
@@ -162,24 +162,28 @@ module.exports = (() => {
|
|
|
162
162
|
f.rate = t.dividend.rate;
|
|
163
163
|
|
|
164
164
|
let shares;
|
|
165
|
-
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
|
|
166
|
+
if (t.dividend.open) {
|
|
167
|
+
shares = t.dividend.open;
|
|
168
|
+
} else {
|
|
169
|
+
if (!t.dividend.rate.getIsZero()) {
|
|
170
|
+
if (t.dividend.native) {
|
|
171
|
+
shares = t.dividend.native.divide(t.dividend.rate);
|
|
172
|
+
} else {
|
|
173
|
+
shares = t.dividend.amount.divide(t.dividend.rate);
|
|
174
|
+
}
|
|
169
175
|
} else {
|
|
170
|
-
shares =
|
|
176
|
+
shares = '';
|
|
171
177
|
}
|
|
172
|
-
} else {
|
|
173
|
-
shares = '';
|
|
174
|
-
}
|
|
175
178
|
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
if (shares) {
|
|
180
|
+
const rounded = shares.round(0);
|
|
178
181
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
if (rounded.subtract(shares).absolute().getIsLessThan(0.01)) {
|
|
183
|
+
shares = rounded;
|
|
184
|
+
} else {
|
|
185
|
+
shares = shares.round(2);
|
|
186
|
+
}
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
|
|
@@ -191,12 +195,12 @@ module.exports = (() => {
|
|
|
191
195
|
|
|
192
196
|
if (t.dividend.native) {
|
|
193
197
|
f.native = t.dividend.native;
|
|
194
|
-
f.raw.native = f.native
|
|
198
|
+
f.raw.native = getRawForDecimal(f.native);
|
|
195
199
|
}
|
|
196
200
|
|
|
197
|
-
f.raw.rate = f.rate
|
|
198
|
-
f.raw.shares = f.shares
|
|
199
|
-
f.raw.total = f.total
|
|
201
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
202
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
203
|
+
f.raw.total = getRawForDecimal(f.total);
|
|
200
204
|
};
|
|
201
205
|
|
|
202
206
|
const distributionCashFormatter = (t, f) => {
|
|
@@ -205,24 +209,28 @@ module.exports = (() => {
|
|
|
205
209
|
|
|
206
210
|
let shares;
|
|
207
211
|
|
|
208
|
-
if (
|
|
209
|
-
|
|
210
|
-
|
|
212
|
+
if (t.dividend.open) {
|
|
213
|
+
shares = t.dividend.open;
|
|
214
|
+
} else {
|
|
215
|
+
if (!t.dividend.rate.getIsZero()) {
|
|
216
|
+
if (t.dividend.native) {
|
|
217
|
+
shares = t.dividend.native.divide(t.dividend.rate);
|
|
218
|
+
} else {
|
|
219
|
+
shares = t.dividend.amount.divide(t.dividend.rate);
|
|
220
|
+
}
|
|
211
221
|
} else {
|
|
212
|
-
shares =
|
|
222
|
+
shares = '';
|
|
213
223
|
}
|
|
214
|
-
} else {
|
|
215
|
-
shares = '';
|
|
216
|
-
}
|
|
217
224
|
|
|
218
|
-
|
|
219
|
-
|
|
225
|
+
if (shares) {
|
|
226
|
+
const rounded = shares.round(0);
|
|
220
227
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
228
|
+
if (rounded.subtract(shares).absolute().getIsLessThan(0.01)) {
|
|
229
|
+
shares = rounded;
|
|
230
|
+
} else {
|
|
231
|
+
shares = shares.round(2);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
226
234
|
}
|
|
227
235
|
|
|
228
236
|
f.shares = shares;
|
|
@@ -233,12 +241,12 @@ module.exports = (() => {
|
|
|
233
241
|
|
|
234
242
|
if (t.dividend.native) {
|
|
235
243
|
f.native = t.dividend.native;
|
|
236
|
-
f.raw.native = f.native
|
|
244
|
+
f.raw.native = getRawForDecimal(f.native);
|
|
237
245
|
}
|
|
238
246
|
|
|
239
|
-
f.raw.rate = f.rate
|
|
240
|
-
f.raw.shares = f.shares
|
|
241
|
-
f.raw.total = f.total
|
|
247
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
248
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
249
|
+
f.raw.total = getRawForDecimal(f.total);
|
|
242
250
|
};
|
|
243
251
|
|
|
244
252
|
const dividendReinvestFormatter = (t, f) => {
|
|
@@ -257,10 +265,10 @@ module.exports = (() => {
|
|
|
257
265
|
|
|
258
266
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
259
267
|
|
|
260
|
-
f.raw.rate = f.rate
|
|
261
|
-
f.raw.shares = f.shares
|
|
262
|
-
f.raw.price = f.price
|
|
263
|
-
f.raw.boughtSold = f.boughtSold
|
|
268
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
269
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
270
|
+
f.raw.price = getRawForDecimal(f.price);
|
|
271
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
264
272
|
};
|
|
265
273
|
|
|
266
274
|
const distributionReinvestFormatter = (t, f) => {
|
|
@@ -279,10 +287,10 @@ module.exports = (() => {
|
|
|
279
287
|
|
|
280
288
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
281
289
|
|
|
282
|
-
f.raw.rate = f.rate
|
|
283
|
-
f.raw.shares = f.shares
|
|
284
|
-
f.raw.price = f.price
|
|
285
|
-
f.raw.boughtSold = f.boughtSold
|
|
290
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
291
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
292
|
+
f.raw.price = getRawForDecimal(f.price);
|
|
293
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
286
294
|
};
|
|
287
295
|
|
|
288
296
|
const dividendStockFormatter = (t, f) => {
|
|
@@ -307,18 +315,18 @@ module.exports = (() => {
|
|
|
307
315
|
|
|
308
316
|
f.rate = rate;
|
|
309
317
|
|
|
310
|
-
f.raw.rate = f.rate
|
|
318
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
311
319
|
|
|
312
320
|
if (t.dividend.price) {
|
|
313
321
|
f.price = t.dividend.price;
|
|
314
|
-
f.raw.price = f.price
|
|
322
|
+
f.raw.price = getRawForDecimal(f.price);
|
|
315
323
|
}
|
|
316
324
|
}
|
|
317
325
|
|
|
318
326
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
319
327
|
|
|
320
|
-
f.raw.shares = f.shares
|
|
321
|
-
f.raw.boughtSold = f.boughtSold
|
|
328
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
329
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
322
330
|
};
|
|
323
331
|
|
|
324
332
|
const distributionFundFormatter = (t, f) => {
|
|
@@ -343,34 +351,34 @@ module.exports = (() => {
|
|
|
343
351
|
|
|
344
352
|
f.rate = rate;
|
|
345
353
|
|
|
346
|
-
f.raw.rate = f.rate
|
|
354
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
347
355
|
|
|
348
356
|
if (t.dividend.price) {
|
|
349
357
|
f.price = t.dividend.price;
|
|
350
|
-
f.raw.price = f.price
|
|
358
|
+
f.raw.price = getRawForDecimal(f.price);
|
|
351
359
|
}
|
|
352
360
|
}
|
|
353
361
|
|
|
354
362
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
355
363
|
|
|
356
|
-
f.raw.shares = f.shares
|
|
357
|
-
f.raw.boughtSold = f.boughtSold
|
|
364
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
365
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
358
366
|
};
|
|
359
367
|
|
|
360
368
|
const incomeFormatter = (t, f) => {
|
|
361
369
|
f.total = t.income.amount;
|
|
362
|
-
f.raw.total = f.total
|
|
370
|
+
f.raw.total = getRawForDecimal(f.total);
|
|
363
371
|
};
|
|
364
372
|
|
|
365
373
|
const feeFormatter = (t, f) => {
|
|
366
374
|
f.fee = t.charge.amount;
|
|
367
375
|
f.total = t.charge.amount;
|
|
368
|
-
f.raw.total = f.total
|
|
376
|
+
f.raw.total = getRawForDecimal(f.total);
|
|
369
377
|
};
|
|
370
378
|
|
|
371
379
|
const feeUnitsFormatter = (t, f) => {
|
|
372
380
|
f.boughtSold = t.quantity;
|
|
373
|
-
f.raw.boughtSold = f.boughtSold
|
|
381
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
374
382
|
};
|
|
375
383
|
|
|
376
384
|
const splitFormatter = (t, f) => {
|
|
@@ -388,9 +396,9 @@ module.exports = (() => {
|
|
|
388
396
|
|
|
389
397
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
390
398
|
|
|
391
|
-
f.raw.rate = f.rate
|
|
392
|
-
f.raw.shares = f.shares
|
|
393
|
-
f.raw.boughtSold = f.boughtSold
|
|
399
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
400
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
401
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
394
402
|
};
|
|
395
403
|
|
|
396
404
|
const valuationFormatter = (t, f) => {
|
|
@@ -409,12 +417,12 @@ module.exports = (() => {
|
|
|
409
417
|
}
|
|
410
418
|
|
|
411
419
|
f.price = rate;
|
|
412
|
-
f.raw.price = f.price
|
|
420
|
+
f.raw.price = getRawForDecimal(f.price);
|
|
413
421
|
};
|
|
414
422
|
|
|
415
423
|
const cashFormatter = (t, f) => {
|
|
416
424
|
f.total = t.quantity;
|
|
417
|
-
f.raw.total = f.total
|
|
425
|
+
f.raw.total = getRawForDecimal(f.total);
|
|
418
426
|
};
|
|
419
427
|
|
|
420
428
|
const debitFormatter = (t, f) => {
|
|
@@ -440,9 +448,9 @@ module.exports = (() => {
|
|
|
440
448
|
|
|
441
449
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
442
450
|
|
|
443
|
-
f.raw.rate = f.rate
|
|
444
|
-
f.raw.shares = f.shares
|
|
445
|
-
f.raw.boughtSold = f.boughtSold
|
|
451
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
452
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
453
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
446
454
|
};
|
|
447
455
|
|
|
448
456
|
const spinoffFormatter = (t, f) => {
|
|
@@ -460,9 +468,9 @@ module.exports = (() => {
|
|
|
460
468
|
|
|
461
469
|
f.shares = t.snapshot.open.subtract(t.quantity);
|
|
462
470
|
|
|
463
|
-
f.raw.rate = f.rate
|
|
464
|
-
f.raw.shares = f.shares
|
|
465
|
-
f.raw.boughtSold = f.boughtSold
|
|
471
|
+
f.raw.rate = getRawForDecimal(f.rate);
|
|
472
|
+
f.raw.shares = getRawForDecimal(f.shares);
|
|
473
|
+
f.raw.boughtSold = getRawForDecimal(f.boughtSold);
|
|
466
474
|
};
|
|
467
475
|
|
|
468
476
|
const formatters = new Map();
|
|
@@ -499,6 +507,10 @@ module.exports = (() => {
|
|
|
499
507
|
return 0;
|
|
500
508
|
}
|
|
501
509
|
}
|
|
510
|
+
|
|
511
|
+
function getRawForDecimal(value) {
|
|
512
|
+
return value && value instanceof Decimal ? value.toFloat() : value;
|
|
513
|
+
}
|
|
502
514
|
|
|
503
515
|
const comparatorAscending = ComparatorBuilder.startWith((a, b) => Day.compareDays(a.date, b.date))
|
|
504
516
|
.thenBy((a, b) => comparators.compareNumbers(getInstrumentTypePriority(a.instrument.type), getInstrumentTypePriority(b.instrument.type)))
|