@lightconexyz/lightcone-sdk 0.1.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/README.md +232 -0
- package/dist/api/client.d.ts +225 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +452 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/error.d.ts +58 -0
- package/dist/api/error.d.ts.map +1 -0
- package/dist/api/error.js +98 -0
- package/dist/api/error.js.map +1 -0
- package/dist/api/index.d.ts +23 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +51 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/types/admin.d.ts +49 -0
- package/dist/api/types/admin.d.ts.map +1 -0
- package/dist/api/types/admin.js +13 -0
- package/dist/api/types/admin.js.map +1 -0
- package/dist/api/types/index.d.ts +14 -0
- package/dist/api/types/index.d.ts.map +1 -0
- package/dist/api/types/index.js +13 -0
- package/dist/api/types/index.js.map +1 -0
- package/dist/api/types/market.d.ts +186 -0
- package/dist/api/types/market.d.ts.map +1 -0
- package/dist/api/types/market.js +6 -0
- package/dist/api/types/market.js.map +1 -0
- package/dist/api/types/order.d.ts +190 -0
- package/dist/api/types/order.d.ts.map +1 -0
- package/dist/api/types/order.js +6 -0
- package/dist/api/types/order.js.map +1 -0
- package/dist/api/types/orderbook.d.ts +36 -0
- package/dist/api/types/orderbook.d.ts.map +1 -0
- package/dist/api/types/orderbook.js +6 -0
- package/dist/api/types/orderbook.js.map +1 -0
- package/dist/api/types/position.d.ts +60 -0
- package/dist/api/types/position.d.ts.map +1 -0
- package/dist/api/types/position.js +6 -0
- package/dist/api/types/position.js.map +1 -0
- package/dist/api/types/price_history.d.ts +68 -0
- package/dist/api/types/price_history.d.ts.map +1 -0
- package/dist/api/types/price_history.js +13 -0
- package/dist/api/types/price_history.js.map +1 -0
- package/dist/api/types/trade.d.ts +67 -0
- package/dist/api/types/trade.d.ts.map +1 -0
- package/dist/api/types/trade.js +13 -0
- package/dist/api/types/trade.js.map +1 -0
- package/dist/api/validation.d.ts +24 -0
- package/dist/api/validation.d.ts.map +1 -0
- package/dist/api/validation.js +53 -0
- package/dist/api/validation.js.map +1 -0
- package/dist/auth.d.ts +80 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +149 -0
- package/dist/auth.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +107 -0
- package/dist/index.js.map +1 -0
- package/dist/network.d.ts +5 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +8 -0
- package/dist/network.js.map +1 -0
- package/dist/program/accounts.d.ts +98 -0
- package/dist/program/accounts.d.ts.map +1 -0
- package/dist/program/accounts.js +319 -0
- package/dist/program/accounts.js.map +1 -0
- package/dist/program/builder.d.ts +94 -0
- package/dist/program/builder.d.ts.map +1 -0
- package/dist/program/builder.js +175 -0
- package/dist/program/builder.js.map +1 -0
- package/dist/program/client.d.ts +56 -0
- package/dist/program/client.d.ts.map +1 -0
- package/dist/program/client.js +288 -0
- package/dist/program/client.js.map +1 -0
- package/dist/program/constants.d.ts +108 -0
- package/dist/program/constants.d.ts.map +1 -0
- package/dist/program/constants.js +112 -0
- package/dist/program/constants.js.map +1 -0
- package/dist/program/index.d.ts +14 -0
- package/dist/program/index.d.ts.map +1 -0
- package/dist/program/index.js +149 -0
- package/dist/program/index.js.map +1 -0
- package/dist/program/instructions.d.ts +248 -0
- package/dist/program/instructions.d.ts.map +1 -0
- package/dist/program/instructions.js +692 -0
- package/dist/program/instructions.js.map +1 -0
- package/dist/program/orders.d.ts +151 -0
- package/dist/program/orders.d.ts.map +1 -0
- package/dist/program/orders.js +417 -0
- package/dist/program/orders.js.map +1 -0
- package/dist/program/pda.d.ts +73 -0
- package/dist/program/pda.d.ts.map +1 -0
- package/dist/program/pda.js +131 -0
- package/dist/program/pda.js.map +1 -0
- package/dist/program/types.d.ts +380 -0
- package/dist/program/types.d.ts.map +1 -0
- package/dist/program/types.js +27 -0
- package/dist/program/types.js.map +1 -0
- package/dist/program/utils.d.ts +91 -0
- package/dist/program/utils.d.ts.map +1 -0
- package/dist/program/utils.js +219 -0
- package/dist/program/utils.js.map +1 -0
- package/dist/shared/index.d.ts +8 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +18 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/price.d.ts +41 -0
- package/dist/shared/price.d.ts.map +1 -0
- package/dist/shared/price.js +57 -0
- package/dist/shared/price.js.map +1 -0
- package/dist/shared/scaling.d.ts +45 -0
- package/dist/shared/scaling.d.ts.map +1 -0
- package/dist/shared/scaling.js +84 -0
- package/dist/shared/scaling.js.map +1 -0
- package/dist/shared/types.d.ts +19 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +23 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/websocket/client.d.ts +238 -0
- package/dist/websocket/client.d.ts.map +1 -0
- package/dist/websocket/client.js +580 -0
- package/dist/websocket/client.js.map +1 -0
- package/dist/websocket/error.d.ts +47 -0
- package/dist/websocket/error.d.ts.map +1 -0
- package/dist/websocket/error.js +83 -0
- package/dist/websocket/error.js.map +1 -0
- package/dist/websocket/handlers.d.ts +97 -0
- package/dist/websocket/handlers.d.ts.map +1 -0
- package/dist/websocket/handlers.js +277 -0
- package/dist/websocket/handlers.js.map +1 -0
- package/dist/websocket/index.d.ts +38 -0
- package/dist/websocket/index.d.ts.map +1 -0
- package/dist/websocket/index.js +75 -0
- package/dist/websocket/index.js.map +1 -0
- package/dist/websocket/state/index.d.ts +7 -0
- package/dist/websocket/state/index.d.ts.map +1 -0
- package/dist/websocket/state/index.js +14 -0
- package/dist/websocket/state/index.js.map +1 -0
- package/dist/websocket/state/orderbook.d.ts +107 -0
- package/dist/websocket/state/orderbook.d.ts.map +1 -0
- package/dist/websocket/state/orderbook.js +293 -0
- package/dist/websocket/state/orderbook.js.map +1 -0
- package/dist/websocket/state/price.d.ts +108 -0
- package/dist/websocket/state/price.d.ts.map +1 -0
- package/dist/websocket/state/price.js +243 -0
- package/dist/websocket/state/price.js.map +1 -0
- package/dist/websocket/state/user.d.ts +83 -0
- package/dist/websocket/state/user.d.ts.map +1 -0
- package/dist/websocket/state/user.js +228 -0
- package/dist/websocket/state/user.js.map +1 -0
- package/dist/websocket/subscriptions.d.ts +143 -0
- package/dist/websocket/subscriptions.d.ts.map +1 -0
- package/dist/websocket/subscriptions.js +244 -0
- package/dist/websocket/subscriptions.js.map +1 -0
- package/dist/websocket/types.d.ts +417 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/dist/websocket/types.js +195 -0
- package/dist/websocket/types.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscription management for WebSocket channels.
|
|
3
|
+
*
|
|
4
|
+
* Tracks active subscriptions and supports re-subscribing after reconnect.
|
|
5
|
+
*/
|
|
6
|
+
import type { SubscribeParams } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Represents a subscription to a specific channel.
|
|
9
|
+
*/
|
|
10
|
+
export type Subscription = {
|
|
11
|
+
type: "BookUpdate";
|
|
12
|
+
orderbookIds: string[];
|
|
13
|
+
} | {
|
|
14
|
+
type: "Trades";
|
|
15
|
+
orderbookIds: string[];
|
|
16
|
+
} | {
|
|
17
|
+
type: "User";
|
|
18
|
+
user: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "PriceHistory";
|
|
21
|
+
orderbookId: string;
|
|
22
|
+
resolution: string;
|
|
23
|
+
includeOhlcv: boolean;
|
|
24
|
+
} | {
|
|
25
|
+
type: "Market";
|
|
26
|
+
marketPubkey: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Convert subscription to SubscribeParams for sending.
|
|
30
|
+
*/
|
|
31
|
+
export declare function subscriptionToParams(sub: Subscription): SubscribeParams;
|
|
32
|
+
/**
|
|
33
|
+
* Get the subscription type as a string.
|
|
34
|
+
*/
|
|
35
|
+
export declare function subscriptionType(sub: Subscription): string;
|
|
36
|
+
/**
|
|
37
|
+
* Manages active subscriptions.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SubscriptionManager {
|
|
40
|
+
/** Book update subscriptions (orderbook_id set) */
|
|
41
|
+
private bookUpdates;
|
|
42
|
+
/** Trades subscriptions (orderbook_id set) */
|
|
43
|
+
private trades;
|
|
44
|
+
/** User subscriptions (user pubkey set) */
|
|
45
|
+
private users;
|
|
46
|
+
/** Price history subscriptions (key -> params) */
|
|
47
|
+
private priceHistory;
|
|
48
|
+
/** Market subscriptions (market_pubkey set) */
|
|
49
|
+
private markets;
|
|
50
|
+
/**
|
|
51
|
+
* Add a book update subscription.
|
|
52
|
+
*/
|
|
53
|
+
addBookUpdate(orderbookIds: string[]): void;
|
|
54
|
+
/**
|
|
55
|
+
* Remove a book update subscription.
|
|
56
|
+
*/
|
|
57
|
+
removeBookUpdate(orderbookIds: string[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* Check if subscribed to book updates for an orderbook.
|
|
60
|
+
*/
|
|
61
|
+
isSubscribedBookUpdate(orderbookId: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Add a trades subscription.
|
|
64
|
+
*/
|
|
65
|
+
addTrades(orderbookIds: string[]): void;
|
|
66
|
+
/**
|
|
67
|
+
* Remove a trades subscription.
|
|
68
|
+
*/
|
|
69
|
+
removeTrades(orderbookIds: string[]): void;
|
|
70
|
+
/**
|
|
71
|
+
* Check if subscribed to trades for an orderbook.
|
|
72
|
+
*/
|
|
73
|
+
isSubscribedTrades(orderbookId: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Add a user subscription.
|
|
76
|
+
*/
|
|
77
|
+
addUser(user: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Remove a user subscription.
|
|
80
|
+
*/
|
|
81
|
+
removeUser(user: string): void;
|
|
82
|
+
/**
|
|
83
|
+
* Check if subscribed to a user.
|
|
84
|
+
*/
|
|
85
|
+
isSubscribedUser(user: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Add a price history subscription.
|
|
88
|
+
*/
|
|
89
|
+
addPriceHistory(orderbookId: string, resolution: string, includeOhlcv: boolean): void;
|
|
90
|
+
/**
|
|
91
|
+
* Remove a price history subscription.
|
|
92
|
+
*/
|
|
93
|
+
removePriceHistory(orderbookId: string, resolution: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Check if subscribed to price history for an orderbook/resolution.
|
|
96
|
+
*/
|
|
97
|
+
isSubscribedPriceHistory(orderbookId: string, resolution: string): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Add a market subscription.
|
|
100
|
+
*/
|
|
101
|
+
addMarket(marketPubkey: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Remove a market subscription.
|
|
104
|
+
*/
|
|
105
|
+
removeMarket(marketPubkey: string): void;
|
|
106
|
+
/**
|
|
107
|
+
* Check if subscribed to market events.
|
|
108
|
+
*/
|
|
109
|
+
isSubscribedMarket(marketPubkey: string): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Get all subscriptions for re-subscribing after reconnect.
|
|
112
|
+
*/
|
|
113
|
+
getAllSubscriptions(): Subscription[];
|
|
114
|
+
/**
|
|
115
|
+
* Clear all subscriptions.
|
|
116
|
+
*/
|
|
117
|
+
clear(): void;
|
|
118
|
+
/**
|
|
119
|
+
* Check if there are any active subscriptions.
|
|
120
|
+
*/
|
|
121
|
+
hasSubscriptions(): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Get count of active subscriptions.
|
|
124
|
+
*/
|
|
125
|
+
subscriptionCount(): number;
|
|
126
|
+
/**
|
|
127
|
+
* Get all subscribed orderbook IDs (for book updates).
|
|
128
|
+
*/
|
|
129
|
+
bookUpdateOrderbooks(): string[];
|
|
130
|
+
/**
|
|
131
|
+
* Get all subscribed orderbook IDs (for trades).
|
|
132
|
+
*/
|
|
133
|
+
tradeOrderbooks(): string[];
|
|
134
|
+
/**
|
|
135
|
+
* Get all subscribed users.
|
|
136
|
+
*/
|
|
137
|
+
subscribedUsers(): string[];
|
|
138
|
+
/**
|
|
139
|
+
* Get all subscribed markets.
|
|
140
|
+
*/
|
|
141
|
+
subscribedMarkets(): string[];
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.d.ts","sourceRoot":"","sources":["../../src/websocket/subscriptions.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAS/C;;GAEG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,GAC9C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IACE,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;CACvB,GACD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,YAAY,GAAG,eAAe,CAiBvE;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,MAAM,CAE1D;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,mDAAmD;IACnD,OAAO,CAAC,WAAW,CAA0B;IAC7C,8CAA8C;IAC9C,OAAO,CAAC,MAAM,CAA0B;IACxC,2CAA2C;IAC3C,OAAO,CAAC,KAAK,CAA0B;IACvC,kDAAkD;IAClD,OAAO,CAAC,YAAY,CAA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3B;;OAEG;IACH,iBAAiB,IAAI,MAAM;IAU3B;;OAEG;IACH,oBAAoB,IAAI,MAAM,EAAE;IAIhC;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE;IAI3B;;OAEG;IACH,iBAAiB,IAAI,MAAM,EAAE;CAG9B"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Subscription management for WebSocket channels.
|
|
4
|
+
*
|
|
5
|
+
* Tracks active subscriptions and supports re-subscribing after reconnect.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.SubscriptionManager = void 0;
|
|
9
|
+
exports.subscriptionToParams = subscriptionToParams;
|
|
10
|
+
exports.subscriptionType = subscriptionType;
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
/**
|
|
13
|
+
* Convert subscription to SubscribeParams for sending.
|
|
14
|
+
*/
|
|
15
|
+
function subscriptionToParams(sub) {
|
|
16
|
+
switch (sub.type) {
|
|
17
|
+
case "BookUpdate":
|
|
18
|
+
return (0, types_1.bookUpdateParams)(sub.orderbookIds);
|
|
19
|
+
case "Trades":
|
|
20
|
+
return (0, types_1.tradesParams)(sub.orderbookIds);
|
|
21
|
+
case "User":
|
|
22
|
+
return (0, types_1.userParams)(sub.user);
|
|
23
|
+
case "PriceHistory":
|
|
24
|
+
return (0, types_1.priceHistoryParams)(sub.orderbookId, sub.resolution, sub.includeOhlcv);
|
|
25
|
+
case "Market":
|
|
26
|
+
return (0, types_1.marketParams)(sub.marketPubkey);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get the subscription type as a string.
|
|
31
|
+
*/
|
|
32
|
+
function subscriptionType(sub) {
|
|
33
|
+
return sub.type.toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Manages active subscriptions.
|
|
37
|
+
*/
|
|
38
|
+
class SubscriptionManager {
|
|
39
|
+
/** Book update subscriptions (orderbook_id set) */
|
|
40
|
+
bookUpdates = new Set();
|
|
41
|
+
/** Trades subscriptions (orderbook_id set) */
|
|
42
|
+
trades = new Set();
|
|
43
|
+
/** User subscriptions (user pubkey set) */
|
|
44
|
+
users = new Set();
|
|
45
|
+
/** Price history subscriptions (key -> params) */
|
|
46
|
+
priceHistory = new Map();
|
|
47
|
+
/** Market subscriptions (market_pubkey set) */
|
|
48
|
+
markets = new Set();
|
|
49
|
+
/**
|
|
50
|
+
* Add a book update subscription.
|
|
51
|
+
*/
|
|
52
|
+
addBookUpdate(orderbookIds) {
|
|
53
|
+
for (const id of orderbookIds) {
|
|
54
|
+
this.bookUpdates.add(id);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Remove a book update subscription.
|
|
59
|
+
*/
|
|
60
|
+
removeBookUpdate(orderbookIds) {
|
|
61
|
+
for (const id of orderbookIds) {
|
|
62
|
+
this.bookUpdates.delete(id);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if subscribed to book updates for an orderbook.
|
|
67
|
+
*/
|
|
68
|
+
isSubscribedBookUpdate(orderbookId) {
|
|
69
|
+
return this.bookUpdates.has(orderbookId);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Add a trades subscription.
|
|
73
|
+
*/
|
|
74
|
+
addTrades(orderbookIds) {
|
|
75
|
+
for (const id of orderbookIds) {
|
|
76
|
+
this.trades.add(id);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Remove a trades subscription.
|
|
81
|
+
*/
|
|
82
|
+
removeTrades(orderbookIds) {
|
|
83
|
+
for (const id of orderbookIds) {
|
|
84
|
+
this.trades.delete(id);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Check if subscribed to trades for an orderbook.
|
|
89
|
+
*/
|
|
90
|
+
isSubscribedTrades(orderbookId) {
|
|
91
|
+
return this.trades.has(orderbookId);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Add a user subscription.
|
|
95
|
+
*/
|
|
96
|
+
addUser(user) {
|
|
97
|
+
this.users.add(user);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Remove a user subscription.
|
|
101
|
+
*/
|
|
102
|
+
removeUser(user) {
|
|
103
|
+
this.users.delete(user);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Check if subscribed to a user.
|
|
107
|
+
*/
|
|
108
|
+
isSubscribedUser(user) {
|
|
109
|
+
return this.users.has(user);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Add a price history subscription.
|
|
113
|
+
*/
|
|
114
|
+
addPriceHistory(orderbookId, resolution, includeOhlcv) {
|
|
115
|
+
const key = `${orderbookId}:${resolution}`;
|
|
116
|
+
this.priceHistory.set(key, [orderbookId, resolution, includeOhlcv]);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove a price history subscription.
|
|
120
|
+
*/
|
|
121
|
+
removePriceHistory(orderbookId, resolution) {
|
|
122
|
+
const key = `${orderbookId}:${resolution}`;
|
|
123
|
+
this.priceHistory.delete(key);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Check if subscribed to price history for an orderbook/resolution.
|
|
127
|
+
*/
|
|
128
|
+
isSubscribedPriceHistory(orderbookId, resolution) {
|
|
129
|
+
const key = `${orderbookId}:${resolution}`;
|
|
130
|
+
return this.priceHistory.has(key);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Add a market subscription.
|
|
134
|
+
*/
|
|
135
|
+
addMarket(marketPubkey) {
|
|
136
|
+
this.markets.add(marketPubkey);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Remove a market subscription.
|
|
140
|
+
*/
|
|
141
|
+
removeMarket(marketPubkey) {
|
|
142
|
+
this.markets.delete(marketPubkey);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Check if subscribed to market events.
|
|
146
|
+
*/
|
|
147
|
+
isSubscribedMarket(marketPubkey) {
|
|
148
|
+
return this.markets.has(marketPubkey) || this.markets.has("all");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get all subscriptions for re-subscribing after reconnect.
|
|
152
|
+
*/
|
|
153
|
+
getAllSubscriptions() {
|
|
154
|
+
const subs = [];
|
|
155
|
+
// Group book updates
|
|
156
|
+
if (this.bookUpdates.size > 0) {
|
|
157
|
+
subs.push({
|
|
158
|
+
type: "BookUpdate",
|
|
159
|
+
orderbookIds: Array.from(this.bookUpdates),
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
// Group trades
|
|
163
|
+
if (this.trades.size > 0) {
|
|
164
|
+
subs.push({
|
|
165
|
+
type: "Trades",
|
|
166
|
+
orderbookIds: Array.from(this.trades),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
// Users
|
|
170
|
+
for (const user of this.users) {
|
|
171
|
+
subs.push({ type: "User", user });
|
|
172
|
+
}
|
|
173
|
+
// Price history
|
|
174
|
+
for (const [orderbookId, resolution, includeOhlcv] of this.priceHistory.values()) {
|
|
175
|
+
subs.push({
|
|
176
|
+
type: "PriceHistory",
|
|
177
|
+
orderbookId,
|
|
178
|
+
resolution,
|
|
179
|
+
includeOhlcv,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
// Markets
|
|
183
|
+
for (const marketPubkey of this.markets) {
|
|
184
|
+
subs.push({ type: "Market", marketPubkey });
|
|
185
|
+
}
|
|
186
|
+
return subs;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Clear all subscriptions.
|
|
190
|
+
*/
|
|
191
|
+
clear() {
|
|
192
|
+
this.bookUpdates.clear();
|
|
193
|
+
this.trades.clear();
|
|
194
|
+
this.users.clear();
|
|
195
|
+
this.priceHistory.clear();
|
|
196
|
+
this.markets.clear();
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Check if there are any active subscriptions.
|
|
200
|
+
*/
|
|
201
|
+
hasSubscriptions() {
|
|
202
|
+
return (this.bookUpdates.size > 0 ||
|
|
203
|
+
this.trades.size > 0 ||
|
|
204
|
+
this.users.size > 0 ||
|
|
205
|
+
this.priceHistory.size > 0 ||
|
|
206
|
+
this.markets.size > 0);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Get count of active subscriptions.
|
|
210
|
+
*/
|
|
211
|
+
subscriptionCount() {
|
|
212
|
+
return (this.bookUpdates.size +
|
|
213
|
+
this.trades.size +
|
|
214
|
+
this.users.size +
|
|
215
|
+
this.priceHistory.size +
|
|
216
|
+
this.markets.size);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get all subscribed orderbook IDs (for book updates).
|
|
220
|
+
*/
|
|
221
|
+
bookUpdateOrderbooks() {
|
|
222
|
+
return Array.from(this.bookUpdates);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get all subscribed orderbook IDs (for trades).
|
|
226
|
+
*/
|
|
227
|
+
tradeOrderbooks() {
|
|
228
|
+
return Array.from(this.trades);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get all subscribed users.
|
|
232
|
+
*/
|
|
233
|
+
subscribedUsers() {
|
|
234
|
+
return Array.from(this.users);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get all subscribed markets.
|
|
238
|
+
*/
|
|
239
|
+
subscribedMarkets() {
|
|
240
|
+
return Array.from(this.markets);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.SubscriptionManager = SubscriptionManager;
|
|
244
|
+
//# sourceMappingURL=subscriptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptions.js","sourceRoot":"","sources":["../../src/websocket/subscriptions.ts"],"names":[],"mappings":";AAAA;;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YAAY,CAAC,IAAI,GAAG,CAAC;YAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CACtB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,CACL,IAAI,CAAC,WAAW,CAAC,IAAI;YACrB,IAAI,CAAC,MAAM,CAAC,IAAI;YAChB,IAAI,CAAC,KAAK,CAAC,IAAI;YACf,IAAI,CAAC,YAAY,CAAC,IAAI;YACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAClB,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;CACF;AAjPD,kDAiPC","sourcesContent":["/**\n * Subscription management for WebSocket channels.\n *\n * Tracks active subscriptions and supports re-subscribing after reconnect.\n */\n\nimport type { SubscribeParams } from \"./types\";\nimport {\n bookUpdateParams,\n tradesParams,\n userParams,\n priceHistoryParams,\n marketParams,\n} from \"./types\";\n\n/**\n * Represents a subscription to a specific channel.\n */\nexport type Subscription =\n | { type: \"BookUpdate\"; orderbookIds: string[] }\n | { type: \"Trades\"; orderbookIds: string[] }\n | { type: \"User\"; user: string }\n | {\n type: \"PriceHistory\";\n orderbookId: string;\n resolution: string;\n includeOhlcv: boolean;\n }\n | { type: \"Market\"; marketPubkey: string };\n\n/**\n * Convert subscription to SubscribeParams for sending.\n */\nexport function subscriptionToParams(sub: Subscription): SubscribeParams {\n switch (sub.type) {\n case \"BookUpdate\":\n return bookUpdateParams(sub.orderbookIds);\n case \"Trades\":\n return tradesParams(sub.orderbookIds);\n case \"User\":\n return userParams(sub.user);\n case \"PriceHistory\":\n return priceHistoryParams(\n sub.orderbookId,\n sub.resolution,\n sub.includeOhlcv\n );\n case \"Market\":\n return marketParams(sub.marketPubkey);\n }\n}\n\n/**\n * Get the subscription type as a string.\n */\nexport function subscriptionType(sub: Subscription): string {\n return sub.type.toLowerCase();\n}\n\n/**\n * Manages active subscriptions.\n */\nexport class SubscriptionManager {\n /** Book update subscriptions (orderbook_id set) */\n private bookUpdates: Set<string> = new Set();\n /** Trades subscriptions (orderbook_id set) */\n private trades: Set<string> = new Set();\n /** User subscriptions (user pubkey set) */\n private users: Set<string> = new Set();\n /** Price history subscriptions (key -> params) */\n private priceHistory: Map<string, [string, string, boolean]> = new Map();\n /** Market subscriptions (market_pubkey set) */\n private markets: Set<string> = new Set();\n\n /**\n * Add a book update subscription.\n */\n addBookUpdate(orderbookIds: string[]): void {\n for (const id of orderbookIds) {\n this.bookUpdates.add(id);\n }\n }\n\n /**\n * Remove a book update subscription.\n */\n removeBookUpdate(orderbookIds: string[]): void {\n for (const id of orderbookIds) {\n this.bookUpdates.delete(id);\n }\n }\n\n /**\n * Check if subscribed to book updates for an orderbook.\n */\n isSubscribedBookUpdate(orderbookId: string): boolean {\n return this.bookUpdates.has(orderbookId);\n }\n\n /**\n * Add a trades subscription.\n */\n addTrades(orderbookIds: string[]): void {\n for (const id of orderbookIds) {\n this.trades.add(id);\n }\n }\n\n /**\n * Remove a trades subscription.\n */\n removeTrades(orderbookIds: string[]): void {\n for (const id of orderbookIds) {\n this.trades.delete(id);\n }\n }\n\n /**\n * Check if subscribed to trades for an orderbook.\n */\n isSubscribedTrades(orderbookId: string): boolean {\n return this.trades.has(orderbookId);\n }\n\n /**\n * Add a user subscription.\n */\n addUser(user: string): void {\n this.users.add(user);\n }\n\n /**\n * Remove a user subscription.\n */\n removeUser(user: string): void {\n this.users.delete(user);\n }\n\n /**\n * Check if subscribed to a user.\n */\n isSubscribedUser(user: string): boolean {\n return this.users.has(user);\n }\n\n /**\n * Add a price history subscription.\n */\n addPriceHistory(\n orderbookId: string,\n resolution: string,\n includeOhlcv: boolean\n ): void {\n const key = `${orderbookId}:${resolution}`;\n this.priceHistory.set(key, [orderbookId, resolution, includeOhlcv]);\n }\n\n /**\n * Remove a price history subscription.\n */\n removePriceHistory(orderbookId: string, resolution: string): void {\n const key = `${orderbookId}:${resolution}`;\n this.priceHistory.delete(key);\n }\n\n /**\n * Check if subscribed to price history for an orderbook/resolution.\n */\n isSubscribedPriceHistory(orderbookId: string, resolution: string): boolean {\n const key = `${orderbookId}:${resolution}`;\n return this.priceHistory.has(key);\n }\n\n /**\n * Add a market subscription.\n */\n addMarket(marketPubkey: string): void {\n this.markets.add(marketPubkey);\n }\n\n /**\n * Remove a market subscription.\n */\n removeMarket(marketPubkey: string): void {\n this.markets.delete(marketPubkey);\n }\n\n /**\n * Check if subscribed to market events.\n */\n isSubscribedMarket(marketPubkey: string): boolean {\n return this.markets.has(marketPubkey) || this.markets.has(\"all\");\n }\n\n /**\n * Get all subscriptions for re-subscribing after reconnect.\n */\n getAllSubscriptions(): Subscription[] {\n const subs: Subscription[] = [];\n\n // Group book updates\n if (this.bookUpdates.size > 0) {\n subs.push({\n type: \"BookUpdate\",\n orderbookIds: Array.from(this.bookUpdates),\n });\n }\n\n // Group trades\n if (this.trades.size > 0) {\n subs.push({\n type: \"Trades\",\n orderbookIds: Array.from(this.trades),\n });\n }\n\n // Users\n for (const user of this.users) {\n subs.push({ type: \"User\", user });\n }\n\n // Price history\n for (const [orderbookId, resolution, includeOhlcv] of this.priceHistory.values()) {\n subs.push({\n type: \"PriceHistory\",\n orderbookId,\n resolution,\n includeOhlcv,\n });\n }\n\n // Markets\n for (const marketPubkey of this.markets) {\n subs.push({ type: \"Market\", marketPubkey });\n }\n\n return subs;\n }\n\n /**\n * Clear all subscriptions.\n */\n clear(): void {\n this.bookUpdates.clear();\n this.trades.clear();\n this.users.clear();\n this.priceHistory.clear();\n this.markets.clear();\n }\n\n /**\n * Check if there are any active subscriptions.\n */\n hasSubscriptions(): boolean {\n return (\n this.bookUpdates.size > 0 ||\n this.trades.size > 0 ||\n this.users.size > 0 ||\n this.priceHistory.size > 0 ||\n this.markets.size > 0\n );\n }\n\n /**\n * Get count of active subscriptions.\n */\n subscriptionCount(): number {\n return (\n this.bookUpdates.size +\n this.trades.size +\n this.users.size +\n this.priceHistory.size +\n this.markets.size\n );\n }\n\n /**\n * Get all subscribed orderbook IDs (for book updates).\n */\n bookUpdateOrderbooks(): string[] {\n return Array.from(this.bookUpdates);\n }\n\n /**\n * Get all subscribed orderbook IDs (for trades).\n */\n tradeOrderbooks(): string[] {\n return Array.from(this.trades);\n }\n\n /**\n * Get all subscribed users.\n */\n subscribedUsers(): string[] {\n return Array.from(this.users);\n }\n\n /**\n * Get all subscribed markets.\n */\n subscribedMarkets(): string[] {\n return Array.from(this.markets);\n }\n}\n"]}
|