laplace-api 4.2.0 → 4.3.1
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 +15 -2
- package/package.json +1 -1
- package/src/client/live-price-web-socket.ts +0 -9
- package/src/client/live-price.ts +22 -4
- package/src/test/readme.test.ts +1 -4
package/README.md
CHANGED
|
@@ -289,16 +289,25 @@ const results = await client.search(
|
|
|
289
289
|
### WebSocket Client
|
|
290
290
|
|
|
291
291
|
```typescript
|
|
292
|
+
// Server Side
|
|
293
|
+
// Initialize LivePriceClient for server side use
|
|
294
|
+
const livePriceClient = new LivePriceClient(config, logger);
|
|
295
|
+
|
|
296
|
+
// Retrieve a websocket connection URL for the client, pass the URL to the client
|
|
297
|
+
const wsURL = await livePriceClient.getClientWebsocketUrl('external-user-id', [LivePriceFeed.LiveBist])
|
|
298
|
+
|
|
299
|
+
// Client Side
|
|
300
|
+
// Client side retrieves the websocket connection URL from the server as wsURL
|
|
292
301
|
// Create WebSocket client for real-time data
|
|
293
302
|
const webSocketClient = new LivePriceWebSocketClient();
|
|
294
303
|
|
|
295
304
|
// Connect to WebSocket
|
|
296
|
-
await webSocketClient.connect(
|
|
305
|
+
await webSocketClient.connect(wsURL);
|
|
297
306
|
|
|
298
307
|
// Subscribe to live price feeds
|
|
299
308
|
const unsubscribe = webSocketClient.subscribe(
|
|
300
309
|
["THYAO", "GARAN"],
|
|
301
|
-
|
|
310
|
+
LivePriceFeed.LiveBist,
|
|
302
311
|
(data) => {
|
|
303
312
|
console.log("Received live data:", data);
|
|
304
313
|
}
|
|
@@ -306,6 +315,10 @@ const unsubscribe = webSocketClient.subscribe(
|
|
|
306
315
|
|
|
307
316
|
// Close connection
|
|
308
317
|
await webSocketClient.close();
|
|
318
|
+
|
|
319
|
+
// Server Side
|
|
320
|
+
// Use livePriceClient.getWebsocketUsageForMonth for getting a report on websocket client usage
|
|
321
|
+
const usage = await livePriceClient.getWebsocketUsageForMonth('8', '2025', LivePriceFeed.LiveBist);
|
|
309
322
|
```
|
|
310
323
|
|
|
311
324
|
### Capital Increase Client
|
package/package.json
CHANGED
|
@@ -112,16 +112,10 @@ export class LivePriceWebSocketClient {
|
|
|
112
112
|
private lastMessageTimestamp: number = 0;
|
|
113
113
|
private inactivityCheckInterval: NodeJS.Timeout | null = null;
|
|
114
114
|
private readonly INACTIVITY_TIMEOUT = 15000;
|
|
115
|
-
private externalUserId: string | null = null;
|
|
116
|
-
private feeds: LivePriceFeed[] | null = null;
|
|
117
115
|
|
|
118
116
|
constructor(
|
|
119
|
-
feeds: LivePriceFeed[],
|
|
120
|
-
externalUserId: string,
|
|
121
117
|
options: WebSocketOptions = {}
|
|
122
118
|
) {
|
|
123
|
-
this.feeds = feeds;
|
|
124
|
-
this.externalUserId = externalUserId;
|
|
125
119
|
this.options = {
|
|
126
120
|
enableLogging: true,
|
|
127
121
|
logLevel: LogLevel.Error,
|
|
@@ -187,9 +181,6 @@ export class LivePriceWebSocketClient {
|
|
|
187
181
|
|
|
188
182
|
async connect(url: string): Promise<WebSocket> {
|
|
189
183
|
this.log("Connecting to WebSocket...");
|
|
190
|
-
if (!this.externalUserId || !this.feeds) {
|
|
191
|
-
throw new Error("External user ID and feeds are required");
|
|
192
|
-
}
|
|
193
184
|
|
|
194
185
|
this.wsUrl = url;
|
|
195
186
|
|
package/src/client/live-price.ts
CHANGED
|
@@ -61,6 +61,12 @@ interface WebSocketUrlResponse {
|
|
|
61
61
|
url: string;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
interface WebSocketUsageResponse {
|
|
65
|
+
externalUserId: string;
|
|
66
|
+
firstConnectionTime: Date;
|
|
67
|
+
uniqueDeviceCount: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
interface WebSocketUrlParams {
|
|
65
71
|
externalUserId: string;
|
|
66
72
|
feeds: LivePriceFeed[];
|
|
@@ -278,13 +284,25 @@ export class LivePriceClient extends Client {
|
|
|
278
284
|
return response.url;
|
|
279
285
|
}
|
|
280
286
|
|
|
281
|
-
async
|
|
282
|
-
|
|
287
|
+
async getWebsocketUsageForMonth(
|
|
288
|
+
month: string,
|
|
289
|
+
year: string,
|
|
290
|
+
feedType: LivePriceFeed,
|
|
291
|
+
): Promise<WebSocketUsageResponse[]> {
|
|
292
|
+
const url = new URL(`${this["baseUrl"]}/api/v1/ws/report`);
|
|
293
|
+
|
|
294
|
+
const params = {
|
|
295
|
+
month,
|
|
296
|
+
year,
|
|
297
|
+
feedType
|
|
298
|
+
};
|
|
283
299
|
|
|
284
|
-
await this.sendRequest<
|
|
285
|
-
method: "
|
|
300
|
+
const response = await this.sendRequest<WebSocketUsageResponse[]>({
|
|
301
|
+
method: "GET",
|
|
286
302
|
url: url.toString(),
|
|
287
303
|
data: params,
|
|
288
304
|
});
|
|
305
|
+
|
|
306
|
+
return response;
|
|
289
307
|
}
|
|
290
308
|
}
|
package/src/test/readme.test.ts
CHANGED
|
@@ -67,10 +67,7 @@ describe("README Examples - Comprehensive Tests", () => {
|
|
|
67
67
|
livePriceClient = new LivePriceClient(config, logger);
|
|
68
68
|
brokerClient = new BrokerClient(config, logger);
|
|
69
69
|
searchClient = new SearchClient(config, logger);
|
|
70
|
-
webSocketClient = new LivePriceWebSocketClient(
|
|
71
|
-
[LivePriceFeed.LiveBist, LivePriceFeed.LiveUs],
|
|
72
|
-
"test-user-id",
|
|
73
|
-
);
|
|
70
|
+
webSocketClient = new LivePriceWebSocketClient();
|
|
74
71
|
capitalIncreaseClient = new CapitalIncreaseClient(config, logger);
|
|
75
72
|
customThemeClient = new CustomThemeClient(config, logger);
|
|
76
73
|
keyInsightClient = new KeyInsightClient(config, logger);
|