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