@barchart/portfolio-client-js 1.4.1 → 1.4.4

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![AWS CodeBuild](https://codebuild.us-east-1.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiM0hCbTN3M253WGFUUUpFcnk1RFZOSTdUcUZnOWJxbXltaEMvQ3JrcENZeWI0cFRDWlFidks2VFhNR3lHeHlBUVdOSjk5TDU5MWd1bE1abGtoc3p1NjFrPSIsIml2UGFyYW1ldGVyU3BlYyI6InZMalFMNG9pZ3E1ekxJSEciLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)](https://github.com/barchart/portfolio-client-js)
4
4
 
5
- A JavaScript SDK for interfacing with the Barchart Portfolio System.
5
+ A JavaScript SDK for Barchart's Portfolio System.
6
6
 
7
7
  ### Development
8
8
 
@@ -12,7 +12,7 @@ The code is documented with [JSDoc](http://usejsdoc.org/). This will be used as
12
12
 
13
13
  #### Package Managers
14
14
 
15
- This library has been published as a *private* module to NPM as [@barchart/common-js](https://www.npmjs.com/package/@barchart/portfolio-client-js).
15
+ This library has been published as a *private* module to NPM as [@barchart/portfolio-client-js](https://www.npmjs.com/package/@barchart/portfolio-client-js).
16
16
 
17
17
  ```shell
18
18
  npm login
package/buildspec.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  version: 0.2
2
2
 
3
+ env:
4
+ secrets-manager:
5
+ NPM_READONLY_TOKEN: NPM_READONLY_TOKEN
6
+
3
7
  phases:
4
8
  install:
5
9
  runtime-versions:
@@ -7,6 +11,7 @@ phases:
7
11
 
8
12
  pre_build:
9
13
  commands:
14
+ - echo -e $'\n'//registry.npmjs.org/:_authToken=$NPM_READONLY_TOKEN >> .npmrc
10
15
  - npm install
11
16
 
12
17
  build:
@@ -1130,6 +1130,9 @@ module.exports = (() => {
1130
1130
  }).withQueryBuilder(qb => {
1131
1131
  qb.withVariableParameter('frames', 'frames', 'frames', true, frames => frames.map(f => f.code).join()).withVariableParameter('periods', 'periods', 'periods', true).withVariableParameter('start', 'start', 'start', true, x => x.format());
1132
1132
  }).withRequestInterceptor(requestInterceptorToUse).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withResponseInterceptor(responseInterceptorForPositionSummaryDeserialization).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
1133
+ this._readPositionsValuesEndpoint = EndpointBuilder.for('read-positions-values', 'read positions values').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(pb => {
1134
+ pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false).withLiteralParameter('values', 'values');
1135
+ }).withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE).withRequestInterceptor(requestInterceptorToUse).withResponseInterceptor(ResponseInterceptor.DATA).withErrorInterceptor(ErrorInterceptor.GENERAL).endpoint;
1133
1136
  this._readTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions').withVerb(VerbType.GET).withProtocol(protocolType).withHost(host).withPort(port).withPathBuilder(pb => {
1134
1137
  pb.withLiteralParameter('portfolios', 'portfolios').withVariableParameter('portfolio', 'portfolio', 'portfolio', false).withLiteralParameter('positions', 'positions').withVariableParameter('position', 'position', 'position', false).withLiteralParameter('transactions', 'transactions');
1135
1138
  }).withQueryBuilder(qb => {
@@ -1374,6 +1377,108 @@ module.exports = (() => {
1374
1377
  scheduleCheck(2500);
1375
1378
  });
1376
1379
  }
1380
+ /**
1381
+ * Returns a promise which resolves as soon as the position's calculating finishes.
1382
+ *
1383
+ * @public
1384
+ * @param {String} portfolio
1385
+ * @param {String} position
1386
+ * @returns {Array}
1387
+ */
1388
+
1389
+
1390
+ observePositionCalculating(portfolio, position) {
1391
+ let disposed = false;
1392
+ const query = promise.build(resolveCallback => {
1393
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
1394
+ assert.argumentIsRequired(position, 'position', String);
1395
+
1396
+ const scheduleCheck = delay => {
1397
+ if (disposed) {
1398
+ return;
1399
+ }
1400
+
1401
+ setTimeout(() => {
1402
+ Gateway.invoke(this._readPositionsEndpoint, {
1403
+ portfolio: portfolio,
1404
+ position: position,
1405
+ includePreviousPrice: false
1406
+ }).then(positions => {
1407
+ const p = positions.find(p => p.position === position);
1408
+
1409
+ if (is.object(p)) {
1410
+ if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
1411
+ scheduleCheck(delay + 1000);
1412
+ } else {
1413
+ resolveCallback(p);
1414
+ }
1415
+ } else {
1416
+ resolveCallback(null);
1417
+ }
1418
+ }).catch(e => {
1419
+ scheduleCheck(delay + 5000);
1420
+ });
1421
+ }, delay);
1422
+ };
1423
+
1424
+ scheduleCheck(2500);
1425
+ });
1426
+
1427
+ const dispose = () => {
1428
+ disposed = true;
1429
+ };
1430
+
1431
+ return [query, dispose];
1432
+ }
1433
+ /**
1434
+ * Returns a promise which resolves as soon as the portfolio calculating finishes.
1435
+ *
1436
+ * @public
1437
+ * @param {String} portfolio
1438
+ * @returns {Array}
1439
+ */
1440
+
1441
+
1442
+ observePortfolioCalculating(portfolio) {
1443
+ let disposed = false;
1444
+ const query = promise.build(resolveCallback => {
1445
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
1446
+
1447
+ const scheduleCheck = delay => {
1448
+ if (disposed) {
1449
+ return;
1450
+ }
1451
+
1452
+ setTimeout(() => {
1453
+ Gateway.invoke(this._readPortfoliosEndpoint, {
1454
+ portfolio: portfolio
1455
+ }).then(portfolios => {
1456
+ const p = portfolios[0];
1457
+
1458
+ if (is.object(p)) {
1459
+ if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
1460
+ scheduleCheck(delay + 1000);
1461
+ } else {
1462
+ resolveCallback(p);
1463
+ }
1464
+ } else {
1465
+ resolveCallback(null);
1466
+ }
1467
+ }).catch(e => {
1468
+ scheduleCheck(delay + 5000);
1469
+ });
1470
+ }, delay);
1471
+ };
1472
+
1473
+ scheduleCheck(2500);
1474
+ });
1475
+
1476
+ const dispose = () => {
1477
+ disposed = true;
1478
+ };
1479
+
1480
+ return [query, dispose];
1481
+ }
1377
1482
  /**
1378
1483
  * Retrieves positions for a user, a user's portfolio, or a single position.
1379
1484
  *
@@ -1443,6 +1548,27 @@ module.exports = (() => {
1443
1548
  return Gateway.invoke(this._readPositionSummariesEndpoint, payload);
1444
1549
  });
1445
1550
  }
1551
+ /**
1552
+ * Retrieves positions values for the entire portfolio or single position.
1553
+ *
1554
+ * @public
1555
+ * @param {String} portfolio
1556
+ * @param {String=} position
1557
+ * @returns {Promise<Object[]>}
1558
+ */
1559
+
1560
+
1561
+ readPositionsValues(portfolio, position) {
1562
+ return Promise.resolve().then(() => {
1563
+ checkStart.call(this);
1564
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
1565
+ assert.argumentIsOptional(position, 'position', String);
1566
+ const payload = {};
1567
+ payload.portfolio = portfolio;
1568
+ payload.position = position || '*';
1569
+ return Gateway.invoke(this._readPositionsValuesEndpoint, payload);
1570
+ });
1571
+ }
1446
1572
  /**
1447
1573
  * Deletes a position.
1448
1574
  *
@@ -2347,7 +2473,7 @@ module.exports = (() => {
2347
2473
  return {
2348
2474
  JwtGateway: JwtGateway,
2349
2475
  PortfolioGateway: PortfolioGateway,
2350
- version: '1.4.1'
2476
+ version: '1.4.4'
2351
2477
  };
2352
2478
  })();
2353
2479
 
@@ -8033,6 +8159,18 @@ module.exports = (() => {
8033
8159
  return this.number(candidate) && candidate < 0;
8034
8160
  },
8035
8161
 
8162
+ /**
8163
+ * Returns true if the argument is iterable.
8164
+ *
8165
+ * @static
8166
+ * @public
8167
+ * @param {*} candidate
8168
+ * @returns {boolean}
8169
+ */
8170
+ iterable(candidate) {
8171
+ return !this.null(candidate) && !this.undefined(candidate) && this.fn(candidate[Symbol.iterator]);
8172
+ },
8173
+
8036
8174
  /**
8037
8175
  * Returns true if the argument is a string.
8038
8176
  *
@@ -11159,6 +11297,7 @@ module.exports = (() => {
11159
11297
  .withField('name', DataType.STRING)
11160
11298
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
11161
11299
  .withField('dates.create', DataType.DAY)
11300
+ .withField('dates.access', DataType.TIMESTAMP, true)
11162
11301
  .withField('defaults.cash', DataType.BOOLEAN, true)
11163
11302
  .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
11164
11303
  .withField('defaults.reinvest', DataType.BOOLEAN, true)
@@ -11169,6 +11308,7 @@ module.exports = (() => {
11169
11308
  .withField('legacy.warnings', DataType.NUMBER, true)
11170
11309
  .withField('legacy.drops', DataType.NUMBER, true)
11171
11310
  .withField('miscellany', DataType.AD_HOC, true)
11311
+ .withField('system.calculate.processors', DataType.NUMBER, true)
11172
11312
  .withField('system.sequence', DataType.NUMBER)
11173
11313
  .withField('system.version', DataType.STRING)
11174
11314
  .withField('system.timestamp', DataType.TIMESTAMP)
@@ -11181,6 +11321,7 @@ module.exports = (() => {
11181
11321
  .withField('name', DataType.STRING)
11182
11322
  .withField('timezone', DataType.forEnum(Timezones, 'Timezone'))
11183
11323
  .withField('dates.create', DataType.DAY)
11324
+ .withField('dates.access', DataType.TIMESTAMP, true)
11184
11325
  .withField('defaults.cash', DataType.BOOLEAN, true)
11185
11326
  .withField('defaults.currency', DataType.forEnum(Currency, 'Currency'))
11186
11327
  .withField('defaults.reinvest', DataType.BOOLEAN, true)
@@ -11191,6 +11332,7 @@ module.exports = (() => {
11191
11332
  .withField('legacy.warnings', DataType.NUMBER, true)
11192
11333
  .withField('legacy.drops', DataType.NUMBER, true)
11193
11334
  .withField('miscellany', DataType.AD_HOC, true)
11335
+ .withField('system.calculate.processors', DataType.NUMBER, true)
11194
11336
  .schema
11195
11337
  );
11196
11338
 
@@ -11332,6 +11474,7 @@ module.exports = (() => {
11332
11474
  .withField('legacy.position', DataType.STRING, true)
11333
11475
  .withField('system.version', DataType.NUMBER, true)
11334
11476
  .withField('system.locked', DataType.BOOLEAN, true)
11477
+ .withField('system.calculate.processors', DataType.NUMBER, true)
11335
11478
  .withField('root', DataType.STRING, true)
11336
11479
  .schema
11337
11480
  );
@@ -11362,6 +11505,7 @@ module.exports = (() => {
11362
11505
  .withField('snapshot.income', DataType.DECIMAL)
11363
11506
  .withField('snapshot.value', DataType.DECIMAL)
11364
11507
  .withField('system.locked', DataType.BOOLEAN, true)
11508
+ .withField('system.calculate.processors', DataType.NUMBER, true)
11365
11509
  .withField('previous', DataType.NUMBER, true)
11366
11510
  .schema
11367
11511
  );
@@ -198,6 +198,24 @@ module.exports = (() => {
198
198
  .withErrorInterceptor(ErrorInterceptor.GENERAL)
199
199
  .endpoint;
200
200
 
201
+ this._readPositionsValuesEndpoint = EndpointBuilder.for('read-positions-values', 'read positions values')
202
+ .withVerb(VerbType.GET)
203
+ .withProtocol(protocolType)
204
+ .withHost(host)
205
+ .withPort(port)
206
+ .withPathBuilder((pb) => {
207
+ pb.withLiteralParameter('portfolios', 'portfolios')
208
+ .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
209
+ .withLiteralParameter('positions', 'positions')
210
+ .withVariableParameter('position', 'position', 'position', false)
211
+ .withLiteralParameter('values', 'values');
212
+ })
213
+ .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
214
+ .withRequestInterceptor(requestInterceptorToUse)
215
+ .withResponseInterceptor(ResponseInterceptor.DATA)
216
+ .withErrorInterceptor(ErrorInterceptor.GENERAL)
217
+ .endpoint;
218
+
201
219
  this._readTransactionsEndpoint = EndpointBuilder.for('read-transactions', 'read transactions')
202
220
  .withVerb(VerbType.GET)
203
221
  .withProtocol(protocolType)
@@ -579,6 +597,104 @@ module.exports = (() => {
579
597
  });
580
598
  }
581
599
 
600
+ /**
601
+ * Returns a promise which resolves as soon as the position's calculating finishes.
602
+ *
603
+ * @public
604
+ * @param {String} portfolio
605
+ * @param {String} position
606
+ * @returns {Array}
607
+ */
608
+ observePositionCalculating(portfolio, position) {
609
+ let disposed = false;
610
+
611
+ const query = promise.build((resolveCallback) => {
612
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
613
+ assert.argumentIsRequired(position, 'position', String);
614
+
615
+ const scheduleCheck = (delay) => {
616
+ if (disposed) {
617
+ return;
618
+ }
619
+
620
+ setTimeout(() => {
621
+ Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
622
+ .then((positions) => {
623
+ const p = positions.find(p => p.position === position);
624
+
625
+ if (is.object(p)) {
626
+ if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
627
+ scheduleCheck(delay + 1000);
628
+ } else {
629
+ resolveCallback(p);
630
+ }
631
+ } else {
632
+ resolveCallback(null);
633
+ }
634
+ }).catch((e) => {
635
+ scheduleCheck(delay + 5000);
636
+ });
637
+ }, delay);
638
+ };
639
+
640
+ scheduleCheck(2500);
641
+ });
642
+
643
+ const dispose = () => {
644
+ disposed = true;
645
+ };
646
+
647
+ return [ query, dispose ];
648
+ }
649
+
650
+ /**
651
+ * Returns a promise which resolves as soon as the portfolio calculating finishes.
652
+ *
653
+ * @public
654
+ * @param {String} portfolio
655
+ * @returns {Array}
656
+ */
657
+ observePortfolioCalculating(portfolio) {
658
+ let disposed = false;
659
+
660
+ const query = promise.build((resolveCallback) => {
661
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
662
+
663
+ const scheduleCheck = (delay) => {
664
+ if (disposed) {
665
+ return;
666
+ }
667
+
668
+ setTimeout(() => {
669
+ Gateway.invoke(this._readPortfoliosEndpoint, { portfolio: portfolio })
670
+ .then((portfolios) => {
671
+ const p = portfolios[0];
672
+
673
+ if (is.object(p)) {
674
+ if (is.object(p.system) && is.object(p.system.calculate) && is.number(p.system.calculate.processors) && p.system.calculate.processors > 0) {
675
+ scheduleCheck(delay + 1000);
676
+ } else {
677
+ resolveCallback(p);
678
+ }
679
+ } else {
680
+ resolveCallback(null);
681
+ }
682
+ }).catch((e) => {
683
+ scheduleCheck(delay + 5000);
684
+ });
685
+ }, delay);
686
+ };
687
+
688
+ scheduleCheck(2500);
689
+ });
690
+
691
+ const dispose = () => {
692
+ disposed = true;
693
+ };
694
+
695
+ return [ query, dispose ];
696
+ }
697
+
582
698
  /**
583
699
  * Retrieves positions for a user, a user's portfolio, or a single position.
584
700
  *
@@ -650,6 +766,31 @@ module.exports = (() => {
650
766
  });
651
767
  }
652
768
 
769
+ /**
770
+ * Retrieves positions values for the entire portfolio or single position.
771
+ *
772
+ * @public
773
+ * @param {String} portfolio
774
+ * @param {String=} position
775
+ * @returns {Promise<Object[]>}
776
+ */
777
+ readPositionsValues(portfolio, position) {
778
+ return Promise.resolve()
779
+ .then(() => {
780
+ checkStart.call(this);
781
+
782
+ assert.argumentIsRequired(portfolio, 'portfolio', String);
783
+ assert.argumentIsOptional(position, 'position', String);
784
+
785
+ const payload = { };
786
+
787
+ payload.portfolio = portfolio;
788
+ payload.position = position || '*';
789
+
790
+ return Gateway.invoke(this._readPositionsValuesEndpoint, payload);
791
+ });
792
+ }
793
+
653
794
  /**
654
795
  * Deletes a position.
655
796
  *
package/lib/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = (() => {
7
7
  return {
8
8
  JwtGateway: JwtGateway,
9
9
  PortfolioGateway: PortfolioGateway,
10
- version: '1.4.1'
10
+ version: '1.4.4'
11
11
  };
12
12
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-client-js",
3
- "version": "1.4.1",
3
+ "version": "1.4.4",
4
4
  "description": "JavaScript library for interfacing with Barchart's Portfolio API",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -18,7 +18,7 @@
18
18
  "Barchart",
19
19
  "JavaScript",
20
20
  "Client",
21
- "API"
21
+ "SDK"
22
22
  ],
23
23
  "dependencies": {
24
24
  "@barchart/common-js": "^3.5.1",