@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.toFloat();
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.toFloat();
156
- f.raw.price = f.price.toFloat();
157
- f.raw.boughtSold = f.boughtSold.toFloat();
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 (!t.dividend.rate.getIsZero()) {
167
- if (t.dividend.native) {
168
- shares = t.dividend.native.divide(t.dividend.rate);
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 = t.dividend.amount.divide(t.dividend.rate);
176
+ shares = '';
171
177
  }
172
- } else {
173
- shares = '';
174
- }
175
178
 
176
- if (shares) {
177
- const rounded = shares.round(0);
179
+ if (shares) {
180
+ const rounded = shares.round(0);
178
181
 
179
- if (rounded.subtract(shares).absolute().getIsLessThan(0.01)) {
180
- shares = rounded;
181
- } else {
182
- shares = shares.round(2);
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.toFloat();
198
+ f.raw.native = getRawForDecimal(f.native);
195
199
  }
196
200
 
197
- f.raw.rate = f.rate.toFloat();
198
- f.raw.shares = f.shares.toFloat();
199
- f.raw.total = f.total.toFloat();
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 (!t.dividend.rate.getIsZero()) {
209
- if (t.dividend.native) {
210
- shares = t.dividend.native.divide(t.dividend.rate);
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 = t.dividend.amount.divide(t.dividend.rate);
222
+ shares = '';
213
223
  }
214
- } else {
215
- shares = '';
216
- }
217
224
 
218
- if (shares) {
219
- const rounded = shares.round(0);
225
+ if (shares) {
226
+ const rounded = shares.round(0);
220
227
 
221
- if (rounded.subtract(shares).absolute().getIsLessThan(0.01)) {
222
- shares = rounded;
223
- } else {
224
- shares = shares.round(2);
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.toFloat();
244
+ f.raw.native = getRawForDecimal(f.native);
237
245
  }
238
246
 
239
- f.raw.rate = f.rate.toFloat();
240
- f.raw.shares = f.shares.toFloat();
241
- f.raw.total = f.total.toFloat();
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.toFloat();
261
- f.raw.shares = f.shares.toFloat();
262
- f.raw.price = f.price.toFloat();
263
- f.raw.boughtSold = f.boughtSold.toFloat();
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.toFloat();
283
- f.raw.shares = f.shares.toFloat();
284
- f.raw.price = f.price.toFloat();
285
- f.raw.boughtSold = f.boughtSold.toFloat();
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.toFloat();
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.toFloat();
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.toFloat();
321
- f.raw.boughtSold = f.boughtSold.toFloat();
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.toFloat();
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.toFloat();
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.toFloat();
357
- f.raw.boughtSold = f.boughtSold.toFloat();
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.toFloat();
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.toFloat();
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.toFloat();
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.toFloat();
392
- f.raw.shares = f.shares.toFloat();
393
- f.raw.boughtSold = f.boughtSold.toFloat();
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.toFloat();
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.toFloat();
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.toFloat();
444
- f.raw.shares = f.shares.toFloat();
445
- f.raw.boughtSold = f.boughtSold.toFloat();
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.toFloat();
464
- f.raw.shares = f.shares.toFloat();
465
- f.raw.boughtSold = f.boughtSold.toFloat();
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)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-api-common",
3
- "version": "1.11.7",
3
+ "version": "1.11.8",
4
4
  "description": "Common code used by the Portfolio system",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",