@luxfi/dex 1.2.1 → 2.0.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.
Files changed (74) hide show
  1. package/dist/client/clob.d.ts +52 -0
  2. package/dist/client/clob.d.ts.map +1 -0
  3. package/dist/client/clob.js +196 -0
  4. package/dist/client/index.d.ts +7 -0
  5. package/dist/client/index.d.ts.map +1 -0
  6. package/dist/client/index.js +6 -0
  7. package/dist/client/types.d.ts +126 -0
  8. package/dist/client/types.d.ts.map +1 -0
  9. package/dist/client/types.js +5 -0
  10. package/dist/hooks/index.d.ts +22 -0
  11. package/dist/hooks/index.d.ts.map +1 -0
  12. package/dist/hooks/index.js +25 -0
  13. package/dist/hooks/use-lxbook.d.ts +95 -0
  14. package/dist/hooks/use-lxbook.d.ts.map +1 -0
  15. package/dist/hooks/use-lxbook.js +213 -0
  16. package/dist/hooks/use-lxfeed.d.ts +111 -0
  17. package/dist/hooks/use-lxfeed.d.ts.map +1 -0
  18. package/dist/hooks/use-lxfeed.js +152 -0
  19. package/dist/hooks/use-lxvault.d.ts +137 -0
  20. package/dist/hooks/use-lxvault.d.ts.map +1 -0
  21. package/dist/hooks/use-lxvault.js +227 -0
  22. package/dist/hooks/use-quote.d.ts +18 -0
  23. package/dist/hooks/use-quote.d.ts.map +1 -0
  24. package/dist/hooks/use-quote.js +65 -0
  25. package/dist/hooks/use-swap.d.ts +17 -0
  26. package/dist/hooks/use-swap.d.ts.map +1 -0
  27. package/dist/hooks/use-swap.js +75 -0
  28. package/dist/index.d.ts +50 -115
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +72 -225
  31. package/dist/precompile/abis.d.ts +991 -0
  32. package/dist/precompile/abis.d.ts.map +1 -0
  33. package/dist/precompile/abis.js +743 -0
  34. package/dist/precompile/addresses.d.ts +129 -0
  35. package/dist/precompile/addresses.d.ts.map +1 -0
  36. package/dist/precompile/addresses.js +117 -0
  37. package/dist/precompile/index.d.ts +19 -0
  38. package/dist/precompile/index.d.ts.map +1 -0
  39. package/dist/precompile/index.js +18 -0
  40. package/dist/precompile/types.d.ts +246 -0
  41. package/dist/precompile/types.d.ts.map +1 -0
  42. package/dist/precompile/types.js +84 -0
  43. package/dist/router/index.d.ts +7 -0
  44. package/dist/router/index.d.ts.map +1 -0
  45. package/dist/router/index.js +6 -0
  46. package/dist/router/router.d.ts +58 -0
  47. package/dist/router/router.d.ts.map +1 -0
  48. package/dist/router/router.js +272 -0
  49. package/dist/router/types.d.ts +76 -0
  50. package/dist/router/types.d.ts.map +1 -0
  51. package/dist/router/types.js +1 -0
  52. package/package.json +55 -29
  53. package/src/client/clob.ts +256 -0
  54. package/src/client/index.ts +6 -0
  55. package/src/client/types.ts +148 -0
  56. package/src/hooks/index.ts +29 -0
  57. package/src/hooks/use-lxbook.ts +343 -0
  58. package/src/hooks/use-lxfeed.ts +179 -0
  59. package/src/hooks/use-lxvault.ts +318 -0
  60. package/src/hooks/use-quote.ts +92 -0
  61. package/src/hooks/use-swap.ts +103 -0
  62. package/src/index.ts +142 -309
  63. package/src/precompile/abis.ts +755 -0
  64. package/src/precompile/addresses.ts +153 -0
  65. package/src/precompile/index.ts +18 -0
  66. package/src/precompile/types.ts +295 -0
  67. package/src/router/index.ts +6 -0
  68. package/src/router/router.ts +338 -0
  69. package/src/router/types.ts +87 -0
  70. package/dist/marketData.d.ts +0 -152
  71. package/dist/marketData.d.ts.map +0 -1
  72. package/dist/marketData.js +0 -253
  73. package/src/marketData.ts +0 -351
  74. package/tsconfig.json +0 -19
