ccxt 4.5.48 → 4.5.49

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 (43) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +10 -10
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/weex.js +11 -0
  5. package/dist/cjs/src/btcbox.js +1 -1
  6. package/dist/cjs/src/bullish.js +2 -1
  7. package/dist/cjs/src/kraken.js +1 -0
  8. package/dist/cjs/src/krakenfutures.js +10 -1
  9. package/dist/cjs/src/kucoin.js +5 -1
  10. package/dist/cjs/src/lighter.js +6 -3
  11. package/dist/cjs/src/mexc.js +7 -12
  12. package/dist/cjs/src/paradex.js +5 -2
  13. package/dist/cjs/src/pro/binance.js +1 -1
  14. package/dist/cjs/src/pro/cex.js +1 -1
  15. package/dist/cjs/src/pro/coinbase.js +1 -1
  16. package/dist/cjs/src/pro/lighter.js +338 -18
  17. package/dist/cjs/src/pro/weex.js +1906 -0
  18. package/dist/cjs/src/weex.js +3823 -0
  19. package/js/ccxt.d.ts +8 -2
  20. package/js/ccxt.js +6 -2
  21. package/js/src/abstract/weex.d.ts +83 -0
  22. package/js/src/abstract/weex.js +11 -0
  23. package/js/src/btcbox.js +1 -1
  24. package/js/src/bullish.js +2 -1
  25. package/js/src/kraken.js +1 -0
  26. package/js/src/krakenfutures.js +10 -1
  27. package/js/src/kucoin.d.ts +4 -0
  28. package/js/src/kucoin.js +5 -1
  29. package/js/src/lighter.d.ts +1 -0
  30. package/js/src/lighter.js +6 -3
  31. package/js/src/mexc.d.ts +2 -0
  32. package/js/src/mexc.js +7 -12
  33. package/js/src/paradex.js +5 -2
  34. package/js/src/pro/binance.js +1 -1
  35. package/js/src/pro/cex.js +1 -1
  36. package/js/src/pro/coinbase.js +1 -1
  37. package/js/src/pro/lighter.d.ts +37 -2
  38. package/js/src/pro/lighter.js +338 -18
  39. package/js/src/pro/weex.d.ts +330 -0
  40. package/js/src/pro/weex.js +1905 -0
  41. package/js/src/weex.d.ts +675 -0
  42. package/js/src/weex.js +3822 -0
  43. package/package.json +1 -1
