ccxt 4.2.24 → 4.2.26

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.
@@ -53,6 +53,7 @@ export default class bitfinex2 extends Exchange {
53
53
  'fetchFundingRates': true,
54
54
  'fetchIndexOHLCV': false,
55
55
  'fetchLedger': true,
56
+ 'fetchLiquidations': true,
56
57
  'fetchMarginMode': false,
57
58
  'fetchMarkOHLCV': false,
58
59
  'fetchMyTrades': true,
@@ -3174,4 +3175,94 @@ export default class bitfinex2 extends Exchange {
3174
3175
  'info': interest,
3175
3176
  }, market);
3176
3177
  }
3178
+ async fetchLiquidations(symbol, since = undefined, limit = undefined, params = {}) {
3179
+ /**
3180
+ * @method
3181
+ * @name bitfinex2#fetchLiquidations
3182
+ * @description retrieves the public liquidations of a trading pair
3183
+ * @see https://docs.bitfinex.com/reference/rest-public-liquidations
3184
+ * @param {string} symbol unified CCXT market symbol
3185
+ * @param {int} [since] the earliest time in ms to fetch liquidations for
3186
+ * @param {int} [limit] the maximum number of liquidation structures to retrieve
3187
+ * @param {object} [params] exchange specific parameters
3188
+ * @param {int} [params.until] timestamp in ms of the latest liquidation
3189
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3190
+ * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
3191
+ */
3192
+ await this.loadMarkets();
3193
+ let paginate = false;
3194
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchLiquidations', 'paginate');
3195
+ if (paginate) {
3196
+ return await this.fetchPaginatedCallDeterministic('fetchLiquidations', symbol, since, limit, '8h', params, 500);
3197
+ }
3198
+ const market = this.market(symbol);
3199
+ let request = {};
3200
+ if (since !== undefined) {
3201
+ request['start'] = since;
3202
+ }
3203
+ if (limit !== undefined) {
3204
+ request['limit'] = limit;
3205
+ }
3206
+ [request, params] = this.handleUntilOption('end', request, params);
3207
+ const response = await this.publicGetLiquidationsHist(this.extend(request, params));
3208
+ //
3209
+ // [
3210
+ // [
3211
+ // [
3212
+ // "pos",
3213
+ // 171085137,
3214
+ // 1706395919788,
3215
+ // null,
3216
+ // "tAVAXF0:USTF0",
3217
+ // -8,
3218
+ // 32.868,
3219
+ // null,
3220
+ // 1,
3221
+ // 1,
3222
+ // null,
3223
+ // 33.255
3224
+ // ]
3225
+ // ],
3226
+ // ]
3227
+ //
3228
+ return this.parseLiquidations(response, market, since, limit);
3229
+ }
3230
+ parseLiquidation(liquidation, market = undefined) {
3231
+ //
3232
+ // [
3233
+ // [
3234
+ // "pos",
3235
+ // 171085137, // position id
3236
+ // 1706395919788, // timestamp
3237
+ // null,
3238
+ // "tAVAXF0:USTF0", // market id
3239
+ // -8, // amount in contracts
3240
+ // 32.868, // base price
3241
+ // null,
3242
+ // 1,
3243
+ // 1,
3244
+ // null,
3245
+ // 33.255 // acquired price
3246
+ // ]
3247
+ // ]
3248
+ //
3249
+ const entry = liquidation[0];
3250
+ const timestamp = this.safeInteger(entry, 2);
3251
+ const marketId = this.safeString(entry, 4);
3252
+ const contracts = Precise.stringAbs(this.safeString(entry, 5));
3253
+ const contractSize = this.safeString(market, 'contractSize');
3254
+ const baseValue = Precise.stringMul(contracts, contractSize);
3255
+ const price = this.safeString(entry, 11);
3256
+ return this.safeLiquidation({
3257
+ 'info': entry,
3258
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
3259
+ 'contracts': this.parseNumber(contracts),
3260
+ 'contractSize': this.parseNumber(contractSize),
3261
+ 'price': this.parseNumber(price),
3262
+ 'baseValue': this.parseNumber(baseValue),
3263
+ 'quoteValue': this.parseNumber(Precise.stringMul(baseValue, price)),
3264
+ 'timestamp': timestamp,
3265
+ 'datetime': this.iso8601(timestamp),
3266
+ });
3267
+ }
3177
3268
  }
