@barchart/portfolio-client-js 2.0.1 → 3.2.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.
File without changes
@@ -0,0 +1,3 @@
1
+ **New Features**
2
+
3
+ * Added ```JwtProvider.forAdmin``` function.
@@ -0,0 +1,3 @@
1
+ **New Features**
2
+
3
+ * Added ability to query positions by symbol. See the ```PortfolioGateway.``` function.
@@ -0,0 +1,59 @@
1
+ const PortfolioGateway = require('./../../lib/gateway/PortfolioGateway'),
2
+ JwtProvider = require('./../../lib/security/JwtProvider');
3
+
4
+ console.info(`Example: Node.js example script started.`);
5
+
6
+ let portfolioGateway = null;
7
+
8
+ process.on('SIGINT', () => {
9
+ console.info('Example: Processing SIGINT');
10
+
11
+ if (portfolioGateway !== null) {
12
+ portfolioGateway.dispose();
13
+ }
14
+
15
+ process.exit();
16
+ });
17
+
18
+ process.on('unhandledRejection', (error) => {
19
+ console.error('Unhandled Promise Rejection', error);
20
+ });
21
+
22
+ process.on('uncaughtException', (error) => {
23
+ console.error('Unhandled Error', error);
24
+ });
25
+
26
+ const userId = process.argv[2];
27
+ const contextId = process.argv[3];
28
+
29
+ const symbol = process.argv[4];
30
+
31
+ if (typeof(userId) !== 'string' || userId.length === 0) {
32
+ console.error('A user identifier must be specified. Usage example: "node example.js user-123"');
33
+ process.exit();
34
+ }
35
+
36
+ console.info(`Example: Initializing PortfolioGateway, connecting to test environment as [ ${userId} ] [ ${contextId} ].`);
37
+
38
+ PortfolioGateway.forDevelopment(JwtProvider.forDevelopment(userId, contextId))
39
+ .then((gateway) => {
40
+ portfolioGateway = gateway;
41
+
42
+ console.info(`Example: Retrieving portfolio(s) for [ ${userId} ] [ ${contextId} ].`);
43
+
44
+ return portfolioGateway.readPortfolios()
45
+ .then((portfolios) => {
46
+ console.info(`Example: Retrieved [ ${portfolios.length} ] portfolio(s) for [ ${userId} ] [ ${contextId} ].`);
47
+ });
48
+ }).then(() => {
49
+ console.info(`Example: Querying positions(s) for [ ${userId} ] [ ${contextId} ] [ ${symbol} ].`);
50
+
51
+ return portfolioGateway.queryPositionsForSymbol(symbol)
52
+ .then((portfolios) => {
53
+ console.info(`Example: Retrieved [ ${portfolios.length} ] portion(s) for [ ${userId} ] [ ${contextId} ] [ ${symbol} ].`);
54
+ });
55
+ }).then(() => {
56
+ portfolioGateway.dispose();
57
+
58
+ console.info(`Example: Node.js example script completed normally.`);
59
+ });
@@ -84,7 +84,8 @@ module.exports = (() => {
84
84
  .withHost(host)
85
85
  .withPort(port)
86
86
  .withPathBuilder((pb) => {
87
- pb.withLiteralParameter('portfolios', 'portfolios')
87
+ pb.withLiteralParameter('version', 'v1')
88
+ .withLiteralParameter('portfolios', 'portfolios')
88
89
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
89
90
  })
90
91
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
@@ -99,7 +100,8 @@ module.exports = (() => {
99
100
  .withHost(host)
100
101
  .withPort(port)
101
102
  .withPathBuilder((pb) => {
102
- pb.withLiteralParameter('portfolios', 'portfolios');
103
+ pb.withLiteralParameter('version', 'v1')
104
+ .withLiteralParameter('portfolios', 'portfolios');
103
105
  })
104
106
  .withBody('portfolio')
105
107
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
@@ -115,7 +117,8 @@ module.exports = (() => {
115
117
  .withHost(host)
116
118
  .withPort(port)
117
119
  .withPathBuilder((pb) => {
118
- pb.withLiteralParameter('portfolios', 'portfolios')
120
+ pb.withLiteralParameter('version', 'v1')
121
+ .withLiteralParameter('portfolios', 'portfolios')
119
122
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
120
123
  })
121
124
  .withBody('portfolio')
@@ -132,7 +135,8 @@ module.exports = (() => {
132
135
  .withHost(host)
133
136
  .withPort(port)
134
137
  .withPathBuilder((pb) => {
135
- pb.withLiteralParameter('portfolios', 'portfolios')
138
+ pb.withLiteralParameter('version', 'v1')
139
+ .withLiteralParameter('portfolios', 'portfolios')
136
140
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false);
137
141
  })
138
142
  .withRequestInterceptor(requestInterceptor)
@@ -145,13 +149,16 @@ module.exports = (() => {
145
149
  .withHost(host)
146
150
  .withPort(port)
147
151
  .withPathBuilder((pb) => {
148
- pb.withLiteralParameter('portfolios', 'portfolios')
152
+ pb.withLiteralParameter('version', 'v1')
153
+ .withLiteralParameter('portfolios', 'portfolios')
149
154
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
150
155
  .withLiteralParameter('positions', 'positions')
151
156
  .withVariableParameter('position', 'position', 'position', false);
152
157
  })
153
158
  .withQueryBuilder((qb) => {
154
- qb.withVariableParameter('includePreviousPrice', 'includePreviousPrice', 'includePreviousPrice', true);
159
+ qb.withVariableParameter('open', 'open', 'open', true)
160
+ .withVariableParameter('symbol', 'symbol', 'symbol', true)
161
+ .withVariableParameter('includePreviousPrice', 'includePreviousPrice', 'includePreviousPrice', true);
155
162
  })
156
163
  .withRequestInterceptor(requestInterceptor)
157
164
  .withRequestInterceptor(RequestInterceptor.PLAIN_TEXT_RESPONSE)
@@ -165,7 +172,8 @@ module.exports = (() => {
165
172
  .withHost(host)
166
173
  .withPort(port)
167
174
  .withPathBuilder((pb) => {
168
- pb.withLiteralParameter('portfolios', 'portfolios')
175
+ pb.withLiteralParameter('version', 'v1')
176
+ .withLiteralParameter('portfolios', 'portfolios')
169
177
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
170
178
  .withLiteralParameter('positions', 'positions')
171
179
  .withVariableParameter('position', 'position', 'position', false);
@@ -183,7 +191,8 @@ module.exports = (() => {
183
191
  .withHost(host)
184
192
  .withPort(port)
185
193
  .withPathBuilder((pb) => {
186
- pb.withLiteralParameter('portfolios', 'portfolios')
194
+ pb.withLiteralParameter('version', 'v1')
195
+ .withLiteralParameter('portfolios', 'portfolios')
187
196
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
188
197
  .withLiteralParameter('positions', 'positions')
189
198
  .withVariableParameter('position', 'position', 'position', false);
@@ -200,7 +209,8 @@ module.exports = (() => {
200
209
  .withHost(host)
201
210
  .withPort(port)
202
211
  .withPathBuilder((pb) => {
203
- pb.withLiteralParameter('portfolios', 'portfolios')
212
+ pb.withLiteralParameter('version', 'v1')
213
+ .withLiteralParameter('portfolios', 'portfolios')
204
214
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
205
215
  .withLiteralParameter('summaries', 'summaries')
206
216
  .withVariableParameter('position', 'position', 'position', false);
@@ -222,7 +232,8 @@ module.exports = (() => {
222
232
  .withHost(host)
223
233
  .withPort(port)
224
234
  .withPathBuilder((pb) => {
225
- pb.withLiteralParameter('portfolios', 'portfolios')
235
+ pb.withLiteralParameter('version', 'v1')
236
+ .withLiteralParameter('portfolios', 'portfolios')
226
237
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
227
238
  .withLiteralParameter('positions', 'positions')
228
239
  .withVariableParameter('position', 'position', 'position', false)
@@ -240,7 +251,8 @@ module.exports = (() => {
240
251
  .withHost(host)
241
252
  .withPort(port)
242
253
  .withPathBuilder((pb) => {
243
- pb.withLiteralParameter('portfolios', 'portfolios')
254
+ pb.withLiteralParameter('version', 'v1')
255
+ .withLiteralParameter('portfolios', 'portfolios')
244
256
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
245
257
  .withLiteralParameter('positions', 'positions')
246
258
  .withVariableParameter('position', 'position', 'position', false)
@@ -261,7 +273,8 @@ module.exports = (() => {
261
273
  .withHost(host)
262
274
  .withPort(port)
263
275
  .withPathBuilder((pb) => {
264
- pb.withLiteralParameter('portfolios', 'portfolios')
276
+ pb.withLiteralParameter('version', 'v1')
277
+ .withLiteralParameter('portfolios', 'portfolios')
265
278
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
266
279
  .withLiteralParameter('positions', 'positions')
267
280
  .withVariableParameter('position', 'position', 'position', false)
@@ -282,7 +295,8 @@ module.exports = (() => {
282
295
  .withHost(host)
283
296
  .withPort(port)
284
297
  .withPathBuilder((pb) => {
285
- pb.withLiteralParameter('portfolios', 'portfolios')
298
+ pb.withLiteralParameter('version', 'v1')
299
+ .withLiteralParameter('portfolios', 'portfolios')
286
300
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
287
301
  .withLiteralParameter('positions', 'positions')
288
302
  .withVariableParameter('position', 'position', 'position', false)
@@ -304,7 +318,8 @@ module.exports = (() => {
304
318
  .withHost(host)
305
319
  .withPort(port)
306
320
  .withPathBuilder((pb) => {
307
- pb.withLiteralParameter('portfolios', 'portfolios')
321
+ pb.withLiteralParameter('version', 'v1')
322
+ .withLiteralParameter('portfolios', 'portfolios')
308
323
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
309
324
  .withLiteralParameter('positions', 'positions')
310
325
  .withVariableParameter('position', 'position', 'position', false)
@@ -327,7 +342,8 @@ module.exports = (() => {
327
342
  .withHost(host)
328
343
  .withPort(port)
329
344
  .withPathBuilder((pb) => {
330
- pb.withLiteralParameter('portfolios', 'portfolios')
345
+ pb.withLiteralParameter('version', 'v1')
346
+ .withLiteralParameter('portfolios', 'portfolios')
331
347
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
332
348
  .withLiteralParameter('positions', 'positions')
333
349
  .withVariableParameter('position', 'position', 'position', true)
@@ -353,7 +369,8 @@ module.exports = (() => {
353
369
  .withHost(host)
354
370
  .withPort(port)
355
371
  .withPathBuilder((pb) => {
356
- pb.withLiteralParameter('portfolios', 'portfolios')
372
+ pb.withLiteralParameter('version', 'v1')
373
+ .withLiteralParameter('portfolios', 'portfolios')
357
374
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
358
375
  .withLiteralParameter('wealthscope', 'wealthscope')
359
376
  .withLiteralParameter('token', 'token');
@@ -370,7 +387,8 @@ module.exports = (() => {
370
387
  .withHost(host)
371
388
  .withPort(port)
372
389
  .withPathBuilder((pb) => {
373
- pb.withLiteralParameter('portfolios', 'portfolios')
390
+ pb.withLiteralParameter('version', 'v1')
391
+ .withLiteralParameter('portfolios', 'portfolios')
374
392
  .withVariableParameter('portfolio', 'portfolio', 'portfolio', false)
375
393
  .withLiteralParameter('reports', 'reports')
376
394
  .withLiteralParameter('brokerage', 'brokerage')
@@ -391,7 +409,8 @@ module.exports = (() => {
391
409
  .withHost(host)
392
410
  .withPort(port)
393
411
  .withPathBuilder((pb) => {
394
- pb.withLiteralParameter('system', 'system')
412
+ pb.withLiteralParameter('version', 'v1')
413
+ .withLiteralParameter('system', 'system')
395
414
  .withLiteralParameter('version', 'version');
396
415
  })
397
416
  .withRequestInterceptor(requestInterceptor)
@@ -543,7 +562,7 @@ module.exports = (() => {
543
562
  }
544
563
 
545
564
  /**
546
- * Retrieves positions for a user, a user's portfolio, or a single position.
565
+ * Retrieves all positions for a user, a user's portfolio, or a single position.
547
566
  *
548
567
  * @public
549
568
  * @param {String=} portfolio
@@ -564,6 +583,38 @@ module.exports = (() => {
564
583
  });
565
584
  }
566
585
 
586
+ /**
587
+ * Queries positions.
588
+ *
589
+ * @public
590
+ * @param {String} symbol
591
+ * @param {Boolean=} open
592
+ * @param {PositionSchema=} schema
593
+ * @returns {Promise<Position[]>}
594
+ */
595
+ queryPositionsForSymbol(symbol, open, schema) {
596
+ return Promise.resolve()
597
+ .then(() => {
598
+ checkStart.call(this);
599
+
600
+ assert.argumentIsRequired(symbol, 'symbol', String);
601
+ assert.argumentIsOptional(open, 'open', Boolean);
602
+
603
+ const payload = { };
604
+
605
+ payload.portfolio = '*';
606
+ payload.position = '*';
607
+
608
+ payload.symbol = symbol;
609
+
610
+ if (open) {
611
+ payload.open = open;
612
+ }
613
+
614
+ return Gateway.invoke(this._readPositionsEndpoint, payload);
615
+ });
616
+ }
617
+
567
618
  /**
568
619
  * Updates a position.
569
620
  *
@@ -1073,19 +1124,6 @@ module.exports = (() => {
1073
1124
  });
1074
1125
  }
1075
1126
 
1076
- /**
1077
- * Returns current API version of portfolio.
1078
- *
1079
- * @public
1080
- * @returns {Promise<Object>}
1081
- */
1082
- readVersion() {
1083
- return Promise.resolve()
1084
- .then(() => {
1085
- return Gateway.invoke(this._readVersionEndpoint);
1086
- });
1087
- }
1088
-
1089
1127
  /**
1090
1128
  * Generates a URL suitable for downloading a brokerage report (as a PDF).
1091
1129
  *
@@ -1110,6 +1148,33 @@ module.exports = (() => {
1110
1148
  });
1111
1149
  }
1112
1150
 
1151
+ /**
1152
+ * Queries existing positions for a specific symbol.
1153
+ *
1154
+ * @public
1155
+ * @param {String} symbol
1156
+ * @returns {Promise<Array>}
1157
+ */
1158
+ querySymbol(symbol) {
1159
+ return Promise.resolve()
1160
+ .then(() => {
1161
+ return [ ];
1162
+ });
1163
+ }
1164
+
1165
+ /**
1166
+ * Returns current API version of portfolio.
1167
+ *
1168
+ * @public
1169
+ * @returns {Promise<Object>}
1170
+ */
1171
+ readVersion() {
1172
+ return Promise.resolve()
1173
+ .then(() => {
1174
+ return Gateway.invoke(this._readVersionEndpoint);
1175
+ });
1176
+ }
1177
+
1113
1178
  /**
1114
1179
  * Creates and starts a new {@link PortfolioGateway} for use in the public test environment.
1115
1180
  *
package/lib/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = (() => {
7
7
  return {
8
8
  JwtGateway: JwtGateway,
9
9
  PortfolioGateway: PortfolioGateway,
10
- version: '2.0.1'
10
+ version: '3.2.0'
11
11
  };
12
12
  })();
@@ -136,6 +136,22 @@ module.exports = (() => {
136
136
  return getJwtProviderForImpersonation(Configuration.getJwtImpersonationHost, 'dev', userId, contextId, permissions);
137
137
  }
138
138
 
139
+ /**
140
+ * Builds a {@link JwtProvider} which will generate tokens impersonating the specified
141
+ * user. The "admin" environment is for Barchart use only and access is restricted
142
+ * to Barchart's internal network.
143
+ *
144
+ * @public
145
+ * @static
146
+ * @param {String} userId - The user identifier to impersonate.
147
+ * @param {String} contextId - The context identifier of the user to impersonate.
148
+ * @param {String=} permissions - The desired permission level.
149
+ * @returns {JwtProvider}
150
+ */
151
+ static forAdmin(userId, contextId, permissions) {
152
+ return getJwtProviderForImpersonation(Configuration.getJwtImpersonationHost, 'admin', userId, contextId, permissions);
153
+ }
154
+
139
155
  _onDispose() {
140
156
  this._scheduler.dispose();
141
157
  this._scheduler = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barchart/portfolio-client-js",
3
- "version": "2.0.1",
3
+ "version": "3.2.0",
4
4
  "description": "JavaScript library for interfacing with Barchart's Portfolio API",
5
5
  "author": {
6
6
  "name": "Bryan Ingle",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "@barchart/common-js": "^3.15.0",
25
- "@barchart/portfolio-api-common": "^1.4.4"
25
+ "@barchart/portfolio-api-common": "^1.5.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@babel/core": "^7.11.1",