@chainstream-io/sdk 0.1.5 → 0.1.7

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.
Files changed (147) hide show
  1. package/README.md +46 -0
  2. package/dist/esm/index.d.ts +1 -1
  3. package/dist/esm/index.js +76 -60
  4. package/dist/esm/openapi/apis/BlockchainApi.js +61 -44
  5. package/dist/esm/openapi/apis/DefiSolanaMoonshotApi.js +67 -50
  6. package/dist/esm/openapi/apis/DefiSolanaPumpfunApi.js +38 -25
  7. package/dist/esm/openapi/apis/DexApi.js +205 -176
  8. package/dist/esm/openapi/apis/DexPoolApi.js +41 -28
  9. package/dist/esm/openapi/apis/EndpointApi.js +212 -175
  10. package/dist/esm/openapi/apis/IpfsApi.js +38 -25
  11. package/dist/esm/openapi/apis/JobsApi.js +65 -48
  12. package/dist/esm/openapi/apis/RankingApi.js +278 -249
  13. package/dist/esm/openapi/apis/RedPacketApi.js +294 -253
  14. package/dist/esm/openapi/apis/TokenApi.js +1145 -1056
  15. package/dist/esm/openapi/apis/TradeApi.js +233 -208
  16. package/dist/esm/openapi/apis/TransactionApi.js +42 -29
  17. package/dist/esm/openapi/apis/WalletApi.js +148 -123
  18. package/dist/esm/openapi/apis/WatchlistApi.js +41 -28
  19. package/dist/esm/openapi/runtime.js +81 -69
  20. package/dist/esm/stream/index.d.ts +3 -0
  21. package/dist/esm/stream/index.js +3 -0
  22. package/dist/esm/{api → stream}/stream.js +36 -29
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +75 -59
  25. package/dist/openapi/apis/BlockchainApi.js +62 -78
  26. package/dist/openapi/apis/DefiSolanaMoonshotApi.js +68 -84
  27. package/dist/openapi/apis/DefiSolanaPumpfunApi.js +39 -59
  28. package/dist/openapi/apis/DexApi.js +206 -210
  29. package/dist/openapi/apis/DexPoolApi.js +42 -62
  30. package/dist/openapi/apis/EndpointApi.js +213 -209
  31. package/dist/openapi/apis/IpfsApi.js +39 -59
  32. package/dist/openapi/apis/JobsApi.js +66 -82
  33. package/dist/openapi/apis/RankingApi.js +279 -283
  34. package/dist/openapi/apis/RedPacketApi.js +295 -287
  35. package/dist/openapi/apis/TokenApi.js +1146 -1090
  36. package/dist/openapi/apis/TradeApi.js +234 -242
  37. package/dist/openapi/apis/TransactionApi.js +43 -63
  38. package/dist/openapi/apis/WalletApi.js +149 -157
  39. package/dist/openapi/apis/WatchlistApi.js +42 -62
  40. package/dist/openapi/runtime.js +81 -69
  41. package/dist/stream/index.d.ts +3 -0
  42. package/dist/stream/index.js +19 -0
  43. package/dist/{api → stream}/stream.js +36 -29
  44. package/package.json +29 -26
  45. package/src/api/stream.fields.ts +0 -271
  46. package/src/api/stream.model.ts +0 -307
  47. package/src/api/stream.ts +0 -1086
  48. package/src/index.ts +0 -188
  49. package/src/openapi/apis/BlockchainApi.ts +0 -140
  50. package/src/openapi/apis/DefiSolanaMoonshotApi.ts +0 -145
  51. package/src/openapi/apis/DefiSolanaPumpfunApi.ts +0 -86
  52. package/src/openapi/apis/DexApi.ts +0 -490
  53. package/src/openapi/apis/DexPoolApi.ts +0 -107
  54. package/src/openapi/apis/EndpointApi.ts +0 -421
  55. package/src/openapi/apis/IpfsApi.ts +0 -66
  56. package/src/openapi/apis/JobsApi.ts +0 -135
  57. package/src/openapi/apis/RankingApi.ts +0 -939
  58. package/src/openapi/apis/RedPacketApi.ts +0 -621
  59. package/src/openapi/apis/TokenApi.ts +0 -2569
  60. package/src/openapi/apis/TradeApi.ts +0 -596
  61. package/src/openapi/apis/TransactionApi.ts +0 -95
  62. package/src/openapi/apis/WalletApi.ts +0 -365
  63. package/src/openapi/apis/WatchlistApi.ts +0 -107
  64. package/src/openapi/apis/index.ts +0 -17
  65. package/src/openapi/index.ts +0 -5
  66. package/src/openapi/models/BlockchainDTO.ts +0 -93
  67. package/src/openapi/models/BlockchainLatestBlockDTO.ts +0 -75
  68. package/src/openapi/models/BooleanResultDTO.ts +0 -66
  69. package/src/openapi/models/CalculatePnlInput.ts +0 -65
  70. package/src/openapi/models/Candle.ts +0 -130
  71. package/src/openapi/models/ClaimRedPacketInput.ts +0 -90
  72. package/src/openapi/models/CreateEndpointInput.ts +0 -121
  73. package/src/openapi/models/CreateRedPacketInput.ts +0 -124
  74. package/src/openapi/models/CreateRedPacketReply.ts +0 -75
  75. package/src/openapi/models/CreateTokenInput.ts +0 -139
  76. package/src/openapi/models/CreateTokenReply.ts +0 -75
  77. package/src/openapi/models/DexDTO.ts +0 -90
  78. package/src/openapi/models/DexPage.ts +0 -114
  79. package/src/openapi/models/DexPoolDTO.ts +0 -141
  80. package/src/openapi/models/EndpointListResponse.ts +0 -97
  81. package/src/openapi/models/EndpointOperationResponse.ts +0 -65
  82. package/src/openapi/models/EndpointResponse.ts +0 -145
  83. package/src/openapi/models/EndpointSecretResponse.ts +0 -65
  84. package/src/openapi/models/FilterCondition.ts +0 -135
  85. package/src/openapi/models/GainersAndLosersDTO.ts +0 -93
  86. package/src/openapi/models/GainersAndLosersPage.ts +0 -114
  87. package/src/openapi/models/JobDTO.ts +0 -75
  88. package/src/openapi/models/JobStreamingDTO.ts +0 -75
  89. package/src/openapi/models/Link.ts +0 -88
  90. package/src/openapi/models/MoonshotCreateTokenInput.ts +0 -182
  91. package/src/openapi/models/MoonshotCreateTokenReply.ts +0 -75
  92. package/src/openapi/models/MoonshotSubmitCreateToken200Response.ts +0 -73
  93. package/src/openapi/models/MoonshotSubmitCreateTokenInput.ts +0 -74
  94. package/src/openapi/models/PumpCreateTokenInput.ts +0 -180
  95. package/src/openapi/models/PumpCreateTokenReply.ts +0 -74
  96. package/src/openapi/models/QuoteResponse.ts +0 -105
  97. package/src/openapi/models/RedPacketClaimDTO.ts +0 -148
  98. package/src/openapi/models/RedPacketClaimsPage.ts +0 -110
  99. package/src/openapi/models/RedPacketDTO.ts +0 -229
  100. package/src/openapi/models/RedPacketReply.ts +0 -66
  101. package/src/openapi/models/RedPacketSendTxInput.ts +0 -66
  102. package/src/openapi/models/RedPacketSendTxResponse.ts +0 -66
  103. package/src/openapi/models/RedPacketsPage.ts +0 -110
  104. package/src/openapi/models/Resolution.ts +0 -61
  105. package/src/openapi/models/SendTxInput.ts +0 -93
  106. package/src/openapi/models/SendTxResponse.ts +0 -84
  107. package/src/openapi/models/SwapInput.ts +0 -157
  108. package/src/openapi/models/SwapReply.ts +0 -75
  109. package/src/openapi/models/SwapRouteInput.ts +0 -186
  110. package/src/openapi/models/SwapRouteResponse.ts +0 -101
  111. package/src/openapi/models/Token.ts +0 -251
  112. package/src/openapi/models/TokenCreationDTO.ts +0 -131
  113. package/src/openapi/models/TokenCreationPage.ts +0 -114
  114. package/src/openapi/models/TokenCreatorsDTO.ts +0 -81
  115. package/src/openapi/models/TokenExtraDTO.ts +0 -225
  116. package/src/openapi/models/TokenHolder.ts +0 -93
  117. package/src/openapi/models/TokenHolderPage.ts +0 -114
  118. package/src/openapi/models/TokenListPage.ts +0 -114
  119. package/src/openapi/models/TokenMarketData.ts +0 -190
  120. package/src/openapi/models/TokenMetadata.ts +0 -188
  121. package/src/openapi/models/TokenPage.ts +0 -122
  122. package/src/openapi/models/TokenPriceDTO.ts +0 -93
  123. package/src/openapi/models/TokenPricePage.ts +0 -114
  124. package/src/openapi/models/TokenSocialMediasDTO.ts +0 -161
  125. package/src/openapi/models/TokenStat.ts +0 -1152
  126. package/src/openapi/models/TopTradersDTO.ts +0 -164
  127. package/src/openapi/models/TopTradersPage.ts +0 -114
  128. package/src/openapi/models/TradeDetailDTO.ts +0 -282
  129. package/src/openapi/models/TradeEvent.ts +0 -184
  130. package/src/openapi/models/TradePage.ts +0 -114
  131. package/src/openapi/models/TradeType.ts +0 -53
  132. package/src/openapi/models/UpdateEndpointInput.ts +0 -129
  133. package/src/openapi/models/WalletBalanceDetailDTO.ts +0 -282
  134. package/src/openapi/models/WalletBalancesDTO.ts +0 -92
  135. package/src/openapi/models/WalletPnlDTO.ts +0 -264
  136. package/src/openapi/models/index.ts +0 -72
  137. package/src/openapi/runtime.ts +0 -432
  138. /package/dist/{api → esm/stream}/stream.d.ts +0 -0
  139. /package/dist/{api → esm/stream}/stream.fields.d.ts +0 -0
  140. /package/dist/esm/{api → stream}/stream.fields.js +0 -0
  141. /package/dist/{api → esm/stream}/stream.model.d.ts +0 -0
  142. /package/dist/esm/{api → stream}/stream.model.js +0 -0
  143. /package/dist/{esm/api → stream}/stream.d.ts +0 -0
  144. /package/dist/{esm/api → stream}/stream.fields.d.ts +0 -0
  145. /package/dist/{api → stream}/stream.fields.js +0 -0
  146. /package/dist/{esm/api → stream}/stream.model.d.ts +0 -0
  147. /package/dist/{api → stream}/stream.model.js +0 -0