@@ -22,14 +22,14 @@ class lighter extends lighter$1["default"] {
22
22
  'watchTrades': true,
23
23
  'watchTradesForSymbols': false,
24
24
  'watchOrderBookForSymbols': false,
25
- 'watchBalance': false,
25
+ 'watchBalance': true,
26
26
  'watchLiquidations': true,
27
27
  'watchLiquidationsForSymbols': false,
28
28
  'watchMyLiquidations': false,
29
29
  'watchMyLiquidationsForSymbols': false,
30
30
  'watchOHLCV': false,
31
31
  'watchOHLCVForSymbols': false,
32
- 'watchOrders': false,
32
+ 'watchOrders': true,
33
33
  'watchMyTrades': true,
34
34
  'watchPositions': false,
35
35
  'watchFundingRate': false,
@@ -41,6 +41,7 @@ class lighter extends lighter$1["default"] {
41
41
  'unWatchMyTrades': true,
42
42
  'unWatchMarkPrice': true,
43
43
  'unWatchMarkPrices': true,
44
+ 'unWatchOrders': true,
44
45
  },
45
46
  'urls': {
46
47
  'api': {
@@ -88,7 +89,7 @@ class lighter extends lighter$1["default"] {
88
89
  };
89
90
  return await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes, subscription);
90
91
  }
91
- async unsubscribePublic(messageHash, params = {}) {
92
+ async unsubscribe(messageHash, params = {}) {
92
93
  const url = this.urls['api']['ws'];
93
94
  const request = {
94
95
  'type': 'unsubscribe',
@@ -99,6 +100,10 @@ class lighter extends lighter$1["default"] {
99
100
  };
100
101
  return await this.watch(url, messageHash, this.extend(request, params), messageHash, subscription);
101
102
  }
103
+ async subscribePrivate(messageHash, params = {}) {
104
+ params['auth'] = this.createAuth(params);
105
+ return await this.subscribePublic(messageHash, params);
106
+ }
102
107
  handleDelta(bookside, delta) {
103
108
  const price = this.safeFloat(delta, 'price');
104
109
  const amount = this.safeFloat(delta, 'size');
@@ -204,7 +209,7 @@ class lighter extends lighter$1["default"] {
204
209
  'channel': 'order_book/' + market['id'],
205
210
  };
206
211
  const messageHash = this.getMessageHash('unsubscribe', symbol);
207
- return await this.unsubscribePublic(messageHash, this.extend(request, params));
212
+ return await this.unsubscribe(messageHash, this.extend(request, params));
208
213
  }
209
214
  handleTicker(client, message) {
210
215
  //
@@ -315,7 +320,7 @@ class lighter extends lighter$1["default"] {
315
320
  'channel': 'market_stats/' + market['id'],
316
321
  };
317
322
  const messageHash = this.getMessageHash('unsubscribe', symbol);
318
- return await this.unsubscribePublic(messageHash, this.extend(request, params));
323
+ return await this.unsubscribe(messageHash, this.extend(request, params));
319
324
  }
320
325
  /**
321
326
  * @method
@@ -370,7 +375,7 @@ class lighter extends lighter$1["default"] {
370
375
  'channel': 'market_stats/all',
371
376
  };
372
377
  const messageHash = this.getMessageHash('unsubscribe');
373
- return await this.unsubscribePublic(messageHash, this.extend(request, params));
378
+ return await this.unsubscribe(messageHash, this.extend(request, params));
374
379
  }
375
380
  /**
376
381
  * @method
@@ -454,10 +459,7 @@ class lighter extends lighter$1["default"] {
454
459
  const priceString = this.safeString(trade, 'price');
455
460
  const amountString = this.safeString(trade, 'size');
456
461
  const isMakerAsk = this.safeBool(trade, 'is_maker_ask');
457
- const side = (isMakerAsk === true) ? 'sell' : 'buy';
458
- const makerFeeRate = this.safeString(market, 'maker_fee');
459
- const maker = Precise["default"].stringDiv(makerFeeRate, '100');
460
- const feeAmount = Precise["default"].stringMul(maker, makerFeeRate);
462
+ const side = isMakerAsk ? 'buy' : 'sell';
461
463
  return this.safeTrade({
462
464
  'info': trade,
463
465
  'id': tradeId,
@@ -467,14 +469,11 @@ class lighter extends lighter$1["default"] {
467
469
  'symbol': this.safeSymbol(undefined, market),
468
470
  'type': undefined,
469
471
  'side': side,
470
- 'takerOrMaker': 'maker',
472
+ 'takerOrMaker': 'taker',
471
473
  'price': priceString,
472
474
  'amount': amountString,
473
475
  'cost': this.safeString(trade, 'usd_amount'),
474
- 'fee': {
475
- 'cost': feeAmount,
476
- 'currency': 'USDC',
477
- },
476
+ 'fee': undefined,
478
477
  }, market);
479
478
  }
480
479
  handleTrades(client, message) {
@@ -577,7 +576,83 @@ class lighter extends lighter$1["default"] {
577
576
  'channel': 'trade/' + market['id'],
578
577
  };
579
578
  const messageHash = this.getMessageHash('unsubscribe', symbol);
580
- return await this.unsubscribePublic(messageHash, this.extend(request, params));
579
+ return await this.unsubscribe(messageHash, this.extend(request, params));
580
+ }
581
+ parseWsOrderTrade(trade, market = undefined) {
582
+ //
583
+ // {
584
+ // "trade_id": 526801155,
585
+ // "tx_hash": "1998d9df580acb7540aa141cc369d6ef926d003b3062196d2007bca15f978ab208e0caae4ac5872b",
586
+ // "type": "trade",
587
+ // "market_id": 0,
588
+ // "size": "0.0346",
589
+ // "price": "3028.85",
590
+ // "usd_amount": "104.798210",
591
+ // "ask_id": 281475673670566,
592
+ // "bid_id": 562949291740362,
593
+ // "ask_client_id": 76303170,
594
+ // "bid_client_id": 27601,
595
+ // "ask_account_id": 99349,
596
+ // "bid_account_id": 243008,
597
+ // "is_maker_ask": false,
598
+ // "block_height": 102322769,
599
+ // "timestamp": 1763623734215,
600
+ // "taker_position_size_before": "0.0346",
601
+ // "taker_entry_quote_before": "104.359926",
602
+ // "taker_initial_margin_fraction_before": 500,
603
+ // "taker_position_sign_changed": true,
604
+ // "maker_fee": 20,
605
+ // "maker_position_size_before": "2.1277",
606
+ // "maker_entry_quote_before": "6444.179555",
607
+ // "maker_initial_margin_fraction_before": 200
608
+ // }
609
+ //
610
+ const timestamp = this.safeInteger(trade, 'timestamp');
611
+ const tradeId = this.safeString(trade, 'trade_id');
612
+ const priceString = this.safeString(trade, 'price');
613
+ const amountString = this.safeString(trade, 'size');
614
+ const costString = this.safeString(trade, 'usd_amount');
615
+ const isMakerAsk = this.safeBool(trade, 'is_maker_ask');
616
+ const side = isMakerAsk ? 'buy' : 'sell';
617
+ const accountIndex = this.safeInteger(trade, 'accountIndex');
618
+ let order = undefined;
619
+ let takerOrMaker = undefined;
620
+ if (accountIndex !== undefined) {
621
+ if (this.safeInteger(trade, 'bid_account_id') === accountIndex) {
622
+ order = this.safeString(trade, 'bid_id');
623
+ takerOrMaker = isMakerAsk ? 'taker' : 'maker';
624
+ }
625
+ else if (this.safeInteger(trade, 'ask_account_id') === accountIndex) {
626
+ order = this.safeString(trade, 'ask_id');
627
+ takerOrMaker = isMakerAsk ? 'maker' : 'taker';
628
+ }
629
+ }
630
+ let fee = undefined;
631
+ if (takerOrMaker !== undefined) {
632
+ const feeRateRaw = (takerOrMaker === 'maker') ? this.safeString(trade, 'maker_fee') : this.safeString(trade, 'taker_fee');
633
+ const feeRate = (feeRateRaw !== undefined) ? Precise["default"].stringDiv(feeRateRaw, '1000000') : '0';
634
+ const feeAmount = Precise["default"].stringMul(costString, feeRate);
635
+ fee = {
636
+ 'cost': feeAmount,
637
+ 'currency': 'USDC',
638
+ 'rate': feeRate,
639
+ };
640
+ }
641
+ return this.safeTrade({
642
+ 'info': trade,
643
+ 'id': tradeId,
644
+ 'order': order,
645
+ 'timestamp': timestamp,
646
+ 'datetime': this.iso8601(timestamp),
647
+ 'symbol': this.safeSymbol(undefined, market),
648
+ 'type': undefined,
649
+ 'side': side,
650
+ 'takerOrMaker': takerOrMaker,
651
+ 'price': priceString,
652
+ 'amount': amountString,
653
+ 'cost': costString,
654
+ 'fee': fee,
655
+ }, market);
581
656
  }
582
657
  handleMyTrades(client, message) {
583
658
  //
@@ -614,6 +689,9 @@ class lighter extends lighter$1["default"] {
614
689
  // "type": "update/account_all_trades"
615
690
  // }
616
691
  //
692
+ const channel = this.safeString(message, 'channel', '');
693
+ const parts = channel.split(':');
694
+ const accountIndex = parts[1];
617
695
  const data = this.safeDict(message, 'trades', {});
618
696
  const marketIds = Object.keys(data);
619
697
  const idsLength = marketIds.length;
@@ -633,7 +711,9 @@ class lighter extends lighter$1["default"] {
633
711
  const tradesLength = trades.length;
634
712
  for (let j = 0; j < tradesLength; j++) {
635
713
  const jReversed = tradesLength - 1 - j;
636
- const trade = this.parseWsTrade(trades[jReversed], market);
714
+ const tradeRaw = trades[jReversed];
715
+ tradeRaw['accountIndex'] = accountIndex;
716
+ const trade = this.parseWsOrderTrade(tradeRaw, market);
637
717
  stored.append(trade);
638
718
  const symbol = trade['symbol'];
639
719
  if (symbol !== undefined) {
@@ -697,7 +777,7 @@ class lighter extends lighter$1["default"] {
697
777
  const request = {
698
778
  'channel': 'account_all_trades/' + accountIndex,
699
779
  };
700
- return await this.unsubscribePublic(messageHash, this.extend(request, params));
780
+ return await this.unsubscribe(messageHash, this.extend(request, params));
701
781
  }
702
782
  parseWsLiquidation(liquidation, market = undefined) {
703
783
  //
@@ -827,6 +907,230 @@ class lighter extends lighter$1["default"] {
827
907
  const messageHash = this.getMessageHash('liquidations', symbol);
828
908
  return await this.subscribePublic(messageHash, this.extend(request, params));
829
909
  }
910
+ /**
911
+ * @method
912
+ * @name lighter#watchBalance
913
+ * @description watch balance and get the amount of funds available for trading or funds locked in orders
914
+ * @see https://apidocs.lighter.xyz/docs/websocket-reference#account-all-assets
915
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
916
+ * @param {string} [params.type] 'spot' or 'swap', default is 'swap'
917
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
918
+ */
919
+ async watchBalance(params = {}) {
920
+ await this.loadMarkets();
921
+ const defaultType = this.safeString2(this.options, 'watchBalance', 'defaultType', 'spot');
922
+ let type = undefined;
923
+ [type, params] = this.handleParamString(params, 'type', defaultType);
924
+ let accountIndex = undefined;
925
+ [accountIndex, params] = await this.handleAccountIndex(params, 'watchBalance', 'accountIndex', 'account_index');
926
+ const messageHash = this.getMessageHash('balances', undefined, type);
927
+ const request = {};
928
+ if (type === 'spot') {
929
+ request['channel'] = 'account_all_assets/' + this.numberToString(accountIndex);
930
+ return await this.subscribePrivate(messageHash, this.extend(request, params));
931
+ }
932
+ else {
933
+ request['channel'] = 'user_stats/' + this.numberToString(accountIndex);
934
+ return await this.subscribePublic(messageHash, this.extend(request, params));
935
+ }
936
+ }
937
+ handleBalance(client, message) {
938
+ //
939
+ // spot balance
940
+ // {
941
+ // "assets": {
942
+ // "1": {
943
+ // "symbol": "ETH",
944
+ // "asset_id": 1,
945
+ // "balance": "7.1072",
946
+ // "locked_balance": "0.0000"
947
+ // },
948
+ // "3": {
949
+ // "symbol": "USDC",
950
+ // "asset_id": 3,
951
+ // "balance": "6343.581906",
952
+ // "locked_balance": "297.000000"
953
+ // }
954
+ // },
955
+ // "channel": "account_all_assets:1234",
956
+ // "timestamp": 1773158679717,
957
+ // "type": "update/account_all_assets"
958
+ // }
959
+ //
960
+ // swap balance
961
+ // {
962
+ // "channel": "user_stats:10",
963
+ // "stats": {
964
+ // "collateral": "5000.00",
965
+ // "portfolio_value": "15000.00",
966
+ // "leverage": "3.0",
967
+ // "available_balance": "2000.00",
968
+ // "margin_usage": "0.80",
969
+ // "buying_power": "4000.00",
970
+ // "account_trading_mode": 1,
971
+ // "cross_stats":{
972
+ // "collateral":"0.000000",
973
+ // "portfolio_value":"0.000000",
974
+ // "leverage":"0.00",
975
+ // "available_balance":"0.000000",
976
+ // "margin_usage":"0.00",
977
+ // "buying_power":"0"
978
+ // },
979
+ // "total_stats":{
980
+ // "collateral":"0.000000",
981
+ // "portfolio_value":"0.000000",
982
+ // "leverage":"0.00",
983
+ // "available_balance":"0.000000",
984
+ // "margin_usage":"0.00",
985
+ // "buying_power":"0"
986
+ // }
987
+ // },
988
+ // "timestamp": 1773158679717,
989
+ // "type": "update/user_stats"
990
+ // }
991
+ //
992
+ const channel = this.safeString(message, 'channel', '');
993
+ let type = 'spot';
994
+ if (channel.indexOf('user_stats:') >= 0) {
995
+ type = 'swap';
996
+ }
997
+ const balance = this.safeDict(this.balance, type, {});
998
+ if (type === 'spot') {
999
+ const assets = this.safeDict(message, 'assets', {});
1000
+ const assetIds = Object.keys(assets);
1001
+ for (let i = 0; i < assetIds.length; i++) {
1002
+ const assetId = assetIds[i];
1003
+ const asset = assets[assetId];
1004
+ const codeId = this.safeString(asset, 'symbol');
1005
+ const code = this.safeCurrencyCode(codeId);
1006
+ const account = this.account();
1007
+ account['used'] = this.safeString(asset, 'locked_balance');
1008
+ account['total'] = this.safeString(asset, 'balance');
1009
+ balance[code] = account;
1010
+ }
1011
+ }
1012
+ else {
1013
+ const stats = this.safeDict(message, 'stats', {});
1014
+ const account = this.account();
1015
+ account['free'] = this.safeString(stats, 'available_balance');
1016
+ account['total'] = this.safeString(stats, 'collateral');
1017
+ account['info'] = stats;
1018
+ balance['USDC'] = account;
1019
+ }
1020
+ const timestamp = this.safeInteger(message, 'timestamp');
1021
+ balance['timestamp'] = timestamp;
1022
+ balance['datetime'] = this.iso8601(timestamp);
1023
+ this.balance[type] = this.safeBalance(balance);
1024
+ const messageHash = this.getMessageHash('balances', undefined, type);
1025
+ client.resolve(this.balance[type], messageHash);
1026
+ return true;
1027
+ }
1028
+ /**
1029
+ * @name lighter#watchOrders
1030
+ * @description watches information on multiple orders made by the user
1031
+ * @see https://apidocs.lighter.xyz/docs/websocket-reference#account-all-orders
1032
+ * @param {string} symbol unified market symbol of the market orders were made in
1033
+ * @param {int} [since] the earliest time in ms to fetch orders for
1034
+ * @param {int} [limit] the maximum number of order structures to retrieve
1035
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1036
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1037
+ */
1038
+ async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1039
+ await this.loadMarkets();
1040
+ let accountIndex = undefined;
1041
+ [accountIndex, params] = await this.handleAccountIndex(params, 'watchOrders', 'accountIndex', 'account_index');
1042
+ let messageHash = undefined;
1043
+ const request = {};
1044
+ if (symbol !== undefined) {
1045
+ const market = this.market(symbol);
1046
+ messageHash = this.getMessageHash('orders', market['symbol']);
1047
+ request['channel'] = 'account_orders/' + market['id'] + '/' + this.numberToString(accountIndex);
1048
+ }
1049
+ else {
1050
+ messageHash = this.getMessageHash('orders');
1051
+ request['channel'] = 'account_all_orders/' + this.numberToString(accountIndex);
1052
+ }
1053
+ const orders = await this.subscribePrivate(messageHash, this.extend(request, params));
1054
+ if (this.newUpdates) {
1055
+ limit = orders.getLimit(symbol, limit);
1056
+ }
1057
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
1058
+ }
1059
+ /**
1060
+ * @method
1061
+ * @name lighter#unWatchOrders
1062
+ * @description unWatches information on multiple orders made by the user
1063
+ * @see https://apidocs.lighter.xyz/docs/websocket-reference#account-all-orders
1064
+ * @param {string} symbol unified market symbol of the market orders were made in
1065
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1066
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
1067
+ */
1068
+ async unWatchOrders(symbol = undefined, params = {}) {
1069
+ await this.loadMarkets();
1070
+ let accountIndex = undefined;
1071
+ [accountIndex, params] = await this.handleAccountIndex(params, 'watchOrders', 'accountIndex', 'account_index');
1072
+ let messageHash = undefined;
1073
+ const request = {};
1074
+ if (symbol !== undefined) {
1075
+ const market = this.market(symbol);
1076
+ messageHash = this.getMessageHash('orders', market['symbol']);
1077
+ request['channel'] = 'account_orders/' + market['id'] + '/' + this.numberToString(accountIndex);
1078
+ }
1079
+ else {
1080
+ messageHash = this.getMessageHash('orders');
1081
+ request['channel'] = 'account_all_orders/' + this.numberToString(accountIndex);
1082
+ }
1083
+ return await this.unsubscribe(messageHash, this.extend(request, params));
1084
+ }
1085
+ handleOrders(client, message) {
1086
+ //
1087
+ // {
1088
+ // "account": {ACCOUNT_INDEX},
1089
+ // "channel": "account_orders:{MARKET_INDEX}",
1090
+ // "nonce": INTEGER,
1091
+ // "orders": {
1092
+ // "{MARKET_INDEX}": [Order] // the only present market index will be the one provided
1093
+ // },
1094
+ // "type": "update/account_orders"
1095
+ // }
1096
+ //
1097
+ // {
1098
+ // "channel": "account_all_orders:{ACCOUNT_ID}",
1099
+ // "orders": {
1100
+ // "{MARKET_INDEX}": [Order]
1101
+ // },
1102
+ // "type": "update/account_all_orders"
1103
+ // }
1104
+ //
1105
+ const data = this.safeDict(message, 'orders', {});
1106
+ const marketIds = Object.keys(data);
1107
+ const idsLength = marketIds.length;
1108
+ if (idsLength === 0) {
1109
+ return false; // nothing to process
1110
+ }
1111
+ if (this.orders === undefined) {
1112
+ const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
1113
+ this.orders = new Cache.ArrayCache(limit);
1114
+ }
1115
+ const stored = this.orders;
1116
+ const messageHash = this.getMessageHash('orders');
1117
+ for (let i = 0; i < marketIds.length; i++) {
1118
+ const marketId = marketIds[i];
1119
+ const market = this.safeMarket(marketId);
1120
+ const orders = this.safeList(data, marketId, []);
1121
+ for (let j = 0; j < orders.length; j++) {
1122
+ const order = this.parseOrder(orders[j], market);
1123
+ stored.append(order);
1124
+ const symbol = order['symbol'];
1125
+ if (symbol !== undefined) {
1126
+ const symbolSpecificMessageHash = this.getMessageHash('orders', symbol);
1127
+ client.resolve(stored, symbolSpecificMessageHash);
1128
+ }
1129
+ }
1130
+ }
1131
+ client.resolve(stored, messageHash);
1132
+ return true;
1133
+ }
830
1134
  handleErrorMessage(client, message) {
831
1135
  //
832
1136
  // {
@@ -877,6 +1181,22 @@ class lighter extends lighter$1["default"] {
877
1181
  this.handleMyTrades(client, message);
878
1182
  return;
879
1183
  }
1184
+ if (channel.indexOf('account_all_assets:') >= 0) {
1185
+ this.handleBalance(client, message);
1186
+ return;
1187
+ }
1188
+ if (channel.indexOf('user_stats:') >= 0) {
1189
+ this.handleBalance(client, message);
1190
+ return;
1191
+ }
1192
+ if (channel.indexOf('account_orders:') >= 0) {
1193
+ this.handleOrders(client, message);
1194
+ return;
1195
+ }
1196
+ if (channel.indexOf('account_all_orders:') >= 0) {
1197
+ this.handleOrders(client, message);
1198
+ return;
1199
+ }
880
1200
  if (channel === '') {
881
1201
  this.handleSubscriptionStatus(client, message);
882
1202
  }