@3rd-eye-labs/openmm 0.0.1
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/LICENSE +21 -0
- package/README.md +70 -0
- package/dist/cli/cli.d.ts +3 -0
- package/dist/cli/cli.d.ts.map +1 -0
- package/dist/cli/cli.js +43 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/commands/balance.d.ts +3 -0
- package/dist/cli/commands/balance.d.ts.map +1 -0
- package/dist/cli/commands/balance.js +51 -0
- package/dist/cli/commands/balance.js.map +1 -0
- package/dist/cli/commands/orderbook.d.ts +3 -0
- package/dist/cli/commands/orderbook.d.ts.map +1 -0
- package/dist/cli/commands/orderbook.js +83 -0
- package/dist/cli/commands/orderbook.js.map +1 -0
- package/dist/cli/commands/orders.d.ts +3 -0
- package/dist/cli/commands/orders.d.ts.map +1 -0
- package/dist/cli/commands/orders.js +196 -0
- package/dist/cli/commands/orders.js.map +1 -0
- package/dist/cli/commands/pool-discovery.d.ts +3 -0
- package/dist/cli/commands/pool-discovery.d.ts.map +1 -0
- package/dist/cli/commands/pool-discovery.js +60 -0
- package/dist/cli/commands/pool-discovery.js.map +1 -0
- package/dist/cli/commands/ticker.d.ts +3 -0
- package/dist/cli/commands/ticker.d.ts.map +1 -0
- package/dist/cli/commands/ticker.js +51 -0
- package/dist/cli/commands/ticker.js.map +1 -0
- package/dist/cli/commands/trade.d.ts +3 -0
- package/dist/cli/commands/trade.d.ts.map +1 -0
- package/dist/cli/commands/trade.js +110 -0
- package/dist/cli/commands/trade.js.map +1 -0
- package/dist/cli/commands/trades.d.ts +3 -0
- package/dist/cli/commands/trades.d.ts.map +1 -0
- package/dist/cli/commands/trades.js +73 -0
- package/dist/cli/commands/trades.js.map +1 -0
- package/dist/cli/exchange-factory.d.ts +40 -0
- package/dist/cli/exchange-factory.d.ts.map +1 -0
- package/dist/cli/exchange-factory.js +77 -0
- package/dist/cli/exchange-factory.js.map +1 -0
- package/dist/cli/pool-discovery-core.d.ts +54 -0
- package/dist/cli/pool-discovery-core.d.ts.map +1 -0
- package/dist/cli/pool-discovery-core.js +193 -0
- package/dist/cli/pool-discovery-core.js.map +1 -0
- package/dist/cli/utils/error-handler.d.ts +40 -0
- package/dist/cli/utils/error-handler.d.ts.map +1 -0
- package/dist/cli/utils/error-handler.js +117 -0
- package/dist/cli/utils/error-handler.js.map +1 -0
- package/dist/cli/utils/validation.d.ts +45 -0
- package/dist/cli/utils/validation.d.ts.map +1 -0
- package/dist/cli/utils/validation.js +118 -0
- package/dist/cli/utils/validation.js.map +1 -0
- package/dist/config/environment.d.ts +25 -0
- package/dist/config/environment.d.ts.map +1 -0
- package/dist/config/environment.js +72 -0
- package/dist/config/environment.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +21 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/launcher-config.d.ts +17 -0
- package/dist/config/launcher-config.d.ts.map +1 -0
- package/dist/config/launcher-config.js +14 -0
- package/dist/config/launcher-config.js.map +1 -0
- package/dist/config/price-aggregation.d.ts +49 -0
- package/dist/config/price-aggregation.d.ts.map +1 -0
- package/dist/config/price-aggregation.js +89 -0
- package/dist/config/price-aggregation.js.map +1 -0
- package/dist/core/exchange/base-exchange-connector.d.ts +45 -0
- package/dist/core/exchange/base-exchange-connector.d.ts.map +1 -0
- package/dist/core/exchange/base-exchange-connector.js +43 -0
- package/dist/core/exchange/base-exchange-connector.js.map +1 -0
- package/dist/core/exchange/base-exchange-data-mapper.d.ts +58 -0
- package/dist/core/exchange/base-exchange-data-mapper.d.ts.map +1 -0
- package/dist/core/exchange/base-exchange-data-mapper.js +60 -0
- package/dist/core/exchange/base-exchange-data-mapper.js.map +1 -0
- package/dist/core/price-aggregation/cardano-price-service.d.ts +31 -0
- package/dist/core/price-aggregation/cardano-price-service.d.ts.map +1 -0
- package/dist/core/price-aggregation/cardano-price-service.js +157 -0
- package/dist/core/price-aggregation/cardano-price-service.js.map +1 -0
- package/dist/core/price-aggregation/index.d.ts +11 -0
- package/dist/core/price-aggregation/index.d.ts.map +1 -0
- package/dist/core/price-aggregation/index.js +21 -0
- package/dist/core/price-aggregation/index.js.map +1 -0
- package/dist/core/price-aggregation/iris-api-client.d.ts +16 -0
- package/dist/core/price-aggregation/iris-api-client.d.ts.map +1 -0
- package/dist/core/price-aggregation/iris-api-client.js +62 -0
- package/dist/core/price-aggregation/iris-api-client.js.map +1 -0
- package/dist/core/price-aggregation/iris-pool-discovery.d.ts +37 -0
- package/dist/core/price-aggregation/iris-pool-discovery.d.ts.map +1 -0
- package/dist/core/price-aggregation/iris-pool-discovery.js +123 -0
- package/dist/core/price-aggregation/iris-pool-discovery.js.map +1 -0
- package/dist/core/price-aggregation/price-calculator.d.ts +27 -0
- package/dist/core/price-aggregation/price-calculator.d.ts.map +1 -0
- package/dist/core/price-aggregation/price-calculator.js +84 -0
- package/dist/core/price-aggregation/price-calculator.js.map +1 -0
- package/dist/core/risk-management/risk-manager.d.ts +14 -0
- package/dist/core/risk-management/risk-manager.d.ts.map +1 -0
- package/dist/core/risk-management/risk-manager.js +40 -0
- package/dist/core/risk-management/risk-manager.js.map +1 -0
- package/dist/core/strategy/base-strategy.d.ts +26 -0
- package/dist/core/strategy/base-strategy.d.ts.map +1 -0
- package/dist/core/strategy/base-strategy.js +46 -0
- package/dist/core/strategy/base-strategy.js.map +1 -0
- package/dist/core/strategy/strategy-factory.d.ts +7 -0
- package/dist/core/strategy/strategy-factory.d.ts.map +1 -0
- package/dist/core/strategy/strategy-factory.js +64 -0
- package/dist/core/strategy/strategy-factory.js.map +1 -0
- package/dist/exchanges/mexc/mexc-auth.d.ts +42 -0
- package/dist/exchanges/mexc/mexc-auth.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-auth.js +122 -0
- package/dist/exchanges/mexc/mexc-auth.js.map +1 -0
- package/dist/exchanges/mexc/mexc-connector.d.ts +125 -0
- package/dist/exchanges/mexc/mexc-connector.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-connector.js +422 -0
- package/dist/exchanges/mexc/mexc-connector.js.map +1 -0
- package/dist/exchanges/mexc/mexc-data-mapper.d.ts +50 -0
- package/dist/exchanges/mexc/mexc-data-mapper.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-data-mapper.js +127 -0
- package/dist/exchanges/mexc/mexc-data-mapper.js.map +1 -0
- package/dist/exchanges/mexc/mexc-protobuf-decoder.d.ts +43 -0
- package/dist/exchanges/mexc/mexc-protobuf-decoder.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-protobuf-decoder.js +235 -0
- package/dist/exchanges/mexc/mexc-protobuf-decoder.js.map +1 -0
- package/dist/exchanges/mexc/mexc-user-stream.d.ts +81 -0
- package/dist/exchanges/mexc/mexc-user-stream.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-user-stream.js +253 -0
- package/dist/exchanges/mexc/mexc-user-stream.js.map +1 -0
- package/dist/exchanges/mexc/mexc-utils.d.ts +31 -0
- package/dist/exchanges/mexc/mexc-utils.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-utils.js +186 -0
- package/dist/exchanges/mexc/mexc-utils.js.map +1 -0
- package/dist/exchanges/mexc/mexc-websocket.d.ts +124 -0
- package/dist/exchanges/mexc/mexc-websocket.d.ts.map +1 -0
- package/dist/exchanges/mexc/mexc-websocket.js +496 -0
- package/dist/exchanges/mexc/mexc-websocket.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/strategies/grid/grid-calculator.d.ts +7 -0
- package/dist/strategies/grid/grid-calculator.d.ts.map +1 -0
- package/dist/strategies/grid/grid-calculator.js +34 -0
- package/dist/strategies/grid/grid-calculator.js.map +1 -0
- package/dist/strategies/grid/grid-order-manager.d.ts +23 -0
- package/dist/strategies/grid/grid-order-manager.d.ts.map +1 -0
- package/dist/strategies/grid/grid-order-manager.js +99 -0
- package/dist/strategies/grid/grid-order-manager.js.map +1 -0
- package/dist/strategies/grid/grid-strategy.d.ts +29 -0
- package/dist/strategies/grid/grid-strategy.d.ts.map +1 -0
- package/dist/strategies/grid/grid-strategy.js +185 -0
- package/dist/strategies/grid/grid-strategy.js.map +1 -0
- package/dist/types/account.d.ts +21 -0
- package/dist/types/account.d.ts.map +1 -0
- package/dist/types/account.js +3 -0
- package/dist/types/account.js.map +1 -0
- package/dist/types/exchange.d.ts +67 -0
- package/dist/types/exchange.d.ts.map +1 -0
- package/dist/types/exchange.js +3 -0
- package/dist/types/exchange.js.map +1 -0
- package/dist/types/grid.d.ts +10 -0
- package/dist/types/grid.d.ts.map +1 -0
- package/dist/types/grid.js +3 -0
- package/dist/types/grid.js.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +27 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/iris.d.ts +58 -0
- package/dist/types/iris.d.ts.map +1 -0
- package/dist/types/iris.js +7 -0
- package/dist/types/iris.js.map +1 -0
- package/dist/types/market.d.ts +16 -0
- package/dist/types/market.d.ts.map +1 -0
- package/dist/types/market.js +3 -0
- package/dist/types/market.js.map +1 -0
- package/dist/types/mexc-raw.d.ts +87 -0
- package/dist/types/mexc-raw.d.ts.map +1 -0
- package/dist/types/mexc-raw.js +7 -0
- package/dist/types/mexc-raw.js.map +1 -0
- package/dist/types/mexc.d.ts +57 -0
- package/dist/types/mexc.d.ts.map +1 -0
- package/dist/types/mexc.js +8 -0
- package/dist/types/mexc.js.map +1 -0
- package/dist/types/price.d.ts +37 -0
- package/dist/types/price.d.ts.map +1 -0
- package/dist/types/price.js +7 -0
- package/dist/types/price.js.map +1 -0
- package/dist/types/risk.d.ts +22 -0
- package/dist/types/risk.d.ts.map +1 -0
- package/dist/types/risk.js +6 -0
- package/dist/types/risk.js.map +1 -0
- package/dist/types/strategy.d.ts +46 -0
- package/dist/types/strategy.d.ts.map +1 -0
- package/dist/types/strategy.js +3 -0
- package/dist/types/strategy.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +29 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +108 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/symbol-utils.d.ts +17 -0
- package/dist/utils/symbol-utils.d.ts.map +1 -0
- package/dist/utils/symbol-utils.js +41 -0
- package/dist/utils/symbol-utils.js.map +1 -0
- package/package.json +53 -0
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MexcConnector = void 0;
|
|
7
|
+
const base_exchange_connector_1 = require("../../core/exchange/base-exchange-connector");
|
|
8
|
+
const mexc_auth_1 = require("./mexc-auth");
|
|
9
|
+
const mexc_websocket_1 = require("./mexc-websocket");
|
|
10
|
+
const mexc_utils_1 = require("./mexc-utils");
|
|
11
|
+
const mexc_user_stream_1 = require("./mexc-user-stream");
|
|
12
|
+
const mexc_data_mapper_1 = require("./mexc-data-mapper");
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
const symbol_utils_1 = require("../../utils/symbol-utils");
|
|
15
|
+
const environment_1 = __importDefault(require("../../config/environment"));
|
|
16
|
+
/**
|
|
17
|
+
* MEXC Exchange Connector
|
|
18
|
+
*/
|
|
19
|
+
class MexcConnector extends base_exchange_connector_1.BaseExchangeConnector {
|
|
20
|
+
constructor() {
|
|
21
|
+
super('mexc', 'MEXC');
|
|
22
|
+
this.dataMapper = new mexc_data_mapper_1.MexcDataMapper();
|
|
23
|
+
this.logger = (0, utils_1.createLogger)('mexc-connector');
|
|
24
|
+
this.baseUrl = 'https://api.mexc.com/api/v3';
|
|
25
|
+
this.setCredentials({
|
|
26
|
+
apiKey: environment_1.default.mexc.apiKey,
|
|
27
|
+
secret: environment_1.default.mexc.secret,
|
|
28
|
+
uid: environment_1.default.mexc.uid
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Initialize connection and set up authentication
|
|
33
|
+
*/
|
|
34
|
+
async connect() {
|
|
35
|
+
try {
|
|
36
|
+
const credentials = this.getCredentials();
|
|
37
|
+
this.auth = new mexc_auth_1.MexcAuth(credentials, this.baseUrl);
|
|
38
|
+
this.userStream = new mexc_user_stream_1.MexcUserStream((endpoint, params, method) => this.auth.makeRequest(endpoint, params, method));
|
|
39
|
+
if (!this.auth.validateCredentials()) {
|
|
40
|
+
this.connected = false;
|
|
41
|
+
this.handleError(new Error('Invalid MEXC credentials'), 'connect');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.connected = true;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.connected = false;
|
|
48
|
+
this.handleError(error, 'connect');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Override disconnect to also disconnect user data stream
|
|
53
|
+
*/
|
|
54
|
+
async disconnect() {
|
|
55
|
+
await this.disconnectWebSocket();
|
|
56
|
+
await this.disconnectUserDataStream();
|
|
57
|
+
this.connected = false;
|
|
58
|
+
this.auth = undefined;
|
|
59
|
+
this.userStream = undefined;
|
|
60
|
+
}
|
|
61
|
+
async getBalance(asset) {
|
|
62
|
+
try {
|
|
63
|
+
const account = await this.makeRequest('/account');
|
|
64
|
+
const balances = this.dataMapper.mapAccountBalances(account);
|
|
65
|
+
if (asset) {
|
|
66
|
+
return balances[asset] || {
|
|
67
|
+
asset,
|
|
68
|
+
free: 0,
|
|
69
|
+
used: 0,
|
|
70
|
+
total: 0,
|
|
71
|
+
available: 0
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return balances;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.handleError(error, 'getBalance');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a new order
|
|
82
|
+
*/
|
|
83
|
+
async createOrder(symbol, type, side, amount, price) {
|
|
84
|
+
try {
|
|
85
|
+
const params = mexc_utils_1.MexcUtils.createOrderParams(symbol, type, side, amount, price);
|
|
86
|
+
const result = await this.makeRequest('/order', params, 'POST');
|
|
87
|
+
return this.dataMapper.mapOrder({
|
|
88
|
+
orderId: result.orderId,
|
|
89
|
+
symbol: (0, symbol_utils_1.toExchangeFormat)(symbol),
|
|
90
|
+
type: type.toUpperCase(),
|
|
91
|
+
side: side.toUpperCase(),
|
|
92
|
+
origQty: amount.toString(),
|
|
93
|
+
price: price?.toString(),
|
|
94
|
+
executedQty: '0',
|
|
95
|
+
status: 'NEW',
|
|
96
|
+
time: Date.now()
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.handleError(error, 'createOrder');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Cancel an order
|
|
105
|
+
*/
|
|
106
|
+
async cancelOrder(orderId, symbol) {
|
|
107
|
+
try {
|
|
108
|
+
await this.makeRequest('/order', {
|
|
109
|
+
symbol: (0, symbol_utils_1.toExchangeFormat)(symbol),
|
|
110
|
+
orderId
|
|
111
|
+
}, 'DELETE');
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
this.handleError(error, 'cancelOrder');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Cancel all open orders on a symbol
|
|
119
|
+
*/
|
|
120
|
+
async cancelAllOrders(symbol) {
|
|
121
|
+
try {
|
|
122
|
+
await this.makeRequest('/openOrders', {
|
|
123
|
+
symbol: (0, symbol_utils_1.toExchangeFormat)(symbol)
|
|
124
|
+
}, 'DELETE');
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
this.handleError(error, 'cancelAllOrders');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get order details
|
|
132
|
+
*/
|
|
133
|
+
async getOrder(orderId, symbol) {
|
|
134
|
+
try {
|
|
135
|
+
const orders = await this.makeRequest('/allOrders', {
|
|
136
|
+
symbol: (0, symbol_utils_1.toExchangeFormat)(symbol),
|
|
137
|
+
orderId
|
|
138
|
+
});
|
|
139
|
+
if (!orders || orders.length === 0) {
|
|
140
|
+
this.handleError(new Error('Order not found'), 'getOrder');
|
|
141
|
+
return {};
|
|
142
|
+
}
|
|
143
|
+
const order = orders[0];
|
|
144
|
+
return this.dataMapper.mapOrder(order);
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
this.handleError(error, 'getOrder');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Get open orders
|
|
152
|
+
*/
|
|
153
|
+
async getOpenOrders(symbol) {
|
|
154
|
+
try {
|
|
155
|
+
const params = {};
|
|
156
|
+
if (symbol) {
|
|
157
|
+
params.symbol = (0, symbol_utils_1.toExchangeFormat)(symbol);
|
|
158
|
+
}
|
|
159
|
+
const orders = await this.makeRequest('/openOrders', params);
|
|
160
|
+
return orders.map((order) => this.dataMapper.mapOrder(order));
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
this.handleError(error, 'getOpenOrders');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get ticker information
|
|
168
|
+
*/
|
|
169
|
+
async getTicker(symbol) {
|
|
170
|
+
try {
|
|
171
|
+
const mexcSymbol = (0, symbol_utils_1.toExchangeFormat)(symbol);
|
|
172
|
+
const [priceData, statsData] = await Promise.all([
|
|
173
|
+
this.makePublicRequest('/ticker/price', { symbol: mexcSymbol }),
|
|
174
|
+
this.makePublicRequest('/ticker/24hr', { symbol: mexcSymbol })
|
|
175
|
+
]);
|
|
176
|
+
return this.dataMapper.mapTicker({ priceData, statsData });
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
this.handleError(error, 'getTicker');
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get order book
|
|
184
|
+
*/
|
|
185
|
+
async getOrderBook(symbol) {
|
|
186
|
+
try {
|
|
187
|
+
const mexcSymbol = (0, symbol_utils_1.toExchangeFormat)(symbol);
|
|
188
|
+
const orderBook = await this.makePublicRequest('/depth', {
|
|
189
|
+
symbol: mexcSymbol,
|
|
190
|
+
limit: 100
|
|
191
|
+
});
|
|
192
|
+
return this.dataMapper.mapOrderBook(orderBook, symbol);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
this.handleError(error, 'getOrderBook');
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get recent trades
|
|
200
|
+
*/
|
|
201
|
+
async getRecentTrades(symbol) {
|
|
202
|
+
try {
|
|
203
|
+
const mexcSymbol = (0, symbol_utils_1.toExchangeFormat)(symbol);
|
|
204
|
+
const trades = await this.makePublicRequest('/trades', {
|
|
205
|
+
symbol: mexcSymbol,
|
|
206
|
+
limit: 100
|
|
207
|
+
});
|
|
208
|
+
return trades.map((trade) => this.dataMapper.mapTrade(trade, symbol));
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
this.handleError(error, 'getRecentTrades');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// WebSocket Methods Implementation
|
|
215
|
+
/**
|
|
216
|
+
* Connect to MEXC WebSocket for real-time data
|
|
217
|
+
*/
|
|
218
|
+
async connectWebSocket() {
|
|
219
|
+
try {
|
|
220
|
+
if (!this.ws) {
|
|
221
|
+
this.ws = new mexc_websocket_1.MexcWebSocket();
|
|
222
|
+
}
|
|
223
|
+
await this.ws.connectWebSocket();
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
this.handleError(error, 'connectWebSocket');
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Disconnect from MEXC WebSocket
|
|
231
|
+
*/
|
|
232
|
+
async disconnectWebSocket() {
|
|
233
|
+
try {
|
|
234
|
+
if (this.ws) {
|
|
235
|
+
await this.ws.disconnectWebSocket();
|
|
236
|
+
this.ws = undefined;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
this.handleError(error, 'disconnectWebSocket');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Subscribe to real-time ticker updates
|
|
245
|
+
*/
|
|
246
|
+
async subscribeTicker(symbol, callback) {
|
|
247
|
+
try {
|
|
248
|
+
if (!this.ws) {
|
|
249
|
+
this.handleError(new Error('WebSocket not connected. Call connectWebSocket() first.'), 'subscribeTicker');
|
|
250
|
+
return '';
|
|
251
|
+
}
|
|
252
|
+
return await this.ws.subscribeTicker(symbol, callback);
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
this.handleError(error, 'subscribeTicker');
|
|
256
|
+
return '';
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Subscribe to real-time order book updates
|
|
261
|
+
*/
|
|
262
|
+
async subscribeOrderBook(symbol, callback) {
|
|
263
|
+
try {
|
|
264
|
+
if (!this.ws) {
|
|
265
|
+
this.handleError(new Error('WebSocket not connected. Call connectWebSocket() first.'), 'subscribeOrderBook');
|
|
266
|
+
return '';
|
|
267
|
+
}
|
|
268
|
+
return await this.ws.subscribeOrderBook(symbol, callback);
|
|
269
|
+
}
|
|
270
|
+
catch (error) {
|
|
271
|
+
this.handleError(error, 'subscribeOrderBook');
|
|
272
|
+
return '';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Subscribe to real-time trade updates
|
|
277
|
+
*/
|
|
278
|
+
async subscribeTrades(symbol, callback) {
|
|
279
|
+
try {
|
|
280
|
+
if (!this.ws) {
|
|
281
|
+
this.handleError(new Error('WebSocket not connected. Call connectWebSocket() first.'), 'subscribeTrades');
|
|
282
|
+
return '';
|
|
283
|
+
}
|
|
284
|
+
return await this.ws.subscribeTrades(symbol, callback);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
this.handleError(error, 'subscribeTrades');
|
|
288
|
+
return '';
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Subscribe to real-time order updates (user data)
|
|
293
|
+
*/
|
|
294
|
+
async subscribeOrders(callback) {
|
|
295
|
+
try {
|
|
296
|
+
if (!this.ws) {
|
|
297
|
+
this.handleError(new Error('WebSocket not connected. Call connectWebSocket() first.'), 'subscribeOrders');
|
|
298
|
+
return '';
|
|
299
|
+
}
|
|
300
|
+
return await this.ws.subscribeOrders(callback);
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
this.handleError(error, 'subscribeOrders');
|
|
304
|
+
return '';
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Unsubscribe from a WebSocket subscription
|
|
309
|
+
*/
|
|
310
|
+
async unsubscribe(subscriptionId) {
|
|
311
|
+
try {
|
|
312
|
+
if (!this.ws) {
|
|
313
|
+
this.handleError(new Error('WebSocket not connected.'), 'unsubscribe');
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
await this.ws.unsubscribe(subscriptionId);
|
|
317
|
+
}
|
|
318
|
+
catch (error) {
|
|
319
|
+
this.handleError(error, 'unsubscribe');
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Check if WebSocket is connected
|
|
324
|
+
*/
|
|
325
|
+
isWebSocketConnected() {
|
|
326
|
+
return this.ws ? this.ws.isConnected() : false;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Get WebSocket connection status
|
|
330
|
+
*/
|
|
331
|
+
getWebSocketStatus() {
|
|
332
|
+
return this.ws ? this.ws.getWebSocketStatus() : 'disconnected';
|
|
333
|
+
}
|
|
334
|
+
// User Data Stream Methods for Order Updates
|
|
335
|
+
/**
|
|
336
|
+
* Connect to user data stream for real-time order updates
|
|
337
|
+
*/
|
|
338
|
+
async connectUserDataStream() {
|
|
339
|
+
try {
|
|
340
|
+
if (!this.userStream) {
|
|
341
|
+
this.handleError(new Error('User stream not initialized'), 'connectUserDataStream');
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
await this.userStream.connectUserDataStream();
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
this.handleError(error, 'connectUserDataStream');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Disconnect user data stream
|
|
352
|
+
*/
|
|
353
|
+
async disconnectUserDataStream() {
|
|
354
|
+
try {
|
|
355
|
+
if (this.userStream) {
|
|
356
|
+
await this.userStream.disconnectUserDataStream();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
catch (error) {
|
|
360
|
+
this.logger.warn('Error disconnecting user data stream', { error });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Subscribe to real-time user order updates (limit/market orders)
|
|
365
|
+
*/
|
|
366
|
+
async subscribeUserOrders(callback) {
|
|
367
|
+
try {
|
|
368
|
+
if (!this.userStream) {
|
|
369
|
+
this.handleError(new Error('User stream not initialized'), 'subscribeUserOrders');
|
|
370
|
+
return '';
|
|
371
|
+
}
|
|
372
|
+
return await this.userStream.subscribeUserOrders(callback);
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
this.handleError(error, 'subscribeUserOrders');
|
|
376
|
+
return '';
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Subscribe to real-time user trade executions
|
|
381
|
+
* Notifies when user's orders are filled/executed
|
|
382
|
+
*/
|
|
383
|
+
async subscribeUserTrades(callback) {
|
|
384
|
+
try {
|
|
385
|
+
if (!this.userStream) {
|
|
386
|
+
this.handleError(new Error('User stream not initialized'), 'subscribeUserTrades');
|
|
387
|
+
return '';
|
|
388
|
+
}
|
|
389
|
+
return await this.userStream.subscribeUserTrades(callback);
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
this.handleError(error, 'subscribeUserTrades');
|
|
393
|
+
return '';
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Check if user data stream is connected
|
|
398
|
+
*/
|
|
399
|
+
isUserDataStreamConnected() {
|
|
400
|
+
return this.userStream?.isUserDataStreamConnected() || false;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Make authenticated request to MEXC API
|
|
404
|
+
*/
|
|
405
|
+
async makeRequest(endpoint, params = {}, method = 'GET') {
|
|
406
|
+
if (!this.auth) {
|
|
407
|
+
throw new Error('MEXC connector not authenticated');
|
|
408
|
+
}
|
|
409
|
+
return this.auth.makeRequest(endpoint, params, method);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Make public request (no authentication required)
|
|
413
|
+
*/
|
|
414
|
+
async makePublicRequest(endpoint, params = {}) {
|
|
415
|
+
if (!this.auth) {
|
|
416
|
+
throw new Error('MEXC connector not authenticated');
|
|
417
|
+
}
|
|
418
|
+
return this.auth.makePublicRequest(endpoint, params);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
exports.MexcConnector = MexcConnector;
|
|
422
|
+
//# sourceMappingURL=mexc-connector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mexc-connector.js","sourceRoot":"","sources":["../../../src/exchanges/mexc/mexc-connector.ts"],"names":[],"mappings":";;;;;;AAAA,yFAAoF;AAEpF,2CAAuC;AACvC,qDAAiD;AACjD,6CAAyC;AACzC,yDAAoD;AACpD,yDAAoD;AACpD,u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eDataMapper } from '../../core/exchange/base-exchange-data-mapper';
|
|
2
|
+
import { Order, OrderBook, Ticker, Trade, OrderStatus } from '../../types';
|
|
3
|
+
import { Balance } from '../../types';
|
|
4
|
+
import { MexcRawOrder, MexcRawBalance, MexcRawAccount, MexcRawPrice, MexcRaw24hrStats, MexcRawOrderBook, MexcRawTrade } from '../../types';
|
|
5
|
+
/**
|
|
6
|
+
* MEXC Data Mapper
|
|
7
|
+
* Maps MEXC API responses to OpenMM standard format
|
|
8
|
+
*/
|
|
9
|
+
export declare class MexcDataMapper extends BaseExchangeDataMapper<MexcRawOrder, MexcRawBalance, {
|
|
10
|
+
priceData: MexcRawPrice;
|
|
11
|
+
statsData?: MexcRaw24hrStats;
|
|
12
|
+
}, MexcRawOrderBook, MexcRawTrade, MexcRawAccount> {
|
|
13
|
+
/**
|
|
14
|
+
* Map MEXC order to OpenMM Order format
|
|
15
|
+
*/
|
|
16
|
+
mapOrder(mexcOrder: MexcRawOrder): Order;
|
|
17
|
+
/**
|
|
18
|
+
* Order status mapping for all MEXC status formats
|
|
19
|
+
* Handles REST API, protobuf, and message pattern statuses
|
|
20
|
+
*/
|
|
21
|
+
static mapToOrderStatus(status: string): OrderStatus;
|
|
22
|
+
/**
|
|
23
|
+
* Map MEXC balance to OpenMM Balance format
|
|
24
|
+
*/
|
|
25
|
+
mapBalance(mexcBalance: MexcRawBalance): Balance;
|
|
26
|
+
/**
|
|
27
|
+
* Map MEXC ticker data to OpenMM Ticker format
|
|
28
|
+
*/
|
|
29
|
+
mapTicker(tickerData: {
|
|
30
|
+
priceData: MexcRawPrice;
|
|
31
|
+
statsData?: MexcRaw24hrStats;
|
|
32
|
+
}): Ticker;
|
|
33
|
+
/**
|
|
34
|
+
* Map MEXC order book to OpenMM OrderBook format
|
|
35
|
+
*/
|
|
36
|
+
mapOrderBook(mexcOrderBook: MexcRawOrderBook, symbol: string): OrderBook;
|
|
37
|
+
/**
|
|
38
|
+
* Map MEXC trade to OpenMM Trade format
|
|
39
|
+
*/
|
|
40
|
+
mapTrade(mexcTrade: MexcRawTrade, symbol: string): Trade;
|
|
41
|
+
/**
|
|
42
|
+
* Map MEXC account response to OpenMM Balance records
|
|
43
|
+
*/
|
|
44
|
+
mapAccountBalances(mexcAccount: MexcRawAccount): Record<string, Balance>;
|
|
45
|
+
/**
|
|
46
|
+
* Override symbol normalization for MEXC format
|
|
47
|
+
*/
|
|
48
|
+
protected normalizeSymbol(symbol: string): string;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=mexc-data-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mexc-data-mapper.d.ts","sourceRoot":"","sources":["../../../src/exchanges/mexc/mexc-data-mapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAwB,WAAW,EAAE,MAAM,aAAa,CAAC;AACjG,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EACL,YAAY,EACZ,cAAc,EACd,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,qBAAa,cAAe,SAAQ,sBAAsB,CACxD,YAAY,EACZ,cAAc,EACd;IAAE,SAAS,EAAE,YAAY,CAAC;IAAC,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAAE,EACzD,gBAAgB,EAChB,YAAY,EACZ,cAAc,CACf;IAEC;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,GAAG,KAAK;IAuBxC;;;OAGG;IACH,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW;IAapD;;OAEG;IACH,UAAU,CAAC,WAAW,EAAE,cAAc,GAAG,OAAO;IAahD;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE;QAAE,SAAS,EAAE,YAAY,CAAC;QAAC,SAAS,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAAG,MAAM;IAaxF;;OAEG;IACH,YAAY,CAAC,aAAa,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS;IASxE;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK;IAWxD;;OAEG;IACH,kBAAkB,CAAC,WAAW,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAcxE;;OAEG;IACH,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAIlD"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MexcDataMapper = void 0;
|
|
4
|
+
const base_exchange_data_mapper_1 = require("../../core/exchange/base-exchange-data-mapper");
|
|
5
|
+
/**
|
|
6
|
+
* MEXC Data Mapper
|
|
7
|
+
* Maps MEXC API responses to OpenMM standard format
|
|
8
|
+
*/
|
|
9
|
+
class MexcDataMapper extends base_exchange_data_mapper_1.BaseExchangeDataMapper {
|
|
10
|
+
/**
|
|
11
|
+
* Map MEXC order to OpenMM Order format
|
|
12
|
+
*/
|
|
13
|
+
mapOrder(mexcOrder) {
|
|
14
|
+
if (!mexcOrder) {
|
|
15
|
+
throw new Error('MEXC order data is required');
|
|
16
|
+
}
|
|
17
|
+
const status = MexcDataMapper.mapToOrderStatus(mexcOrder.status || 'NEW');
|
|
18
|
+
const filled = this.parseAmount(mexcOrder.executedQty);
|
|
19
|
+
const amount = this.parseAmount(mexcOrder.origQty || mexcOrder.quantity);
|
|
20
|
+
return {
|
|
21
|
+
id: (mexcOrder.orderId || mexcOrder.id)?.toString() || '',
|
|
22
|
+
symbol: this.normalizeSymbol(mexcOrder.symbol || ''),
|
|
23
|
+
type: (mexcOrder.type || 'LIMIT').toLowerCase(),
|
|
24
|
+
side: (mexcOrder.side || 'BUY').toLowerCase(),
|
|
25
|
+
amount,
|
|
26
|
+
price: mexcOrder.price ? this.parsePrice(mexcOrder.price) : undefined,
|
|
27
|
+
filled,
|
|
28
|
+
remaining: amount - filled,
|
|
29
|
+
status,
|
|
30
|
+
timestamp: this.parseTimestamp(mexcOrder.time || mexcOrder.updateTime)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Order status mapping for all MEXC status formats
|
|
35
|
+
* Handles REST API, protobuf, and message pattern statuses
|
|
36
|
+
*/
|
|
37
|
+
static mapToOrderStatus(status) {
|
|
38
|
+
const upperStatus = status.toUpperCase();
|
|
39
|
+
if (upperStatus.includes('NEW'))
|
|
40
|
+
return 'open';
|
|
41
|
+
if (upperStatus.includes('PARTIAL'))
|
|
42
|
+
return 'open';
|
|
43
|
+
if (upperStatus.includes('FILL'))
|
|
44
|
+
return 'filled';
|
|
45
|
+
if (upperStatus.includes('CANCEL'))
|
|
46
|
+
return 'cancelled';
|
|
47
|
+
if (upperStatus.includes('REJECT') || upperStatus.includes('EXPIRED'))
|
|
48
|
+
return 'rejected';
|
|
49
|
+
if (upperStatus.includes('EXEC'))
|
|
50
|
+
return 'filled';
|
|
51
|
+
return 'open';
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Map MEXC balance to OpenMM Balance format
|
|
55
|
+
*/
|
|
56
|
+
mapBalance(mexcBalance) {
|
|
57
|
+
const free = this.parseAmount(mexcBalance.free);
|
|
58
|
+
const used = this.parseAmount(mexcBalance.locked);
|
|
59
|
+
return {
|
|
60
|
+
asset: mexcBalance.asset,
|
|
61
|
+
free,
|
|
62
|
+
used,
|
|
63
|
+
total: free + used,
|
|
64
|
+
available: free
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Map MEXC ticker data to OpenMM Ticker format
|
|
69
|
+
*/
|
|
70
|
+
mapTicker(tickerData) {
|
|
71
|
+
const { priceData, statsData } = tickerData;
|
|
72
|
+
return {
|
|
73
|
+
symbol: this.normalizeSymbol(priceData.symbol),
|
|
74
|
+
last: this.parsePrice(priceData.price),
|
|
75
|
+
bid: this.parsePrice(statsData?.bidPrice || priceData.price),
|
|
76
|
+
ask: this.parsePrice(statsData?.askPrice || priceData.price),
|
|
77
|
+
baseVolume: this.parseAmount(statsData?.volume || '0'),
|
|
78
|
+
timestamp: Date.now()
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Map MEXC order book to OpenMM OrderBook format
|
|
83
|
+
*/
|
|
84
|
+
mapOrderBook(mexcOrderBook, symbol) {
|
|
85
|
+
return {
|
|
86
|
+
symbol: this.normalizeSymbol(symbol),
|
|
87
|
+
bids: this.parseOrderBookEntries(mexcOrderBook.bids),
|
|
88
|
+
asks: this.parseOrderBookEntries(mexcOrderBook.asks),
|
|
89
|
+
timestamp: Date.now()
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Map MEXC trade to OpenMM Trade format
|
|
94
|
+
*/
|
|
95
|
+
mapTrade(mexcTrade, symbol) {
|
|
96
|
+
return {
|
|
97
|
+
id: (mexcTrade.id || mexcTrade.tradeId)?.toString() || '',
|
|
98
|
+
symbol: this.normalizeSymbol(symbol),
|
|
99
|
+
side: mexcTrade.isBuyerMaker === false ? 'buy' : 'sell',
|
|
100
|
+
amount: this.parseAmount(mexcTrade.qty || mexcTrade.quantity),
|
|
101
|
+
price: this.parsePrice(mexcTrade.price),
|
|
102
|
+
timestamp: this.parseTimestamp(mexcTrade.time)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Map MEXC account response to OpenMM Balance records
|
|
107
|
+
*/
|
|
108
|
+
mapAccountBalances(mexcAccount) {
|
|
109
|
+
const balances = {};
|
|
110
|
+
mexcAccount.balances.forEach((mexcBalance) => {
|
|
111
|
+
const balance = this.mapBalance(mexcBalance);
|
|
112
|
+
if (balance.total > 0) {
|
|
113
|
+
balances[balance.asset] = balance;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
return balances;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Override symbol normalization for MEXC format
|
|
120
|
+
*/
|
|
121
|
+
normalizeSymbol(symbol) {
|
|
122
|
+
// MEXC uses format like 'BTCUSDT'
|
|
123
|
+
return symbol.toUpperCase();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.MexcDataMapper = MexcDataMapper;
|
|
127
|
+
//# sourceMappingURL=mexc-data-mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mexc-data-mapper.js","sourceRoot":"","sources":["../../../src/exchanges/mexc/mexc-data-mapper.ts"],"names":[],"mappings":";;;AAAA,6FAAuF;AAavF;;;GAGG;AACH,MAAa,cAAe,SAAQ,kDAOnC;IAEC;;OAEG;IACH,QAAQ,CAAC,SAAuB;QAC9B,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,MAAM,GAAG,cAAc,CAAC,gBAAgB,CAAC,SAAS,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;QAC1E,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,QAAQ,CAAC,CAAC;QAEzE,OAAO;YACL,EAAE,EAAE,CAAC,SAAS,CAAC,OAAO,IAAI,SAAS,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE;YACzD,MAAM,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,CAAC;YACpD,IAAI,EAAE,CAAC,SAAS,CAAC,IAAI,IAAI,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AM,EAAE,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC;YACpC,IAAI,EAAE,SAAS,CAAC,YAAY,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM;YACvD,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC;YAC7D,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC;YACvC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,IAAI,CAAC;SAC/C,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,kBAAkB,CAAC,WAA2B;QAC5C,MAAM,QAAQ,GAA4B,EAAE,CAAC;QAE7C,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,WAA2B,EAAE,EAAE;YAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;YAE7C,IAAI,OAAO,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC;gBACtB,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC;YACpC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACO,eAAe,CAAC,MAAc;QACtC,mCAAmC;QACnC,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;IAC9B,CAAC;CACF;AAtID,wCAsIC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { DecodedMexcMessage } from '../../types';
|
|
2
|
+
/**
|
|
3
|
+
* MEXC Protobuf Message Decoder
|
|
4
|
+
*
|
|
5
|
+
* This decoder supports:
|
|
6
|
+
* - Private order messages for user data stream functionality
|
|
7
|
+
* - Market data messages for real-time ticker, orderbook, and trade data
|
|
8
|
+
*
|
|
9
|
+
* Official MEXC Protocol Buffers Documentation:
|
|
10
|
+
* https://www.mexc.com/api-docs/spot-v3/websocket-market-streams#protocol-buffers-integration
|
|
11
|
+
*
|
|
12
|
+
* Supported message types:
|
|
13
|
+
* - spot@private.orders.v3.api.pb (private orders)
|
|
14
|
+
* - spot@public.aggre.bookTicker.v3.api.pb (ticker data)
|
|
15
|
+
* - spot@public.bookTicker.batch.v3.api.pb (batch ticker data)
|
|
16
|
+
* - spot@public.aggre.deals.v3.api.pb (trade data)
|
|
17
|
+
*/
|
|
18
|
+
export declare class MexcProtobufDecoder {
|
|
19
|
+
/**
|
|
20
|
+
* Main decoder function for MEXC protobuf messages
|
|
21
|
+
*/
|
|
22
|
+
static decode(rawMessage: string): DecodedMexcMessage;
|
|
23
|
+
/**
|
|
24
|
+
* Decode order-related protobuf messages for user data stream
|
|
25
|
+
* Format: spot@private.orders.v3.api.pb\u001a\bINDYUSDT0...
|
|
26
|
+
*/
|
|
27
|
+
private static decodeOrderMessage;
|
|
28
|
+
/**
|
|
29
|
+
* Decode ticker protobuf messages
|
|
30
|
+
* Format: spot@public.aggre.bookTicker.v3.api.pb@100ms@INDYUSDT...
|
|
31
|
+
*/
|
|
32
|
+
private static decodeTickerMessage;
|
|
33
|
+
/**
|
|
34
|
+
* Decode trades protobuf messages
|
|
35
|
+
* Format: spot@public.aggre.deals.v3.api.pb@100ms@INDYUSDT...
|
|
36
|
+
*/
|
|
37
|
+
private static decodeTradesMessage;
|
|
38
|
+
/**
|
|
39
|
+
* Extract order status from MEXC protobuf message
|
|
40
|
+
*/
|
|
41
|
+
private static extractProtobufOrderStatus;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=mexc-protobuf-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mexc-protobuf-decoder.d.ts","sourceRoot":"","sources":["../../../src/exchanges/mexc/mexc-protobuf-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAGrB;;;;;;;;;;;;;;;GAeG;AAEH,qBAAa,mBAAmB;IAE9B;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB;IA6BrD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAsEjC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IA8ClC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAwClC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAuB1C"}
|