package/js/src/gate.js CHANGED
@@ -3440,7 +3440,7 @@ export default class gate extends Exchange {
3440
3440
  // "price": "333"
3441
3441
  // }
3442
3442
  //
3443
- const id = this.safeString(trade, 'id');
3443
+ const id = this.safeString2(trade, 'id', 'trade_id');
3444
3444
  let timestamp = this.safeTimestamp2(trade, 'time', 'create_time');
3445
3445
  timestamp = this.safeInteger(trade, 'create_time_ms', timestamp);
3446
3446
  const marketId = this.safeString2(trade, 'currency_pair', 'contract');
@@ -1,8 +1,11 @@
1
1
  import bingxRest from '../bingx.js';
2
- import type { Int, OHLCV, Str, OrderBook, Order, Trade, Balances } from '../base/types.js';
2
+ import type { Int, OHLCV, Str, OrderBook, Order, Trade, Balances, Ticker } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class bingx extends bingxRest {
5
5
  describe(): any;
6
+ watchTicker(symbol: string, params?: {}): Promise<Ticker>;
7
+ handleTicker(client: Client, message: any): void;
8
+ parseWsTicker(message: any, market?: any): Ticker;
6
9
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
7
10
  handleTrades(client: Client, message: any): void;
8
11
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
@@ -20,7 +20,7 @@ export default class bingx extends bingxRest {
20
20
  'watchOHLCV': true,
21
21
  'watchOrders': true,
22
22
  'watchMyTrades': true,
23
- 'watchTicker': false,
23
+ 'watchTicker': true,
24
24
  'watchTickers': false,
25
25
  'watchBalance': true,
26
26
  },
@@ -75,6 +75,151 @@ export default class bingx extends bingxRest {
75
75
  },
76
76
  });
77
77
  }
