@barchart/portfolio-client-js 1.2.19 → 1.2.20

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.
@@ -2,7 +2,9 @@ const assert = require('@barchart/common-js/lang/assert'),
2
2
  Day = require('@barchart/common-js/lang/Day'),
3
3
  Disposable = require('@barchart/common-js/lang/Disposable'),
4
4
  Enum = require('@barchart/common-js/lang/Enum'),
5
- is = require('@barchart/common-js/lang/is');
5
+ is = require('@barchart/common-js/lang/is'),
6
+ promise = require('@barchart/common-js/lang/promise'),
7
+ Scheduler = require('@barchart/common-js/timing/Sceduler');
6
8
 
7
9
  const TransactionType = require('@barchart/portfolio-api-common/lib/data/TransactionType');
8
10
 
@@ -57,6 +59,8 @@ module.exports = (() => {
57
59
  requestInterceptorToUse = RequestInterceptor.EMPTY;
58
60
  }
59
61
 
62
+ this._positionObservers = { };
63
+
60
64
  this._readPortfoliosEndpoint = EndpointBuilder.for('read-portfolios', 'read portfolios')
61
65
  .withVerb(VerbType.GET)
62
66
  .withProtocol(protocolType)
@@ -330,7 +334,7 @@ module.exports = (() => {
330
334
  * Returns a description of the environment (e.g. development or production).
331
335
  *
332
336
  * @public
333
- * @return {*}
337
+ * @returns {*}
334
338
  */
335
339
  get environment() {
336
340
  return this._environment;
@@ -368,7 +372,7 @@ module.exports = (() => {
368
372
  *
369
373
  * @public
370
374
  * @param {String=} portfolio
371
- * @return {Promise.<Portfolio[]>}
375
+ * @returns {Promise.<Portfolio[]>}
372
376
  */
373
377
  readPortfolios(portfolio) {
374
378
  return Promise.resolve()
@@ -386,7 +390,7 @@ module.exports = (() => {
386
390
  *
387
391
  * @public
388
392
  * @param {Object} portfolio
389
- * @return {Promise.<Portfolio>}
393
+ * @returns {Promise.<Portfolio>}
390
394
  */
391
395
  createPortfolio(portfolio) {
392
396
  return Promise.resolve()
@@ -404,7 +408,7 @@ module.exports = (() => {
404
408
  *
405
409
  * @public
406
410
  * @param {Object} portfolio
407
- * @return {Promise.<Portfolio>}
411
+ * @returns {Promise.<Portfolio>}
408
412
  */
409
413
  importPortfolio(portfolio, transactions) {
410
414
  return Promise.resolve()
@@ -423,7 +427,7 @@ module.exports = (() => {
423
427
  *
424
428
  * @public
425
429
  * @param {Object} portfolio
426
- * @return {Promise.<Portfolio>}
430
+ * @returns {Promise.<Portfolio>}
427
431
  */
428
432
  updatePortfolio(portfolio) {
429
433
  return Promise.resolve()
@@ -441,7 +445,7 @@ module.exports = (() => {
441
445
  *
442
446
  * @public
443
447
  * @param {String} portfolio - ID of the portfolio to update
444
- * @return {Promise.<Portfolio>}
448
+ * @returns {Promise.<Portfolio>}
445
449
  */
446
450
  deletePortfolio(portfolio) {
447
451
  return Promise.resolve()
@@ -481,7 +485,7 @@ module.exports = (() => {
481
485
  *
482
486
  * @public
483
487
  * @param {Object} position
484
- * @return {Promise.<Position>}
488
+ * @returns {Promise.<Position>}
485
489
  */
486
490
  updatePosition(position) {
487
491
  return Promise.resolve()
@@ -494,6 +498,45 @@ module.exports = (() => {
494
498
  });
495
499
  }
496
500
 
501
+ /**
502
+ * Returns a promise which resolves as soon as the position's lock status
503
+ * changes to false.
504
+ *
505
+ * @public
506
+ * @param {String} portfolio
507
+ * @param {String} position
508
+ * @returns {Promise}
509
+ */
510
+ observePosition(portfolio, position) {
511
+ return promise.build((resolveCallback, rejectCallback) => {
512
+ assert.argumentIsOptional(portfolio, 'portfolio', String);
513
+ assert.argumentIsOptional(position, 'position', String);
514
+
515
+ const scheduleCheck = (delay) => {
516
+ setTimeout(() => {
517
+ return Gateway.invoke(this._readPositionsEndpoint, { portfolio: portfolio, position: position, includePreviousPrice: false })
518
+ .then((positions) => {
519
+ const p = positions.find(p => p.position === position);
520
+
521
+ if (is.object(p)) {
522
+ if (is.object(p.system) && is.object(p.system) && is.boolean(p.system.locked)) {
523
+ scheduleCheck(5000);
524
+ } else {
525
+ resolveCallback(p);
526
+ }
527
+ } else {
528
+ resolveCallback(null);
529
+ }
530
+ }).catch((e) => {
531
+ scheduleCheck(delay + 5000);
532
+ });
533
+ }, delay);
534
+ };
535
+
536
+ scheduleCheck(2500);
537
+ });
538
+ }
539
+
497
540
  /**
498
541
  * Retrieves positions for a user, a user's portfolio, or a single position.
499
542
  *
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.2.19'
10
+ version: '1.2.20'
11
11
  };
12
12
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-client-js",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "description": "JavaScript library for interfacing with Barchart's Portfolio API",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",