ccxt 4.5.44 → 4.5.45

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 (81) hide show
  1. package/README.md +9 -12
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -12
  4. package/dist/cjs/src/abstract/kucoinfutures.js +1 -1
  5. package/dist/cjs/src/base/Exchange.js +36 -3
  6. package/dist/cjs/src/base/functions/encode.js +2 -2
  7. package/dist/cjs/src/base/functions/generic.js +8 -2
  8. package/dist/cjs/src/bitrue.js +1 -1
  9. package/dist/cjs/src/bitteam.js +1 -1
  10. package/dist/cjs/src/btcbox.js +1 -1
  11. package/dist/cjs/src/cex.js +1 -0
  12. package/dist/cjs/src/gate.js +227 -168
  13. package/dist/cjs/src/grvt.js +3 -2
  14. package/dist/cjs/src/hyperliquid.js +16 -5
  15. package/dist/cjs/src/kraken.js +2 -2
  16. package/dist/cjs/src/krakenfutures.js +1 -5
  17. package/dist/cjs/src/kucoin.js +4729 -970
  18. package/dist/cjs/src/kucoinfutures.js +14 -3434
  19. package/dist/cjs/src/lbank.js +1 -1
  20. package/dist/cjs/src/poloniex.js +1 -1
  21. package/dist/cjs/src/pro/gate.js +37 -1
  22. package/dist/cjs/src/pro/kucoin.js +819 -178
  23. package/dist/cjs/src/pro/kucoinfutures.js +95 -1261
  24. package/dist/cjs/src/pro/mexc.js +10 -5
  25. package/dist/cjs/src/pro/okx.js +84 -39
  26. package/js/ccxt.d.ts +2 -14
  27. package/js/ccxt.js +2 -10
  28. package/js/src/abstract/kucoin.d.ts +46 -3
  29. package/js/src/abstract/kucoinfutures.d.ts +27 -12
  30. package/js/src/base/Exchange.d.ts +12 -1
  31. package/js/src/base/Exchange.js +36 -3
  32. package/js/src/base/functions/encode.js +2 -2
  33. package/js/src/base/functions/generic.js +9 -3
  34. package/js/src/bitrue.js +1 -1
  35. package/js/src/bitteam.js +1 -1
  36. package/js/src/btcbox.js +1 -1
  37. package/js/src/cex.js +2 -1
  38. package/js/src/gate.d.ts +125 -119
  39. package/js/src/gate.js +227 -168
  40. package/js/src/grvt.js +3 -2
  41. package/js/src/hyperliquid.d.ts +3 -1
  42. package/js/src/hyperliquid.js +16 -5
  43. package/js/src/kraken.js +2 -2
  44. package/js/src/krakenfutures.js +1 -5
  45. package/js/src/kucoin.d.ts +696 -100
  46. package/js/src/kucoin.js +4730 -971
  47. package/js/src/kucoinfutures.d.ts +4 -522
  48. package/js/src/kucoinfutures.js +14 -3434
  49. package/js/src/lbank.js +1 -1
  50. package/js/src/poloniex.js +1 -1
  51. package/js/src/pro/gate.d.ts +30 -1
  52. package/js/src/pro/gate.js +37 -1
  53. package/js/src/pro/kucoin.d.ts +70 -30
  54. package/js/src/pro/kucoin.js +821 -180
  55. package/js/src/pro/kucoinfutures.d.ts +17 -195
  56. package/js/src/pro/kucoinfutures.js +96 -1262
  57. package/js/src/pro/mexc.js +10 -5
  58. package/js/src/pro/okx.d.ts +1 -0
  59. package/js/src/pro/okx.js +84 -39
  60. package/package.json +1 -1
  61. package/dist/cjs/src/abstract/alp.js +0 -11
  62. package/dist/cjs/src/abstract/defx.js +0 -11
  63. package/dist/cjs/src/abstract/timex.js +0 -11
  64. package/dist/cjs/src/alp.js +0 -1059
  65. package/dist/cjs/src/defx.js +0 -2142
  66. package/dist/cjs/src/pro/defx.js +0 -866
  67. package/dist/cjs/src/timex.js +0 -1793
  68. package/js/src/abstract/alp.d.ts +0 -21
  69. package/js/src/abstract/alp.js +0 -5
  70. package/js/src/abstract/defx.d.ts +0 -72
  71. package/js/src/abstract/defx.js +0 -5
  72. package/js/src/abstract/timex.d.ts +0 -65
  73. package/js/src/abstract/timex.js +0 -5
  74. package/js/src/alp.d.ts +0 -209
  75. package/js/src/alp.js +0 -1052
  76. package/js/src/defx.d.ts +0 -348
  77. package/js/src/defx.js +0 -2135
  78. package/js/src/pro/defx.d.ts +0 -236
  79. package/js/src/pro/defx.js +0 -859
  80. package/js/src/timex.d.ts +0 -247
  81. package/js/src/timex.js +0 -1786
