@luxfi/dex 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/clob.d.ts +52 -0
- package/dist/client/clob.d.ts.map +1 -0
- package/dist/client/clob.js +196 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +6 -0
- package/dist/client/types.d.ts +126 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +5 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +6 -0
- package/dist/hooks/use-quote.d.ts +18 -0
- package/dist/hooks/use-quote.d.ts.map +1 -0
- package/dist/hooks/use-quote.js +65 -0
- package/dist/hooks/use-swap.d.ts +17 -0
- package/dist/hooks/use-swap.d.ts.map +1 -0
- package/dist/hooks/use-swap.js +75 -0
- package/dist/index.d.ts +33 -115
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -225
- package/dist/precompile/abis.d.ts +400 -0
- package/dist/precompile/abis.d.ts.map +1 -0
- package/dist/precompile/abis.js +287 -0
- package/dist/precompile/addresses.d.ts +65 -0
- package/dist/precompile/addresses.d.ts.map +1 -0
- package/dist/precompile/addresses.js +52 -0
- package/dist/precompile/index.d.ts +8 -0
- package/dist/precompile/index.d.ts.map +1 -0
- package/dist/precompile/index.js +7 -0
- package/dist/precompile/types.d.ts +76 -0
- package/dist/precompile/types.d.ts.map +1 -0
- package/dist/precompile/types.js +17 -0
- package/dist/router/index.d.ts +7 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +6 -0
- package/dist/router/router.d.ts +58 -0
- package/dist/router/router.d.ts.map +1 -0
- package/dist/router/router.js +272 -0
- package/dist/router/types.d.ts +76 -0
- package/dist/router/types.d.ts.map +1 -0
- package/dist/router/types.js +1 -0
- package/package.json +55 -29
- package/src/client/clob.ts +256 -0
- package/src/client/index.ts +6 -0
- package/src/client/types.ts +148 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/use-quote.ts +92 -0
- package/src/hooks/use-swap.ts +103 -0
- package/src/index.ts +76 -309
- package/src/precompile/abis.ts +291 -0
- package/src/precompile/addresses.ts +72 -0
- package/src/precompile/index.ts +7 -0
- package/src/precompile/types.ts +96 -0
- package/src/router/index.ts +6 -0
- package/src/router/router.ts +338 -0
- package/src/router/types.ts +87 -0
- package/dist/marketData.d.ts +0 -152
- package/dist/marketData.d.ts.map +0 -1
- package/dist/marketData.js +0 -253
- package/src/marketData.ts +0 -351
- package/tsconfig.json +0 -19
package/dist/marketData.d.ts
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Market data, liquidation, and settlement features for LX TypeScript SDK
|
|
3
|
-
*/
|
|
4
|
-
import WebSocket from 'ws';
|
|
5
|
-
export interface MarketDataSource {
|
|
6
|
-
name: string;
|
|
7
|
-
symbol: string;
|
|
8
|
-
price: number;
|
|
9
|
-
bid: number;
|
|
10
|
-
ask: number;
|
|
11
|
-
volume: number;
|
|
12
|
-
latencyNs: number;
|
|
13
|
-
provider: string;
|
|
14
|
-
}
|
|
15
|
-
export interface LiquidationInfo {
|
|
16
|
-
userId: string;
|
|
17
|
-
positionId: string;
|
|
18
|
-
symbol: string;
|
|
19
|
-
size: number;
|
|
20
|
-
liquidationPrice: number;
|
|
21
|
-
markPrice: number;
|
|
22
|
-
status: string;
|
|
23
|
-
timestamp: Date;
|
|
24
|
-
}
|
|
25
|
-
export interface SettlementBatch {
|
|
26
|
-
batchId: number;
|
|
27
|
-
orderIds: number[];
|
|
28
|
-
status: string;
|
|
29
|
-
txHash?: string;
|
|
30
|
-
gasUsed?: number;
|
|
31
|
-
timestamp: Date;
|
|
32
|
-
}
|
|
33
|
-
export interface MarginInfo {
|
|
34
|
-
userId: string;
|
|
35
|
-
initialMargin: number;
|
|
36
|
-
maintenanceMargin: number;
|
|
37
|
-
marginRatio: number;
|
|
38
|
-
freeMargin: number;
|
|
39
|
-
marginLevel: number;
|
|
40
|
-
}
|
|
41
|
-
export interface InsuranceFundStatus {
|
|
42
|
-
totalFund: number;
|
|
43
|
-
availableFund: number;
|
|
44
|
-
usedFund: number;
|
|
45
|
-
pendingClaims: number;
|
|
46
|
-
lastUpdate: Date;
|
|
47
|
-
}
|
|
48
|
-
export interface MarketStats {
|
|
49
|
-
symbol: string;
|
|
50
|
-
volume24h: number;
|
|
51
|
-
high24h: number;
|
|
52
|
-
low24h: number;
|
|
53
|
-
priceChange24h: number;
|
|
54
|
-
priceChangePercent24h: number;
|
|
55
|
-
openInterest: number;
|
|
56
|
-
fundingRate: number;
|
|
57
|
-
nextFundingTime: Date;
|
|
58
|
-
}
|
|
59
|
-
export interface LiquidationRisk {
|
|
60
|
-
userId: string;
|
|
61
|
-
riskLevel: 'low' | 'medium' | 'high' | 'critical';
|
|
62
|
-
marginLevel: number;
|
|
63
|
-
liquidationPrice: number;
|
|
64
|
-
timeToLiquidation: number | null;
|
|
65
|
-
recommendations: string[];
|
|
66
|
-
}
|
|
67
|
-
export declare class MarketDataClient {
|
|
68
|
-
private jsonRpc;
|
|
69
|
-
constructor(jsonRpcClient: any);
|
|
70
|
-
/**
|
|
71
|
-
* Get market data from a specific source
|
|
72
|
-
*/
|
|
73
|
-
getMarketData(symbol: string, source: string): Promise<MarketDataSource>;
|
|
74
|
-
/**
|
|
75
|
-
* Get aggregated market data from all sources
|
|
76
|
-
*/
|
|
77
|
-
getAggregatedMarketData(symbol: string): Promise<MarketDataSource[]>;
|
|
78
|
-
/**
|
|
79
|
-
* Get recent liquidations
|
|
80
|
-
*/
|
|
81
|
-
getLiquidations(symbol: string, limit?: number): Promise<LiquidationInfo[]>;
|
|
82
|
-
/**
|
|
83
|
-
* Get settlement batch information
|
|
84
|
-
*/
|
|
85
|
-
getSettlementBatch(batchId: number): Promise<SettlementBatch>;
|
|
86
|
-
/**
|
|
87
|
-
* Get margin information for a user
|
|
88
|
-
*/
|
|
89
|
-
getMarginInfo(userId: string): Promise<MarginInfo>;
|
|
90
|
-
/**
|
|
91
|
-
* Check liquidation risk for a user
|
|
92
|
-
*/
|
|
93
|
-
checkLiquidationRisk(userId: string): Promise<LiquidationRisk>;
|
|
94
|
-
/**
|
|
95
|
-
* Get insurance fund status
|
|
96
|
-
*/
|
|
97
|
-
getInsuranceFundStatus(): Promise<InsuranceFundStatus>;
|
|
98
|
-
/**
|
|
99
|
-
* Get list of available market data sources
|
|
100
|
-
*/
|
|
101
|
-
getMarketDataSources(): Promise<string[]>;
|
|
102
|
-
/**
|
|
103
|
-
* Get comprehensive market statistics
|
|
104
|
-
*/
|
|
105
|
-
getMarketStats(symbol: string): Promise<MarketStats>;
|
|
106
|
-
}
|
|
107
|
-
export declare class LiquidationMonitor {
|
|
108
|
-
private ws;
|
|
109
|
-
private callbacks;
|
|
110
|
-
constructor(wsConnection: WebSocket | null);
|
|
111
|
-
/**
|
|
112
|
-
* Set WebSocket connection
|
|
113
|
-
*/
|
|
114
|
-
setWebSocket(ws: WebSocket): void;
|
|
115
|
-
/**
|
|
116
|
-
* Subscribe to liquidation events
|
|
117
|
-
*/
|
|
118
|
-
subscribeLiquidations(callback: (liquidation: LiquidationInfo) => void): void;
|
|
119
|
-
/**
|
|
120
|
-
* Subscribe to settlement events
|
|
121
|
-
*/
|
|
122
|
-
subscribeSettlements(callback: (settlement: SettlementBatch) => void): void;
|
|
123
|
-
/**
|
|
124
|
-
* Subscribe to margin call events for a user
|
|
125
|
-
*/
|
|
126
|
-
subscribeMarginCalls(userId: string, callback: (marginCall: any) => void): void;
|
|
127
|
-
/**
|
|
128
|
-
* Unsubscribe from a channel
|
|
129
|
-
*/
|
|
130
|
-
unsubscribe(channel: string): void;
|
|
131
|
-
/**
|
|
132
|
-
* Handle incoming message
|
|
133
|
-
*/
|
|
134
|
-
handleMessage(channel: string, data: any): void;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Market data sources supported by LX
|
|
138
|
-
*/
|
|
139
|
-
export declare const MarketDataProviders: {
|
|
140
|
-
readonly ALPACA: "alpaca";
|
|
141
|
-
readonly NYSE_ARCA: "nyse_arca";
|
|
142
|
-
readonly IEX_CLOUD: "iex";
|
|
143
|
-
readonly POLYGON: "polygon";
|
|
144
|
-
readonly CME_GROUP: "cme";
|
|
145
|
-
readonly REFINITIV: "refinitiv";
|
|
146
|
-
readonly ICE_DATA: "ice";
|
|
147
|
-
readonly BLOOMBERG: "bloomberg";
|
|
148
|
-
readonly NASDAQ_TOTALVIEW: "nasdaq";
|
|
149
|
-
readonly COINBASE_PRO: "coinbase";
|
|
150
|
-
};
|
|
151
|
-
export type MarketDataProvider = typeof MarketDataProviders[keyof typeof MarketDataProviders];
|
|
152
|
-
//# sourceMappingURL=marketData.d.ts.map
|
package/dist/marketData.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"marketData.d.ts","sourceRoot":"","sources":["../src/marketData.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAA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CAAC,UAAU,EAAE,GAAG,KAAK,IAAI,GAAG,IAAI;IAe/E;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAWlC;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI;CAMhD;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;CAWtB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAAG,OAAO,mBAAmB,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC"}
|
package/dist/marketData.js
DELETED
|
@@ -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
|
-
};
|