ccxt 4.3.1 → 4.3.3

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 (46) hide show
  1. package/README.md +6 -5
  2. package/dist/cjs/ccxt.js +1 -1
  3. package/dist/cjs/src/base/Exchange.js +25 -0
  4. package/dist/cjs/src/binance.js +320 -21
  5. package/dist/cjs/src/bingx.js +2 -2
  6. package/dist/cjs/src/bitget.js +81 -4
  7. package/dist/cjs/src/coinbase.js +11 -2
  8. package/dist/cjs/src/coinbasepro.js +1 -1
  9. package/dist/cjs/src/coinex.js +109 -146
  10. package/dist/cjs/src/cryptocom.js +5 -5
  11. package/dist/cjs/src/hyperliquid.js +161 -13
  12. package/dist/cjs/src/okx.js +116 -0
  13. package/dist/cjs/src/poloniexfutures.js +12 -2
  14. package/dist/cjs/src/pro/hyperliquid.js +8 -7
  15. package/dist/cjs/src/pro/kraken.js +1 -1
  16. package/dist/cjs/src/pro/wazirx.js +2 -1
  17. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +27 -2
  18. package/dist/cjs/src/woo.js +110 -6
  19. package/js/ccxt.d.ts +1 -1
  20. package/js/ccxt.js +1 -1
  21. package/js/src/base/Exchange.d.ts +3 -1
  22. package/js/src/base/Exchange.js +25 -0
  23. package/js/src/base/types.d.ts +5 -0
  24. package/js/src/binance.d.ts +3 -0
  25. package/js/src/binance.js +320 -21
  26. package/js/src/bingx.js +3 -3
  27. package/js/src/bitget.d.ts +1 -0
  28. package/js/src/bitget.js +81 -4
  29. package/js/src/coinbase.js +11 -2
  30. package/js/src/coinbasepro.js +1 -1
  31. package/js/src/coinex.js +109 -146
  32. package/js/src/cryptocom.js +5 -5
  33. package/js/src/hyperliquid.d.ts +3 -1
  34. package/js/src/hyperliquid.js +162 -14
  35. package/js/src/okx.d.ts +2 -0
  36. package/js/src/okx.js +116 -0
  37. package/js/src/poloniexfutures.js +12 -2
  38. package/js/src/pro/hyperliquid.js +8 -7
  39. package/js/src/pro/kraken.js +1 -1
  40. package/js/src/pro/wazirx.js +2 -1
  41. package/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.d.ts +2 -2
  42. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.d.ts +24 -357
  43. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +27 -0
  44. package/js/src/woo.d.ts +2 -0
  45. package/js/src/woo.js +110 -6
  46. package/package.json +1 -1