@@ -1,253 +0,0 @@
1
- "use strict";
2
- /**
3
- * Market data, liquidation, and settlement features for LX TypeScript SDK
4
- */
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MarketDataProviders = exports.LiquidationMonitor = exports.MarketDataClient = void 0;
10
- const ws_1 = __importDefault(require("ws"));
11
- class MarketDataClient {
12
- constructor(jsonRpcClient) {
13
- this.jsonRpc = jsonRpcClient;
14
- }
15
- /**
16
- * Get market data from a specific source
17
- */
18
- async getMarketData(symbol, source) {
19
- const result = await this.jsonRpc.call('market_data.get', {
20
- symbol,
21
- source
22
- });
23
- return {
24
- name: result.name,
25
- symbol: result.symbol,
26
- price: result.price,
27
- bid: result.bid,
28
- ask: result.ask,
29
- volume: result.volume,
30
- latencyNs: result.latency_ns,
31
- provider: result.provider
32
- };
33
- }
34
- /**
35
- * Get aggregated market data from all sources
36
- */
37
- async getAggregatedMarketData(symbol) {
38
- const result = await this.jsonRpc.call('market_data.aggregate', {
39
- symbol
40
- });
41
- return result.map((data) => ({
42
- name: data.name,
43
- symbol: data.symbol,
44
- price: data.price,
45
- bid: data.bid,
46
- ask: data.ask,
47
- volume: data.volume,
48
- latencyNs: data.latency_ns,
49
- provider: data.provider
50
- }));
51
- }
52
- /**
53
- * Get recent liquidations
54
- */
55
- async getLiquidations(symbol, limit = 100) {
56
- const result = await this.jsonRpc.call('liquidations.get', {
57
- symbol,
58
- limit
59
- });
60
- return result.map((liq) => ({
61
- userId: liq.user_id,
62
- positionId: liq.position_id,
63
- symbol: liq.symbol,
64
- size: liq.size,
65
- liquidationPrice: liq.liquidation_price,
66
- markPrice: liq.mark_price,
67
- status: liq.status,
68
- timestamp: new Date(liq.timestamp)
69
- }));
70
- }
71
- /**
72
- * Get settlement batch information
73
- */
74
- async getSettlementBatch(batchId) {
75
- const result = await this.jsonRpc.call('settlement.batch', {
76
- batch_id: batchId
77
- });
78
- return {
79
- batchId: result.batch_id,
80
- orderIds: result.order_ids,
81
- status: result.status,
82
- txHash: result.tx_hash,
83
- gasUsed: result.gas_used,
84
- timestamp: new Date(result.timestamp)
85
- };
86
- }
87
- /**
88
- * Get margin information for a user
89
- */
90
- async getMarginInfo(userId) {
91
- const result = await this.jsonRpc.call('margin.info', {
92
- user_id: userId
93
- });
94
- return {
95
- userId: result.user_id,
96
- initialMargin: result.initial_margin,
97
- maintenanceMargin: result.maintenance_margin,
98
- marginRatio: result.margin_ratio,
99
- freeMargin: result.free_margin,
100
- marginLevel: result.margin_level
101
- };
102
- }
103
- /**
104
- * Check liquidation risk for a user
105
- */
106
- async checkLiquidationRisk(userId) {
107
- const result = await this.jsonRpc.call('margin.liquidation_risk', {
108
- user_id: userId
109
- });
110
- return {
111
- userId: result.user_id,
112
- riskLevel: result.risk_level,
113
- marginLevel: result.margin_level,
114
- liquidationPrice: result.liquidation_price,
115
- timeToLiquidation: result.time_to_liquidation,
116
- recommendations: result.recommendations || []
117
- };
118
- }
119
- /**
120
- * Get insurance fund status
121
- */
122
- async getInsuranceFundStatus() {
123
- const result = await this.jsonRpc.call('insurance_fund.status');
124
- return {
125
- totalFund: result.total_fund,
126
- availableFund: result.available_fund,
127
- usedFund: result.used_fund,
128
- pendingClaims: result.pending_claims,
129
- lastUpdate: new Date(result.last_update)
130
- };
131
- }
132
- /**
133
- * Get list of available market data sources
134
- */
135
- async getMarketDataSources() {
136
- return await this.jsonRpc.call('market_data.sources');
137
- }
138
- /**
139
- * Get comprehensive market statistics
140
- */
141
- async getMarketStats(symbol) {
142
- const result = await this.jsonRpc.call('market.stats', {
143
- symbol
144
- });
145
- return {
146
- symbol: result.symbol,
147
- volume24h: result.volume_24h,
148
- high24h: result.high_24h,
149
- low24h: result.low_24h,
150
- priceChange24h: result.price_change_24h,
151
- priceChangePercent24h: result.price_change_percent_24h,
152
- openInterest: result.open_interest,
153
- fundingRate: result.funding_rate,
154
- nextFundingTime: new Date(result.next_funding_time)
155
- };
156
- }
157
- }
158
- exports.MarketDataClient = MarketDataClient;
159
- class LiquidationMonitor {
160
- constructor(wsConnection) {
161
- this.callbacks = new Map();
162
- this.ws = wsConnection;
163
- }
164
- /**
165
- * Set WebSocket connection
166
- */
167
- setWebSocket(ws) {
168
- this.ws = ws;
169
- }
170
- /**
171
- * Subscribe to liquidation events
172
- */
173
- subscribeLiquidations(callback) {
174
- if (!this.callbacks.has('liquidations')) {
175
- this.callbacks.set('liquidations', []);
176
- }
177
- this.callbacks.get('liquidations').push(callback);
178
- if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
179
- this.ws.send(JSON.stringify({
180
- type: 'subscribe',
181
- channel: 'liquidations'
182
- }));
183
- }
184
- }
185
- /**
186
- * Subscribe to settlement events
187
- */
188
- subscribeSettlements(callback) {
189
- if (!this.callbacks.has('settlements')) {
190
- this.callbacks.set('settlements', []);
191
- }
192
- this.callbacks.get('settlements').push(callback);
193
- if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
194
- this.ws.send(JSON.stringify({
195
- type: 'subscribe',
196
- channel: 'settlements'
197
- }));
198
- }
199
- }
200
- /**
201
- * Subscribe to margin call events for a user
202
- */
203
- subscribeMarginCalls(userId, callback) {
204
- const channel = `margin_calls:${userId}`;
205
- if (!this.callbacks.has(channel)) {
206
- this.callbacks.set(channel, []);
207
- }
208
- this.callbacks.get(channel).push(callback);
209
- if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
210
- this.ws.send(JSON.stringify({
211
- type: 'subscribe',
212
- channel
213
- }));
214
- }
215
- }
216
- /**
217
- * Unsubscribe from a channel
218
- */
219
- unsubscribe(channel) {
220
- this.callbacks.delete(channel);
221
- if (this.ws && this.ws.readyState === ws_1.default.OPEN) {
222
- this.ws.send(JSON.stringify({
223
- type: 'unsubscribe',
224
- channel
225
- }));
226
- }
227
- }
228
- /**
229
- * Handle incoming message
230
- */
231
- handleMessage(channel, data) {
232
- const callbacks = this.callbacks.get(channel);
233
- if (callbacks) {
234
- callbacks.forEach(cb => cb(data));
235
- }
236
- }
237
- }
238
- exports.LiquidationMonitor = LiquidationMonitor;
239
- /**
240
- * Market data sources supported by LX
241
- */
242
- exports.MarketDataProviders = {
243
- ALPACA: 'alpaca',
244
- NYSE_ARCA: 'nyse_arca',
245
- IEX_CLOUD: 'iex',
246
- POLYGON: 'polygon',
247
- CME_GROUP: 'cme',
248
- REFINITIV: 'refinitiv',
249
- ICE_DATA: 'ice',
250
- BLOOMBERG: 'bloomberg',
251
- NASDAQ_TOTALVIEW: 'nasdaq',
252
- COINBASE_PRO: 'coinbase'
253
- };
package/src/marketData.ts DELETED
@@ -1,351 +0,0 @@
1
- /**
2
- * Market data, liquidation, and settlement features for LX TypeScript SDK
3
- */
4
-
5
- import WebSocket from 'ws';
6
-
7
- export interface MarketDataSource {
8
- name: string;
9
- symbol: string;
10
- price: number;
11
- bid: number;
12
- ask: number;
13
- volume: number;
14
- latencyNs: number;
15
- provider: string;
16
- }
17
-
18
- export interface LiquidationInfo {
19
- userId: string;
20
- positionId: string;
21
- symbol: string;
22
- size: number;
23
- liquidationPrice: number;
24
- markPrice: number;
25
- status: string;
26
- timestamp: Date;
27
- }
28
-
29
- export interface SettlementBatch {
30
- batchId: number;
31
- orderIds: number[];
32
- status: string;
33
- txHash?: string;
34
- gasUsed?: number;
35
- timestamp: Date;
36
- }
37
-
38
- export interface MarginInfo {
39
- userId: string;
40
- initialMargin: number;
41
- maintenanceMargin: number;
42
- marginRatio: number;
43
- freeMargin: number;
44
- marginLevel: number;
45
- }
46
-
47
- export interface InsuranceFundStatus {
48
- totalFund: number;
49
- availableFund: number;
50
- usedFund: number;
51
- pendingClaims: number;
52
- lastUpdate: Date;
53
- }
54
-
55
- export interface MarketStats {
56
- symbol: string;
57
- volume24h: number;
58
- high24h: number;
59
- low24h: number;
60
- priceChange24h: number;
61
- priceChangePercent24h: number;
62
- openInterest: number;
63
- fundingRate: number;
64
- nextFundingTime: Date;
65
- }
66
-
67
- export interface LiquidationRisk {
68
- userId: string;
69
- riskLevel: 'low' | 'medium' | 'high' | 'critical';
70
- marginLevel: number;
71
- liquidationPrice: number;
72
- timeToLiquidation: number | null;
73
- recommendations: string[];
74
- }
75
-
76
- export class MarketDataClient {
77
- private jsonRpc: any;
78
-
79
- constructor(jsonRpcClient: any) {
80
- this.jsonRpc = jsonRpcClient;
81
- }
82
-
83
- /**
84
- * Get market data from a specific source
85
- */
86
- async getMarketData(symbol: string, source: string): Promise<MarketDataSource> {
87
- const result = await this.jsonRpc.call('market_data.get', {
88
- symbol,
89
- source
90
- });
91
-
92
- return {
93
- name: result.name,
94
- symbol: result.symbol,
95
- price: result.price,
96
- bid: result.bid,
97
- ask: result.ask,
98
- volume: result.volume,
99
- latencyNs: result.latency_ns,
100
- provider: result.provider
101
- };
102
- }
103
-
104
- /**
105
- * Get aggregated market data from all sources
106
- */
107
- async getAggregatedMarketData(symbol: string): Promise<MarketDataSource[]> {
108
- const result = await this.jsonRpc.call('market_data.aggregate', {
109
- symbol
110
- });
111
-
112
- return result.map((data: any) => ({
113
- name: data.name,
114
- symbol: data.symbol,
115
- price: data.price,
116
- bid: data.bid,
117
- ask: data.ask,
118
- volume: data.volume,
119
- latencyNs: data.latency_ns,
120
- provider: data.provider
121
- }));
122
- }
123
-
124
- /**
125
- * Get recent liquidations
126
- */
127
- async getLiquidations(symbol: string, limit: number = 100): Promise<LiquidationInfo[]> {
128
- const result = await this.jsonRpc.call('liquidations.get', {
129
- symbol,
130
- limit
131
- });
132
-
133
- return result.map((liq: any) => ({
134
- userId: liq.user_id,
135
- positionId: liq.position_id,
136
- symbol: liq.symbol,
137
- size: liq.size,
138
- liquidationPrice: liq.liquidation_price,
139
- markPrice: liq.mark_price,
140
- status: liq.status,
141
- timestamp: new Date(liq.timestamp)
142
- }));
143
- }
144
-
145
- /**
146
- * Get settlement batch information
147
- */
148
- async getSettlementBatch(batchId: number): Promise<SettlementBatch> {
149
- const result = await this.jsonRpc.call('settlement.batch', {
150
- batch_id: batchId
151
- });
152
-
153
- return {
154
- batchId: result.batch_id,
155
- orderIds: result.order_ids,
156
- status: result.status,
157
- txHash: result.tx_hash,
158
- gasUsed: result.gas_used,
159
- timestamp: new Date(result.timestamp)
160
- };
161
- }
162
-
163
- /**
164
- * Get margin information for a user
165
- */
166
- async getMarginInfo(userId: string): Promise<MarginInfo> {
167
- const result = await this.jsonRpc.call('margin.info', {
168
- user_id: userId
169
- });
170
-
171
- return {
172
- userId: result.user_id,
173
- initialMargin: result.initial_margin,
174
- maintenanceMargin: result.maintenance_margin,
175
- marginRatio: result.margin_ratio,
176
- freeMargin: result.free_margin,
177
- marginLevel: result.margin_level
178
- };
179
- }
180
-
181
- /**
182
- * Check liquidation risk for a user
183
- */
184
- async checkLiquidationRisk(userId: string): Promise<LiquidationRisk> {
185
- const result = await this.jsonRpc.call('margin.liquidation_risk', {
186
- user_id: userId
187
- });
188
-
189
- return {
190
- userId: result.user_id,
191
- riskLevel: result.risk_level,
192
- marginLevel: result.margin_level,
193
- liquidationPrice: result.liquidation_price,
194
- timeToLiquidation: result.time_to_liquidation,
195
- recommendations: result.recommendations || []
196
- };
197
- }
198
-
199
- /**
200
- * Get insurance fund status
201
- */
202
- async getInsuranceFundStatus(): Promise<InsuranceFundStatus> {
203
- const result = await this.jsonRpc.call('insurance_fund.status');
204
-
205
- return {
206
- totalFund: result.total_fund,
207
- availableFund: result.available_fund,
208
- usedFund: result.used_fund,
209
- pendingClaims: result.pending_claims,
210
- lastUpdate: new Date(result.last_update)
211
- };
212
- }
213
-
214
- /**
215
- * Get list of available market data sources
216
- */
217
- async getMarketDataSources(): Promise<string[]> {
218
- return await this.jsonRpc.call('market_data.sources');
219
- }
220
-
221
- /**
222
- * Get comprehensive market statistics
223
- */
224
- async getMarketStats(symbol: string): Promise<MarketStats> {
225
- const result = await this.jsonRpc.call('market.stats', {
226
- symbol
227
- });
228
-
229
- return {
230
- symbol: result.symbol,
231
- volume24h: result.volume_24h,
232
- high24h: result.high_24h,
233
- low24h: result.low_24h,
234
- priceChange24h: result.price_change_24h,
235
- priceChangePercent24h: result.price_change_percent_24h,
236
- openInterest: result.open_interest,
237
- fundingRate: result.funding_rate,
238
- nextFundingTime: new Date(result.next_funding_time)
239
- };
240
- }
241
- }
242
-
243
- export class LiquidationMonitor {
244
- private ws: WebSocket | null;
245
- private callbacks: Map<string, Function[]> = new Map();
246
-
247
- constructor(wsConnection: WebSocket | null) {
248
- this.ws = wsConnection;
249
- }
250
-
251
- /**
252
- * Set WebSocket connection
253
- */
254
- setWebSocket(ws: WebSocket): void {
255
- this.ws = ws;
256
- }
257
-
258
- /**
259
- * Subscribe to liquidation events
260
- */
261
- subscribeLiquidations(callback: (liquidation: LiquidationInfo) => void): void {
262
- if (!this.callbacks.has('liquidations')) {
263
- this.callbacks.set('liquidations', []);
264
- }
265
- this.callbacks.get('liquidations')!.push(callback);
266
-
267
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
268
- this.ws.send(JSON.stringify({
269
- type: 'subscribe',
270
- channel: 'liquidations'
271
- }));
272
- }
273
- }
274
-
275
- /**
276
- * Subscribe to settlement events
277
- */
278
- subscribeSettlements(callback: (settlement: SettlementBatch) => void): void {
279
- if (!this.callbacks.has('settlements')) {
280
- this.callbacks.set('settlements', []);
281
- }
282
- this.callbacks.get('settlements')!.push(callback);
283
-
284
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
285
- this.ws.send(JSON.stringify({
286
- type: 'subscribe',
287
- channel: 'settlements'
288
- }));
289
- }
290
- }
291
-
292
- /**
293
- * Subscribe to margin call events for a user
294
- */
295
- subscribeMarginCalls(userId: string, callback: (marginCall: any) => void): void {
296
- const channel = `margin_calls:${userId}`;
297
- if (!this.callbacks.has(channel)) {
298
- this.callbacks.set(channel, []);
299
- }
300
- this.callbacks.get(channel)!.push(callback);
301
-
302
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
303
- this.ws.send(JSON.stringify({
304
- type: 'subscribe',
305
- channel
306
- }));
307
- }
308
- }
309
-
310
- /**
311
- * Unsubscribe from a channel
312
- */
313
- unsubscribe(channel: string): void {
314
- this.callbacks.delete(channel);
315
-
316
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
317
- this.ws.send(JSON.stringify({
318
- type: 'unsubscribe',
319
- channel
320
- }));
321
- }
322
- }
323
-
324
- /**
325
- * Handle incoming message
326
- */
327
- handleMessage(channel: string, data: any): void {
328
- const callbacks = this.callbacks.get(channel);
329
- if (callbacks) {
330
- callbacks.forEach(cb => cb(data));
331
- }
332
- }
333
- }
334
-
335
- /**
336
- * Market data sources supported by LX
337
- */
338
- export const MarketDataProviders = {
339
- ALPACA: 'alpaca',
340
- NYSE_ARCA: 'nyse_arca',
341
- IEX_CLOUD: 'iex',
342
- POLYGON: 'polygon',
343
- CME_GROUP: 'cme',
344
- REFINITIV: 'refinitiv',
345
- ICE_DATA: 'ice',
346
- BLOOMBERG: 'bloomberg',
347
- NASDAQ_TOTALVIEW: 'nasdaq',
348
- COINBASE_PRO: 'coinbase'
349
- } as const;
350
-
351
- export type MarketDataProvider = typeof MarketDataProviders[keyof typeof MarketDataProviders];
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": ["ES2020"],
6
- "declaration": true,
7
- "declarationMap": true,
8
- "outDir": "./dist",
9
- "rootDir": "./src",
10
- "strict": true,
11
- "esModuleInterop": true,
12
- "skipLibCheck": true,
13
- "forceConsistentCasingInFileNames": true,
14
- "resolveJsonModule": true,
15
- "moduleResolution": "node"
16
- },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules", "dist"]
19
- }