laplace-api 4.1.0 → 4.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laplace-api",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
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": {
@@ -1,31 +1,3 @@
1
- import { Logger } from "winston";
2
- import { LaplaceConfiguration } from "../utilities/configuration";
3
- import { Client } from "./client";
4
-
5
- interface WebSocketUrlResponse {
6
- url: string;
7
- }
8
-
9
- interface WebSocketUrlParams {
10
- externalUserId: string;
11
- feeds: LivePriceFeed[];
12
- }
13
-
14
- export enum AccessorType {
15
- User = "user",
16
- }
17
-
18
- interface UpdateUserDetailsParams {
19
- externalUserID: string;
20
- firstName?: string;
21
- lastName?: string;
22
- address?: string;
23
- city?: string;
24
- countryCode?: string;
25
- accessorType?: AccessorType;
26
- active: boolean;
27
- }
28
-
29
1
  interface RawBISTStockLiveData {
30
2
  _id: number;
31
3
  symbol: string;
@@ -115,7 +87,7 @@ export class WebSocketError extends Error {
115
87
  }
116
88
  }
117
89
 
118
- export class LivePriceWebSocketClient extends Client {
90
+ export class LivePriceWebSocketClient {
119
91
  private ws: WebSocket | null = null;
120
92
  private subscriptionCounter = 0;
121
93
  private subscriptions = new Map<
@@ -146,11 +118,8 @@ export class LivePriceWebSocketClient extends Client {
146
118
  constructor(
147
119
  feeds: LivePriceFeed[],
148
120
  externalUserId: string,
149
- cfg: LaplaceConfiguration,
150
- logger: Logger,
151
121
  options: WebSocketOptions = {}
152
122
  ) {
153
- super(cfg, logger);
154
123
  this.feeds = feeds;
155
124
  this.externalUserId = externalUserId;
156
125
  this.options = {
@@ -216,40 +185,13 @@ export class LivePriceWebSocketClient extends Client {
216
185
  }
217
186
  }
218
187
 
219
- async updateUserDetails(params: UpdateUserDetailsParams): Promise<void> {
220
- const url = new URL(`${this["baseUrl"]}/api/v1/ws/user`);
221
-
222
- await this.sendRequest<void>({
223
- method: "PUT",
224
- url: url.toString(),
225
- data: params,
226
- });
227
- }
228
-
229
- private async getWebSocketUrl(): Promise<string> {
230
- const url = new URL(`${this["baseUrl"]}/api/v2/ws/url`);
231
-
232
- const params: WebSocketUrlParams = {
233
- externalUserId: this.externalUserId!,
234
- feeds: this.feeds!,
235
- };
236
-
237
- const response = await this.sendRequest<WebSocketUrlResponse>({
238
- method: "POST",
239
- url: url.toString(),
240
- data: params,
241
- });
242
-
243
- return response.url;
244
- }
245
-
246
- async connect(url?: string): Promise<WebSocket> {
188
+ async connect(url: string): Promise<WebSocket> {
247
189
  this.log("Connecting to WebSocket...");
248
190
  if (!this.externalUserId || !this.feeds) {
249
191
  throw new Error("External user ID and feeds are required");
250
192
  }
251
193
 
252
- this.wsUrl = url || (await this.getWebSocketUrl());
194
+ this.wsUrl = url;
253
195
 
254
196
  if (!this.ws || this.ws.readyState === WebSocket.CLOSED) {
255
197
  this.ws = new WebSocket(this.wsUrl);
@@ -1,6 +1,7 @@
1
1
  import { Client } from "./client";
2
2
  import { Region } from "./collections";
3
3
  import { v4 as uuidv4 } from "uuid";
4
+ import { LivePriceFeed } from "./live-price-web-socket";
4
5
 
5
6
  export type MessageType = "pr" | "state_change" | "heartbeat" | "ob";
6
7
 
@@ -56,6 +57,30 @@ export enum PriceDataType {
56
57
  Orderbook = "orderbook",
57
58
  }
58
59
 
60
+ interface WebSocketUrlResponse {
61
+ url: string;
62
+ }
63
+
64
+ interface WebSocketUrlParams {
65
+ externalUserId: string;
66
+ feeds: LivePriceFeed[];
67
+ }
68
+
69
+ export enum AccessorType {
70
+ User = "user",
71
+ }
72
+
73
+ interface UpdateUserDetailsParams {
74
+ externalUserID: string;
75
+ firstName?: string;
76
+ lastName?: string;
77
+ address?: string;
78
+ city?: string;
79
+ countryCode?: string;
80
+ accessorType?: AccessorType;
81
+ active: boolean;
82
+ }
83
+
59
84
  export interface ILivePriceClient<T> {
60
85
  close(): void;
61
86
  receive(): AsyncIterable<T>;
@@ -232,4 +257,34 @@ export class LivePriceClient extends Client {
232
257
  getOrderbookForBIST(symbols: string[]): ILivePriceClient<OrderbookLiveData> {
233
258
  return getOrderbookForBIST(this, symbols);
234
259
  }
260
+
261
+ async getClientWebsocketUrl(
262
+ externalUserId: string,
263
+ feeds: LivePriceFeed[]
264
+ ): Promise<string> {
265
+ const url = new URL(`${this["baseUrl"]}/api/v2/ws/url`);
266
+
267
+ const params: WebSocketUrlParams = {
268
+ externalUserId,
269
+ feeds
270
+ };
271
+
272
+ const response = await this.sendRequest<WebSocketUrlResponse>({
273
+ method: "POST",
274
+ url: url.toString(),
275
+ data: params,
276
+ });
277
+
278
+ return response.url;
279
+ }
280
+
281
+ async updateUserDetails(params: UpdateUserDetailsParams): Promise<void> {
282
+ const url = new URL(`${this["baseUrl"]}/api/v1/ws/user`);
283
+
284
+ await this.sendRequest<void>({
285
+ method: "PUT",
286
+ url: url.toString(),
287
+ data: params,
288
+ });
289
+ }
235
290
  }
@@ -70,8 +70,6 @@ describe("README Examples - Comprehensive Tests", () => {
70
70
  webSocketClient = new LivePriceWebSocketClient(
71
71
  [LivePriceFeed.LiveBist, LivePriceFeed.LiveUs],
72
72
  "test-user-id",
73
- config,
74
- logger
75
73
  );
76
74
  capitalIncreaseClient = new CapitalIncreaseClient(config, logger);
77
75
  customThemeClient = new CustomThemeClient(config, logger);