@@ -60,6 +60,8 @@ class woo extends woo$1 {
60
60
  'fetchClosedOrders': true,
61
61
  'fetchConvertCurrencies': true,
62
62
  'fetchConvertQuote': true,
63
+ 'fetchConvertTrade': true,
64
+ 'fetchConvertTradeHistory': true,
63
65
  'fetchCurrencies': true,
64
66
  'fetchDepositAddress': true,
65
67
  'fetchDeposits': true,
@@ -3061,6 +3063,96 @@ class woo extends woo$1 {
3061
3063
  const data = this.safeDict(response, 'data', {});
3062
3064
  return this.parseConversion(data);
3063
3065
  }
3066
+ async fetchConvertTrade(id, code = undefined, params = {}) {
3067
+ /**
3068
+ * @method
3069
+ * @name woo#fetchConvertTrade
3070
+ * @description fetch the data for a conversion trade
3071
+ * @see https://docs.woo.org/#get-quote-trade
3072
+ * @param {string} id the id of the trade that you want to fetch
3073
+ * @param {string} [code] the unified currency code of the conversion trade
3074
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3075
+ * @returns {object} a [conversion structure]{@link https://docs.ccxt.com/#/?id=conversion-structure}
3076
+ */
3077
+ await this.loadMarkets();
3078
+ const request = {
3079
+ 'quoteId': id,
3080
+ };
3081
+ const response = await this.v3PrivateGetConvertTrade(this.extend(request, params));
3082
+ //
3083
+ // {
3084
+ // "success": true,
3085
+ // "data": {
3086
+ // "quoteId": 12,
3087
+ // "buyAsset": "",
3088
+ // "sellAsset": "",
3089
+ // "buyAmount": 12.11,
3090
+ // "sellAmount": 12.11,
3091
+ // "tradeStatus": 12,
3092
+ // "createdTime": ""
3093
+ // }
3094
+ // }
3095
+ //
3096
+ const data = this.safeDict(response, 'data', {});
3097
+ const fromCurrencyId = this.safeString(data, 'sellAsset');
3098
+ const toCurrencyId = this.safeString(data, 'buyAsset');
3099
+ let fromCurrency = undefined;
3100
+ let toCurrency = undefined;
3101
+ if (fromCurrencyId !== undefined) {
3102
+ fromCurrency = this.currency(fromCurrencyId);
3103
+ }
3104
+ if (toCurrencyId !== undefined) {
3105
+ toCurrency = this.currency(toCurrencyId);
3106
+ }
3107
+ return this.parseConversion(data, fromCurrency, toCurrency);
3108
+ }
3109
+ async fetchConvertTradeHistory(code = undefined, since = undefined, limit = undefined, params = {}) {
3110
+ /**
3111
+ * @method
3112
+ * @name woo#fetchConvertTradeHistory
3113
+ * @description fetch the users history of conversion trades
3114
+ * @see https://docs.woo.org/#get-quote-trades
3115
+ * @param {string} [code] the unified currency code
3116
+ * @param {int} [since] the earliest time in ms to fetch conversions for
3117
+ * @param {int} [limit] the maximum number of conversion structures to retrieve
3118
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3119
+ * @param {int} [params.until] timestamp in ms of the latest conversion to fetch
3120
+ * @returns {object[]} a list of [conversion structures]{@link https://docs.ccxt.com/#/?id=conversion-structure}
3121
+ */
3122
+ await this.loadMarkets();
3123
+ let request = {};
3124
+ [request, params] = this.handleUntilOption('endTime', request, params);
3125
+ if (since !== undefined) {
3126
+ request['startTime'] = since;
3127
+ }
3128
+ if (limit !== undefined) {
3129
+ request['size'] = limit;
3130
+ }
3131
+ const response = await this.v3PrivateGetConvertTrades(this.extend(request, params));
3132
+ //
3133
+ // {
3134
+ // "success": true,
3135
+ // "data": {
3136
+ // "count": 12,
3137
+ // "tradeVos":[
3138
+ // {
3139
+ // "quoteId": 12,
3140
+ // "buyAsset": "",
3141
+ // "sellAsset": "",
3142
+ // "buyAmount": 12.11,
3143
+ // "sellAmount": 12.11,
3144
+ // "tradeStatus": 12,
3145
+ // "createdTime": ""
3146
+ // }
3147
+ // ...
3148
+ // ]
3149
+ // }
3150
+ // }
3151
+ //
3152
+ const data = this.safeDict(response, 'data', {});
3153
+ const rows = this.safeList(data, 'tradeVos', []);
3154
+ return this.parseConversions(rows, 'sellAsset', 'buyAsset', since, limit);
3155
+ }
3064
3156
  parseConversion(conversion, fromCurrency = undefined, toCurrency = undefined) {
3065
3157
  //
3066
3158
  // fetchConvertQuote
@@ -3085,10 +3177,22 @@ class woo extends woo$1 {
3085
3177
  // "rftAccepted": 1 // 1 -> success; 2 -> processing; 3 -> fail
3086
3178
  // }
3087
3179
  //
3088
- const timestamp = this.safeInteger(conversion, 'expireTimestamp');
3089
- const fromCoin = this.safeString(conversion, 'sellToken');
3090
- const fromCode = this.safeCurrencyCode(fromCoin, fromCurrency);
3091
- const to = this.safeString(conversion, 'buyToken');
3180
+ // fetchConvertTrade, fetchConvertTradeHistory
3181
+ //
3182
+ // {
3183
+ // "quoteId": 12,
3184
+ // "buyAsset": "",
3185
+ // "sellAsset": "",
3186
+ // "buyAmount": 12.11,
3187
+ // "sellAmount": 12.11,
3188
+ // "tradeStatus": 12,
3189
+ // "createdTime": ""
3190
+ // }
3191
+ //
3192
+ const timestamp = this.safeInteger2(conversion, 'expireTimestamp', 'createdTime');
3193
+ const fromCurr = this.safeString2(conversion, 'sellToken', 'buyAsset');
3194
+ const fromCode = this.safeCurrencyCode(fromCurr, fromCurrency);
3195
+ const to = this.safeString2(conversion, 'buyToken', 'sellAsset');
3092
3196
  const toCode = this.safeCurrencyCode(to, toCurrency);
3093
3197
  return {
3094
3198
  'info': conversion,
@@ -3096,9 +3200,9 @@ class woo extends woo$1 {
3096
3200
  'datetime': this.iso8601(timestamp),
3097
3201
  'id': this.safeString(conversion, 'quoteId'),
3098
3202
  'fromCurrency': fromCode,
3099
- 'fromAmount': this.safeNumber(conversion, 'sellQuantity'),
3203
+ 'fromAmount': this.safeNumber2(conversion, 'sellQuantity', 'sellAmount'),
3100
3204
  'toCurrency': toCode,
3101
- 'toAmount': this.safeNumber(conversion, 'buyQuantity'),
3205
+ 'toAmount': this.safeNumber2(conversion, 'buyQuantity', 'buyAmount'),
3102
3206
  'price': this.safeNumber(conversion, 'buyPrice'),
3103
3207
  'fee': undefined,
3104
3208
  };
package/js/ccxt.d.ts CHANGED
@@ -4,7 +4,7 @@ import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
5
  import type { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, MarginMode, Greeks, Leverage, Leverages, Option, OptionChain, Conversion } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
7
- declare const version = "4.3.0";
7
+ declare const version = "4.3.2";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, AuthenticationError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, OperationRejected, NoChange, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, AddressPending, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, ContractUnavailable, NotSupported, ProxyError, ExchangeClosedByUser, OperationFailed, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.3.1';
41
+ const version = '4.3.3';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -3,7 +3,7 @@ import { // eslint-disable-line object-curly-newline
3
3
  ExchangeError, AuthenticationError, DDoSProtection, RequestTimeout, ExchangeNotAvailable, RateLimitExceeded } from "./errors.js";
4
4
  import WsClient from './ws/WsClient.js';
5
5
  import { OrderBook as WsOrderBook, IndexedOrderBook, CountedOrderBook } from './ws/OrderBook.js';
6
- import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion } from './types.js';
6
+ import type { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRate, DepositWithdrawFeeNetwork, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, MarginModification, TradingFeeInterface, Currencies, TradingFees, Conversion, CancellationRequest } from './types.js';
7
7
  export type { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, LedgerEntry, BorrowInterest, OpenInterest, LeverageTier, TransferEntry, BorrowRate, FundingRateHistory, Liquidation, FundingHistory, OrderRequest, MarginMode, Tickers, Greeks, Option, OptionChain, Str, Num, MarketInterface, CurrencyInterface, BalanceAccount, MarginModes, MarketType, Leverage, Leverages, LastPrice, LastPrices, Account, Strings, Conversion } from './types.js';
8
8
  import { ArrayCache, ArrayCacheByTimestamp } from './ws/Cache.js';
9
9
  import { OrderBook as Ob } from './ws/OrderBook.js';
@@ -894,6 +894,7 @@ export default class Exchange {
894
894
  cancelOrderWs(id: string, symbol?: Str, params?: {}): Promise<{}>;
895
895
  cancelOrdersWs(ids: string[], symbol?: Str, params?: {}): Promise<{}>;
896
896
  cancelAllOrders(symbol?: Str, params?: {}): Promise<{}>;
897
+ cancelOrdersForSymbols(orders: CancellationRequest[], params?: {}): Promise<{}>;
897
898
  cancelAllOrdersWs(symbol?: Str, params?: {}): Promise<{}>;
898
899
  cancelUnifiedOrder(order: any, params?: {}): Promise<{}>;
899
900
  fetchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
@@ -1020,6 +1021,7 @@ export default class Exchange {
1020
1021
  parseMarginMode(marginMode: any, market?: Market): MarginMode;
1021
1022
  parseLeverages(response: object[], symbols?: string[], symbolKey?: Str, marketType?: MarketType): Leverages;
1022
1023
  parseLeverage(leverage: any, market?: Market): Leverage;
1024
+ parseConversions(conversions: any[], fromCurrencyKey?: Str, toCurrencyKey?: Str, since?: Int, limit?: Int, params?: {}): Conversion[];
1023
1025
  parseConversion(conversion: any, fromCurrency?: Currency, toCurrency?: Currency): Conversion;
1024
1026
  convertExpireDate(date: string): string;
1025
1027
  convertExpireDateToMarketIdDate(date: string): string;
@@ -4464,6 +4464,9 @@ export default class Exchange {
4464
4464
  async cancelAllOrders(symbol = undefined, params = {}) {
4465
4465
  throw new NotSupported(this.id + ' cancelAllOrders() is not supported yet');
4466
4466
  }
4467
+ async cancelOrdersForSymbols(orders, params = {}) {
4468
+ throw new NotSupported(this.id + ' cancelOrdersForSymbols() is not supported yet');
4469
+ }
4467
4470
  async cancelAllOrdersWs(symbol = undefined, params = {}) {
4468
4471
  throw new NotSupported(this.id + ' cancelAllOrdersWs() is not supported yet');
4469
4472
  }
@@ -5793,6 +5796,28 @@ export default class Exchange {
5793
5796
  parseLeverage(leverage, market = undefined) {
5794
5797
  throw new NotSupported(this.id + ' parseLeverage () is not supported yet');
5795
5798
  }
5799
+ parseConversions(conversions, fromCurrencyKey = undefined, toCurrencyKey = undefined, since = undefined, limit = undefined, params = {}) {
5800
+ conversions = this.toArray(conversions);
5801
+ const result = [];
5802
+ let fromCurrency = undefined;
5803
+ let toCurrency = undefined;
5804
+ for (let i = 0; i < conversions.length; i++) {
5805
+ const entry = conversions[i];
5806
+ const fromId = this.safeString(entry, fromCurrencyKey);
5807
+ const toId = this.safeString(entry, toCurrencyKey);
5808
+ if (fromId !== undefined) {
5809
+ fromCurrency = this.currency(fromId);
5810
+ }
5811
+ if (toId !== undefined) {
5812
+ toCurrency = this.currency(toId);
5813
+ }
5814
+ const conversion = this.extend(this.parseConversion(entry, fromCurrency, toCurrency), params);
5815
+ result.push(conversion);
5816
+ }
5817
+ const sorted = this.sortBy(result, 'timestamp');
5818
+ const code = (fromCurrency !== undefined) ? fromCurrency['code'] : undefined;
5819
+ return this.filterByCurrencySinceLimit(sorted, code, since, limit);
5820
+ }
5796
5821
  parseConversion(conversion, fromCurrency = undefined, toCurrency = undefined) {
5797
5822
  throw new NotSupported(this.id + ' parseConversion () is not supported yet');
5798
5823
  }
@@ -393,6 +393,11 @@ export interface OrderRequest {
393
393
  price?: number | undefined;
394
394
  params?: any;
395
395
  }
396
+ export interface CancellationRequest {
397
+ id: string;
398
+ clientOrderId?: string;
399
+ symbol: string;
400
+ }
396
401
  export interface FundingHistory {
397
402
  info: any;
398
403
  symbol: string;
@@ -440,6 +440,9 @@ export default class binance extends Exchange {
440
440
  };
441
441
  fetchMarginAdjustmentHistory(symbol?: Str, type?: Str, since?: Num, limit?: Num, params?: {}): Promise<MarginModification[]>;
442
442
  fetchConvertCurrencies(params?: {}): Promise<Currencies>;
443
+ fetchConvertQuote(fromCode: string, toCode: string, amount?: Num, params?: {}): Promise<Conversion>;
443
444
  createConvertTrade(id: string, fromCode: string, toCode: string, amount?: Num, params?: {}): Promise<Conversion>;
445
+ fetchConvertTrade(id: string, code?: Str, params?: {}): Promise<Conversion>;
446
+ fetchConvertTradeHistory(code?: Str, since?: Int, limit?: Int, params?: {}): Promise<Conversion[]>;
444
447
  parseConversion(conversion: any, fromCurrency?: Currency, toCurrency?: Currency): Conversion;
445
448
  }
package/js/src/binance.js CHANGED
@@ -76,7 +76,9 @@ export default class binance extends Exchange {
76
76
  'fetchClosedOrder': false,
77
77
  'fetchClosedOrders': 'emulated',
78
78
  'fetchConvertCurrencies': true,
79
- 'fetchConvertQuote': false,
79
+ 'fetchConvertQuote': true,
80
+ 'fetchConvertTrade': true,
81
+ 'fetchConvertTradeHistory': true,
80
82
  'fetchCrossBorrowRate': true,
81
83
  'fetchCrossBorrowRates': false,
82
84
  'fetchCurrencies': true,
@@ -12650,57 +12652,354 @@ export default class binance extends Exchange {
12650
12652
  }
12651
12653
  return result;
12652
12654
  }
12653
- async createConvertTrade(id, fromCode, toCode, amount = undefined, params = {}) {
12655
+ async fetchConvertQuote(fromCode, toCode, amount = undefined, params = {}) {
12654
12656
  /**
12655
12657
  * @method
12656
- * @name binance#createConvertTrade
12657
- * @description convert from one currency to another
12658
- * @see https://binance-docs.github.io/apidocs/spot/en/#busd-convert-trade
12659
- * @param {string} id the id of the trade that you want to make
12658
+ * @name binance#fetchConvertQuote
12659
+ * @description fetch a quote for converting from one currency to another
12660
+ * @see https://binance-docs.github.io/apidocs/spot/en/#send-quote-request-user_data
12660
12661
  * @param {string} fromCode the currency that you want to sell and convert from
12661
12662
  * @param {string} toCode the currency that you want to buy and convert into
12662
- * @param {float} [amount] how much you want to trade in units of the from currency
12663
+ * @param {float} amount how much you want to trade in units of the from currency
12663
12664
  * @param {object} [params] extra parameters specific to the exchange API endpoint
12665
+ * @param {string} [params.walletType] either 'SPOT' or 'FUNDING', the default is 'SPOT'
12664
12666
  * @returns {object} a [conversion structure]{@link https://docs.ccxt.com/#/?id=conversion-structure}
12665
12667
  */
12668
+ if (amount === undefined) {
12669
+ throw new ArgumentsRequired(this.id + ' fetchConvertQuote() requires an amount argument');
12670
+ }
12666
12671
  await this.loadMarkets();
12667
12672
  const request = {
12668
- 'clientTranId': id,
12669
- 'asset': fromCode,
12670
- 'targetAsset': toCode,
12671
- 'amount': amount,
12673
+ 'fromAsset': fromCode,
12674
+ 'toAsset': toCode,
12675
+ 'fromAmount': amount,
12672
12676
  };
12673
- const response = await this.sapiPostAssetConvertTransfer(this.extend(request, params));
12677
+ const response = await this.sapiPostConvertGetQuote(this.extend(request, params));
12674
12678
  //
12675
12679
  // {
12676
- // "tranId": 118263407119,
12677
- // "status": "S"
12680
+ // "quoteId":"12415572564",
12681
+ // "ratio":"38163.7",
12682
+ // "inverseRatio":"0.0000262",
12683
+ // "validTimestamp":1623319461670,
12684
+ // "toAmount":"3816.37",
12685
+ // "fromAmount":"0.1"
12678
12686
  // }
12679
12687
  //
12680
12688
  const fromCurrency = this.currency(fromCode);
12681
12689
  const toCurrency = this.currency(toCode);
12682
12690
  return this.parseConversion(response, fromCurrency, toCurrency);
12683
12691
  }
12692
+ async createConvertTrade(id, fromCode, toCode, amount = undefined, params = {}) {
12693
+ /**
12694
+ * @method
12695
+ * @name binance#createConvertTrade
12696
+ * @description convert from one currency to another
12697
+ * @see https://binance-docs.github.io/apidocs/spot/en/#busd-convert-trade
12698
+ * @see https://binance-docs.github.io/apidocs/spot/en/#accept-quote-trade
12699
+ * @param {string} id the id of the trade that you want to make
12700
+ * @param {string} fromCode the currency that you want to sell and convert from
12701
+ * @param {string} toCode the currency that you want to buy and convert into
12702
+ * @param {float} [amount] how much you want to trade in units of the from currency
12703
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
12704
+ * @returns {object} a [conversion structure]{@link https://docs.ccxt.com/#/?id=conversion-structure}
12705
+ */
12706
+ await this.loadMarkets();
12707
+ const request = {};
12708
+ let response = undefined;
12709
+ if ((fromCode === 'BUSD') || (toCode === 'BUSD')) {
12710
+ if (amount === undefined) {
12711
+ throw new ArgumentsRequired(this.id + ' createConvertTrade() requires an amount argument');
12712
+ }
12713
+ request['clientTranId'] = id;
12714
+ request['asset'] = fromCode;
12715
+ request['targetAsset'] = toCode;
12716
+ request['amount'] = amount;
12717
+ response = await this.sapiPostAssetConvertTransfer(this.extend(request, params));
12718
+ //
12719
+ // {
12720
+ // "tranId": 118263407119,
12721
+ // "status": "S"
12722
+ // }
12723
+ //
12724
+ }
12725
+ else {
12726
+ request['quoteId'] = id;
12727
+ response = await this.sapiPostConvertAcceptQuote(this.extend(request, params));
12728
+ //
12729
+ // {
12730
+ // "orderId":"933256278426274426",
12731
+ // "createTime":1623381330472,
12732
+ // "orderStatus":"PROCESS"
12733
+ // }
12734
+ //
12735
+ }
12736
+ const fromCurrency = this.currency(fromCode);
12737
+ const toCurrency = this.currency(toCode);
12738
+ return this.parseConversion(response, fromCurrency, toCurrency);
12739
+ }
12740
+ async fetchConvertTrade(id, code = undefined, params = {}) {
12741
+ /**
12742
+ * @method
12743
+ * @name binance#fetchConvertTrade
12744
+ * @description fetch the data for a conversion trade
12745
+ * @see https://binance-docs.github.io/apidocs/spot/en/#busd-convert-history-user_data
12746
+ * @see https://binance-docs.github.io/apidocs/spot/en/#order-status-user_data
12747
+ * @param {string} id the id of the trade that you want to fetch
12748
+ * @param {string} [code] the unified currency code of the conversion trade
12749
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
12750
+ * @returns {object} a [conversion structure]{@link https://docs.ccxt.com/#/?id=conversion-structure}
12751
+ */
12752
+ await this.loadMarkets();
12753
+ const request = {};
12754
+ let response = undefined;
12755
+ if (code === 'BUSD') {
12756
+ const msInDay = 86400000;
12757
+ const now = this.milliseconds();
12758
+ if (code !== undefined) {
12759
+ const currency = this.currency(code);
12760
+ request['asset'] = currency['id'];
12761
+ }
12762
+ request['tranId'] = id;
12763
+ request['startTime'] = now - msInDay;
12764
+ request['endTime'] = now;
12765
+ response = await this.sapiGetAssetConvertTransferQueryByPage(this.extend(request, params));
12766
+ //
12767
+ // {
12768
+ // "total": 3,
12769
+ // "rows": [
12770
+ // {
12771
+ // "tranId": 118263615991,
12772
+ // "type": 244,
12773
+ // "time": 1664442078000,
12774
+ // "deductedAsset": "BUSD",
12775
+ // "deductedAmount": "1",
12776
+ // "targetAsset": "USDC",
12777
+ // "targetAmount": "1",
12778
+ // "status": "S",
12779
+ // "accountType": "MAIN"
12780
+ // },
12781
+ // ]
12782
+ // }
12783
+ //
12784
+ }
12785
+ else {
12786
+ request['orderId'] = id;
12787
+ response = await this.sapiGetConvertOrderStatus(this.extend(request, params));
12788
+ //
12789
+ // {
12790
+ // "orderId":933256278426274426,
12791
+ // "orderStatus":"SUCCESS",
12792
+ // "fromAsset":"BTC",
12793
+ // "fromAmount":"0.00054414",
12794
+ // "toAsset":"USDT",
12795
+ // "toAmount":"20",
12796
+ // "ratio":"36755",
12797
+ // "inverseRatio":"0.00002721",
12798
+ // "createTime":1623381330472
12799
+ // }
12800
+ //
12801
+ }
12802
+ let data = response;
12803
+ if (code === 'BUSD') {
12804
+ const rows = this.safeList(response, 'rows', []);
12805
+ data = this.safeDict(rows, 0, {});
12806
+ }
12807
+ const fromCurrencyId = this.safeString2(data, 'deductedAsset', 'fromAsset');
12808
+ const toCurrencyId = this.safeString2(data, 'targetAsset', 'toAsset');
12809
+ let fromCurrency = undefined;
12810
+ let toCurrency = undefined;
12811
+ if (fromCurrencyId !== undefined) {
12812
+ fromCurrency = this.currency(fromCurrencyId);
12813
+ }
12814
+ if (toCurrencyId !== undefined) {
12815
+ toCurrency = this.currency(toCurrencyId);
12816
+ }
12817
+ return this.parseConversion(data, fromCurrency, toCurrency);
12818
+ }
12819
+ async fetchConvertTradeHistory(code = undefined, since = undefined, limit = undefined, params = {}) {
12820
+ /**
12821
+ * @method
12822
+ * @name binance#fetchConvertTradeHistory
12823
+ * @description fetch the users history of conversion trades
12824
+ * @see https://binance-docs.github.io/apidocs/spot/en/#busd-convert-history-user_data
12825
+ * @see https://binance-docs.github.io/apidocs/spot/en/#get-convert-trade-history-user_data
12826
+ * @param {string} [code] the unified currency code
12827
+ * @param {int} [since] the earliest time in ms to fetch conversions for
12828
+ * @param {int} [limit] the maximum number of conversion structures to retrieve
12829
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
12830
+ * @param {int} [params.until] timestamp in ms of the latest conversion to fetch
12831
+ * @returns {object[]} a list of [conversion structures]{@link https://docs.ccxt.com/#/?id=conversion-structure}
12832
+ */
12833
+ await this.loadMarkets();
12834
+ const request = {};
12835
+ const msInThirtyDays = 2592000000;
12836
+ const now = this.milliseconds();
12837
+ if (since !== undefined) {
12838
+ request['startTime'] = since;
12839
+ }
12840
+ else {
12841
+ request['startTime'] = now - msInThirtyDays;
12842
+ }
12843
+ const endTime = this.safeString2(params, 'endTime', 'until');
12844
+ if (endTime !== undefined) {
12845
+ request['endTime'] = endTime;
12846
+ }
12847
+ else {
12848
+ request['endTime'] = now;
12849
+ }
12850
+ params = this.omit(params, 'until');
12851
+ let response = undefined;
12852
+ let responseQuery = undefined;
12853
+ let fromCurrencyKey = undefined;
12854
+ let toCurrencyKey = undefined;
12855
+ if (code === 'BUSD') {
12856
+ const currency = this.currency(code);
12857
+ request['asset'] = currency['id'];
12858
+ if (limit !== undefined) {
12859
+ request['size'] = limit;
12860
+ }
12861
+ fromCurrencyKey = 'deductedAsset';
12862
+ toCurrencyKey = 'targetAsset';
12863
+ responseQuery = 'rows';
12864
+ response = await this.sapiGetAssetConvertTransferQueryByPage(this.extend(request, params));
12865
+ //
12866
+ // {
12867
+ // "total": 3,
12868
+ // "rows": [
12869
+ // {
12870
+ // "tranId": 118263615991,
12871
+ // "type": 244,
12872
+ // "time": 1664442078000,
12873
+ // "deductedAsset": "BUSD",
12874
+ // "deductedAmount": "1",
12875
+ // "targetAsset": "USDC",
12876
+ // "targetAmount": "1",
12877
+ // "status": "S",
12878
+ // "accountType": "MAIN"
12879
+ // },
12880
+ // ]
12881
+ // }
12882
+ //
12883
+ }
12884
+ else {
12885
+ if (limit !== undefined) {
12886
+ request['limit'] = limit;
12887
+ }
12888
+ fromCurrencyKey = 'fromAsset';
12889
+ toCurrencyKey = 'toAsset';
12890
+ responseQuery = 'list';
12891
+ response = await this.sapiGetConvertTradeFlow(this.extend(request, params));
12892
+ //
12893
+ // {
12894
+ // "list": [
12895
+ // {
12896
+ // "quoteId": "f3b91c525b2644c7bc1e1cd31b6e1aa6",
12897
+ // "orderId": 940708407462087195,
12898
+ // "orderStatus": "SUCCESS",
12899
+ // "fromAsset": "USDT",
12900
+ // "fromAmount": "20",
12901
+ // "toAsset": "BNB",
12902
+ // "toAmount": "0.06154036",
12903
+ // "ratio": "0.00307702",
12904
+ // "inverseRatio": "324.99",
12905
+ // "createTime": 1624248872184
12906
+ // }
12907
+ // ],
12908
+ // "startTime": 1623824139000,
12909
+ // "endTime": 1626416139000,
12910
+ // "limit": 100,
12911
+ // "moreData": false
12912
+ // }
12913
+ //
12914
+ }
12915
+ const rows = this.safeList(response, responseQuery, []);
12916
+ return this.parseConversions(rows, fromCurrencyKey, toCurrencyKey, since, limit);
12917
+ }
12684
12918
  parseConversion(conversion, fromCurrency = undefined, toCurrency = undefined) {
12919
+ //
12920
+ // fetchConvertQuote
12921
+ //
12922
+ // {
12923
+ // "quoteId":"12415572564",
12924
+ // "ratio":"38163.7",
12925
+ // "inverseRatio":"0.0000262",
12926
+ // "validTimestamp":1623319461670,
12927
+ // "toAmount":"3816.37",
12928
+ // "fromAmount":"0.1"
12929
+ // }
12685
12930
  //
12686
12931
  // createConvertTrade
12687
12932
  //
12688
12933
  // {
12934
+ // "orderId":"933256278426274426",
12935
+ // "createTime":1623381330472,
12936
+ // "orderStatus":"PROCESS"
12937
+ // }
12938
+ //
12939
+ // createConvertTrade BUSD
12940
+ //
12941
+ // {
12689
12942
  // "tranId": 118263407119,
12690
12943
  // "status": "S"
12691
12944
  // }
12692
12945
  //
12693
- const fromCode = this.safeCurrencyCode(undefined, fromCurrency);
12694
- const toCode = this.safeCurrencyCode(undefined, toCurrency);
12946
+ // fetchConvertTrade, fetchConvertTradeHistory BUSD
12947
+ //
12948
+ // {
12949
+ // "tranId": 118263615991,
12950
+ // "type": 244,
12951
+ // "time": 1664442078000,
12952
+ // "deductedAsset": "BUSD",
12953
+ // "deductedAmount": "1",
12954
+ // "targetAsset": "USDC",
12955
+ // "targetAmount": "1",
12956
+ // "status": "S",
12957
+ // "accountType": "MAIN"
12958
+ // }
12959
+ //
12960
+ // fetchConvertTrade
12961
+ //
12962
+ // {
12963
+ // "orderId":933256278426274426,
12964
+ // "orderStatus":"SUCCESS",
12965
+ // "fromAsset":"BTC",
12966
+ // "fromAmount":"0.00054414",
12967
+ // "toAsset":"USDT",
12968
+ // "toAmount":"20",
12969
+ // "ratio":"36755",
12970
+ // "inverseRatio":"0.00002721",
12971
+ // "createTime":1623381330472
12972
+ // }
12973
+ //
12974
+ // fetchConvertTradeHistory
12975
+ //
12976
+ // {
12977
+ // "quoteId": "f3b91c525b2644c7bc1e1cd31b6e1aa6",
12978
+ // "orderId": 940708407462087195,
12979
+ // "orderStatus": "SUCCESS",
12980
+ // "fromAsset": "USDT",
12981
+ // "fromAmount": "20",
12982
+ // "toAsset": "BNB",
12983
+ // "toAmount": "0.06154036",
12984
+ // "ratio": "0.00307702",
12985
+ // "inverseRatio": "324.99",
12986
+ // "createTime": 1624248872184
12987
+ // }
12988
+ //
12989
+ const timestamp = this.safeIntegerN(conversion, ['time', 'validTimestamp', 'createTime']);
12990
+ const fromCur = this.safeString2(conversion, 'deductedAsset', 'fromAsset');
12991
+ const fromCode = this.safeCurrencyCode(fromCur, fromCurrency);
12992
+ const to = this.safeString2(conversion, 'targetAsset', 'toAsset');
12993
+ const toCode = this.safeCurrencyCode(to, toCurrency);
12695
12994
  return {
12696
12995
  'info': conversion,
12697
- 'timestamp': undefined,
12698
- 'datetime': undefined,
12699
- 'id': this.safeString(conversion, 'tranId'),
12996
+ 'timestamp': timestamp,
12997
+ 'datetime': this.iso8601(timestamp),
12998
+ 'id': this.safeStringN(conversion, ['tranId', 'orderId', 'quoteId']),
12700
12999
  'fromCurrency': fromCode,
12701
- 'fromAmount': undefined,
13000
+ 'fromAmount': this.safeNumber2(conversion, 'deductedAmount', 'fromAmount'),
12702
13001
  'toCurrency': toCode,
12703
- 'toAmount': undefined,
13002
+ 'toAmount': this.safeNumber2(conversion, 'targetAmount', 'toAmount'),
12704
13003
  'price': undefined,
12705
13004
  'fee': undefined,
12706
13005
  };