laplace-api 1.2.1 → 1.3.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.
package/package.json
CHANGED
|
@@ -29,6 +29,8 @@ export interface StockStats {
|
|
|
29
29
|
dailyChange: number;
|
|
30
30
|
dayLow: number;
|
|
31
31
|
dayHigh: number;
|
|
32
|
+
lowerPriceLimit: number;
|
|
33
|
+
upperPriceLimit: number;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export enum StockStatsKey {
|
|
@@ -67,11 +69,10 @@ export class FinancialFundamentalsClient extends Client {
|
|
|
67
69
|
});
|
|
68
70
|
}
|
|
69
71
|
|
|
70
|
-
async getStockStats(symbols: string[],
|
|
71
|
-
const url = new URL(`${this['baseUrl']}/api/
|
|
72
|
+
async getStockStats(symbols: string[], region: Region): Promise<StockStats[]> {
|
|
73
|
+
const url = new URL(`${this['baseUrl']}/api/v2/stock/stats`);
|
|
72
74
|
url.searchParams.append('symbols', symbols.join(','));
|
|
73
75
|
url.searchParams.append('region', region);
|
|
74
|
-
url.searchParams.append('keys', keys.join(','));
|
|
75
76
|
|
|
76
77
|
return this.sendRequest<StockStats[]>({
|
|
77
78
|
method: 'GET',
|
|
@@ -244,10 +244,12 @@ export class LivePriceWebSocketClient {
|
|
|
244
244
|
this.reconnectTimeout = setTimeout(async () => {
|
|
245
245
|
try {
|
|
246
246
|
await this.connect(url);
|
|
247
|
+
|
|
248
|
+
this.isClosed = false
|
|
249
|
+
|
|
247
250
|
const activeSymbols = this.getActiveSymbols();
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
+
this.addSymbols(activeSymbols);
|
|
252
|
+
|
|
251
253
|
if (this.reconnectTimeout) {
|
|
252
254
|
clearTimeout(this.reconnectTimeout);
|
|
253
255
|
this.reconnectTimeout = null;
|
|
@@ -273,18 +275,14 @@ export class LivePriceWebSocketClient {
|
|
|
273
275
|
symbolsToAdd.push(symbol);
|
|
274
276
|
}
|
|
275
277
|
}
|
|
276
|
-
|
|
277
|
-
this.addSymbols(symbolsToAdd);
|
|
278
|
-
}
|
|
278
|
+
this.addSymbols(symbolsToAdd);
|
|
279
279
|
|
|
280
280
|
return () => {
|
|
281
281
|
this.subscriptions.delete(subscriptionId);
|
|
282
282
|
const symbolsForRemove = symbols.filter(
|
|
283
283
|
(s) => this.getHandlersForSymbol(s).length === 0
|
|
284
284
|
);
|
|
285
|
-
|
|
286
|
-
this.removeSymbols(symbolsForRemove);
|
|
287
|
-
}
|
|
285
|
+
this.removeSymbols(symbolsForRemove);
|
|
288
286
|
};
|
|
289
287
|
}
|
|
290
288
|
|
|
@@ -297,6 +295,8 @@ export class LivePriceWebSocketClient {
|
|
|
297
295
|
}
|
|
298
296
|
|
|
299
297
|
private async removeSymbols(symbols: string[]) {
|
|
298
|
+
if (symbols.length === 0) return;
|
|
299
|
+
|
|
300
300
|
if (!this.ws) {
|
|
301
301
|
throw new WebSocketError(
|
|
302
302
|
"WebSocket is not initialized",
|
|
@@ -319,6 +319,8 @@ export class LivePriceWebSocketClient {
|
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
private async addSymbols(symbols: string[]) {
|
|
322
|
+
if (symbols.length === 0) return;
|
|
323
|
+
|
|
322
324
|
if (!this.ws) {
|
|
323
325
|
throw new WebSocketError(
|
|
324
326
|
"WebSocket is not initialized",
|
|
@@ -28,26 +28,7 @@ describe('FinancialFundamentals', () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
test('GetStockStats', async () => {
|
|
31
|
-
|
|
32
|
-
StockStatsKey.PreviousClose,
|
|
33
|
-
StockStatsKey.MarketCap,
|
|
34
|
-
StockStatsKey.FK,
|
|
35
|
-
StockStatsKey.PDDD,
|
|
36
|
-
StockStatsKey.YearLow,
|
|
37
|
-
StockStatsKey.YearHigh,
|
|
38
|
-
StockStatsKey.WeeklyReturn,
|
|
39
|
-
StockStatsKey.MonthlyReturn,
|
|
40
|
-
StockStatsKey.ThreeMonthReturn,
|
|
41
|
-
StockStatsKey.YtdReturn,
|
|
42
|
-
StockStatsKey.YearlyReturn,
|
|
43
|
-
StockStatsKey.ThreeYearReturn,
|
|
44
|
-
StockStatsKey.FiveYearReturn,
|
|
45
|
-
StockStatsKey.LatestPrice,
|
|
46
|
-
StockStatsKey.DailyChange,
|
|
47
|
-
StockStatsKey.DayLow,
|
|
48
|
-
StockStatsKey.DayHigh,
|
|
49
|
-
]
|
|
50
|
-
const resp = await stockClient.getStockStats(['TUPRS'], statKeys, Region.Tr);
|
|
31
|
+
const resp = await stockClient.getStockStats(['TUPRS'], Region.Tr);
|
|
51
32
|
expect(resp).not.toBeEmpty();
|
|
52
33
|
expect(resp.length).toBe(1);
|
|
53
34
|
|
|
@@ -61,17 +42,19 @@ describe('FinancialFundamentals', () => {
|
|
|
61
42
|
expect(currentStockStats.pbRatio).not.toBe(0.0);
|
|
62
43
|
expect(currentStockStats.yearLow).toBeGreaterThan(0.0);
|
|
63
44
|
expect(currentStockStats.yearHigh).toBeGreaterThan(0.0);
|
|
64
|
-
expect(currentStockStats.weeklyReturn).
|
|
65
|
-
expect(currentStockStats.monthlyReturn).
|
|
66
|
-
expect(currentStockStats['3MonthReturn']).
|
|
67
|
-
expect(currentStockStats.ytdReturn).
|
|
68
|
-
expect(currentStockStats.yearlyReturn).
|
|
69
|
-
expect(currentStockStats['3YearReturn']).
|
|
70
|
-
expect(currentStockStats['5YearReturn']).
|
|
45
|
+
expect(typeof currentStockStats.weeklyReturn).toBe('number');;
|
|
46
|
+
expect(typeof currentStockStats.monthlyReturn).toBe('number');
|
|
47
|
+
expect(typeof currentStockStats['3MonthReturn']).toBe('number');
|
|
48
|
+
expect(typeof currentStockStats.ytdReturn).toBe('number');
|
|
49
|
+
expect(typeof currentStockStats.yearlyReturn).toBe('number');
|
|
50
|
+
expect(typeof currentStockStats['3YearReturn']).toBe('number');
|
|
51
|
+
expect(typeof currentStockStats['5YearReturn']).toBe('number');
|
|
71
52
|
expect(currentStockStats.latestPrice).toBeGreaterThan(0.0);
|
|
72
|
-
expect(currentStockStats.dailyChange).
|
|
53
|
+
expect(typeof currentStockStats.dailyChange).toBe('number');
|
|
73
54
|
expect(currentStockStats.dayLow).toBeGreaterThan(0.0);
|
|
74
55
|
expect(currentStockStats.dayHigh).toBeGreaterThan(0.0);
|
|
56
|
+
expect(currentStockStats.upperPriceLimit).toBeGreaterThan(0.0)
|
|
57
|
+
expect(currentStockStats.lowerPriceLimit).toBeGreaterThan(0.0)
|
|
75
58
|
});
|
|
76
59
|
|
|
77
60
|
test('GetTopMovers', async () => {
|