laplace-api 1.1.5 → 1.1.6

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laplace-api",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "Client library for Laplace API for the US stock market and BIST (Istanbul stock market) fundamental financial data.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -2,6 +2,14 @@ import { Client } from "./client";
2
2
  import { Region } from "./collections";
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
 
5
+ interface WebSocketUrlResponse {
6
+ url: string;
7
+ }
8
+
9
+ interface WebSocketUrlParams {
10
+ externalUserId: string;
11
+ }
12
+
5
13
  export interface BISTStockLiveData {
6
14
  s: string; // Symbol
7
15
  ch: number; // DailyPercentChange
@@ -37,15 +45,17 @@ export class LivePriceWebSocketUrlClient extends Client {
37
45
  url.searchParams.append("region", region);
38
46
  url.searchParams.append("accessLevel", "KRMD1");
39
47
 
40
- const response = await this.sendRequest<string>({
48
+ const params: WebSocketUrlParams = {
49
+ externalUserId,
50
+ };
51
+
52
+ const response = await this.sendRequest<WebSocketUrlResponse>({
41
53
  method: "POST",
42
54
  url: url.toString(),
43
- data: {
44
- externalUserId: externalUserId,
45
- },
55
+ data: params,
46
56
  });
47
57
 
48
- return response;
58
+ return response.url;
49
59
  }
50
60
 
51
61
  getLivePriceForBIST(
@@ -6,7 +6,6 @@ import { Region, Locale } from '../client/collections';
6
6
  import './client_test_suite';
7
7
 
8
8
  describe('FinancialRatios', () => {
9
- let client: Client;
10
9
  let financialClient: FinancialClient;
11
10
 
12
11
  beforeAll(() => {
@@ -47,105 +47,63 @@ describe("LivePrice", () => {
47
47
 
48
48
  describe("BIST Live Price Tests", () => {
49
49
  const symbols = ["TUPRS", "SASA", "THYAO", "GARAN", "YKBNK"];
50
- const newSymbols = ["AKBNK", "KCHOL"];
50
+ // const newSymbols = ["AKBNK", "KCHOL"];
51
51
 
52
52
  it(
53
53
  "should receive data for initial and updated symbols",
54
54
  async () => {
55
55
  const receivedData: BISTStockLiveData[] = [];
56
56
 
57
- await new Promise<void>((resolve, reject) => {
58
- const timeoutId = setTimeout(() => {
59
- reject(new Error("Test timeout: No data received"));
60
- }, TEST_CONSTANTS.MAIN_TIMEOUT).unref();
61
-
62
- let unsubscribeNewSymbols: (() => void) | null = null;
63
-
64
- const initialHandler = (data: BISTStockLiveData) => {
65
- receivedData.push(data);
66
-
67
- if (symbols.includes(data.symbol)) {
68
- const unsubscribeInitial = ws.subscribe(symbols, initialHandler);
69
- unsubscribeInitial();
70
-
71
- unsubscribeNewSymbols = ws.subscribe(newSymbols, (data) => {
72
- receivedData.push(data);
73
-
74
- if (newSymbols.includes(data.symbol)) {
75
- clearTimeout(timeoutId);
76
- if (unsubscribeNewSymbols) unsubscribeNewSymbols();
77
- resolve();
78
- }
79
- });
80
- }
81
- };
82
-
83
- ws.subscribe(symbols, initialHandler);
57
+ let unsubscribe: (() => void) | null = ws.subscribe(symbols, (data) => {
58
+ console.log("RECEIVED DATA", data);
59
+ receivedData.push(data);
84
60
  });
85
61
 
86
- const newSymbolData = receivedData.filter((data) =>
87
- newSymbols.includes(data.symbol)
88
- );
89
- const oldSymbolData = receivedData.filter((data) =>
90
- symbols.includes(data.symbol)
91
- );
92
-
93
- expect(oldSymbolData.length).toBeGreaterThan(0);
94
- expect(newSymbolData.length).toBeGreaterThan(0);
95
-
96
- newSymbolData.forEach((data) => {
97
- expect(newSymbols).toContain(data.symbol);
98
- expect(typeof data.symbol).toBe("string");
99
- expect(typeof data.c).toBe("number");
100
- expect(typeof data.cl).toBe("number");
101
- });
62
+ await new Promise((resolve) => setTimeout(resolve, 20000));
102
63
 
103
- const lastNewSymbolIndex = receivedData.findIndex((data) =>
104
- newSymbols.includes(data.symbol)
105
- );
106
- const dataAfterUpdate = receivedData.slice(lastNewSymbolIndex);
107
- const oldSymbolDataAfterUpdate = dataAfterUpdate.filter((data) =>
108
- symbols.includes(data.symbol)
109
- );
64
+ for (const symbol of symbols) {
65
+ const symbolData = receivedData.filter((data) => data.symbol === symbol);
66
+ expect(symbolData.length).toBeGreaterThan(0);
67
+ }
110
68
 
111
- expect(oldSymbolDataAfterUpdate.length).toBe(0);
69
+ unsubscribe();
112
70
  },
113
71
  TEST_CONSTANTS.JEST_TIMEOUT
114
72
  );
115
73
 
116
- it(
117
- "should handle multiple subscriptions for the same symbol",
118
- async () => {
119
- const symbol = "GARAN";
120
- const receivedData1: BISTStockLiveData[] = [];
121
- const receivedData2: BISTStockLiveData[] = [];
122
-
123
- await new Promise<void>((resolve, reject) => {
124
- const timeoutId = setTimeout(() => {
125
- reject(new Error("Test timeout: No data received"));
126
- }, TEST_CONSTANTS.MAIN_TIMEOUT).unref();
127
-
128
- const unsubscribe1 = ws.subscribe([symbol], (data) => {
129
- receivedData1.push(data);
130
- });
131
-
132
- const unsubscribe2 = ws.subscribe([symbol], (data) => {
133
- receivedData2.push(data);
134
- if (receivedData2.length >= 2) {
135
- clearTimeout(timeoutId);
136
- unsubscribe1();
137
- unsubscribe2();
138
- resolve();
139
- }
140
- });
141
- });
142
-
143
- expect(receivedData1.length).toBeGreaterThan(0);
144
- expect(receivedData2.length).toBeGreaterThan(0);
145
- expect(receivedData1).toEqual(receivedData2);
146
- },
147
- TEST_CONSTANTS.JEST_TIMEOUT
148
- );
74
+ // it(
75
+ // "should handle multiple subscriptions for the same symbol",
76
+ // async () => {
77
+ // const symbol = "GARAN";
78
+ // const receivedData1: BISTStockLiveData[] = [];
79
+ // const receivedData2: BISTStockLiveData[] = [];
80
+
81
+ // await new Promise<void>((resolve, reject) => {
82
+ // const timeoutId = setTimeout(() => {
83
+ // reject(new Error("Test timeout: No data received"));
84
+ // }, TEST_CONSTANTS.MAIN_TIMEOUT).unref();
85
+
86
+ // const unsubscribe1 = ws.subscribe([symbol], (data) => {
87
+ // receivedData1.push(data);
88
+ // });
89
+
90
+ // const unsubscribe2 = ws.subscribe([symbol], (data) => {
91
+ // receivedData2.push(data);
92
+ // if (receivedData2.length >= 2) {
93
+ // clearTimeout(timeoutId);
94
+ // unsubscribe1();
95
+ // unsubscribe2();
96
+ // resolve();
97
+ // }
98
+ // });
99
+ // });
100
+
101
+ // expect(receivedData1.length).toBeGreaterThan(0);
102
+ // expect(receivedData2.length).toBeGreaterThan(0);
103
+ // expect(receivedData1).toEqual(receivedData2);
104
+ // },
105
+ // TEST_CONSTANTS.JEST_TIMEOUT
106
+ // );
149
107
  });
150
108
 
151
109
  // const testLivePrice = async (
@@ -1,2 +1,2 @@
1
- BASE_URL=
2
- API_KEY=
1
+ BASE_URL=https://api.finfree.app
2
+ API_KEY=api-6fa6cefb-16df-4a19-8351-54f83c6bbe2f