78
+ async watchTicker(symbol, params = {}) {
79
+ /**
80
+ * @method
81
+ * @name bingx#watchTicker
82
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
83
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
84
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
85
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
86
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
87
+ */
88
+ await this.loadMarkets();
89
+ const market = this.market(symbol);
90
+ const [marketType, query] = this.handleMarketTypeAndParams('watchTrades', market, params);
91
+ const url = this.safeValue(this.urls['api']['ws'], marketType);
92
+ if (url === undefined) {
93
+ throw new BadRequest(this.id + ' watchTrades is not supported for ' + marketType + ' markets.');
94
+ }
95
+ const messageHash = market['id'] + '@ticker';
96
+ const uuid = this.uuid();
97
+ const request = {
98
+ 'id': uuid,
99
+ 'dataType': messageHash,
100
+ };
101
+ if (marketType === 'swap') {
102
+ request['reqType'] = 'sub';
103
+ }
104
+ return await this.watch(url, messageHash, this.extend(request, query), messageHash);
105
+ }
106
+ handleTicker(client, message) {
107
+ //
108
+ // swap
109
+ //
110
+ // {
111
+ // "code": 0,
112
+ // "dataType": "BTC-USDT@ticker",
113
+ // "data": {
114
+ // "e": "24hTicker",
115
+ // "E": 1706498923556,
116
+ // "s": "BTC-USDT",
117
+ // "p": "346.4",
118
+ // "P": "0.82",
119
+ // "c": "42432.5",
120
+ // "L": "0.0529",
121
+ // "h": "42855.4",
122
+ // "l": "41578.3",
123
+ // "v": "64310.9754",
124
+ // "q": "2728360284.15",
125
+ // "o": "42086.1",
126
+ // "O": 1706498922655,
127
+ // "C": 1706498883023,
128
+ // "A": "42437.8",
129
+ // "a": "1.4160",
130
+ // "B": "42437.1",
131
+ // "b": "2.5747"
132
+ // }
133
+ // }
134
+ //
135
+ // spot
136
+ //
137
+ // {
138
+ // "code": 0,
139
+ // "timestamp": 1706506795473,
140
+ // "data": {
141
+ // "e": "24hTicker",
142
+ // "E": 1706506795472,
143
+ // "s": "BTC-USDT",
144
+ // "p": -372.12,
145
+ // "P": "-0.87%",
146
+ // "o": 42548.95,
147
+ // "h": 42696.1,
148
+ // "l": 41621.29,
149
+ // "c": 42176.83,
150
+ // "v": 4943.33,
151
+ // "q": 208842236.5,
152
+ // "O": 1706420395472,
153
+ // "C": 1706506795472,
154
+ // "A": 42177.23,
155
+ // "a": 5.14484,
156
+ // "B": 42176.38,
157
+ // "b": 5.36117
158
+ // }
159
+ // }
160
+ //
161
+ const data = this.safeValue(message, 'data', {});
162
+ const marketId = this.safeString(data, 's');
163
+ // const marketId = messageHash.split('@')[0];
164
+ const isSwap = client.url.indexOf('swap') >= 0;
165
+ const marketType = isSwap ? 'swap' : 'spot';
166
+ const market = this.safeMarket(marketId, undefined, undefined, marketType);
167
+ const symbol = market['symbol'];
168
+ const ticker = this.parseWsTicker(data, market);
169
+ this.tickers[symbol] = ticker;
170
+ const messageHash = market['id'] + '@ticker';
171
+ client.resolve(ticker, messageHash);
172
+ }
173
+ parseWsTicker(message, market = undefined) {
174
+ //
175
+ // {
176
+ // "e": "24hTicker",
177
+ // "E": 1706498923556,
178
+ // "s": "BTC-USDT",
179
+ // "p": "346.4",
180
+ // "P": "0.82",
181
+ // "c": "42432.5",
182
+ // "L": "0.0529",
183
+ // "h": "42855.4",
184
+ // "l": "41578.3",
185
+ // "v": "64310.9754",
186
+ // "q": "2728360284.15",
187
+ // "o": "42086.1",
188
+ // "O": 1706498922655,
189
+ // "C": 1706498883023,
190
+ // "A": "42437.8",
191
+ // "a": "1.4160",
192
+ // "B": "42437.1",
193
+ // "b": "2.5747"
194
+ // }
195
+ //
196
+ const timestamp = this.safeInteger(message, 'ts');
197
+ const marketId = this.safeString(message, 's');
198
+ market = this.safeMarket(marketId, market);
199
+ const close = this.safeString(message, 'c');
200
+ return this.safeTicker({
201
+ 'symbol': market['symbol'],
202
+ 'timestamp': timestamp,
203
+ 'datetime': this.iso8601(timestamp),
204
+ 'high': this.safeString(message, 'h'),
205
+ 'low': this.safeString(message, 'l'),
206
+ 'bid': this.safeString(message, 'B'),
207
+ 'bidVolume': this.safeString(message, 'b'),
208
+ 'ask': this.safeString(message, 'A'),
209
+ 'askVolume': this.safeString(message, 'a'),
210
+ 'vwap': undefined,
211
+ 'open': this.safeString(message, 'o'),
212
+ 'close': close,
213
+ 'last': close,
214
+ 'previousClose': undefined,
215
+ 'change': this.safeString(message, 'p'),
216
+ 'percentage': undefined,
217
+ 'average': undefined,
218
+ 'baseVolume': this.safeString(message, 'v'),
219
+ 'quoteVolume': this.safeString(message, 'q'),
220
+ 'info': message,
221
+ }, market);
222
+ }
78
223
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
79
224
  /**
80
225
  * @method
@@ -911,6 +1056,10 @@ export default class bingx extends bingxRest {
911
1056
  this.handleOrderBook(client, message);
912
1057
  return;
913
1058
  }
1059
+ if (dataType.indexOf('@ticker') >= 0) {
1060
+ this.handleTicker(client, message);
1061
+ return;
1062
+ }
914
1063
  if (dataType.indexOf('@trade') >= 0) {
915
1064
  this.handleTrades(client, message);
916
1065
  return;
@@ -941,5 +1090,10 @@ export default class bingx extends bingxRest {
941
1090
  this.handleMyTrades(client, message);
942
1091
  }
943
1092
  }
1093
+ const msgData = this.safeValue(message, 'data');
1094
+ const msgEvent = this.safeString(msgData, 'e');
1095
+ if (msgEvent === '24hTicker') {
1096
+ this.handleTicker(client, message);
1097
+ }
944
1098
  }
945
1099
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.24",
3
+ "version": "4.2.26",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",