laplace-api 4.1.0 → 4.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
|
@@ -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
|
|
90
|
+
export class LivePriceWebSocketClient {
|
|
119
91
|
private ws: WebSocket | null = null;
|
|
120
92
|
private subscriptionCounter = 0;
|
|
121
93
|
private subscriptions = new Map<
|
|
@@ -140,19 +112,10 @@ export class LivePriceWebSocketClient extends Client {
|
|
|
140
112
|
private lastMessageTimestamp: number = 0;
|
|
141
113
|
private inactivityCheckInterval: NodeJS.Timeout | null = null;
|
|
142
114
|
private readonly INACTIVITY_TIMEOUT = 15000;
|
|
143
|
-
private externalUserId: string | null = null;
|
|
144
|
-
private feeds: LivePriceFeed[] | null = null;
|
|
145
115
|
|
|
146
116
|
constructor(
|
|
147
|
-
feeds: LivePriceFeed[],
|
|
148
|
-
externalUserId: string,
|
|
149
|
-
cfg: LaplaceConfiguration,
|
|
150
|
-
logger: Logger,
|
|
151
117
|
options: WebSocketOptions = {}
|
|
152
118
|
) {
|
|
153
|
-
super(cfg, logger);
|
|
154
|
-
this.feeds = feeds;
|
|
155
|
-
this.externalUserId = externalUserId;
|
|
156
119
|
this.options = {
|
|
157
120
|
enableLogging: true,
|
|
158
121
|
logLevel: LogLevel.Error,
|
|
@@ -216,40 +179,10 @@ export class LivePriceWebSocketClient extends Client {
|
|
|
216
179
|
}
|
|
217
180
|
}
|
|
218
181
|
|
|
219
|
-
async
|
|
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> {
|
|
182
|
+
async connect(url: string): Promise<WebSocket> {
|
|
247
183
|
this.log("Connecting to WebSocket...");
|
|
248
|
-
if (!this.externalUserId || !this.feeds) {
|
|
249
|
-
throw new Error("External user ID and feeds are required");
|
|
250
|
-
}
|
|
251
184
|
|
|
252
|
-
this.wsUrl = url
|
|
185
|
+
this.wsUrl = url;
|
|
253
186
|
|
|
254
187
|
if (!this.ws || this.ws.readyState === WebSocket.CLOSED) {
|
|
255
188
|
this.ws = new WebSocket(this.wsUrl);
|
package/src/client/live-price.ts
CHANGED
|
@@ -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
|
}
|
package/src/test/readme.test.ts
CHANGED
|
@@ -67,12 +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
|
-
config,
|
|
74
|
-
logger
|
|
75
|
-
);
|
|
70
|
+
webSocketClient = new LivePriceWebSocketClient();
|
|
76
71
|
capitalIncreaseClient = new CapitalIncreaseClient(config, logger);
|
|
77
72
|
customThemeClient = new CustomThemeClient(config, logger);
|
|
78
73
|
keyInsightClient = new KeyInsightClient(config, logger);
|