ccxt 4.3.53 → 4.3.54

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.
@@ -135,7 +135,7 @@ export default class bybit extends bybitRest {
135
135
  this.options['requestId'] = requestId;
136
136
  return requestId;
137
137
  }
138
- getUrlByMarketType(symbol = undefined, isPrivate = false, method = undefined, params = {}) {
138
+ async getUrlByMarketType(symbol = undefined, isPrivate = false, method = undefined, params = {}) {
139
139
  const accessibility = isPrivate ? 'private' : 'public';
140
140
  let isUsdcSettled = undefined;
141
141
  let isSpot = undefined;
@@ -155,7 +155,15 @@ export default class bybit extends bybitRest {
155
155
  }
156
156
  isSpot = (type === 'spot');
157
157
  if (isPrivate) {
158
- url = (isUsdcSettled) ? url[accessibility]['usdc'] : url[accessibility]['contract'];
158
+ const unified = await this.isUnifiedEnabled();
159
+ const isUnifiedMargin = this.safeBool(unified, 0, false);
160
+ const isUnifiedAccount = this.safeBool(unified, 1, false);
161
+ if (isUsdcSettled && !isUnifiedMargin && !isUnifiedAccount) {
162
+ url = url[accessibility]['usdc'];
163
+ }
164
+ else {
165
+ url = url[accessibility]['contract'];
166
+ }
159
167
  }
160
168
  else {
161
169
  if (isSpot) {
@@ -322,7 +330,7 @@ export default class bybit extends bybitRest {
322
330
  const market = this.market(symbol);
323
331
  symbol = market['symbol'];
324
332
  const messageHash = 'ticker:' + symbol;
325
- const url = this.getUrlByMarketType(symbol, false, 'watchTicker', params);
333
+ const url = await this.getUrlByMarketType(symbol, false, 'watchTicker', params);
326
334
  params = this.cleanParams(params);
327
335
  const options = this.safeValue(this.options, 'watchTicker', {});
328
336
  let topic = this.safeString(options, 'name', 'tickers');
@@ -347,7 +355,7 @@ export default class bybit extends bybitRest {
347
355
  await this.loadMarkets();
348
356
  symbols = this.marketSymbols(symbols, undefined, false);
349
357
  const messageHashes = [];
350
- const url = this.getUrlByMarketType(symbols[0], false, 'watchTickers', params);
358
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchTickers', params);
351
359
  params = this.cleanParams(params);
352
360
  const options = this.safeValue(this.options, 'watchTickers', {});
353
361
  const topic = this.safeString(options, 'name', 'tickers');
@@ -528,7 +536,7 @@ export default class bybit extends bybitRest {
528
536
  await this.loadMarkets();
529
537
  const market = this.market(symbol);
530
538
  symbol = market['symbol'];
531
- const url = this.getUrlByMarketType(symbol, false, 'watchOHLCV', params);
539
+ const url = await this.getUrlByMarketType(symbol, false, 'watchOHLCV', params);
532
540
  params = this.cleanParams(params);
533
541
  let ohlcv = undefined;
534
542
  const timeframeId = this.safeString(this.timeframes, timeframe, timeframe);
@@ -646,7 +654,7 @@ export default class bybit extends bybitRest {
646
654
  throw new ArgumentsRequired(this.id + ' watchOrderBookForSymbols() requires a non-empty array of symbols');
647
655
  }
648
656
  symbols = this.marketSymbols(symbols);
649
- const url = this.getUrlByMarketType(symbols[0], false, 'watchOrderBook', params);
657
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchOrderBook', params);
650
658
  params = this.cleanParams(params);
651
659
  const market = this.market(symbols[0]);
652
660
  if (limit === undefined) {
@@ -778,7 +786,7 @@ export default class bybit extends bybitRest {
778
786
  throw new ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
779
787
  }
780
788
  params = this.cleanParams(params);
781
- const url = this.getUrlByMarketType(symbols[0], false, 'watchTrades', params);
789
+ const url = await this.getUrlByMarketType(symbols[0], false, 'watchTrades', params);
782
790
  const topics = [];
783
791
  const messageHashes = [];
784
792
  for (let i = 0; i < symbols.length; i++) {
@@ -941,7 +949,7 @@ export default class bybit extends bybitRest {
941
949
  symbol = this.symbol(symbol);
942
950
  messageHash += ':' + symbol;
943
951
  }
944
- const url = this.getUrlByMarketType(symbol, true, method, params);
952
+ const url = await this.getUrlByMarketType(symbol, true, method, params);
945
953
  await this.authenticate(url);
946
954
  const topicByMarket = {
947
955
  'spot': 'ticketInfo',
@@ -1070,7 +1078,7 @@ export default class bybit extends bybitRest {
1070
1078
  messageHash = '::' + symbols.join(',');
1071
1079
  }
1072
1080
  const firstSymbol = this.safeString(symbols, 0);
1073
- const url = this.getUrlByMarketType(firstSymbol, true, method, params);
1081
+ const url = await this.getUrlByMarketType(firstSymbol, true, method, params);
1074
1082
  messageHash = 'positions' + messageHash;
1075
1083
  const client = this.client(url);
1076
1084
  await this.authenticate(url);
@@ -1221,7 +1229,7 @@ export default class bybit extends bybitRest {
1221
1229
  await this.loadMarkets();
1222
1230
  const market = this.market(symbol);
1223
1231
  symbol = market['symbol'];
1224
- const url = this.getUrlByMarketType(symbol, false, 'watchLiquidations', params);
1232
+ const url = await this.getUrlByMarketType(symbol, false, 'watchLiquidations', params);
1225
1233
  params = this.cleanParams(params);
1226
1234
  const messageHash = 'liquidations::' + symbol;
1227
1235
  const topic = 'liquidation.' + market['id'];
@@ -1305,7 +1313,7 @@ export default class bybit extends bybitRest {
1305
1313
  symbol = this.symbol(symbol);
1306
1314
  messageHash += ':' + symbol;
1307
1315
  }
1308
- const url = this.getUrlByMarketType(symbol, true, method, params);
1316
+ const url = await this.getUrlByMarketType(symbol, true, method, params);
1309
1317
  await this.authenticate(url);
1310
1318
  const topicsByMarket = {
1311
1319
  'spot': ['order', 'stopOrder'],
@@ -1617,7 +1625,7 @@ export default class bybit extends bybitRest {
1617
1625
  const unified = await this.isUnifiedEnabled();
1618
1626
  const isUnifiedMargin = this.safeBool(unified, 0, false);
1619
1627
  const isUnifiedAccount = this.safeBool(unified, 1, false);
1620
- const url = this.getUrlByMarketType(undefined, true, method, params);
1628
+ const url = await this.getUrlByMarketType(undefined, true, method, params);
1621
1629
  await this.authenticate(url);
1622
1630
  const topicByMarket = {
1623
1631
  'spot': 'outboundAccountInfo',
@@ -159,6 +159,7 @@ export default class kucoin extends kucoinRest {
159
159
  * @method
160
160
  * @name kucoin#watchTicker
161
161
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
162
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/market-snapshot
162
163
  * @param {string} symbol unified symbol of the market to fetch the ticker for
163
164
  * @param {object} [params] extra parameters specific to the exchange API endpoint
164
165
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
@@ -391,6 +392,7 @@ export default class kucoin extends kucoinRest {
391
392
  * @method
392
393
  * @name kucoin#watchOHLCV
393
394
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
395
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/klines
394
396
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
395
397
  * @param {string} timeframe the length of time each candle represents
396
398
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -459,6 +461,7 @@ export default class kucoin extends kucoinRest {
459
461
  * @method
460
462
  * @name kucoin#watchTrades
461
463
  * @description get the list of most recent trades for a particular symbol
464
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
462
465
  * @param {string} symbol unified symbol of the market to fetch trades for
463
466
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
464
467
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -472,6 +475,7 @@ export default class kucoin extends kucoinRest {
472
475
  * @method
473
476
  * @name kucoin#watchTrades
474
477
  * @description get the list of most recent trades for a particular symbol
478
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
475
479
  * @param {string} symbol unified symbol of the market to fetch trades for
476
480
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
477
481
  * @param {int} [limit] the maximum amount of trades to fetch
@@ -806,6 +810,8 @@ export default class kucoin extends kucoinRest {
806
810
  * @method
807
811
  * @name kucoin#watchOrders
808
812
  * @description watches information on multiple orders made by the user
813
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/private-channels/private-order-change
814
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/private-channels/stop-order-event
809
815
  * @param {string} symbol unified market symbol of the market orders were made in
810
816
  * @param {int} [since] the earliest time in ms to fetch orders for
811
817
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -942,6 +948,10 @@ export default class kucoin extends kucoinRest {
942
948
  //
943
949
  const messageHash = 'orders';
944
950
  const data = this.safeValue(message, 'data');
951
+ const tradeId = this.safeString(data, 'tradeId');
952
+ if (tradeId !== undefined) {
953
+ this.handleMyTrade(client, message);
954
+ }
945
955
  const parsed = this.parseWsOrder(data);
946
956
  const symbol = this.safeString(parsed, 'symbol');
947
957
  const orderId = this.safeString(parsed, 'id');
@@ -971,6 +981,7 @@ export default class kucoin extends kucoinRest {
971
981
  * @method
972
982
  * @name kucoin#watchMyTrades
973
983
  * @description watches information on multiple trades made by the user
984
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/private-channels/private-order-change
974
985
  * @param {string} symbol unified market symbol of the market trades were made in
975
986
  * @param {int} [since] the earliest time in ms to fetch trades for
976
987
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -979,7 +990,7 @@ export default class kucoin extends kucoinRest {
979
990
  */
980
991
  await this.loadMarkets();
981
992
  const url = await this.negotiate(true);
982
- const topic = '/spot/tradeFills';
993
+ const topic = '/spotMarket/tradeOrders';
983
994
  const request = {
984
995
  'privateChannel': true,
985
996
  };
@@ -996,6 +1007,34 @@ export default class kucoin extends kucoinRest {
996
1007
  return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
997
1008
  }
998
1009
  handleMyTrade(client, message) {
1010
+ //
1011
+ // {
1012
+ // "type": "message",
1013
+ // "topic": "/spotMarket/tradeOrders",
1014
+ // "subject": "orderChange",
1015
+ // "channelType": "private",
1016
+ // "data": {
1017
+ // "symbol": "KCS-USDT",
1018
+ // "orderType": "limit",
1019
+ // "side": "sell",
1020
+ // "orderId": "5efab07953bdea00089965fa",
1021
+ // "liquidity": "taker",
1022
+ // "type": "match",
1023
+ // "feeType": "takerFee",
1024
+ // "orderTime": 1670329987026,
1025
+ // "size": "0.1",
1026
+ // "filledSize": "0.1",
1027
+ // "price": "0.938",
1028
+ // "matchPrice": "0.96738",
1029
+ // "matchSize": "0.1",
1030
+ // "tradeId": "5efab07a4ee4c7000a82d6d9",
1031
+ // "clientOid": "1593487481000313",
1032
+ // "remainSize": "0",
1033
+ // "status": "match",
1034
+ // "ts": 1670329987311000000
1035
+ // }
1036
+ // }
1037
+ //
999
1038
  if (this.myTrades === undefined) {
1000
1039
  const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
1001
1040
  this.myTrades = new ArrayCacheBySymbolById(limit);
@@ -1010,19 +1049,26 @@ export default class kucoin extends kucoinRest {
1010
1049
  }
1011
1050
  parseWsTrade(trade, market = undefined) {
1012
1051
  //
1013
- // {
1014
- // "fee": 0.00262148,
1015
- // "feeCurrency": "USDT",
1016
- // "feeRate": 0.001,
1017
- // "orderId": "62417436b29df8000183df2f",
1018
- // "orderType": "market",
1019
- // "price": 131.074,
1020
- // "side": "sell",
1021
- // "size": 0.02,
1022
- // "symbol": "LTC-USDT",
1023
- // "time": "1648456758734571745",
1024
- // "tradeId": "624174362e113d2f467b3043"
1025
- // }
1052
+ // {
1053
+ // "symbol": "KCS-USDT",
1054
+ // "orderType": "limit",
1055
+ // "side": "sell",
1056
+ // "orderId": "5efab07953bdea00089965fa",
1057
+ // "liquidity": "taker",
1058
+ // "type": "match",
1059
+ // "feeType": "takerFee",
1060
+ // "orderTime": 1670329987026,
1061
+ // "size": "0.1",
1062
+ // "filledSize": "0.1",
1063
+ // "price": "0.938",
1064
+ // "matchPrice": "0.96738",
1065
+ // "matchSize": "0.1",
1066
+ // "tradeId": "5efab07a4ee4c7000a82d6d9",
1067
+ // "clientOid": "1593487481000313",
1068
+ // "remainSize": "0",
1069
+ // "status": "match",
1070
+ // "ts": 1670329987311000000
1071
+ // }
1026
1072
  //
1027
1073
  const marketId = this.safeString(trade, 'symbol');
1028
1074
  market = this.safeMarket(marketId, market, '-');
@@ -1033,15 +1079,7 @@ export default class kucoin extends kucoinRest {
1033
1079
  const price = this.safeString(trade, 'price');
1034
1080
  const amount = this.safeString(trade, 'size');
1035
1081
  const order = this.safeString(trade, 'orderId');
1036
- const timestamp = this.safeIntegerProduct(trade, 'time', 0.000001);
1037
- const feeCurrency = market['quote'];
1038
- const feeRate = this.safeString(trade, 'feeRate');
1039
- const feeCost = this.safeString(trade, 'fee');
1040
- const fee = {
1041
- 'cost': feeCost,
1042
- 'rate': feeRate,
1043
- 'currency': feeCurrency,
1044
- };
1082
+ const timestamp = this.safeIntegerProduct(trade, 'ts', 0.000001);
1045
1083
  return this.safeTrade({
1046
1084
  'info': trade,
1047
1085
  'timestamp': timestamp,
@@ -1050,12 +1088,12 @@ export default class kucoin extends kucoinRest {
1050
1088
  'id': tradeId,
1051
1089
  'order': order,
1052
1090
  'type': type,
1053
- 'takerOrMaker': undefined,
1091
+ 'takerOrMaker': this.safeString(trade, 'liquidity'),
1054
1092
  'side': side,
1055
1093
  'price': price,
1056
1094
  'amount': amount,
1057
1095
  'cost': undefined,
1058
- 'fee': fee,
1096
+ 'fee': undefined,
1059
1097
  }, market);
1060
1098
  }
1061
1099
  async watchBalance(params = {}) {
@@ -1063,6 +1101,7 @@ export default class kucoin extends kucoinRest {
1063
1101
  * @method
1064
1102
  * @name kucoin#watchBalance
1065
1103
  * @description watch balance and get the amount of funds available for trading or funds locked in orders
1104
+ * @see https://www.kucoin.com/docs/websocket/spot-trading/private-channels/account-balance-change
1066
1105
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1067
1106
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1068
1107
  */
@@ -1161,7 +1200,6 @@ export default class kucoin extends kucoinRest {
1161
1200
  'trade.l3match': this.handleTrade,
1162
1201
  'trade.candles.update': this.handleOHLCV,
1163
1202
  'account.balance': this.handleBalance,
1164
- '/spot/tradeFills': this.handleMyTrade,
1165
1203
  'orderChange': this.handleOrder,
1166
1204
  'stopOrder': this.handleOrder,
1167
1205
  };
@@ -325,7 +325,7 @@ export default class vertex extends vertexRest {
325
325
  // "ask_qty": "1000" // quantity at the lowest ask
326
326
  // }
327
327
  //
328
- const timestamp = Precise.stringDiv(this.safeString(ticker, 'timestamp'), '1000000');
328
+ const timestamp = this.safeIntegerProduct(ticker, 'timestamp', 0.000001);
329
329
  return this.safeTicker({
330
330
  'symbol': this.safeSymbol(undefined, market),
331
331
  'timestamp': timestamp,
package/js/src/woo.d.ts CHANGED
@@ -22,6 +22,7 @@ export default class woo extends Exchange {
22
22
  fetchTradingFees(params?: {}): Promise<TradingFees>;
23
23
  fetchCurrencies(params?: {}): Promise<Currencies>;
24
24
  createMarketBuyOrderWithCost(symbol: string, cost: number, params?: {}): Promise<Order>;
25
+ createMarketSellOrderWithCost(symbol: string, cost: number, params?: {}): Promise<Order>;
25
26
  createTrailingAmountOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, trailingAmount?: any, trailingTriggerPrice?: any, params?: {}): Promise<Order>;
26
27
  createTrailingPercentOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, trailingPercent?: any, trailingTriggerPrice?: any, params?: {}): Promise<Order>;
27
28
  createOrder(symbol: string, type: OrderType, side: OrderSide, amount: number, price?: Num, params?: {}): Promise<Order>;
package/js/src/woo.js CHANGED
@@ -45,7 +45,7 @@ export default class woo extends Exchange {
45
45
  'createMarketBuyOrderWithCost': true,
46
46
  'createMarketOrder': false,
47
47
  'createMarketOrderWithCost': false,
48
- 'createMarketSellOrderWithCost': false,
48
+ 'createMarketSellOrderWithCost': true,
49
49
  'createOrder': true,
50
50
  'createOrderWithTakeProfitAndStopLoss': true,
51
51
  'createReduceOnlyOrder': true,
@@ -853,8 +853,25 @@ export default class woo extends Exchange {
853
853
  if (!market['spot']) {
854
854
  throw new NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
855
855
  }
856
- params['createMarketBuyOrderRequiresPrice'] = false;
857
- return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
856
+ return await this.createOrder(symbol, 'market', 'buy', cost, 1, params);
857
+ }
858
+ async createMarketSellOrderWithCost(symbol, cost, params = {}) {
859
+ /**
860
+ * @method
861
+ * @name woo#createMarketSellOrderWithCost
862
+ * @description create a market sell order by providing the symbol and cost
863
+ * @see https://docs.woo.org/#send-order
864
+ * @param {string} symbol unified symbol of the market to create an order in
865
+ * @param {float} cost how much you want to trade in units of the quote currency
866
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
867
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
868
+ */
869
+ await this.loadMarkets();
870
+ const market = this.market(symbol);
871
+ if (!market['spot']) {
872
+ throw new NotSupported(this.id + ' createMarketSellOrderWithCost() supports spot orders only');
873
+ }
874
+ return await this.createOrder(symbol, 'market', 'sell', cost, 1, params);
858
875
  }
859
876
  async createTrailingAmountOrder(symbol, type, side, amount, price = undefined, trailingAmount = undefined, trailingTriggerPrice = undefined, params = {}) {
860
877
  /**
@@ -977,33 +994,24 @@ export default class woo extends Exchange {
977
994
  if (reduceOnly) {
978
995
  request[reduceOnlyKey] = reduceOnly;
979
996
  }
980
- if (price !== undefined) {
997
+ if (!isMarket && price !== undefined) {
981
998
  request[priceKey] = this.priceToPrecision(symbol, price);
982
999
  }
983
1000
  if (isMarket && !isStop) {
984
1001
  // for market buy it requires the amount of quote currency to spend
985
- if (market['spot'] && orderSide === 'BUY') {
1002
+ const cost = this.safeString2(params, 'cost', 'order_amount');
1003
+ params = this.omit(params, ['cost', 'order_amount']);
1004
+ const isPriceProvided = price !== undefined;
1005
+ if (market['spot'] && (isPriceProvided || (cost !== undefined))) {
986
1006
  let quoteAmount = undefined;
987
- let createMarketBuyOrderRequiresPrice = true;
988
- [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
989
- const cost = this.safeNumber2(params, 'cost', 'order_amount');
990
- params = this.omit(params, ['cost', 'order_amount']);
991
1007
  if (cost !== undefined) {
992
1008
  quoteAmount = this.costToPrecision(symbol, cost);
993
1009
  }
994
- else if (createMarketBuyOrderRequiresPrice) {
995
- if (price === undefined) {
996
- throw new InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
997
- }
998
- else {
999
- const amountString = this.numberToString(amount);
1000
- const priceString = this.numberToString(price);
1001
- const costRequest = Precise.stringMul(amountString, priceString);
1002
- quoteAmount = this.costToPrecision(symbol, costRequest);
1003
- }
1004
- }
1005
1010
  else {
1006
- quoteAmount = this.costToPrecision(symbol, amount);
1011
+ const amountString = this.numberToString(amount);
1012
+ const priceString = this.numberToString(price);
1013
+ const costRequest = Precise.stringMul(amountString, priceString);
1014
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1007
1015
  }
1008
1016
  request['order_amount'] = quoteAmount;
1009
1017
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.3.53",
3
+ "version": "4.3.54",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.min.js",
6
6
  "type": "module",