laplace-api 1.3.2 → 1.3.4

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.3.2",
3
+ "version": "1.3.4",
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,13 +1,18 @@
1
- import { WebSocket } from "ws";
2
-
3
1
  export interface BISTStockLiveData {
4
2
  symbol: string;
5
3
  cl: number; // Close
6
4
  c: number; // PercentChange
7
5
  }
8
6
 
7
+ export enum LogLevel {
8
+ Info = "info",
9
+ Warn = "warn",
10
+ Error = "error",
11
+ }
12
+
9
13
  interface WebSocketOptions {
10
14
  enableLogging?: boolean;
15
+ logLevel?: LogLevel;
11
16
  reconnectAttempts?: number;
12
17
  reconnectDelay?: number;
13
18
  maxReconnectDelay?: number;
@@ -69,6 +74,7 @@ export class LivePriceWebSocketClient {
69
74
  constructor(options: WebSocketOptions = {}) {
70
75
  this.options = {
71
76
  enableLogging: true,
77
+ logLevel: LogLevel.Error,
72
78
  reconnectAttempts: 5,
73
79
  reconnectDelay: 5000,
74
80
  maxReconnectDelay: 30000,
@@ -80,6 +86,15 @@ export class LivePriceWebSocketClient {
80
86
  if (!this.options.enableLogging) return;
81
87
 
82
88
  const prefix = `[LivePriceWebSocket][${level.toUpperCase()}]`;
89
+ const logLevel = this.options.logLevel;
90
+
91
+ if (logLevel === LogLevel.Error && level !== "error") {
92
+ return;
93
+ }
94
+
95
+ if (logLevel === LogLevel.Warn && level === "info") {
96
+ return;
97
+ }
83
98
 
84
99
  switch (level) {
85
100
  case "error":
@@ -138,7 +153,7 @@ export class LivePriceWebSocketClient {
138
153
  this.ws.onerror = (error) => {
139
154
  reject(
140
155
  new WebSocketError(
141
- `WebSocket connection error: ${error.error}`,
156
+ `WebSocket connection error: ${error}`,
142
157
  WebSocketErrorType.CONNECTION_ERROR
143
158
  )
144
159
  );