@orderly.network/net 1.0.11 → 1.0.13
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +7 -35
- package/dist/index.d.ts +7 -35
- package/dist/index.js +43 -286
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -285
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +0 -2
- package/src/ws/ws.ts +57 -19
- package/src/ws/contants.ts +0 -13
- package/src/ws/index.ts +0 -336
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @orderly.network/net@1.0.
|
|
2
|
+
> @orderly.network/net@1.0.12 build /Users/leo/orderly/orderly-web/packages/net
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
CLI Building entry: src/index.ts
|
|
@@ -10,13 +10,13 @@ CLI Target: es6
|
|
|
10
10
|
CLI Cleaning output folder
|
|
11
11
|
CJS Build start
|
|
12
12
|
ESM Build start
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
ESM dist/index.mjs 12.55 KB
|
|
14
|
+
ESM dist/index.mjs.map 21.28 KB
|
|
15
|
+
ESM ⚡️ Build success in 10ms
|
|
16
|
+
CJS dist/index.js 13.59 KB
|
|
17
|
+
CJS dist/index.js.map 21.52 KB
|
|
18
|
+
CJS ⚡️ Build success in 11ms
|
|
19
19
|
DTS Build start
|
|
20
|
-
DTS ⚡️ Build success in
|
|
21
|
-
DTS dist/index.d.ts
|
|
22
|
-
DTS dist/index.d.mts
|
|
20
|
+
DTS ⚡️ Build success in 1142ms
|
|
21
|
+
DTS dist/index.d.ts 2.19 KB
|
|
22
|
+
DTS dist/index.d.mts 2.19 KB
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,45 +1,15 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
1
|
declare function get<R>(url: string, options?: RequestInit, formatter?: (data: any) => R): Promise<R>;
|
|
4
2
|
declare function post(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
5
3
|
declare function put(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
6
4
|
declare function del(url: string, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
7
5
|
declare function mutate(url: string, init: RequestInit): Promise<any>;
|
|
8
6
|
|
|
9
|
-
type NetworkId$1 = "testnet" | "mainnet";
|
|
10
|
-
type WSOptions$1 = {
|
|
11
|
-
url?: string;
|
|
12
|
-
networkId?: NetworkId$1;
|
|
13
|
-
accountId?: string;
|
|
14
|
-
onSigntureRequest?: (accountId: string) => Promise<any>;
|
|
15
|
-
};
|
|
16
|
-
declare class WebSocketClient {
|
|
17
|
-
private static __topicRefCountMap;
|
|
18
|
-
private wsSubject;
|
|
19
|
-
private privateWsSubject?;
|
|
20
|
-
private authenticated;
|
|
21
|
-
private _pendingPrivateSubscribe;
|
|
22
|
-
constructor(options: WSOptions$1);
|
|
23
|
-
private createSubject;
|
|
24
|
-
private createPrivateSubject;
|
|
25
|
-
private bindSubscribe;
|
|
26
|
-
private authenticate;
|
|
27
|
-
send: (message: any) => void;
|
|
28
|
-
privateSend: (message: any) => void;
|
|
29
|
-
get isAuthed(): boolean;
|
|
30
|
-
observe<T>(params: any, unsubscribe?: () => any, messageFilter?: (value: T) => boolean): Observable<T>;
|
|
31
|
-
privateObserve<T>(params: any, unsubscribe?: () => any, messageFilter?: (value: T) => boolean): Observable<T>;
|
|
32
|
-
private _observe;
|
|
33
|
-
private generateMessage;
|
|
34
|
-
private _sendPendingPrivateMessage;
|
|
35
|
-
desotry(): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
7
|
declare const __ORDERLY_API_URL_KEY__: string;
|
|
39
8
|
|
|
40
9
|
type NetworkId = "testnet" | "mainnet";
|
|
41
10
|
type WSOptions = {
|
|
42
|
-
|
|
11
|
+
privateUrl: string;
|
|
12
|
+
publicUrl: string;
|
|
43
13
|
networkId?: NetworkId;
|
|
44
14
|
accountId?: string;
|
|
45
15
|
onSigntureRequest?: (accountId: string) => Promise<any>;
|
|
@@ -53,7 +23,7 @@ type WSMessageHandler = {
|
|
|
53
23
|
formatter?: (message: any) => any;
|
|
54
24
|
};
|
|
55
25
|
declare class WS {
|
|
56
|
-
private
|
|
26
|
+
private options;
|
|
57
27
|
private publicSocket;
|
|
58
28
|
private privateSocket?;
|
|
59
29
|
private publicIsReconnecting;
|
|
@@ -64,11 +34,13 @@ declare class WS {
|
|
|
64
34
|
private _pendingPublicSubscribe;
|
|
65
35
|
private _eventHandlers;
|
|
66
36
|
constructor(options: WSOptions);
|
|
37
|
+
openPrivate(accountId: string): void;
|
|
67
38
|
private createPublicSC;
|
|
68
39
|
private createPrivateSC;
|
|
69
40
|
private onOpen;
|
|
70
41
|
private onPrivateOpen;
|
|
71
42
|
private onMessage;
|
|
43
|
+
private handlePendingPrivateTopic;
|
|
72
44
|
private onClose;
|
|
73
45
|
private onError;
|
|
74
46
|
private onPrivateError;
|
|
@@ -76,7 +48,7 @@ declare class WS {
|
|
|
76
48
|
close(): void;
|
|
77
49
|
set accountId(accountId: string);
|
|
78
50
|
private authenticate;
|
|
79
|
-
privateSubscribe(params: any, callback: WSMessageHandler): void;
|
|
51
|
+
privateSubscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean): void;
|
|
80
52
|
subscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean): unsubscribe | undefined;
|
|
81
53
|
onceSubscribe(params: any, callback: Omit<WSMessageHandler, "onUnsubscribe">): void;
|
|
82
54
|
private unsubscribe;
|
|
@@ -84,4 +56,4 @@ declare class WS {
|
|
|
84
56
|
private reconnectPublic;
|
|
85
57
|
}
|
|
86
58
|
|
|
87
|
-
export {
|
|
59
|
+
export { WS, __ORDERLY_API_URL_KEY__, del, get, mutate, post, put };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,45 +1,15 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
|
|
3
1
|
declare function get<R>(url: string, options?: RequestInit, formatter?: (data: any) => R): Promise<R>;
|
|
4
2
|
declare function post(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
5
3
|
declare function put(url: string, data: any, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
6
4
|
declare function del(url: string, options?: Omit<RequestInit, "method">): Promise<any>;
|
|
7
5
|
declare function mutate(url: string, init: RequestInit): Promise<any>;
|
|
8
6
|
|
|
9
|
-
type NetworkId$1 = "testnet" | "mainnet";
|
|
10
|
-
type WSOptions$1 = {
|
|
11
|
-
url?: string;
|
|
12
|
-
networkId?: NetworkId$1;
|
|
13
|
-
accountId?: string;
|
|
14
|
-
onSigntureRequest?: (accountId: string) => Promise<any>;
|
|
15
|
-
};
|
|
16
|
-
declare class WebSocketClient {
|
|
17
|
-
private static __topicRefCountMap;
|
|
18
|
-
private wsSubject;
|
|
19
|
-
private privateWsSubject?;
|
|
20
|
-
private authenticated;
|
|
21
|
-
private _pendingPrivateSubscribe;
|
|
22
|
-
constructor(options: WSOptions$1);
|
|
23
|
-
private createSubject;
|
|
24
|
-
private createPrivateSubject;
|
|
25
|
-
private bindSubscribe;
|
|
26
|
-
private authenticate;
|
|
27
|
-
send: (message: any) => void;
|
|
28
|
-
privateSend: (message: any) => void;
|
|
29
|
-
get isAuthed(): boolean;
|
|
30
|
-
observe<T>(params: any, unsubscribe?: () => any, messageFilter?: (value: T) => boolean): Observable<T>;
|
|
31
|
-
privateObserve<T>(params: any, unsubscribe?: () => any, messageFilter?: (value: T) => boolean): Observable<T>;
|
|
32
|
-
private _observe;
|
|
33
|
-
private generateMessage;
|
|
34
|
-
private _sendPendingPrivateMessage;
|
|
35
|
-
desotry(): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
7
|
declare const __ORDERLY_API_URL_KEY__: string;
|
|
39
8
|
|
|
40
9
|
type NetworkId = "testnet" | "mainnet";
|
|
41
10
|
type WSOptions = {
|
|
42
|
-
|
|
11
|
+
privateUrl: string;
|
|
12
|
+
publicUrl: string;
|
|
43
13
|
networkId?: NetworkId;
|
|
44
14
|
accountId?: string;
|
|
45
15
|
onSigntureRequest?: (accountId: string) => Promise<any>;
|
|
@@ -53,7 +23,7 @@ type WSMessageHandler = {
|
|
|
53
23
|
formatter?: (message: any) => any;
|
|
54
24
|
};
|
|
55
25
|
declare class WS {
|
|
56
|
-
private
|
|
26
|
+
private options;
|
|
57
27
|
private publicSocket;
|
|
58
28
|
private privateSocket?;
|
|
59
29
|
private publicIsReconnecting;
|
|
@@ -64,11 +34,13 @@ declare class WS {
|
|
|
64
34
|
private _pendingPublicSubscribe;
|
|
65
35
|
private _eventHandlers;
|
|
66
36
|
constructor(options: WSOptions);
|
|
37
|
+
openPrivate(accountId: string): void;
|
|
67
38
|
private createPublicSC;
|
|
68
39
|
private createPrivateSC;
|
|
69
40
|
private onOpen;
|
|
70
41
|
private onPrivateOpen;
|
|
71
42
|
private onMessage;
|
|
43
|
+
private handlePendingPrivateTopic;
|
|
72
44
|
private onClose;
|
|
73
45
|
private onError;
|
|
74
46
|
private onPrivateError;
|
|
@@ -76,7 +48,7 @@ declare class WS {
|
|
|
76
48
|
close(): void;
|
|
77
49
|
set accountId(accountId: string);
|
|
78
50
|
private authenticate;
|
|
79
|
-
privateSubscribe(params: any, callback: WSMessageHandler): void;
|
|
51
|
+
privateSubscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean): void;
|
|
80
52
|
subscribe(params: any, callback: WSMessageHandler | Omit<WSMessageHandler, "onUnsubscribe">, once?: boolean): unsubscribe | undefined;
|
|
81
53
|
onceSubscribe(params: any, callback: Omit<WSMessageHandler, "onUnsubscribe">): void;
|
|
82
54
|
private unsubscribe;
|
|
@@ -84,4 +56,4 @@ declare class WS {
|
|
|
84
56
|
private reconnectPublic;
|
|
85
57
|
}
|
|
86
58
|
|
|
87
|
-
export {
|
|
59
|
+
export { WS, __ORDERLY_API_URL_KEY__, del, get, mutate, post, put };
|
package/dist/index.js
CHANGED
|
@@ -58,7 +58,6 @@ var __async = (__this, __arguments, generator) => {
|
|
|
58
58
|
var src_exports = {};
|
|
59
59
|
__export(src_exports, {
|
|
60
60
|
WS: () => WS,
|
|
61
|
-
WebSocketClient: () => ws_default,
|
|
62
61
|
__ORDERLY_API_URL_KEY__: () => __ORDERLY_API_URL_KEY__,
|
|
63
62
|
del: () => del,
|
|
64
63
|
get: () => get,
|
|
@@ -153,26 +152,8 @@ function mutate(url, init) {
|
|
|
153
152
|
});
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
// src/
|
|
157
|
-
var
|
|
158
|
-
|
|
159
|
-
// src/ws/contants.ts
|
|
160
|
-
var WS_URL = {
|
|
161
|
-
testnet: {
|
|
162
|
-
// public: "wss://testnet-ws.orderly.org/ws/stream/",
|
|
163
|
-
public: "wss://dev-ws-v2.orderly.org/ws/stream/",
|
|
164
|
-
// private:
|
|
165
|
-
// "wss://dev-ws-private-v2.orderly.org/wsprivate/v2/ws/private/stream/",
|
|
166
|
-
private: "wss://dev-ws-private-v2.orderly.org/v2/ws/private/stream/"
|
|
167
|
-
},
|
|
168
|
-
mainnet: {
|
|
169
|
-
public: "wss://mainnet-ws.orderly.io",
|
|
170
|
-
private: "wss://mainnet-ws.orderly.io"
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// src/ws/index.ts
|
|
175
|
-
var import_rxjs = require("rxjs");
|
|
155
|
+
// src/constants.ts
|
|
156
|
+
var __ORDERLY_API_URL_KEY__ = "__ORDERLY_API_URL__";
|
|
176
157
|
|
|
177
158
|
// src/ws/handler/baseHandler.ts
|
|
178
159
|
var BaseHandler = class {
|
|
@@ -194,254 +175,6 @@ var messageHandlers = /* @__PURE__ */ new Map([
|
|
|
194
175
|
["ping", new PingHandler()]
|
|
195
176
|
]);
|
|
196
177
|
|
|
197
|
-
// src/ws/index.ts
|
|
198
|
-
var _WebSocketClient = class _WebSocketClient {
|
|
199
|
-
constructor(options) {
|
|
200
|
-
this.authenticated = false;
|
|
201
|
-
this._pendingPrivateSubscribe = [];
|
|
202
|
-
this.send = (message) => {
|
|
203
|
-
this.wsSubject.next(message);
|
|
204
|
-
};
|
|
205
|
-
this.privateSend = (message) => {
|
|
206
|
-
if (!this.privateWsSubject) {
|
|
207
|
-
console.warn("private ws not connected");
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
this.privateWsSubject.next(message);
|
|
211
|
-
};
|
|
212
|
-
this.wsSubject = this.createSubject(options);
|
|
213
|
-
if (!!options.accountId) {
|
|
214
|
-
this.privateWsSubject = this.createPrivateSubject(options);
|
|
215
|
-
}
|
|
216
|
-
this.bindSubscribe();
|
|
217
|
-
}
|
|
218
|
-
createSubject(options) {
|
|
219
|
-
let url;
|
|
220
|
-
if (typeof options.url === "string") {
|
|
221
|
-
url = options.url;
|
|
222
|
-
} else {
|
|
223
|
-
url = WS_URL[options.networkId || "testnet"].public;
|
|
224
|
-
}
|
|
225
|
-
return (0, import_webSocket.webSocket)({
|
|
226
|
-
url: `${url}${options.accountId || ""}`,
|
|
227
|
-
openObserver: {
|
|
228
|
-
next: () => {
|
|
229
|
-
console.log("Connection ok");
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
closeObserver: {
|
|
233
|
-
next: () => {
|
|
234
|
-
console.log("Connection closed");
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
createPrivateSubject(options) {
|
|
240
|
-
const url = WS_URL[options.networkId || "testnet"].private;
|
|
241
|
-
const ws = (0, import_webSocket.webSocket)({
|
|
242
|
-
url: `${url}${options.accountId}`,
|
|
243
|
-
openObserver: {
|
|
244
|
-
next: () => {
|
|
245
|
-
var _a;
|
|
246
|
-
console.log("Private connection ok");
|
|
247
|
-
if (this.authenticated || !options.accountId)
|
|
248
|
-
return;
|
|
249
|
-
(_a = options.onSigntureRequest) == null ? void 0 : _a.call(options, options.accountId).then((signature) => {
|
|
250
|
-
this.authenticate(options.accountId, signature);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
closeObserver: {
|
|
255
|
-
next: () => {
|
|
256
|
-
console.log("Private connection closed");
|
|
257
|
-
this.authenticated = false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
return ws;
|
|
262
|
-
}
|
|
263
|
-
bindSubscribe() {
|
|
264
|
-
this.wsSubject.subscribe({
|
|
265
|
-
next: (message) => {
|
|
266
|
-
const handler = messageHandlers.get(message.event);
|
|
267
|
-
if (handler) {
|
|
268
|
-
handler.handle(message, this.send);
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
error(err) {
|
|
272
|
-
console.log("WS Error: ", err);
|
|
273
|
-
},
|
|
274
|
-
complete() {
|
|
275
|
-
console.log("WS Connection closed");
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
if (!this.privateWsSubject)
|
|
279
|
-
return;
|
|
280
|
-
this.privateWsSubject.subscribe({
|
|
281
|
-
next: (message) => {
|
|
282
|
-
if (message.event === "auth") {
|
|
283
|
-
this.authenticated = true;
|
|
284
|
-
this._sendPendingPrivateMessage();
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const handler = messageHandlers.get(message.event);
|
|
288
|
-
if (handler) {
|
|
289
|
-
handler.handle(message, this.privateSend);
|
|
290
|
-
}
|
|
291
|
-
},
|
|
292
|
-
error(err) {
|
|
293
|
-
console.log("WS Error: ", err);
|
|
294
|
-
},
|
|
295
|
-
complete() {
|
|
296
|
-
console.log("WS Connection closed");
|
|
297
|
-
}
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
authenticate(accountId, message) {
|
|
301
|
-
var _a;
|
|
302
|
-
if (this.authenticated)
|
|
303
|
-
return;
|
|
304
|
-
if (!this.privateWsSubject) {
|
|
305
|
-
console.error("private ws not connected");
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
console.log("push auth message:", message);
|
|
309
|
-
(_a = this.privateWsSubject) == null ? void 0 : _a.next({
|
|
310
|
-
id: "auth",
|
|
311
|
-
event: "auth",
|
|
312
|
-
params: {
|
|
313
|
-
orderly_key: message.publicKey,
|
|
314
|
-
sign: message.signature,
|
|
315
|
-
timestamp: message.timestamp
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
get isAuthed() {
|
|
320
|
-
return this.authenticated;
|
|
321
|
-
}
|
|
322
|
-
// observe<T>(topic: string): Observable<T>;
|
|
323
|
-
// observe<T>(topic: string, unsubscribe?: () => any): Observable<T>;
|
|
324
|
-
// observe<T>(
|
|
325
|
-
// params: {
|
|
326
|
-
// event: string;
|
|
327
|
-
// } & Record<string, any>,
|
|
328
|
-
// unsubscribe?: () => any
|
|
329
|
-
// ): Observable<T>;
|
|
330
|
-
observe(params, unsubscribe, messageFilter) {
|
|
331
|
-
return this._observe(false, params, unsubscribe, messageFilter);
|
|
332
|
-
}
|
|
333
|
-
// privateObserve<T>(topic: string): Observable<T>;
|
|
334
|
-
// privateObserve<T>(topic: string, unsubscribe?: () => any): Observable<T>;
|
|
335
|
-
// privateObserve<T>(
|
|
336
|
-
// params: {
|
|
337
|
-
// event: string;
|
|
338
|
-
// } & Record<string, any>,
|
|
339
|
-
// unsubscribe?: () => any
|
|
340
|
-
// ): Observable<T>;
|
|
341
|
-
privateObserve(params, unsubscribe, messageFilter) {
|
|
342
|
-
return this._observe(true, params, unsubscribe, messageFilter);
|
|
343
|
-
}
|
|
344
|
-
_observe(isPrivate, params, unsubscribe, messageFilter) {
|
|
345
|
-
console.log(
|
|
346
|
-
"observe---------------------------",
|
|
347
|
-
params,
|
|
348
|
-
unsubscribe,
|
|
349
|
-
messageFilter
|
|
350
|
-
);
|
|
351
|
-
if (isPrivate && !this.privateWsSubject) {
|
|
352
|
-
throw new Error("private ws not connected");
|
|
353
|
-
}
|
|
354
|
-
const subject = isPrivate ? this.privateWsSubject : this.wsSubject;
|
|
355
|
-
const sendFunc = isPrivate ? this.privateSend : this.send;
|
|
356
|
-
const [subscribeMessage, unsubscribeMessage, filter, messageFormatter] = this.generateMessage(params, unsubscribe, messageFilter);
|
|
357
|
-
return new import_rxjs.Observable((observer) => {
|
|
358
|
-
if (isPrivate && !this.authenticated) {
|
|
359
|
-
this._pendingPrivateSubscribe.push(params);
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
try {
|
|
363
|
-
const refCount = _WebSocketClient.__topicRefCountMap.get(subscribeMessage.topic) || 0;
|
|
364
|
-
if (refCount === 0) {
|
|
365
|
-
sendFunc(subscribeMessage);
|
|
366
|
-
_WebSocketClient.__topicRefCountMap.set(
|
|
367
|
-
subscribeMessage.topic,
|
|
368
|
-
refCount + 1
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
} catch (err) {
|
|
372
|
-
observer.error(err);
|
|
373
|
-
}
|
|
374
|
-
const subscription = subject.subscribe({
|
|
375
|
-
next: (x) => {
|
|
376
|
-
try {
|
|
377
|
-
if (filter(x)) {
|
|
378
|
-
observer.next(messageFormatter(x));
|
|
379
|
-
}
|
|
380
|
-
} catch (err) {
|
|
381
|
-
observer.error(err);
|
|
382
|
-
}
|
|
383
|
-
},
|
|
384
|
-
error: (err) => observer.error(err),
|
|
385
|
-
complete: () => observer.complete()
|
|
386
|
-
});
|
|
387
|
-
return () => {
|
|
388
|
-
try {
|
|
389
|
-
const refCount = _WebSocketClient.__topicRefCountMap.get(subscribeMessage.topic) || 0;
|
|
390
|
-
if (refCount > 1) {
|
|
391
|
-
_WebSocketClient.__topicRefCountMap.set(
|
|
392
|
-
subscribeMessage.topic,
|
|
393
|
-
refCount - 1
|
|
394
|
-
);
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
if (!!unsubscribeMessage) {
|
|
398
|
-
this.send(unsubscribeMessage);
|
|
399
|
-
}
|
|
400
|
-
_WebSocketClient.__topicRefCountMap.delete(subscribeMessage.topic);
|
|
401
|
-
} catch (err) {
|
|
402
|
-
observer.error(err);
|
|
403
|
-
}
|
|
404
|
-
subscription.unsubscribe();
|
|
405
|
-
};
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
generateMessage(params, unsubscribe, messageFilter) {
|
|
409
|
-
let subscribeMessage, unsubscribeMessage;
|
|
410
|
-
let filter, messageFormatter = (message) => message.data;
|
|
411
|
-
if (typeof params === "string") {
|
|
412
|
-
subscribeMessage = { event: "subscribe", topic: params };
|
|
413
|
-
unsubscribeMessage = { event: "unsubscribe", topic: params };
|
|
414
|
-
filter = (message) => message.topic === params;
|
|
415
|
-
} else {
|
|
416
|
-
subscribeMessage = params;
|
|
417
|
-
unsubscribeMessage = typeof unsubscribe === "function" ? unsubscribe() : unsubscribe;
|
|
418
|
-
filter = messageFilter || ((message) => true);
|
|
419
|
-
}
|
|
420
|
-
return [subscribeMessage, unsubscribeMessage, filter, messageFormatter];
|
|
421
|
-
}
|
|
422
|
-
_sendPendingPrivateMessage() {
|
|
423
|
-
if (this._pendingPrivateSubscribe.length === 0)
|
|
424
|
-
return;
|
|
425
|
-
this._pendingPrivateSubscribe.forEach((params) => {
|
|
426
|
-
this.privateObserve(params).subscribe();
|
|
427
|
-
});
|
|
428
|
-
this._pendingPrivateSubscribe = [];
|
|
429
|
-
}
|
|
430
|
-
// 取消所有订阅
|
|
431
|
-
desotry() {
|
|
432
|
-
var _a;
|
|
433
|
-
this.wsSubject.unsubscribe();
|
|
434
|
-
(_a = this.privateWsSubject) == null ? void 0 : _a.unsubscribe();
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
// the topic reference count;
|
|
438
|
-
_WebSocketClient.__topicRefCountMap = /* @__PURE__ */ new Map();
|
|
439
|
-
var WebSocketClient = _WebSocketClient;
|
|
440
|
-
var ws_default = WebSocketClient;
|
|
441
|
-
|
|
442
|
-
// src/constants.ts
|
|
443
|
-
var __ORDERLY_API_URL_KEY__ = "__ORDERLY_API_URL__";
|
|
444
|
-
|
|
445
178
|
// src/ws/ws.ts
|
|
446
179
|
var defaultMessageFormatter = (message) => message.data;
|
|
447
180
|
var COMMON_ID = "OqdphuyCtYWxwzhxyLLjOWNdFP7sQt8RPWzmb5xY";
|
|
@@ -472,22 +205,30 @@ var WS = class {
|
|
|
472
205
|
this.createPrivateSC(options);
|
|
473
206
|
}
|
|
474
207
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
if (
|
|
478
|
-
|
|
479
|
-
} else {
|
|
480
|
-
url = WS_URL[options.networkId || "testnet"].public;
|
|
208
|
+
openPrivate(accountId) {
|
|
209
|
+
var _a;
|
|
210
|
+
if (((_a = this.privateSocket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
|
|
211
|
+
return;
|
|
481
212
|
}
|
|
482
|
-
this.
|
|
213
|
+
this.createPrivateSC(__spreadProps(__spreadValues({}, this.options), {
|
|
214
|
+
accountId
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
createPublicSC(options) {
|
|
218
|
+
this.publicSocket = new WebSocket(
|
|
219
|
+
`${this.options.publicUrl}/ws/stream/${COMMON_ID}`
|
|
220
|
+
);
|
|
483
221
|
this.publicSocket.onopen = this.onOpen.bind(this);
|
|
484
222
|
this.publicSocket.onmessage = this.onMessage.bind(this);
|
|
485
223
|
this.publicSocket.onclose = this.onClose.bind(this);
|
|
486
224
|
this.publicSocket.onerror = this.onError.bind(this);
|
|
487
225
|
}
|
|
488
226
|
createPrivateSC(options) {
|
|
489
|
-
|
|
490
|
-
this.
|
|
227
|
+
console.log("to open private webSocket ---->>>>");
|
|
228
|
+
this.options = options;
|
|
229
|
+
this.privateSocket = new WebSocket(
|
|
230
|
+
`${this.options.privateUrl}/v2/ws/private/stream/${options.accountId}`
|
|
231
|
+
);
|
|
491
232
|
this.privateSocket.onopen = this.onPrivateOpen.bind(this);
|
|
492
233
|
this.privateSocket.onmessage = this.onMessage.bind(this);
|
|
493
234
|
this.privateSocket.onerror = this.onPrivateError.bind(this);
|
|
@@ -505,18 +246,18 @@ var WS = class {
|
|
|
505
246
|
}
|
|
506
247
|
onPrivateOpen(event) {
|
|
507
248
|
console.log("Private WebSocket connection opened:");
|
|
508
|
-
|
|
509
|
-
this._pendingPrivateSubscribe.forEach(([params, cb]) => {
|
|
510
|
-
this.subscribe(params, cb);
|
|
511
|
-
});
|
|
512
|
-
this._pendingPrivateSubscribe = [];
|
|
513
|
-
}
|
|
249
|
+
this.authenticate(this.options.accountId);
|
|
514
250
|
this.privateIsReconnecting = false;
|
|
515
251
|
}
|
|
516
252
|
onMessage(event) {
|
|
517
253
|
try {
|
|
518
254
|
const message = JSON.parse(event.data);
|
|
519
255
|
const commoneHandler = messageHandlers.get(message.event);
|
|
256
|
+
if (message.event === "auth" && message.success) {
|
|
257
|
+
this.authenticated = true;
|
|
258
|
+
this.handlePendingPrivateTopic();
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
520
261
|
if (commoneHandler) {
|
|
521
262
|
commoneHandler.handle(message, this.send);
|
|
522
263
|
} else {
|
|
@@ -536,6 +277,14 @@ var WS = class {
|
|
|
536
277
|
console.log("WebSocket message received:", event.data);
|
|
537
278
|
}
|
|
538
279
|
}
|
|
280
|
+
handlePendingPrivateTopic() {
|
|
281
|
+
if (this._pendingPrivateSubscribe.length > 0) {
|
|
282
|
+
this._pendingPrivateSubscribe.forEach(([params, cb]) => {
|
|
283
|
+
this.privateSubscribe(params, cb);
|
|
284
|
+
});
|
|
285
|
+
this._pendingPrivateSubscribe = [];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
539
288
|
onClose(event) {
|
|
540
289
|
console.log("WebSocket connection closed:", event.reason);
|
|
541
290
|
}
|
|
@@ -589,7 +338,13 @@ var WS = class {
|
|
|
589
338
|
);
|
|
590
339
|
});
|
|
591
340
|
}
|
|
592
|
-
privateSubscribe(params, callback) {
|
|
341
|
+
privateSubscribe(params, callback, once) {
|
|
342
|
+
var _a, _b;
|
|
343
|
+
console.log("\u{1F449}", params, callback, (_a = this.privateSocket) == null ? void 0 : _a.readyState);
|
|
344
|
+
if (((_b = this.privateSocket) == null ? void 0 : _b.readyState) !== WebSocket.OPEN) {
|
|
345
|
+
this._pendingPrivateSubscribe.push([params, callback]);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
593
348
|
}
|
|
594
349
|
subscribe(params, callback, once) {
|
|
595
350
|
console.log("\u{1F449}", params, callback, this.publicSocket.readyState);
|
|
@@ -626,6 +381,9 @@ var WS = class {
|
|
|
626
381
|
};
|
|
627
382
|
}
|
|
628
383
|
}
|
|
384
|
+
// sendPublicMessage(){
|
|
385
|
+
// if(this.publicSocket.readyState !== )
|
|
386
|
+
// }
|
|
629
387
|
onceSubscribe(params, callback) {
|
|
630
388
|
this.subscribe(params, callback, true);
|
|
631
389
|
}
|
|
@@ -677,7 +435,6 @@ var WS = class {
|
|
|
677
435
|
// Annotate the CommonJS export names for ESM import in node:
|
|
678
436
|
0 && (module.exports = {
|
|
679
437
|
WS,
|
|
680
|
-
WebSocketClient,
|
|
681
438
|
__ORDERLY_API_URL_KEY__,
|
|
682
439
|
del,
|
|
683
440
|
get,
|