@@ -1,859 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- import defxRest from '../defx.js';
3
- import { ArgumentsRequired, ExchangeError } from '../base/errors.js';
4
- import { ArrayCache, ArrayCacheBySymbolById, ArrayCacheByTimestamp } from '../base/ws/Cache.js';
5
- // ---------------------------------------------------------------------------
6
- export default class defx extends defxRest {
7
- describe() {
8
- return this.deepExtend(super.describe(), {
9
- 'has': {
10
- 'ws': true,
11
- 'watchBalance': true,
12
- 'watchTicker': true,
13
- 'watchTickers': true,
14
- 'watchBidsAsks': true,
15
- 'watchTrades': true,
16
- 'watchTradesForSymbols': true,
17
- 'watchMyTrades': false,
18
- 'watchOrders': true,
19
- 'watchOrderBook': true,
20
- 'watchOrderBookForSymbols': true,
21
- 'watchOHLCV': true,
22
- 'watchOHLCVForSymbols': true,
23
- },
24
- 'urls': {
25
- 'test': {
26
- 'ws': {
27
- 'public': 'wss://stream.testnet.defx.com/pricefeed',
28
- 'private': 'wss://ws.testnet.defx.com/user',
29
- },
30
- },
31
- 'api': {
32
- 'ws': {
33
- 'public': 'wss://marketfeed.api.defx.com/pricefeed',
34
- 'private': 'wss://userfeed.api.defx.com/user',
35
- },
36
- },
37
- },
38
- 'options': {
39
- 'listenKeyRefreshRate': 3540000,
40
- 'ws': {
41
- 'timeframes': {
42
- '1m': '1m',
43
- '3m': '3m',
44
- '5m': '5m',
45
- '15m': '15m',
46
- '30m': '30m',
47
- '1h': '1h',
48
- '2h': '2h',
49
- '4h': '4h',
50
- '12h': '12h',
51
- '1d': '1d',
52
- '1w': '1w',
53
- '1M': '1M',
54
- },
55
- },
56
- },
57
- 'streaming': {},
58
- 'exceptions': {},
59
- });
60
- }
61
- async watchPublic(topics, messageHashes, params = {}) {
62
- await this.loadMarkets();
63
- const url = this.urls['api']['ws']['public'];
64
- const request = {
65
- 'method': 'SUBSCRIBE',
66
- 'topics': topics,
67
- };
68
- const message = this.extend(request, params);
69
- return await this.watchMultiple(url, messageHashes, message, messageHashes);
70
- }
71
- async unWatchPublic(topics, messageHashes, params = {}) {
72
- await this.loadMarkets();
73
- const url = this.urls['api']['ws']['public'];
74
- const request = {
75
- 'method': 'UNSUBSCRIBE',
76
- 'topics': topics,
77
- };
78
- const message = this.extend(request, params);
79
- return await this.watchMultiple(url, messageHashes, message, messageHashes);
80
- }
81
- /**
82
- * @method
83
- * @name defx#watchOHLCV
84
- * @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
85
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
86
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
87
- * @param {string} timeframe the length of time each candle represents
88
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
89
- * @param {int} [limit] the maximum amount of candles to fetch
90
- * @param {object} [params] extra parameters specific to the exchange API endpoint
91
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
92
- */
93
- async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
94
- const result = await this.watchOHLCVForSymbols([[symbol, timeframe]], since, limit, params);
95
- return result[symbol][timeframe];
96
- }
97
- /**
98
- * @method
99
- * @name defx#unWatchOHLCV
100
- * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
101
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
102
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
103
- * @param {string} timeframe the length of time each candle represents
104
- * @param {object} [params] extra parameters specific to the exchange API endpoint
105
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
106
- */
107
- async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
108
- return await this.unWatchOHLCVForSymbols([[symbol, timeframe]], params);
109
- }
110
- /**
111
- * @method
112
- * @name defx#watchOHLCVForSymbols
113
- * @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
114
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
115
- * @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
116
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
117
- * @param {int} [limit] the maximum amount of candles to fetch
118
- * @param {object} [params] extra parameters specific to the exchange API endpoint
119
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
120
- */
121
- async watchOHLCVForSymbols(symbolsAndTimeframes, since = undefined, limit = undefined, params = {}) {
122
- const symbolsLength = symbolsAndTimeframes.length;
123
- if (symbolsLength === 0 || !Array.isArray(symbolsAndTimeframes[0])) {
124
- throw new ArgumentsRequired(this.id + " watchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]");
125
- }
126
- await this.loadMarkets();
127
- const topics = [];
128
- const messageHashes = [];
129
- for (let i = 0; i < symbolsAndTimeframes.length; i++) {
130
- const symbolAndTimeframe = symbolsAndTimeframes[i];
131
- const marketId = this.safeString(symbolAndTimeframe, 0);
132
- const market = this.market(marketId);
133
- const tf = this.safeString(symbolAndTimeframe, 1);
134
- const interval = this.safeString(this.timeframes, tf, tf);
135
- topics.push('symbol:' + market['id'] + ':ohlc:' + interval);
136
- messageHashes.push('candles:' + interval + ':' + market['symbol']);
137
- }
138
- const [symbol, timeframe, candles] = await this.watchPublic(topics, messageHashes, params);
139
- if (this.newUpdates) {
140
- limit = candles.getLimit(symbol, limit);
141
- }
142
- const filtered = this.filterBySinceLimit(candles, since, limit, 0, true);
143
- return this.createOHLCVObject(symbol, timeframe, filtered);
144
- }
145
- /**
146
- * @method
147
- * @name defx#unWatchOHLCVForSymbols
148
- * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
149
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
150
- * @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
151
- * @param {object} [params] extra parameters specific to the exchange API endpoint
152
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
153
- */
154
- async unWatchOHLCVForSymbols(symbolsAndTimeframes, params = {}) {
155
- const symbolsLength = symbolsAndTimeframes.length;
156
- if (symbolsLength === 0 || !Array.isArray(symbolsAndTimeframes[0])) {
157
- throw new ArgumentsRequired(this.id + " unWatchOHLCVForSymbols() requires a an array of symbols and timeframes, like [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]");
158
- }
159
- await this.loadMarkets();
160
- const topics = [];
161
- const messageHashes = [];
162
- for (let i = 0; i < symbolsAndTimeframes.length; i++) {
163
- const symbolAndTimeframe = symbolsAndTimeframes[i];
164
- const marketId = this.safeString(symbolAndTimeframe, 0);
165
- const market = this.market(marketId);
166
- const tf = this.safeString(symbolAndTimeframe, 1);
167
- const interval = this.safeString(this.timeframes, tf, tf);
168
- topics.push('symbol:' + market['id'] + ':ohlc:' + interval);
169
- messageHashes.push('candles:' + interval + ':' + market['symbol']);
170
- }
171
- return await this.unWatchPublic(topics, messageHashes, params);
172
- }
173
- handleOHLCV(client, message) {
174
- //
175
- // {
176
- // "topic": "symbol:BTC_USDC:ohlc:3m",
177
- // "event": "ohlc",
178
- // "timestamp": 1730794277104,
179
- // "data": {
180
- // "symbol": "BTC_USDC",
181
- // "window": "3m",
182
- // "open": "57486.90000000",
183
- // "high": "57486.90000000",
184
- // "low": "57486.90000000",
185
- // "close": "57486.90000000",
186
- // "volume": "0.000",
187
- // "quoteAssetVolume": "0.00000000",
188
- // "takerBuyAssetVolume": "0.000",
189
- // "takerBuyQuoteAssetVolume": "0.00000000",
190
- // "numberOfTrades": 0,
191
- // "start": 1730794140000,
192
- // "end": 1730794320000,
193
- // "isClosed": false
194
- // }
195
- // }
196
- //
197
- const data = this.safeDict(message, 'data', {});
198
- const marketId = this.safeString(data, 'symbol');
199
- const market = this.market(marketId);
200
- const symbol = market['symbol'];
201
- const timeframe = this.safeString(data, 'window');
202
- if (!(symbol in this.ohlcvs)) {
203
- this.ohlcvs[symbol] = {};
204
- }
205
- if (!(timeframe in this.ohlcvs[symbol])) {
206
- const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
207
- const stored = new ArrayCacheByTimestamp(limit);
208
- this.ohlcvs[symbol][timeframe] = stored;
209
- }
210
- const ohlcv = this.ohlcvs[symbol][timeframe];
211
- const parsed = this.parseOHLCV(data);
212
- ohlcv.append(parsed);
213
- const messageHash = 'candles:' + timeframe + ':' + symbol;
214
- client.resolve([symbol, timeframe, ohlcv], messageHash);
215
- }
216
- /**
217
- * @method
218
- * @name defx#watchTicker
219
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
220
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
221
- * @param {string} symbol unified symbol of the market to fetch the ticker for
222
- * @param {object} [params] extra parameters specific to the exchange API endpoint
223
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
224
- */
225
- async watchTicker(symbol, params = {}) {
226
- await this.loadMarkets();
227
- const market = this.market(symbol);
228
- symbol = market['symbol'];
229
- const topic = 'symbol:' + market['id'] + ':24hrTicker';
230
- const messageHash = 'ticker:' + symbol;
231
- return await this.watchPublic([topic], [messageHash], params);
232
- }
233
- /**
234
- * @method
235
- * @name defx#unWatchTicker
236
- * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
237
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
238
- * @param {string} symbol unified symbol of the market to fetch the ticker for
239
- * @param {object} [params] extra parameters specific to the exchange API endpoint
240
- * @param {string} [params.channel] the channel to subscribe to, tickers by default. Can be tickers, sprd-tickers, index-tickers, block-tickers
241
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
242
- */
243
- async unWatchTicker(symbol, params = {}) {
244
- return await this.unWatchTickers([symbol], params);
245
- }
246
- /**
247
- * @method
248
- * @name defx#watchTickers
249
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
250
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
251
- * @param {string[]} [symbols] unified symbol of the market to fetch the ticker for
252
- * @param {object} [params] extra parameters specific to the exchange API endpoint
253
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
254
- */
255
- async watchTickers(symbols = undefined, params = {}) {
256
- await this.loadMarkets();
257
- symbols = this.marketSymbols(symbols, undefined, false);
258
- const topics = [];
259
- const messageHashes = [];
260
- for (let i = 0; i < symbols.length; i++) {
261
- const symbol = symbols[i];
262
- const marketId = this.marketId(symbol);
263
- topics.push('symbol:' + marketId + ':24hrTicker');
264
- messageHashes.push('ticker:' + symbol);
265
- }
266
- await this.watchPublic(topics, messageHashes, params);
267
- return this.filterByArray(this.tickers, 'symbol', symbols);
268
- }
269
- /**
270
- * @method
271
- * @name defx#unWatchTickers
272
- * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
273
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
274
- * @param {string[]} [symbols] unified symbol of the market to fetch the ticker for
275
- * @param {object} [params] extra parameters specific to the exchange API endpoint
276
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
277
- */
278
- async unWatchTickers(symbols = undefined, params = {}) {
279
- await this.loadMarkets();
280
- symbols = this.marketSymbols(symbols, undefined, false);
281
- const topics = [];
282
- const messageHashes = [];
283
- for (let i = 0; i < symbols.length; i++) {
284
- const symbol = symbols[i];
285
- const marketId = this.marketId(symbol);
286
- topics.push('symbol:' + marketId + ':24hrTicker');
287
- messageHashes.push('ticker:' + symbol);
288
- }
289
- return await this.unWatchPublic(topics, messageHashes, params);
290
- }
291
- handleTicker(client, message) {
292
- //
293
- // {
294
- // "topic": "symbol:BTC_USDC:24hrTicker",
295
- // "event": "24hrTicker",
296
- // "timestamp": 1730862543095,
297
- // "data": {
298
- // "symbol": "BTC_USDC",
299
- // "priceChange": "17114.70000000",
300
- // "priceChangePercent": "29.77",
301
- // "weightedAvgPrice": "6853147668",
302
- // "lastPrice": "74378.90000000",
303
- // "lastQty": "0.107",
304
- // "bestBidPrice": "61987.60000000",
305
- // "bestBidQty": "0.005",
306
- // "bestAskPrice": "84221.60000000",
307
- // "bestAskQty": "0.015",
308
- // "openPrice": "57486.90000000",
309
- // "highPrice": "88942.60000000",
310
- // "lowPrice": "47364.20000000",
311
- // "volume": "28.980",
312
- // "quoteVolume": "1986042.19424035",
313
- // "openTime": 1730776080000,
314
- // "closeTime": 1730862540000,
315
- // "openInterestBase": "67.130",
316
- // "openInterestQuote": "5008005.40800000"
317
- // }
318
- // }
319
- //
320
- this.handleBidAsk(client, message);
321
- const data = this.safeDict(message, 'data', {});
322
- const parsedTicker = this.parseTicker(data);
323
- const symbol = parsedTicker['symbol'];
324
- const timestamp = this.safeInteger(message, 'timestamp');
325
- parsedTicker['timestamp'] = timestamp;
326
- parsedTicker['datetime'] = this.iso8601(timestamp);
327
- this.tickers[symbol] = parsedTicker;
328
- const messageHash = 'ticker:' + symbol;
329
- client.resolve(parsedTicker, messageHash);
330
- }
331
- /**
332
- * @method
333
- * @name defx#watchBidsAsks
334
- * @description watches best bid & ask for symbols
335
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
336
- * @param {string[]} symbols unified symbol of the market to fetch the ticker for
337
- * @param {object} [params] extra parameters specific to the exchange API endpoint
338
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
339
- */
340
- async watchBidsAsks(symbols = undefined, params = {}) {
341
- await this.loadMarkets();
342
- symbols = this.marketSymbols(symbols, undefined, false);
343
- const topics = [];
344
- const messageHashes = [];
345
- for (let i = 0; i < symbols.length; i++) {
346
- const symbol = symbols[i];
347
- const marketId = this.marketId(symbol);
348
- topics.push('symbol:' + marketId + ':24hrTicker');
349
- messageHashes.push('bidask:' + symbol);
350
- }
351
- await this.watchPublic(topics, messageHashes, params);
352
- return this.filterByArray(this.bidsasks, 'symbol', symbols);
353
- }
354
- handleBidAsk(client, message) {
355
- const data = this.safeDict(message, 'data', {});
356
- const parsedTicker = this.parseWsBidAsk(data);
357
- const symbol = parsedTicker['symbol'];
358
- const timestamp = this.safeInteger(message, 'timestamp');
359
- parsedTicker['timestamp'] = timestamp;
360
- parsedTicker['datetime'] = this.iso8601(timestamp);
361
- this.bidsasks[symbol] = parsedTicker;
362
- const messageHash = 'bidask:' + symbol;
363
- client.resolve(parsedTicker, messageHash);
364
- }
365
- parseWsBidAsk(ticker, market = undefined) {
366
- const marketId = this.safeString(ticker, 'symbol');
367
- market = this.safeMarket(marketId, market);
368
- const symbol = this.safeString(market, 'symbol');
369
- return this.safeTicker({
370
- 'symbol': symbol,
371
- 'timestamp': undefined,
372
- 'datetime': undefined,
373
- 'ask': this.safeString(ticker, 'bestAskPrice'),
374
- 'askVolume': this.safeString(ticker, 'bestAskQty'),
375
- 'bid': this.safeString(ticker, 'bestBidPrice'),
376
- 'bidVolume': this.safeString(ticker, 'bestBidQty'),
377
- 'info': ticker,
378
- }, market);
379
- }
380
- /**
381
- * @method
382
- * @name defx#watchTrades
383
- * @description watches information on multiple trades made in a market
384
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
385
- * @param {string} symbol unified symbol of the market to fetch the ticker for
386
- * @param {int} [since] the earliest time in ms to fetch trades for
387
- * @param {int} [limit] the maximum number of trade structures to retrieve
388
- * @param {object} [params] extra parameters specific to the exchange API endpoint
389
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
390
- */
391
- async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
392
- return await this.watchTradesForSymbols([symbol], since, limit, params);
393
- }
394
- /**
395
- * @method
396
- * @name defx#unWatchTrades
397
- * @description unWatches from the stream channel
398
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
399
- * @param {string} symbol unified symbol of the market to fetch trades for
400
- * @param {object} [params] extra parameters specific to the exchange API endpoint
401
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
402
- */
403
- async unWatchTrades(symbol, params = {}) {
404
- return await this.unWatchTradesForSymbols([symbol], params);
405
- }
406
- /**
407
- * @method
408
- * @name defx#watchTradesForSymbols
409
- * @description watches information on multiple trades made in a market
410
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
411
- * @param {string[]} symbols unified symbol of the market to fetch trades for
412
- * @param {int} [since] the earliest time in ms to fetch trades for
413
- * @param {int} [limit] the maximum number of trade structures to retrieve
414
- * @param {object} [params] extra parameters specific to the exchange API endpoint
415
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
416
- */
417
- async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
418
- await this.loadMarkets();
419
- symbols = this.marketSymbols(symbols);
420
- const symbolsLength = symbols.length;
421
- if (symbolsLength === 0) {
422
- throw new ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
423
- }
424
- const topics = [];
425
- const messageHashes = [];
426
- for (let i = 0; i < symbols.length; i++) {
427
- const symbol = symbols[i];
428
- const marketId = this.marketId(symbol);
429
- topics.push('symbol:' + marketId + ':trades');
430
- messageHashes.push('trade:' + symbol);
431
- }
432
- const trades = await this.watchPublic(topics, messageHashes, params);
433
- if (this.newUpdates) {
434
- const first = this.safeValue(trades, 0);
435
- const tradeSymbol = this.safeString(first, 'symbol');
436
- limit = trades.getLimit(tradeSymbol, limit);
437
- }
438
- return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
439
- }
440
- /**
441
- * @method
442
- * @name defx#unWatchTradesForSymbols
443
- * @description unWatches from the stream channel
444
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
445
- * @param {string[]} symbols unified symbol of the market to fetch trades for
446
- * @param {object} [params] extra parameters specific to the exchange API endpoint
447
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
448
- */
449
- async unWatchTradesForSymbols(symbols, params = {}) {
450
- await this.loadMarkets();
451
- symbols = this.marketSymbols(symbols);
452
- const symbolsLength = symbols.length;
453
- if (symbolsLength === 0) {
454
- throw new ArgumentsRequired(this.id + ' unWatchTradesForSymbols() requires a non-empty array of symbols');
455
- }
456
- const topics = [];
457
- const messageHashes = [];
458
- for (let i = 0; i < symbols.length; i++) {
459
- const symbol = symbols[i];
460
- const marketId = this.marketId(symbol);
461
- topics.push('symbol:' + marketId + ':trades');
462
- messageHashes.push('trade:' + symbol);
463
- }
464
- return await this.unWatchPublic(topics, messageHashes, params);
465
- }
466
- handleTrades(client, message) {
467
- //
468
- // {
469
- // "topic": "symbol:SOL_USDC:trades",
470
- // "event": "trades",
471
- // "timestamp": 1730967426331,
472
- // "data": {
473
- // "buyerMaker": true,
474
- // "price": "188.38700000",
475
- // "qty": "1.00",
476
- // "symbol": "SOL_USDC",
477
- // "timestamp": 1730967426328
478
- // }
479
- // }
480
- //
481
- const data = this.safeDict(message, 'data', {});
482
- const parsedTrade = this.parseTrade(data);
483
- const symbol = parsedTrade['symbol'];
484
- if (!(symbol in this.trades)) {
485
- const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
486
- const stored = new ArrayCache(limit);
487
- this.trades[symbol] = stored;
488
- }
489
- const trades = this.trades[symbol];
490
- trades.append(parsedTrade);
491
- const messageHash = 'trade:' + symbol;
492
- client.resolve(trades, messageHash);
493
- }
494
- /**
495
- * @method
496
- * @name defx#watchOrderBook
497
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
498
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
499
- * @param {string} symbol unified symbol of the market to fetch the order book for
500
- * @param {int} [limit] the maximum amount of order book entries to return
501
- * @param {object} [params] extra parameters specific to the exchange API endpoint
502
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
503
- */
504
- async watchOrderBook(symbol, limit = undefined, params = {}) {
505
- return await this.watchOrderBookForSymbols([symbol], limit, params);
506
- }
507
- /**
508
- * @method
509
- * @name defx#unWatchOrderBook
510
- * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
511
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
512
- * @param {string} symbol unified array of symbols
513
- * @param {object} [params] extra parameters specific to the exchange API endpoint
514
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
515
- */
516
- async unWatchOrderBook(symbol, params = {}) {
517
- return await this.unWatchOrderBookForSymbols([symbol], params);
518
- }
519
- /**
520
- * @method
521
- * @name defx#watchOrderBookForSymbols
522
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
523
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
524
- * @param {string[]} symbols unified array of symbols
525
- * @param {int} [limit] the maximum amount of order book entries to return
526
- * @param {object} [params] extra parameters specific to the exchange API endpoint
527
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
528
- */
529
- async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
530
- await this.loadMarkets();
531
- const symbolsLength = symbols.length;
532
- if (symbolsLength === 0) {
533
- throw new ArgumentsRequired(this.id + ' watchOrderBookForSymbols() requires a non-empty array of symbols');
534
- }
535
- symbols = this.marketSymbols(symbols);
536
- const topics = [];
537
- const messageHashes = [];
538
- for (let i = 0; i < symbols.length; i++) {
539
- const symbol = symbols[i];
540
- const marketId = this.marketId(symbol);
541
- topics.push('symbol:' + marketId + ':depth:20:0.001');
542
- messageHashes.push('orderbook:' + symbol);
543
- }
544
- const orderbook = await this.watchPublic(topics, messageHashes, params);
545
- return orderbook.limit();
546
- }
547
- /**
548
- * @method
549
- * @name defx#unWatchOrderBookForSymbols
550
- * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
551
- * @see https://www.postman.com/defxcode/defx-public-apis/collection/667939a1b5d8069c13d614e9
552
- * @param {string[]} symbols unified array of symbols
553
- * @param {object} [params] extra parameters specific to the exchange API endpoint
554
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
555
- */
556
- async unWatchOrderBookForSymbols(symbols, params = {}) {
557
- await this.loadMarkets();
558
- const symbolsLength = symbols.length;
559
- if (symbolsLength === 0) {
560
- throw new ArgumentsRequired(this.id + ' unWatchOrderBookForSymbols() requires a non-empty array of symbols');
561
- }
562
- symbols = this.marketSymbols(symbols);
563
- const topics = [];
564
- const messageHashes = [];
565
- for (let i = 0; i < symbols.length; i++) {
566
- const symbol = symbols[i];
567
- const marketId = this.marketId(symbol);
568
- topics.push('symbol:' + marketId + ':depth:20:0.001');
569
- messageHashes.push('orderbook:' + symbol);
570
- }
571
- return await this.unWatchPublic(topics, messageHashes, params);
572
- }
573
- handleOrderBook(client, message) {
574
- //
575
- // {
576
- // "topic": "symbol:SOL_USDC:depth:20:0.01",
577
- // "event": "depth",
578
- // "timestamp": 1731030695319,
579
- // "data": {
580
- // "symbol": "SOL_USDC",
581
- // "timestamp": 1731030695319,
582
- // "lastTradeTimestamp": 1731030275258,
583
- // "level": "20",
584
- // "slab": "0.01",
585
- // "bids": [
586
- // {
587
- // "price": "198.27000000",
588
- // "qty": "1.52"
589
- // }
590
- // ],
591
- // "asks": [
592
- // {
593
- // "price": "198.44000000",
594
- // "qty": "6.61"
595
- // }
596
- // ]
597
- // }
598
- // }
599
- //
600
- const data = this.safeDict(message, 'data', {});
601
- const marketId = this.safeString(data, 'symbol');
602
- const market = this.market(marketId);
603
- const symbol = market['symbol'];
604
- const timestamp = this.safeInteger(data, 'timestamp');
605
- const snapshot = this.parseOrderBook(data, symbol, timestamp, 'bids', 'asks', 'price', 'qty');
606
- if (!(symbol in this.orderbooks)) {
607
- const ob = this.orderBook(snapshot);
608
- this.orderbooks[symbol] = ob;
609
- }
610
- const orderbook = this.orderbooks[symbol];
611
- orderbook.reset(snapshot);
612
- const messageHash = 'orderbook:' + symbol;
613
- client.resolve(orderbook, messageHash);
614
- }
615
- async keepAliveListenKey(params = {}) {
616
- const listenKey = this.safeString(this.options, 'listenKey');
617
- if (listenKey === undefined) {
618
- // A network error happened: we can't renew a listen key that does not exist.
619
- return;
620
- }
621
- try {
622
- await this.v1PrivatePutApiUsersSocketListenKeysListenKey({ 'listenKey': listenKey }); // extend the expiry
623
- }
624
- catch (error) {
625
- const url = this.urls['api']['ws']['private'] + '?listenKey=' + listenKey;
626
- const client = this.client(url);
627
- const messageHashes = Object.keys(client.futures);
628
- for (let j = 0; j < messageHashes.length; j++) {
629
- const messageHash = messageHashes[j];
630
- client.reject(error, messageHash);
631
- }
632
- this.options['listenKey'] = undefined;
633
- this.options['lastAuthenticatedTime'] = 0;
634
- return;
635
- }
636
- // whether or not to schedule another listenKey keepAlive request
637
- const listenKeyRefreshRate = this.safeInteger(this.options, 'listenKeyRefreshRate', 3540000);
638
- this.delay(listenKeyRefreshRate, this.keepAliveListenKey, params);
639
- }
640
- async authenticate(params = {}) {
641
- const time = this.milliseconds();
642
- const lastAuthenticatedTime = this.safeInteger(this.options, 'lastAuthenticatedTime', 0);
643
- const listenKeyRefreshRate = this.safeInteger(this.options, 'listenKeyRefreshRate', 3540000); // 1 hour
644
- if (time - lastAuthenticatedTime > listenKeyRefreshRate) {
645
- const response = await this.v1PrivatePostApiUsersSocketListenKeys();
646
- this.options['listenKey'] = this.safeString(response, 'listenKey');
647
- this.options['lastAuthenticatedTime'] = time;
648
- this.delay(listenKeyRefreshRate, this.keepAliveListenKey, params);
649
- }
650
- }
651
- /**
652
- * @method
653
- * @name defx#watchBalance
654
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
655
- * @see https://www.postman.com/defxcode/defx-public-apis/ws-raw-request/667939b2f00f79161bb47809
656
- * @param {object} [params] extra parameters specific to the exchange API endpoint
657
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
658
- */
659
- async watchBalance(params = {}) {
660
- await this.loadMarkets();
661
- await this.authenticate();
662
- const baseUrl = this.urls['api']['ws']['private'];
663
- const messageHash = 'WALLET_BALANCE_UPDATE';
664
- const url = baseUrl + '?listenKey=' + this.options['listenKey'];
665
- return await this.watch(url, messageHash, undefined, messageHash);
666
- }
667
- handleBalance(client, message) {
668
- //
669
- // {
670
- // "event": "WALLET_BALANCE_UPDATE",
671
- // "timestamp": 1711015961396,
672
- // "data": {
673
- // "asset": "USDC", "balance": "27.64712963"
674
- // }
675
- // }
676
- //
677
- const messageHash = this.safeString(message, 'event');
678
- const data = this.safeDict(message, 'data', []);
679
- const timestamp = this.safeInteger(message, 'timestamp');
680
- if (this.balance === undefined) {
681
- this.balance = {};
682
- }
683
- this.balance['info'] = data;
684
- this.balance['timestamp'] = timestamp;
685
- this.balance['datetime'] = this.iso8601(timestamp);
686
- const currencyId = this.safeString(data, 'asset');
687
- const code = this.safeCurrencyCode(currencyId);
688
- const account = (code in this.balance) ? this.balance[code] : this.account();
689
- account['free'] = this.safeString(data, 'balance');
690
- this.balance[code] = account;
691
- this.balance = this.safeBalance(this.balance);
692
- client.resolve(this.balance, messageHash);
693
- }
694
- /**
695
- * @method
696
- * @name defx#watchOrders
697
- * @description watches information on multiple orders made by the user
698
- * @see https://www.postman.com/defxcode/defx-public-apis/ws-raw-request/667939b2f00f79161bb47809
699
- * @param {string} [symbol] unified market symbol of the market the orders were made in
700
- * @param {int} [since] the earliest time in ms to fetch orders for
701
- * @param {int} [limit] the maximum number of order structures to retrieve
702
- * @param {object} [params] extra parameters specific to the exchange API endpoint
703
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
704
- */
705
- async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
706
- await this.loadMarkets();
707
- await this.authenticate();
708
- const baseUrl = this.urls['api']['ws']['private'];
709
- let messageHash = 'orders';
710
- if (symbol !== undefined) {
711
- const market = this.market(symbol);
712
- messageHash += ':' + market['symbol'];
713
- }
714
- const url = baseUrl + '?listenKey=' + this.options['listenKey'];
715
- const orders = await this.watch(url, messageHash, undefined, messageHash);
716
- if (this.newUpdates) {
717
- limit = orders.getLimit(symbol, limit);
718
- }
719
- return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
720
- }
721
- handleOrder(client, message) {
722
- //
723
- // {
724
- // "event": "ORDER_UPDATE",
725
- // "timestamp": 1731417961446,
726
- // "data": {
727
- // "orderId": "766738557656630928",
728
- // "symbol": "SOL_USDC",
729
- // "side": "SELL",
730
- // "type": "MARKET",
731
- // "status": "FILLED",
732
- // "clientOrderId": "0193208d-717b-7811-a80e-c036e220ad9b",
733
- // "reduceOnly": false,
734
- // "postOnly": false,
735
- // "timeInForce": "GTC",
736
- // "isTriggered": false,
737
- // "createdAt": "2024-11-12T13:26:00.829Z",
738
- // "updatedAt": "2024-11-12T13:26:01.436Z",
739
- // "avgPrice": "209.60000000",
740
- // "cumulativeQuote": "104.80000000",
741
- // "totalFee": "0.05764000",
742
- // "executedQty": "0.50",
743
- // "origQty": "0.50",
744
- // "role": "TAKER",
745
- // "pnl": "0.00000000",
746
- // "lastFillPnL": "0.00000000",
747
- // "lastFillPrice": "209.60000000",
748
- // "lastFillQty": "0.50",
749
- // "linkedOrderParentType": null,
750
- // "workingType": null
751
- // }
752
- // }
753
- //
754
- const channel = 'orders';
755
- const data = this.safeDict(message, 'data', {});
756
- if (this.orders === undefined) {
757
- const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
758
- this.orders = new ArrayCacheBySymbolById(limit);
759
- }
760
- const orders = this.orders;
761
- const parsedOrder = this.parseOrder(data);
762
- orders.append(parsedOrder);
763
- const messageHash = channel + ':' + parsedOrder['symbol'];
764
- client.resolve(orders, channel);
765
- client.resolve(orders, messageHash);
766
- }
767
- /**
768
- * @method
769
- * @name defx#watchPositions
770
- * @description watch all open positions
771
- * @see https://www.postman.com/defxcode/defx-public-apis/ws-raw-request/667939b2f00f79161bb47809
772
- * @param {string[]|undefined} symbols list of unified market symbols
773
- * @param {number} [since] since timestamp
774
- * @param {number} [limit] limit
775
- * @param {object} params extra parameters specific to the exchange API endpoint
776
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
777
- */
778
- async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
779
- await this.loadMarkets();
780
- await this.authenticate();
781
- symbols = this.marketSymbols(symbols);
782
- const baseUrl = this.urls['api']['ws']['private'];
783
- const channel = 'positions';
784
- const url = baseUrl + '?listenKey=' + this.options['listenKey'];
785
- let newPosition = undefined;
786
- if (symbols !== undefined) {
787
- const messageHashes = [];
788
- for (let i = 0; i < symbols.length; i++) {
789
- const symbol = symbols[i];
790
- messageHashes.push(channel + ':' + symbol);
791
- }
792
- newPosition = await this.watchMultiple(url, messageHashes, undefined, messageHashes);
793
- }
794
- else {
795
- newPosition = await this.watch(url, channel, undefined, channel);
796
- }
797
- if (this.newUpdates) {
798
- return newPosition;
799
- }
800
- return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
801
- }
802
- handlePositions(client, message) {
803
- //
804
- // {
805
- // "event": "POSITION_UPDATE",
806
- // "timestamp": 1731417961456,
807
- // "data": {
808
- // "positionId": "0193208d-735d-7fe9-90bd-8bc6d6bc1eda",
809
- // "createdAt": 1289847904328,
810
- // "symbol": "SOL_USDC",
811
- // "positionSide": "SHORT",
812
- // "entryPrice": "209.60000000",
813
- // "quantity": "0.50",
814
- // "status": "ACTIVE",
815
- // "marginAsset": "USDC",
816
- // "marginAmount": "15.17475649",
817
- // "realizedPnL": "0.00000000"
818
- // }
819
- // }
820
- //
821
- const channel = 'positions';
822
- const data = this.safeDict(message, 'data', {});
823
- if (this.positions === undefined) {
824
- this.positions = new ArrayCacheBySymbolById();
825
- }
826
- const cache = this.positions;
827
- const parsedPosition = this.parsePosition(data);
828
- const timestamp = this.safeInteger(message, 'timestamp');
829
- parsedPosition['timestamp'] = timestamp;
830
- parsedPosition['datetime'] = this.iso8601(timestamp);
831
- cache.append(parsedPosition);
832
- const messageHash = channel + ':' + parsedPosition['symbol'];
833
- client.resolve([parsedPosition], channel);
834
- client.resolve([parsedPosition], messageHash);
835
- }
836
- handleMessage(client, message) {
837
- const error = this.safeString(message, 'code');
838
- if (error !== undefined) {
839
- const errorMsg = this.safeString(message, 'msg');
840
- throw new ExchangeError(this.id + ' ' + errorMsg);
841
- }
842
- const event = this.safeString(message, 'event');
843
- if (event !== undefined) {
844
- const methods = {
845
- 'ohlc': this.handleOHLCV,
846
- '24hrTicker': this.handleTicker,
847
- 'trades': this.handleTrades,
848
- 'depth': this.handleOrderBook,
849
- 'WALLET_BALANCE_UPDATE': this.handleBalance,
850
- 'ORDER_UPDATE': this.handleOrder,
851
- 'POSITION_UPDATE': this.handlePositions,
852
- };
853
- const exacMethod = this.safeValue(methods, event);
854
- if (exacMethod !== undefined) {
855
- exacMethod.call(this, client, message);
856
- }
857
- }
858
- }
859
- }