package/src/api/stream.ts DELETED
@@ -1,1086 +0,0 @@
1
- import { Centrifuge, ConnectionTokenContext } from "@chainstream-io/centrifuge";
2
- import { DexRequestContext } from "..";
3
- import { Resolution } from "../openapi";
4
- import {
5
- DexPoolBalance,
6
- NewToken,
7
- TokenMetadata,
8
- TokenHolder,
9
- TokenStat,
10
- TokenLiquidity,
11
- WalletBalance,
12
- TokenSupply,
13
- WalletPnl,
14
- ChannelType,
15
- TokenCandle,
16
- TradeActivity,
17
- WalletTokenPnl,
18
- RankingType,
19
- Dex,
20
- RankingTokenList,
21
- TokenBondingCurve,
22
- } from "./stream.model";
23
- import { replaceFilterFields } from "./stream.fields";
24
-
25
- export interface Unsubscrible {
26
- unsubscribe(): void;
27
- }
28
-
29
- export class StreamApi {
30
- private realtimeClient: Centrifuge;
31
- private listenersMap: Map<string, Set<(data: any) => void>>;
32
-
33
- constructor(context: DexRequestContext) {
34
- const realtimeEndpoint = context.streamUrl;
35
- this.realtimeClient = new Centrifuge(realtimeEndpoint, {
36
- getToken: async (_ctx: ConnectionTokenContext) => {
37
- return typeof context.accessToken === "string"
38
- ? context.accessToken
39
- : await context.accessToken.getToken();
40
- },
41
- });
42
-
43
- this.realtimeClient
44
- .on("connected", () => {
45
- console.log("[streaming] connected");
46
- })
47
- .on("disconnected", (err) => {
48
- console.warn("[streaming] disconnected", err);
49
- })
50
- .on("error", (err) => {
51
- console.error("[streaming] error: ", err);
52
- });
53
-
54
- this.listenersMap = new Map();
55
- }
56
-
57
- connect() {
58
- this.realtimeClient.connect();
59
- }
60
-
61
- /**
62
- * Start batching commands for efficient bulk operations
63
- * All subscription commands after this call will be batched until stopBatching is called
64
- */
65
- startBatching() {
66
- this.realtimeClient.startBatching();
67
- }
68
-
69
- /**
70
- * Stop batching and flush all collected commands to the server
71
- * This will send all batched subscription commands in a single network request
72
- */
73
- stopBatching() {
74
- this.realtimeClient.stopBatching();
75
- }
76
-
77
- /**
78
- * Batch subscribe method that accepts a function containing subscription calls
79
- * All subscription methods called within the function will be batched
80
- * @param batchFunction Function containing subscription method calls
81
- * @returns Array of unsubscribe functions
82
- */
83
- batchSubscribe(batchFunction: () => Unsubscrible[]): Unsubscrible[] {
84
- // Start batching commands
85
- this.startBatching();
86
-
87
- // Execute the batch function (all subscription calls will be batched)
88
- const unsubscribles = batchFunction();
89
-
90
- // Stop batching and flush all commands
91
- this.stopBatching();
92
-
93
- return unsubscribles;
94
- }
95
-
96
- /**
97
- * Batch unsubscribe method that accepts an array of unsubscribe functions
98
- * All unsubscribe calls will be executed at once
99
- * @param unsubscribles Array of unsubscribe functions to execute
100
- */
101
- batchUnsubscribe(unsubscribles: Unsubscrible[]): void {
102
- if (!unsubscribles || unsubscribles.length === 0) {
103
- return;
104
- }
105
-
106
- // Execute all unsubscribe calls
107
- unsubscribles.forEach((unsub) => {
108
- if (unsub && typeof unsub.unsubscribe === "function") {
109
- unsub.unsubscribe();
110
- }
111
- });
112
- }
113
-
114
- subscribe<T = any>(channel: string, fn: (data: T) => void, filter?: string, methodName?: string): Unsubscrible {
115
- let sub = this.realtimeClient.getSubscription(channel);
116
- let listeners = this.listenersMap.get(channel);
117
-
118
- if (!sub) {
119
- listeners = new Set();
120
- this.listenersMap.set(channel, listeners);
121
-
122
- console.log("[xrealtime] create new sub: ", channel);
123
-
124
- // Process filter expression with method-specific field mappings
125
- const processedFilter = filter && methodName ? replaceFilterFields(filter, methodName) : filter;
126
-
127
- sub = this.realtimeClient.newSubscription(channel, {
128
- delta: "fossil",
129
- ...(processedFilter && { filter: processedFilter }),
130
- });
131
-
132
- sub
133
- .on("subscribed", () => {
134
- console.log("[xrealtime] subscribed", channel);
135
- })
136
- .on("unsubscribed", () => {
137
- console.log("[xrealtime] unsubscribed", channel);
138
- })
139
- .on("publication", (ctx) => {
140
- // console.log('[xrealtime] publication, ctx.data: ', ctx.data);
141
- listeners?.forEach((it) => it(ctx.data));
142
- })
143
- .subscribe();
144
- }
145
-
146
- listeners?.add(fn);
147
-
148
- return new StreamUnsubscrible<T>(this, channel, fn);
149
- }
150
-
151
- unsubscribe<T = any>(channel: string, fn: (data: T) => void) {
152
- const listeners = this.listenersMap.get(channel);
153
- if (!listeners) {
154
- return;
155
- }
156
-
157
- listeners.delete(fn);
158
- console.log("unsubscribe, remain listeners: ", listeners.size);
159
-
160
- if (listeners.size === 0) {
161
- console.log("unsubscribe channel: ", channel);
162
-
163
- const sub = this.realtimeClient.getSubscription(channel);
164
- if (sub) {
165
- sub.unsubscribe();
166
- this.realtimeClient.removeSubscription(sub);
167
- }
168
-
169
- this.listenersMap.delete(channel);
170
- }
171
- }
172
-
173
- private formatScientificNotation(value: any): string {
174
- if (value === null || value === undefined) {
175
- return "0";
176
- }
177
-
178
- const strValue = value.toString();
179
- if (strValue.includes("e-") || strValue.includes("E-")) {
180
- return Number(value)
181
- .toFixed(20)
182
- .replace(/\.?0+$/, "");
183
- }
184
-
185
- return strValue;
186
- }
187
-
188
- subscribeTokenCandles({
189
- chain,
190
- tokenAddress,
191
- resolution,
192
- callback,
193
- filter,
194
- }: {
195
- chain: string;
196
- tokenAddress: string;
197
- resolution: Resolution;
198
- callback: (data: TokenCandle) => void;
199
- filter?: string;
200
- }): Unsubscrible {
201
- const channel = `dex-candle:${chain}_${tokenAddress}_${resolution}`;
202
- return this.subscribe(channel, (data: any) => {
203
- callback({
204
- open: data.o,
205
- close: data.c,
206
- high: data.h,
207
- low: data.l,
208
- volume: data.v,
209
- resolution: data.r,
210
- time: data.t,
211
- number: data.n,
212
- });
213
- }, filter, "subscribeTokenCandles");
214
- }
215
-
216
- subscribeTokenStats({
217
- chain,
218
- tokenAddress,
219
- callback,
220
- filter,
221
- }: {
222
- chain: string;
223
- tokenAddress: string;
224
- callback: (data: TokenStat) => void;
225
- filter?: string;
226
- }): Unsubscrible {
227
- const channel = `dex-token-stats:${chain}_${tokenAddress}`;
228
- return this.subscribe(channel, (data: any) =>
229
- callback({
230
- address: data.a,
231
- timestamp: data.t,
232
- buys1m: data.b1m,
233
- sells1m: data.s1m,
234
- buyers1m: data.be1m,
235
- sellers1m: data.se1m,
236
- buyVolumeInUsd1m: this.formatScientificNotation(data.bviu1m),
237
- sellVolumeInUsd1m: this.formatScientificNotation(data.sviu1m),
238
- price1m: this.formatScientificNotation(data.p1m),
239
- openInUsd1m: this.formatScientificNotation(data.oiu1m),
240
- closeInUsd1m: this.formatScientificNotation(data.ciu1m),
241
-
242
- buys5m: data.b5m,
243
- sells5m: data.s5m,
244
- buyers5m: data.be5m,
245
- sellers5m: data.se5m,
246
- buyVolumeInUsd5m: this.formatScientificNotation(data.bviu5m),
247
- sellVolumeInUsd5m: this.formatScientificNotation(data.sviu5m),
248
- price5m: this.formatScientificNotation(data.p5m),
249
- openInUsd5m: this.formatScientificNotation(data.oiu5m),
250
- closeInUsd5m: this.formatScientificNotation(data.ciu5m),
251
-
252
- buys15m: data.b15m,
253
- sells15m: data.s15m,
254
- buyers15m: data.be15m,
255
- sellers15m: data.se15m,
256
- buyVolumeInUsd15m: this.formatScientificNotation(data.bviu15m),
257
- sellVolumeInUsd15m: this.formatScientificNotation(data.sviu15m),
258
- price15m: this.formatScientificNotation(data.p15m),
259
- openInUsd15m: this.formatScientificNotation(data.oiu15m),
260
- closeInUsd15m: this.formatScientificNotation(data.ciu15m),
261
-
262
- buys30m: data.b30m,
263
- sells30m: data.s30m,
264
- buyers30m: data.be30m,
265
- sellers30m: data.se30m,
266
- buyVolumeInUsd30m: this.formatScientificNotation(data.bviu30m),
267
- sellVolumeInUsd30m: this.formatScientificNotation(data.sviu30m),
268
- price30m: this.formatScientificNotation(data.p30m),
269
- openInUsd30m: this.formatScientificNotation(data.oiu30m),
270
- closeInUsd30m: this.formatScientificNotation(data.ciu30m),
271
-
272
- buys1h: data.b1h,
273
- sells1h: data.s1h,
274
- buyers1h: data.be1h,
275
- sellers1h: data.se1h,
276
- buyVolumeInUsd1h: this.formatScientificNotation(data.bviu1h),
277
- sellVolumeInUsd1h: this.formatScientificNotation(data.sviu1h),
278
- price1h: this.formatScientificNotation(data.p1h),
279
- openInUsd1h: this.formatScientificNotation(data.oiu1h),
280
- closeInUsd1h: this.formatScientificNotation(data.ciu1h),
281
-
282
- buys4h: data.b4h,
283
- sells4h: data.s4h,
284
- buyers4h: data.be4h,
285
- sellers4h: data.se4h,
286
- buyVolumeInUsd4h: this.formatScientificNotation(data.bviu4h),
287
- sellVolumeInUsd4h: this.formatScientificNotation(data.sviu4h),
288
- price4h: this.formatScientificNotation(data.p4h),
289
- openInUsd4h: this.formatScientificNotation(data.oiu4h),
290
- closeInUsd4h: this.formatScientificNotation(data.ciu4h),
291
-
292
- buys24h: data.b24h,
293
- sells24h: data.s24h,
294
- buyers24h: data.be24h,
295
- sellers24h: data.se24h,
296
- buyVolumeInUsd24h: this.formatScientificNotation(data.bviu24h),
297
- sellVolumeInUsd24h: this.formatScientificNotation(data.sviu24h),
298
- price24h: this.formatScientificNotation(data.p24h),
299
- openInUsd24h: this.formatScientificNotation(data.oiu24h),
300
- closeInUsd24h: this.formatScientificNotation(data.ciu24h),
301
-
302
- price: this.formatScientificNotation(data.p),
303
- }), filter, "subscribeTokenStats");
304
- }
305
-
306
- subscribeTokenHolders({
307
- chain,
308
- tokenAddress,
309
- callback,
310
- filter,
311
- }: {
312
- chain: string;
313
- tokenAddress: string;
314
- callback: (data: TokenHolder) => void;
315
- filter?: string;
316
- }): Unsubscrible {
317
- const channel = `dex-token-holding:${chain}_${tokenAddress}`;
318
- return this.subscribe(channel, (data: any) =>
319
- callback({
320
- tokenAddress: data.a,
321
- holders: data.h,
322
- top100Amount: this.formatScientificNotation(data.t100a),
323
- top10Amount: this.formatScientificNotation(data.t10a),
324
- top100Holders: data.t100h,
325
- top10Holders: data.t10h,
326
- top100Ratio: this.formatScientificNotation(data.t100r),
327
- top10Ratio: this.formatScientificNotation(data.t10r),
328
- creatorsHolders: data.ch,
329
- creatorsAmount: this.formatScientificNotation(data.ca),
330
- creatorsRatio: this.formatScientificNotation(data.cr),
331
- timestamp: data.ts,
332
- }), filter, "subscribeTokenHolders");
333
- }
334
-
335
- subscribeNewToken({
336
- chain,
337
- callback,
338
- filter,
339
- }: {
340
- chain: string;
341
- callback: (data: NewToken) => void;
342
- filter?: string;
343
- }): Unsubscrible {
344
- const channel = `dex-new-token:${chain}`;
345
- return this.subscribe(channel, (data: any) => {
346
- const result: any = {
347
- tokenAddress: data.a,
348
- name: data.n,
349
- symbol: data.s,
350
- createdAtMs: data.cts,
351
- };
352
-
353
- if (data.dec) {
354
- result.decimals = data.dec;
355
- }
356
-
357
- if (data.lf) {
358
- result.launchFrom = {};
359
- if (data.lf.pa) { result.launchFrom.programAddress = data.lf.pa }
360
- if (data.lf.pf) { result.launchFrom.protocolFamily = data.lf.pf }
361
- if (data.lf.pn) { result.launchFrom.protocolName = data.lf.pn }
362
- }
363
-
364
- callback(result);
365
- }, filter, "subscribeNewToken");
366
- }
367
-
368
- subscribeNewTokensMetadata({
369
- chain,
370
- callback,
371
- }: {
372
- chain: string;
373
- callback: (data: TokenMetadata[]) => void;
374
- }): Unsubscrible {
375
- const channel = `dex-new-tokens-metadata:${chain}`;
376
- return this.subscribe(channel, (data: any[]) =>
377
- callback(
378
- data.map(
379
- (it: any) =>
380
- ({
381
- tokenAddress: it.a,
382
- name: it.n,
383
- symbol: it.s,
384
- imageUrl: it.iu,
385
- description: it.de,
386
- socialMedia: (() => {
387
- const socialMedia: any = {};
388
- if (it.sm?.tw) { socialMedia.twitter = it.sm.tw }
389
- if (it.sm?.tg) { socialMedia.telegram = it.sm.tg }
390
- if (it.sm?.w) { socialMedia.website = it.sm.w }
391
- if (it.sm?.tt) { socialMedia.tiktok = it.sm.tt }
392
- if (it.sm?.dc) { socialMedia.discord = it.sm.dc }
393
- if (it.sm?.fb) { socialMedia.facebook = it.sm.fb }
394
- if (it.sm?.gh) { socialMedia.github = it.sm.gh }
395
- if (it.sm?.ig) { socialMedia.instagram = it.sm.ig }
396
- if (it.sm?.li) { socialMedia.linkedin = it.sm.li }
397
- if (it.sm?.md) { socialMedia.medium = it.sm.md }
398
- if (it.sm?.rd) { socialMedia.reddit = it.sm.rd }
399
- if (it.sm?.yt) { socialMedia.youtube = it.sm.yt }
400
- if (it.sm?.bb) { socialMedia.bitbucket = it.sm.bb }
401
- return socialMedia;
402
- })(),
403
- createdAtMs: it.cts,
404
- })
405
- )
406
- )
407
- );
408
- }
409
-
410
- // subscribeNewTokens({
411
- // chain,
412
- // callback,
413
- // }: {
414
- // chain: string;
415
- // callback: (data: NewToken[]) => void;
416
- // }): Unsubscrible {
417
- // const channel = `dex-new-tokens:${chain}`;
418
- // return this.subscribe(channel, (data: any[]) =>
419
- // callback(
420
- // data.map(
421
- // (it: any) =>
422
- // ({
423
- // tokenAddress: it.a,
424
- // name: it.n,
425
- // symbol: it.s,
426
- // description: it.de,
427
- // createdAtMs: it.cts,
428
- // }) as NewToken
429
- // )
430
- // )
431
- // );
432
- // }
433
-
434
- subscribeTokenSupply({
435
- chain,
436
- tokenAddress,
437
- callback,
438
- filter,
439
- }: {
440
- chain: string;
441
- tokenAddress: string;
442
- callback: (data: TokenSupply) => void;
443
- filter?: string;
444
- }): Unsubscrible {
445
- const channel = `dex-token-supply:${chain}_${tokenAddress}`;
446
- return this.subscribe(channel, (data: any) =>
447
- callback({
448
- tokenAddress: data.a,
449
- supply: data.s,
450
- marketCapInUsd: data.mc,
451
- timestamp: data.ts,
452
- }), filter, "subscribeTokenSupply");
453
- }
454
-
455
- subscribeTokenLiquidity({
456
- chain,
457
- tokenAddress,
458
- callback,
459
- filter,
460
- }: {
461
- chain: string;
462
- tokenAddress: string;
463
- callback: (data: TokenLiquidity) => void;
464
- filter?: string;
465
- }): Unsubscrible {
466
- const channel = `dex-token-general-stat-num:${chain}_${tokenAddress}`;
467
- return this.subscribe(channel, (data: any) =>
468
- callback({
469
- tokenAddress: data.a,
470
- metricType: data.t,
471
- value: data.v,
472
- timestamp: data.ts,
473
- }), filter, "subscribeTokenLiquidity");
474
- }
475
-
476
- subscribeRankingTokensLiquidity({
477
- chain,
478
- channelType,
479
- callback,
480
- }: {
481
- chain: string;
482
- channelType: ChannelType;
483
- callback: (data: TokenLiquidity[]) => void;
484
- }): Unsubscrible {
485
- const channel = `dex-ranking-token-general_stat_num-list:${chain}_${channelType}`;
486
- return this.subscribe(channel, (data: any[]) =>
487
- callback(
488
- data?.map(
489
- (it: any) =>
490
- ({
491
- tokenAddress: it.a,
492
- metricType: it.t,
493
- value: it.v,
494
- timestamp: it.ts,
495
- }) as TokenLiquidity
496
- )
497
- )
498
- );
499
- }
500
-
501
- subscribeRankingTokensList({
502
- chain,
503
- ranking_type,
504
- dex,
505
- callback,
506
- }: {
507
- chain: string;
508
- ranking_type: RankingType;
509
- dex?: Dex;
510
- callback: (data: RankingTokenList[]) => void;
511
- }): Unsubscrible {
512
- const channel = dex
513
- ? `dex-ranking-list:${chain}_${ranking_type}_${dex}`
514
- : `dex-ranking-list:${chain}_${ranking_type}`;
515
- return this.subscribe(channel, (data: any[]) =>
516
- callback(
517
- data?.map((item: any) => {
518
- const result: RankingTokenList = {} as RankingTokenList;
519
-
520
- // TokenMetadata (t)
521
- if (item.t) {
522
- result.metadata = {
523
- tokenAddress: item.t.a,
524
- };
525
- if (item.t.n) { result.metadata.name = item.t.n }
526
- if (item.t.s) { result.metadata.symbol = item.t.s }
527
- if (item.t.iu) { result.metadata.imageUrl = item.t.iu }
528
- if (item.t.de) { result.metadata.description = item.t.de }
529
- if (item.t.d) { result.metadata.decimals = item.t.dec }
530
- if (item.t.cts) { result.metadata.createdAtMs = item.t.cts }
531
- if (item.t.lf) {
532
- result.metadata.launchFrom = {};
533
- if (item.t.lf.pa) { result.metadata.launchFrom.programAddress = item.t.lf.pa }
534
- if (item.t.lf.pf) { result.metadata.launchFrom.protocolFamily = item.t.lf.pf }
535
- if (item.t.lf.pn) { result.metadata.launchFrom.protocolName = item.t.lf.pn }
536
- }
537
- if (item.t.mt) {
538
- result.metadata.migratedTo = {};
539
- if (item.t.mt.pa) { result.metadata.migratedTo.programAddress = item.t.mt.pa }
540
- if (item.t.mt.pf) { result.metadata.migratedTo.protocolFamily = item.t.mt.pf }
541
- if (item.t.mt.pn) { result.metadata.migratedTo.protocolName = item.t.mt.pn }
542
- }
543
- if (item.t.sm) {
544
- result.metadata.socialMedia = {};
545
- if (item.t.sm.tw) { result.metadata.socialMedia.twitter = item.t.sm.tw }
546
- if (item.t.sm.tg) { result.metadata.socialMedia.telegram = item.t.sm.tg }
547
- if (item.t.sm.w) { result.metadata.socialMedia.website = item.t.sm.w }
548
- if (item.t.sm.tt) { result.metadata.socialMedia.tiktok = item.t.sm.tt }
549
- if (item.t.sm.dc) { result.metadata.socialMedia.discord = item.t.sm.dc }
550
- if (item.t.sm.fb) { result.metadata.socialMedia.facebook = item.t.sm.fb }
551
- if (item.t.sm.gh) { result.metadata.socialMedia.github = item.t.sm.gh }
552
- if (item.t.sm.ig) { result.metadata.socialMedia.instagram = item.t.sm.ig }
553
- if (item.t.sm.li) { result.metadata.socialMedia.linkedin = item.t.sm.li }
554
- if (item.t.sm.md) { result.metadata.socialMedia.medium = item.t.sm.md }
555
- if (item.t.sm.rd) { result.metadata.socialMedia.reddit = item.t.sm.rd }
556
- if (item.t.sm.yt) { result.metadata.socialMedia.youtube = item.t.sm.yt }
557
- if (item.t.sm.bb) { result.metadata.socialMedia.bitbucket = item.t.sm.bb }
558
- }
559
- if (item.t.cts) { result.metadata.createdAtMs = item.t.cts }
560
- }
561
-
562
- // TokenBondingCurve (bc)
563
- if (item.bc) {
564
- result.bondingCurve = {};
565
- if (item.bc.pr) { result.bondingCurve.progressRatio = this.formatScientificNotation(item.bc.pr) }
566
- }
567
-
568
- // TokenHolder (h)
569
- if (item.h) {
570
- result.holder = {
571
- tokenAddress: item.h.a,
572
- timestamp: item.h.ts || 0,
573
- };
574
- if (item.h.h) { result.holder.holders = item.h.h }
575
- if (item.h.t100a) { result.holder.top100Amount = this.formatScientificNotation(item.h.t100a) }
576
- if (item.h.t10a) { result.holder.top10Amount = this.formatScientificNotation(item.h.t10a) }
577
- if (item.h.t100h) { result.holder.top100Holders = item.h.t100h }
578
- if (item.h.t10h) { result.holder.top10Holders = item.h.t10h }
579
- if (item.h.t100r) { result.holder.top100Ratio = this.formatScientificNotation(item.h.t100r) }
580
- if (item.h.t10r) { result.holder.top10Ratio = this.formatScientificNotation(item.h.t10r) }
581
- }
582
-
583
- // TokenSupply (s)
584
- if (item.s) {
585
- result.supply = {
586
- tokenAddress: item.s.a,
587
- timestamp: item.s.ts || 0,
588
- };
589
- if (item.s.s) { result.supply.supply = item.s.s }
590
- if (item.s.mc) { result.supply.marketCapInUsd = item.s.mc }
591
- }
592
-
593
- // TokenStat (ts)
594
- if (item.ts) {
595
- result.stat = {
596
- address: item.ts.a,
597
- timestamp: item.ts.t || 0,
598
- };
599
-
600
- // 1m data
601
- if (item.ts.b1m) { result.stat.buys1m = item.ts.b1m }
602
- if (item.ts.s1m) { result.stat.sells1m = item.ts.s1m }
603
- if (item.ts.be1m) { result.stat.buyers1m = item.ts.be1m }
604
- if (item.ts.se1m) { result.stat.sellers1m = item.ts.se1m }
605
- if (item.ts.bviu1m) { result.stat.buyVolumeInUsd1m = this.formatScientificNotation(item.ts.bviu1m) }
606
- if (item.ts.sviu1m) { result.stat.sellVolumeInUsd1m = this.formatScientificNotation(item.ts.sviu1m) }
607
- if (item.ts.p1m) { result.stat.price1m = this.formatScientificNotation(item.ts.p1m) }
608
- if (item.ts.oiu1m) { result.stat.openInUsd1m = this.formatScientificNotation(item.ts.oiu1m) }
609
- if (item.ts.ciu1m) { result.stat.closeInUsd1m = this.formatScientificNotation(item.ts.ciu1m) }
610
-
611
- // 5m data
612
- if (item.ts.b5m) { result.stat.buys5m = item.ts.b5m }
613
- if (item.ts.s5m) { result.stat.sells5m = item.ts.s5m }
614
- if (item.ts.be5m) { result.stat.buyers5m = item.ts.be5m }
615
- if (item.ts.se5m) { result.stat.sellers5m = item.ts.se5m }
616
- if (item.ts.bviu5m) { result.stat.buyVolumeInUsd5m = this.formatScientificNotation(item.ts.bviu5m) }
617
- if (item.ts.sviu5m) { result.stat.sellVolumeInUsd5m = this.formatScientificNotation(item.ts.sviu5m) }
618
- if (item.ts.p5m) { result.stat.price5m = this.formatScientificNotation(item.ts.p5m) }
619
- if (item.ts.oiu5m) { result.stat.openInUsd5m = this.formatScientificNotation(item.ts.oiu5m) }
620
- if (item.ts.ciu5m) { result.stat.closeInUsd5m = this.formatScientificNotation(item.ts.ciu5m) }
621
-
622
- // 15m data
623
- if (item.ts.b15m) { result.stat.buys15m = item.ts.b15m }
624
- if (item.ts.s15m) { result.stat.sells15m = item.ts.s15m }
625
- if (item.ts.be15m) { result.stat.buyers15m = item.ts.be15m }
626
- if (item.ts.se15m) { result.stat.sellers15m = item.ts.se15m }
627
- if (item.ts.bviu15m) { result.stat.buyVolumeInUsd15m = this.formatScientificNotation(item.ts.bviu15m) }
628
- if (item.ts.sviu15m) { result.stat.sellVolumeInUsd15m = this.formatScientificNotation(item.ts.sviu15m) }
629
- if (item.ts.p15m) { result.stat.price15m = this.formatScientificNotation(item.ts.p15m) }
630
- if (item.ts.oiu15m) { result.stat.openInUsd15m = this.formatScientificNotation(item.ts.oiu15m) }
631
- if (item.ts.ciu15m) { result.stat.closeInUsd15m = this.formatScientificNotation(item.ts.ciu15m) }
632
-
633
- // 30m data
634
- if (item.ts.b30m) { result.stat.buys30m = item.ts.b30m }
635
- if (item.ts.s30m) { result.stat.sells30m = item.ts.s30m }
636
- if (item.ts.be30m) { result.stat.buyers30m = item.ts.be30m }
637
- if (item.ts.se30m) { result.stat.sellers30m = item.ts.se30m }
638
- if (item.ts.bviu30m) { result.stat.buyVolumeInUsd30m = this.formatScientificNotation(item.ts.bviu30m) }
639
- if (item.ts.sviu30m) { result.stat.sellVolumeInUsd30m = this.formatScientificNotation(item.ts.sviu30m) }
640
- if (item.ts.p30m) { result.stat.price30m = this.formatScientificNotation(item.ts.p30m) }
641
- if (item.ts.oiu30m) { result.stat.openInUsd30m = this.formatScientificNotation(item.ts.oiu30m) }
642
- if (item.ts.ciu30m) { result.stat.closeInUsd30m = this.formatScientificNotation(item.ts.ciu30m) }
643
-
644
- // 1h data
645
- if (item.ts.b1h) { result.stat.buys1h = item.ts.b1h }
646
- if (item.ts.s1h) { result.stat.sells1h = item.ts.s1h }
647
- if (item.ts.be1h) { result.stat.buyers1h = item.ts.be1h }
648
- if (item.ts.se1h) { result.stat.sellers1h = item.ts.se1h }
649
- if (item.ts.bviu1h) { result.stat.buyVolumeInUsd1h = this.formatScientificNotation(item.ts.bviu1h) }
650
- if (item.ts.sviu1h) { result.stat.sellVolumeInUsd1h = this.formatScientificNotation(item.ts.sviu1h) }
651
- if (item.ts.p1h) { result.stat.price1h = this.formatScientificNotation(item.ts.p1h) }
652
- if (item.ts.oiu1h) { result.stat.openInUsd1h = this.formatScientificNotation(item.ts.oiu1h) }
653
- if (item.ts.ciu1h) { result.stat.closeInUsd1h = this.formatScientificNotation(item.ts.ciu1h) }
654
-
655
- // 4h data
656
- if (item.ts.b4h) { result.stat.buys4h = item.ts.b4h }
657
- if (item.ts.s4h) { result.stat.sells4h = item.ts.s4h }
658
- if (item.ts.be4h) { result.stat.buyers4h = item.ts.be4h }
659
- if (item.ts.se4h) { result.stat.sellers4h = item.ts.se4h }
660
- if (item.ts.bviu4h) { result.stat.buyVolumeInUsd4h = this.formatScientificNotation(item.ts.bviu4h) }
661
- if (item.ts.sviu4h) { result.stat.sellVolumeInUsd4h = this.formatScientificNotation(item.ts.sviu4h) }
662
- if (item.ts.p4h) { result.stat.price4h = this.formatScientificNotation(item.ts.p4h) }
663
- if (item.ts.oiu4h) { result.stat.openInUsd4h = this.formatScientificNotation(item.ts.oiu4h) }
664
- if (item.ts.ciu4h) { result.stat.closeInUsd4h = this.formatScientificNotation(item.ts.ciu4h) }
665
-
666
- // 24h data
667
- if (item.ts.b24h) { result.stat.buys24h = item.ts.b24h }
668
- if (item.ts.s24h) { result.stat.sells24h = item.ts.s24h }
669
- if (item.ts.be24h) { result.stat.buyers24h = item.ts.be24h }
670
- if (item.ts.se24h) { result.stat.sellers24h = item.ts.se24h }
671
- if (item.ts.bviu24h) { result.stat.buyVolumeInUsd24h = this.formatScientificNotation(item.ts.bviu24h) }
672
- if (item.ts.sviu24h) { result.stat.sellVolumeInUsd24h = this.formatScientificNotation(item.ts.sviu24h) }
673
- if (item.ts.p24h) { result.stat.price24h = this.formatScientificNotation(item.ts.p24h) }
674
- if (item.ts.oiu24h) { result.stat.openInUsd24h = this.formatScientificNotation(item.ts.oiu24h) }
675
- if (item.ts.ciu24h) { result.stat.closeInUsd24h = this.formatScientificNotation(item.ts.ciu24h) }
676
-
677
- // Current price
678
- if (item.ts.p) { result.stat.price = this.formatScientificNotation(item.ts.p) }
679
- }
680
-
681
- return result;
682
- })
683
- )
684
- );
685
- }
686
-
687
- subscribeRankingTokensStats({
688
- chain,
689
- channelType,
690
- callback,
691
- }: {
692
- chain: string;
693
- channelType: ChannelType;
694
- callback: (data: TokenStat[]) => void;
695
- }): Unsubscrible {
696
- const channel = `dex-ranking-token-stats-list:${chain}_${channelType}`;
697
- return this.subscribe(channel, (data: any[]) =>
698
- callback(
699
- data?.map(
700
- (it: any) =>
701
- ({
702
- address: it.a,
703
- timestamp: it.t,
704
- buys1m: it.b1m,
705
- sells1m: it.s1m,
706
- buyers1m: it.be1m,
707
- sellers1m: it.se1m,
708
- buyVolumeInUsd1m: this.formatScientificNotation(it.bviu1m),
709
- sellVolumeInUsd1m: this.formatScientificNotation(it.sviu1m),
710
- price1m: this.formatScientificNotation(it.p1m),
711
- openInUsd1m: this.formatScientificNotation(it.oiu1m),
712
- closeInUsd1m: this.formatScientificNotation(it.ciu1m),
713
- buys5m: it.b5m,
714
- sells5m: it.s5m,
715
- buyers5m: it.be5m,
716
- sellers5m: it.se5m,
717
- buyVolumeInUsd5m: this.formatScientificNotation(it.bviu5m),
718
- sellVolumeInUsd5m: this.formatScientificNotation(it.sviu5m),
719
- price5m: this.formatScientificNotation(it.p5m),
720
- openInUsd5m: this.formatScientificNotation(it.oiu5m),
721
- closeInUsd5m: this.formatScientificNotation(it.ciu5m),
722
- buys15m: it.b15m,
723
- sells15m: it.s15m,
724
- buyers15m: it.be15m,
725
- sellers15m: it.se15m,
726
- buyVolumeInUsd15m: this.formatScientificNotation(it.bviu15m),
727
- sellVolumeInUsd15m: this.formatScientificNotation(it.sviu15m),
728
- price15m: this.formatScientificNotation(it.p15m),
729
- openInUsd15m: this.formatScientificNotation(it.oiu15m),
730
- closeInUsd15m: this.formatScientificNotation(it.ciu15m),
731
- buys30m: it.b30m,
732
- sells30m: it.s30m,
733
- buyers30m: it.be30m,
734
- sellers30m: it.se30m,
735
- buyVolumeInUsd30m: this.formatScientificNotation(it.bviu30m),
736
- sellVolumeInUsd30m: this.formatScientificNotation(it.sviu30m),
737
- price30m: this.formatScientificNotation(it.p30m),
738
- openInUsd30m: this.formatScientificNotation(it.oiu30m),
739
- closeInUsd30m: this.formatScientificNotation(it.ciu30m),
740
- buys1h: it.b1h,
741
- sells1h: it.s1h,
742
- buyers1h: it.be1h,
743
- sellers1h: it.se1h,
744
- buyVolumeInUsd1h: this.formatScientificNotation(it.bviu1h),
745
- sellVolumeInUsd1h: this.formatScientificNotation(it.sviu1h),
746
- price1h: this.formatScientificNotation(it.p1h),
747
- openInUsd1h: this.formatScientificNotation(it.oiu1h),
748
- closeInUsd1h: this.formatScientificNotation(it.ciu1h),
749
- buys4h: it.b4h,
750
- sells4h: it.s4h,
751
- buyers4h: it.be4h,
752
- sellers4h: it.se4h,
753
- buyVolumeInUsd4h: this.formatScientificNotation(it.bviu4h),
754
- sellVolumeInUsd4h: this.formatScientificNotation(it.sviu4h),
755
- price4h: this.formatScientificNotation(it.p4h),
756
- openInUsd4h: this.formatScientificNotation(it.oiu4h),
757
- closeInUsd4h: this.formatScientificNotation(it.ciu4h),
758
- buys24h: it.b24h,
759
- sells24h: it.s24h,
760
- buyers24h: it.be24h,
761
- sellers24h: it.se24h,
762
- buyVolumeInUsd24h: this.formatScientificNotation(it.bviu24h),
763
- sellVolumeInUsd24h: this.formatScientificNotation(it.sviu24h),
764
- price24h: this.formatScientificNotation(it.p24h),
765
- price: this.formatScientificNotation(it.p),
766
- openInUsd24h: this.formatScientificNotation(it.oiu24h),
767
- closeInUsd24h: this.formatScientificNotation(it.ciu24h),
768
- }) as TokenStat
769
- )
770
- )
771
- );
772
- }
773
-
774
- subscribeRankingTokensHolders({
775
- chain,
776
- channelType,
777
- callback,
778
- }: {
779
- chain: string;
780
- channelType: ChannelType;
781
- callback: (data: TokenHolder[]) => void;
782
- }): Unsubscrible {
783
- const channel = `dex-ranking-token-holding-list:${chain}_${channelType}`;
784
- return this.subscribe(channel, (data: any[]) =>
785
- callback(
786
- data?.map(
787
- (it: any) =>
788
- ({
789
- tokenAddress: it.a,
790
- holders: it.h,
791
- top100Amount: this.formatScientificNotation(it.t100a),
792
- top10Amount: this.formatScientificNotation(it.t10a),
793
- top100Holders: it.t100h,
794
- top10Holders: it.t10h,
795
- top100Ratio: this.formatScientificNotation(it.t100r),
796
- top10Ratio: this.formatScientificNotation(it.t10r),
797
- timestamp: it.ts,
798
- }) as TokenHolder
799
- )
800
- )
801
- );
802
- }
803
-
804
- subscribeRankingTokensSupply({
805
- chain,
806
- channelType,
807
- callback,
808
- }: {
809
- chain: string;
810
- channelType: ChannelType;
811
- callback: (data: TokenSupply[]) => void;
812
- }): Unsubscrible {
813
- const channel = `dex-ranking-token-supply-list:${chain}_${channelType}`;
814
- return this.subscribe(channel, (data: any[]) =>
815
- callback(
816
- data?.map(
817
- (it: any) =>
818
- ({
819
- tokenAddress: it.a,
820
- supply: it.s,
821
- marketCapInUsd: it.mc,
822
- timestamp: it.ts,
823
- })
824
- )
825
- )
826
- );
827
- }
828
-
829
- subscribeRankingTokensBondingCurve({
830
- chain,
831
- callback,
832
- }: {
833
- chain: string;
834
- callback: (data: TokenBondingCurve[]) => void;
835
- }): Unsubscrible {
836
- const channel = `dex-ranking-token-bounding-curve-list:${chain}_new`;
837
- return this.subscribe(channel, (data: any[]) =>
838
- callback(
839
- data?.map(
840
- (it: any) =>
841
- ({
842
- tokenAddress: it.a,
843
- progressRatio: it.pr,
844
- })
845
- )
846
- )
847
- );
848
- }
849
-
850
- // subscribeTokenTrades({
851
- // chain,
852
- // tokenAddress,
853
- // callback,
854
- // }: {
855
- // chain: string;
856
- // tokenAddress: string;
857
- // callback: (data: TradeEvent[]) => void;
858
- // }): Unsubscrible {
859
- // const channel = `dex-trades:${chain}_${tokenAddress}`;
860
- // return this.subscribe(channel, (data: any[]) =>
861
- // callback(
862
- // data?.map(
863
- // (it: any) =>
864
- // ({
865
- // maker: it.bwa,
866
- // baseAmount: it.ba,
867
- // quoteAmount: it.sa,
868
- // // quoteSymbol: ,
869
- // quoteAddress: it.swa,
870
- // amountInUsd: it.baiu,
871
- // timestamp: it.t,
872
- // event: it.k,
873
- // txHash: it.h,
874
- // // priceInUsd: ,
875
- // // id: ,
876
- // // buyCostUsd: it.,
877
- // tokenAddress: it.a,
878
- // }) as TradeEvent
879
- // )
880
- // )
881
- // );
882
- // }
883
-
884
- subscribeWalletBalance({
885
- chain,
886
- walletAddress,
887
- callback,
888
- filter,
889
- }: {
890
- chain: string;
891
- walletAddress: string;
892
- callback: (data: WalletBalance[]) => void;
893
- filter?: string;
894
- }): Unsubscrible {
895
- const channel = `dex-wallet-balance:${chain}_${walletAddress}`;
896
- return this.subscribe(channel, (data: any) =>
897
- callback([
898
- {
899
- walletAddress: data.a,
900
- tokenAddress: data.ta,
901
- tokenPriceInUsd: data.tpiu,
902
- balance: data.b,
903
- timestamp: data.t,
904
- },
905
- ]), filter, "subscribeWalletBalance");
906
- }
907
-
908
- subscribeWalletPnl({
909
- chain,
910
- walletAddress,
911
- callback,
912
- filter,
913
- }: {
914
- chain: string;
915
- walletAddress: string;
916
- callback: (data: WalletTokenPnl) => void;
917
- filter?: string;
918
- }): Unsubscrible {
919
- const channel = `dex-wallet-token-pnl:${chain}_${walletAddress}`;
920
- return this.subscribe(channel, (data: any) =>
921
- callback({
922
- walletAddress: data.a,
923
- tokenAddress: data.ta,
924
- tokenPriceInUsd: data.tpiu,
925
- timestamp: data.t,
926
- opentime: data.ot,
927
- lasttime: data.lt,
928
- closetime: data.ct,
929
- buyAmount: data.ba,
930
- buyAmountInUsd: data.baiu,
931
- buyCount: data.bs,
932
- buyCount30d: data.bs30d,
933
- buyCount7d: data.bs7d,
934
- sellAmount: data.sa,
935
- sellAmountInUsd: data.saiu,
936
- sellCount: data.ss,
937
- sellCount30d: data.ss30d,
938
- sellCount7d: data.ss7d,
939
- heldDurationTimestamp: data.hdts,
940
- averageBuyPriceInUsd: data.abpiu,
941
- averageSellPriceInUsd: data.aspiu,
942
- unrealizedProfitInUsd: data.upiu,
943
- unrealizedProfitRatio: data.upr,
944
- realizedProfitInUsd: data.rpiu,
945
- realizedProfitRatio: data.rpr,
946
- totalRealizedProfitInUsd: data.trpiu,
947
- totalRealizedProfitRatio: data.trr,
948
- }), filter, "subscribeWalletPnl");
949
- }
950
-
951
- subscribeWalletPnlList({
952
- chain,
953
- walletAddress,
954
- callback,
955
- }: {
956
- chain: string;
957
- walletAddress: string;
958
- callback: (data: WalletPnl[]) => void;
959
- }): Unsubscrible {
960
- const channel = `dex-wallet-pnl-list:${chain}_${walletAddress}`;
961
- return this.subscribe(channel, (data: any[]) =>
962
- callback(
963
- data?.map(
964
- (it: any) =>
965
- ({
966
- walletAddress: it.a,
967
- buys: it.bs,
968
- buyAmount: it.ba,
969
- buyAmountInUsd: it.baiu,
970
- averageBuyPriceInUsd: it.abpiu,
971
- sellAmount: it.sa,
972
- sellAmountInUsd: it.saiu,
973
- sells: it.ss,
974
- wins: it.ws,
975
- winRatio: it.wr,
976
- pnlInUsd: it.piu,
977
- averagePnlInUsd: it.apiu,
978
- pnlRatio: it.pr,
979
- profitableDays: it.pd,
980
- losingDays: it.ld,
981
- tokens: it.ts,
982
- resolution: it.r,
983
- }) as WalletPnl
984
- )
985
- )
986
- );
987
- }
988
-
989
- subscribeTokenTrade({
990
- chain,
991
- tokenAddress,
992
- callback,
993
- filter,
994
- }: {
995
- chain: string;
996
- tokenAddress: string;
997
- callback: (data: TradeActivity) => void;
998
- filter?: string;
999
- }): Unsubscrible {
1000
- const channel = `dex-trade:${chain}_${tokenAddress}`;
1001
- return this.subscribe(channel, (data: any) =>
1002
- callback({
1003
- tokenAddress: data.a,
1004
- timestamp: data.t,
1005
- kind: data.k,
1006
- buyAmount: data.ba,
1007
- buyAmountInUsd: data.baiu,
1008
- buyTokenAddress: data.btma,
1009
- buyTokenName: data.btn,
1010
- buyTokenSymbol: data.bts,
1011
- buyWalletAddress: data.bwa,
1012
- sellAmount: data.sa,
1013
- sellAmountInUsd: data.saiu,
1014
- sellTokenAddress: data.stma,
1015
- sellTokenName: data.stn,
1016
- sellTokenSymbol: data.sts,
1017
- sellWalletAddress: data.swa,
1018
- txHash: data.h,
1019
- }), filter, "subscribeTokenTrades");
1020
- }
1021
-
1022
- subscribeWalletTrade({
1023
- chain,
1024
- walletAddress,
1025
- callback,
1026
- filter,
1027
- }: {
1028
- chain: string;
1029
- walletAddress: string;
1030
- callback: (data: TradeActivity) => void;
1031
- filter?: string;
1032
- }): Unsubscrible {
1033
- const channel = `dex-wallet-trade:${chain}_${walletAddress}`;
1034
- return this.subscribe(channel, (data: any) =>
1035
- callback({
1036
- tokenAddress: data.a,
1037
- timestamp: data.t,
1038
- kind: data.k,
1039
- buyAmount: data.ba,
1040
- buyAmountInUsd: data.baiu,
1041
- buyTokenAddress: data.btma,
1042
- buyTokenName: data.btn,
1043
- buyTokenSymbol: data.bts,
1044
- buyWalletAddress: data.bwa,
1045
- sellAmount: data.sa,
1046
- sellAmountInUsd: data.saiu,
1047
- sellTokenAddress: data.stma,
1048
- sellTokenName: data.stn,
1049
- sellTokenSymbol: data.sts,
1050
- sellWalletAddress: data.swa,
1051
- txHash: data.h,
1052
- }), filter, "subscribeTokenTrades");
1053
- }
1054
-
1055
- subscribeDexPoolBalance({
1056
- chain,
1057
- poolAddress,
1058
- callback,
1059
- }: {
1060
- chain: string;
1061
- poolAddress: string;
1062
- callback: (data: DexPoolBalance) => void;
1063
- }): Unsubscrible {
1064
- const channel = `dex-pool-balance:${chain}_${poolAddress}`;
1065
- return this.subscribe(channel, (data: any) =>
1066
- callback({
1067
- poolAddress: data.a,
1068
- tokenAAddress: data.taa,
1069
- tokenALiquidityInUsd: data.taliu,
1070
- tokenBAddress: data.tba,
1071
- tokenBLiquidityInUsd: data.tbliu,
1072
- })
1073
- );
1074
- }
1075
- }
1076
- class StreamUnsubscrible<T> {
1077
- constructor(
1078
- private readonly streamApi: StreamApi,
1079
- private readonly channel: string,
1080
- private readonly fn: (data: T) => void
1081
- ) { }
1082
-
1083
- unsubscribe() {
1084
- this.streamApi.unsubscribe(this.channel, this.fn);
1085
- }
1086
- }