ccxt 4.1.30 → 4.1.31

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.
@@ -33,6 +33,7 @@ class hitbtc extends hitbtc$1 {
33
33
  'cancelOrder': true,
34
34
  'createDepositAddress': true,
35
35
  'createOrder': true,
36
+ 'createPostOnlyOrder': true,
36
37
  'createReduceOnlyOrder': true,
37
38
  'createStopLimitOrder': true,
38
39
  'createStopMarketOrder': true,
@@ -2047,14 +2048,24 @@ class hitbtc extends hitbtc$1 {
2047
2048
  * @param {float} amount how much of currency you want to trade in units of base currency
2048
2049
  * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2049
2050
  * @param {object} [params] extra parameters specific to the hitbtc api endpoint
2050
- * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported, defaults to spot-margin endpoint if this is set
2051
+ * @param {string} [params.marginMode] 'cross' or 'isolated' only 'isolated' is supported for spot-margin, swap supports both
2051
2052
  * @param {bool} [params.margin] true for creating a margin order
2052
2053
  * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
2054
+ * @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
2055
+ * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", "Day", "GTD"
2053
2056
  * @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
2054
2057
  */
2055
2058
  await this.loadMarkets();
2056
2059
  const market = this.market(symbol);
2057
2060
  const isLimit = (type === 'limit');
2061
+ const reduceOnly = this.safeValue(params, 'reduceOnly');
2062
+ const timeInForce = this.safeString(params, 'timeInForce');
2063
+ const triggerPrice = this.safeNumberN(params, ['triggerPrice', 'stopPrice', 'stop_price']);
2064
+ let marketType = undefined;
2065
+ [marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
2066
+ let marginMode = undefined;
2067
+ [marginMode, params] = this.handleMarginModeAndParams('createOrder', params);
2068
+ const isPostOnly = this.isPostOnly(type === 'market', undefined, params);
2058
2069
  const request = {
2059
2070
  'type': type,
2060
2071
  'side': side,
@@ -2072,7 +2083,6 @@ class hitbtc extends hitbtc$1 {
2072
2083
  // 'take_rate': 0.001, // Optional
2073
2084
  // 'make_rate': 0.001, // Optional
2074
2085
  };
2075
- const reduceOnly = this.safeValue(params, 'reduceOnly');
2076
2086
  if (reduceOnly !== undefined) {
2077
2087
  if ((market['type'] !== 'swap') && (market['type'] !== 'margin')) {
2078
2088
  throw new errors.InvalidOrder(this.id + ' createOrder() does not support reduce_only for ' + market['type'] + ' orders, reduce_only orders are supported for swap and margin markets only');
@@ -2081,8 +2091,12 @@ class hitbtc extends hitbtc$1 {
2081
2091
  if (reduceOnly === true) {
2082
2092
  request['reduce_only'] = reduceOnly;
2083
2093
  }
2084
- const timeInForce = this.safeString2(params, 'timeInForce', 'time_in_force');
2085
- const triggerPrice = this.safeNumberN(params, ['triggerPrice', 'stopPrice', 'stop_price']);
2094
+ if (isPostOnly) {
2095
+ request['post_only'] = true;
2096
+ }
2097
+ if (timeInForce !== undefined) {
2098
+ request['time_in_force'] = timeInForce;
2099
+ }
2086
2100
  if (isLimit || (type === 'stopLimit') || (type === 'takeProfitLimit')) {
2087
2101
  if (price === undefined) {
2088
2102
  throw new errors.ExchangeError(this.id + ' createOrder() requires a price argument for limit orders');
@@ -2107,19 +2121,20 @@ class hitbtc extends hitbtc$1 {
2107
2121
  else if ((type === 'stopLimit') || (type === 'stopMarket') || (type === 'takeProfitLimit') || (type === 'takeProfitMarket')) {
2108
2122
  throw new errors.ExchangeError(this.id + ' createOrder() requires a stopPrice parameter for stop-loss and take-profit orders');
2109
2123
  }
2110
- let marketType = undefined;
2111
- [marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
2112
- let method = this.getSupportedMapping(marketType, {
2113
- 'spot': 'privatePostSpotOrder',
2114
- 'swap': 'privatePostFuturesOrder',
2115
- 'margin': 'privatePostMarginOrder',
2116
- });
2117
- const [marginMode, query] = this.handleMarginModeAndParams('createOrder', params);
2118
- if (marginMode !== undefined) {
2119
- method = 'privatePostMarginOrder';
2124
+ params = this.omit(params, ['triggerPrice', 'timeInForce', 'stopPrice', 'stop_price', 'reduceOnly', 'postOnly']);
2125
+ if ((marketType === 'swap') && (marginMode !== undefined)) {
2126
+ request['margin_mode'] = marginMode;
2127
+ }
2128
+ let response = undefined;
2129
+ if (marketType === 'swap') {
2130
+ response = await this.privatePostFuturesOrder(this.extend(request, params));
2131
+ }
2132
+ else if ((marketType === 'margin') || (marginMode !== undefined)) {
2133
+ response = await this.privatePostMarginOrder(this.extend(request, params));
2134
+ }
2135
+ else {
2136
+ response = await this.privatePostSpotOrder(this.extend(request, params));
2120
2137
  }
2121
- params = this.omit(params, ['triggerPrice', 'timeInForce', 'time_in_force', 'stopPrice', 'stop_price', 'reduceOnly']);
2122
- const response = await this[method](this.extend(request, query));
2123
2138
  return this.parseOrder(response, market);
2124
2139
  }
2125
2140
  parseOrderStatus(status) {
@@ -3042,12 +3057,7 @@ class hitbtc extends hitbtc$1 {
3042
3057
  const isMargin = this.safeValue(params, 'margin', false);
3043
3058
  let marginMode = undefined;
3044
3059
  [marginMode, params] = super.handleMarginModeAndParams(methodName, params, defaultValue);
3045
- if (marginMode !== undefined) {
3046
- if (marginMode !== 'isolated') {
3047
- throw new errors.NotSupported(this.id + ' only isolated margin is supported');
3048
- }
3049
- }
3050
- else {
3060
+ if (marginMode === undefined) {
3051
3061
  if ((defaultType === 'margin') || (isMargin === true)) {
3052
3062
  marginMode = 'isolated';
3053
3063
  }
@@ -27,8 +27,8 @@ class mexc extends mexc$1 {
27
27
  'spot': true,
28
28
  'margin': true,
29
29
  'swap': true,
30
- 'future': true,
31
- 'option': undefined,
30
+ 'future': false,
31
+ 'option': false,
32
32
  'addMargin': true,
33
33
  'borrowMargin': true,
34
34
  'cancelAllOrders': true,
@@ -396,10 +396,6 @@ class mexc extends mexc$1 {
396
396
  'fetchMarkets': {
397
397
  'types': {
398
398
  'spot': true,
399
- 'future': {
400
- 'linear': false,
401
- 'inverse': false,
402
- },
403
399
  'swap': {
404
400
  'linear': true,
405
401
  'inverse': false,
@@ -3085,6 +3085,7 @@ class okx extends okx$1 {
3085
3085
  parseOrderStatus(status) {
3086
3086
  const statuses = {
3087
3087
  'canceled': 'canceled',
3088
+ 'order_failed': 'canceled',
3088
3089
  'live': 'open',
3089
3090
  'partially_filled': 'open',
3090
3091
  'filled': 'closed',
package/js/ccxt.d.ts CHANGED
@@ -2,9 +2,9 @@ import { Exchange } from './src/base/Exchange.js';
2
2
  import { Precise } from './src/base/Precise.js';
3
3
  import * as functions from './src/base/functions.js';
4
4
  import * as errors from './src/base/errors.js';
5
- import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation } from './src/base/types.js';
5
+ import { Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory } from './src/base/types.js';
6
6
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
7
- declare const version = "4.1.29";
7
+ declare const version = "4.1.30";
8
8
  import ace from './src/ace.js';
9
9
  import alpaca from './src/alpaca.js';
10
10
  import ascendex from './src/ascendex.js';
@@ -513,5 +513,5 @@ declare const ccxt: {
513
513
  zaif: typeof zaif;
514
514
  zonda: typeof zonda;
515
515
  } & typeof functions & typeof errors;
516
- export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange, Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitforex, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitstamp1, bittrex, bitvavo, bl3p, blockchaincom, btcalpha, btcbox, btcmarkets, btctradeua, btcturk, bybit, cex, coinbase, coinbaseprime, coinbasepro, coincheck, coinex, coinfalcon, coinmate, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, huobi, huobijp, huobipro, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, lbank2, luno, lykke, mercado, mexc, mexc3, ndax, novadax, oceanex, okcoin, okex, okex5, okx, paymium, phemex, poloniex, poloniexfutures, probit, tidex, timex, tokocrypto, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
516
+ export { version, Exchange, exchanges, pro, Precise, functions, errors, BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange, Market, Trade, Fee, Ticker, OrderBook, Order, Transaction, Tickers, Currency, Balance, DepositAddress, WithdrawalResponse, DepositAddressResponse, OHLCV, Balances, PartialBalances, Dictionary, MinMax, Position, FundingRateHistory, Liquidation, FundingHistory, ace, alpaca, ascendex, bequant, bigone, binance, binancecoinm, binanceus, binanceusdm, bingx, bit2c, bitbank, bitbay, bitbns, bitcoincom, bitfinex, bitfinex2, bitflyer, bitforex, bitget, bithumb, bitmart, bitmex, bitopro, bitpanda, bitrue, bitso, bitstamp, bitstamp1, bittrex, bitvavo, bl3p, blockchaincom, btcalpha, btcbox, btcmarkets, btctradeua, btcturk, bybit, cex, coinbase, coinbaseprime, coinbasepro, coincheck, coinex, coinfalcon, coinmate, coinone, coinsph, coinspot, cryptocom, currencycom, delta, deribit, digifinex, exmo, fmfwio, gate, gateio, gemini, hitbtc, hitbtc3, hollaex, huobi, huobijp, huobipro, idex, independentreserve, indodax, kraken, krakenfutures, kucoin, kucoinfutures, kuna, latoken, lbank, lbank2, luno, lykke, mercado, mexc, mexc3, ndax, novadax, oceanex, okcoin, okex, okex5, okx, paymium, phemex, poloniex, poloniexfutures, probit, tidex, timex, tokocrypto, upbit, wavesexchange, wazirx, whitebit, woo, yobit, zaif, zonda, };
517
517
  export default ccxt;
package/js/ccxt.js CHANGED
@@ -38,7 +38,7 @@ import * as errors from './src/base/errors.js';
38
38
  import { BaseError, ExchangeError, PermissionDenied, AccountNotEnabled, AccountSuspended, ArgumentsRequired, BadRequest, BadSymbol, MarginModeAlreadySet, BadResponse, NullResponse, InsufficientFunds, InvalidAddress, InvalidOrder, OrderNotFound, OrderNotCached, CancelPending, OrderImmediatelyFillable, OrderNotFillable, DuplicateOrderId, NotSupported, NetworkError, DDoSProtection, RateLimitExceeded, ExchangeNotAvailable, OnMaintenance, InvalidNonce, RequestTimeout, AuthenticationError, AddressPending, NoChange } from './src/base/errors.js';
39
39
  //-----------------------------------------------------------------------------
40
40
  // this is updated by vss.js when building
41
- const version = '4.1.30';
41
+ const version = '4.1.31';
42
42
  Exchange.ccxtVersion = version;
43
43
  //-----------------------------------------------------------------------------
44
44
  import ace from './src/ace.js';
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/ascendex.js';
2
- import { Int, Order, OrderSide, OrderType } from './base/types.js';
2
+ import { FundingHistory, Int, Order, OrderSide, OrderType } from './base/types.js';
3
3
  /**
4
4
  * @class ascendex
5
5
  * @extends Exchange
@@ -148,6 +148,16 @@ export default class ascendex extends Exchange {
148
148
  status: string;
149
149
  };
150
150
  parseTransferStatus(status: any): "ok" | "failed";
151
+ fetchFundingHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
152
+ parseIncome(income: any, market?: any): {
153
+ info: any;
154
+ symbol: any;
155
+ code: string;
156
+ timestamp: number;
157
+ datetime: string;
158
+ id: any;
159
+ amount: number;
160
+ };
151
161
  sign(path: any, api?: string, method?: string, params?: {}, headers?: any, body?: any): {
152
162
  url: string;
153
163
  method: string;
@@ -32,7 +32,7 @@ export default class ascendex extends Exchange {
32
32
  'spot': true,
33
33
  'margin': true,
34
34
  'swap': true,
35
- 'future': true,
35
+ 'future': false,
36
36
  'option': false,
37
37
  'addMargin': true,
38
38
  'cancelAllOrders': true,
@@ -54,7 +54,7 @@ export default class ascendex extends Exchange {
54
54
  'fetchDepositsWithdrawals': true,
55
55
  'fetchDepositWithdrawFee': 'emulated',
56
56
  'fetchDepositWithdrawFees': true,
57
- 'fetchFundingHistory': false,
57
+ 'fetchFundingHistory': true,
58
58
  'fetchFundingRate': 'emulated',
59
59
  'fetchFundingRateHistory': false,
60
60
  'fetchFundingRates': true,
@@ -268,7 +268,6 @@ export default class ascendex extends Exchange {
268
268
  'accountsByType': {
269
269
  'spot': 'cash',
270
270
  'swap': 'futures',
271
- 'future': 'futures',
272
271
  'margin': 'margin',
273
272
  },
274
273
  'transfer': {
@@ -2766,22 +2765,21 @@ export default class ascendex extends Exchange {
2766
2765
  * @method
2767
2766
  * @name ascendex#setLeverage
2768
2767
  * @description set the level of leverage for a market
2768
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#change-contract-leverage
2769
2769
  * @param {float} leverage the rate of leverage
2770
2770
  * @param {string} symbol unified market symbol
2771
2771
  * @param {object} [params] extra parameters specific to the ascendex api endpoint
2772
2772
  * @returns {object} response from the exchange
2773
2773
  */
2774
- if (symbol === undefined) {
2775
- throw new ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
2776
- }
2774
+ this.checkRequiredSymbol('setLeverage', symbol);
2777
2775
  if ((leverage < 1) || (leverage > 100)) {
2778
2776
  throw new BadRequest(this.id + ' leverage should be between 1 and 100');
2779
2777
  }
2780
2778
  await this.loadMarkets();
2781
2779
  await this.loadAccounts();
2782
2780
  const market = this.market(symbol);
2783
- if (market['type'] !== 'future') {
2784
- throw new BadSymbol(this.id + ' setLeverage() supports futures contracts only');
2781
+ if (!market['swap']) {
2782
+ throw new BadSymbol(this.id + ' setLeverage() supports swap contracts only');
2785
2783
  }
2786
2784
  const account = this.safeValue(this.accounts, 0, {});
2787
2785
  const accountGroup = this.safeString(account, 'id');
@@ -2797,11 +2795,13 @@ export default class ascendex extends Exchange {
2797
2795
  * @method
2798
2796
  * @name ascendex#setMarginMode
2799
2797
  * @description set margin mode to 'cross' or 'isolated'
2798
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#change-margin-type
2800
2799
  * @param {string} marginMode 'cross' or 'isolated'
2801
2800
  * @param {string} symbol unified market symbol
2802
2801
  * @param {object} [params] extra parameters specific to the ascendex api endpoint
2803
2802
  * @returns {object} response from the exchange
2804
2803
  */
2804
+ this.checkRequiredSymbol('setMarginMode', symbol);
2805
2805
  marginMode = marginMode.toLowerCase();
2806
2806
  if (marginMode === 'cross') {
2807
2807
  marginMode = 'crossed';
@@ -2817,10 +2817,10 @@ export default class ascendex extends Exchange {
2817
2817
  const request = {
2818
2818
  'account-group': accountGroup,
2819
2819
  'symbol': market['id'],
2820
- 'marginMode': marginMode,
2820
+ 'marginType': marginMode,
2821
2821
  };
2822
- if (market['type'] !== 'future') {
2823
- throw new BadSymbol(this.id + ' setMarginMode() supports futures contracts only');
2822
+ if (!market['swap']) {
2823
+ throw new BadSymbol(this.id + ' setMarginMode() supports swap contracts only');
2824
2824
  }
2825
2825
  return await this.v2PrivateAccountGroupPostFuturesMarginType(this.extend(request, params));
2826
2826
  }
@@ -3001,7 +3001,7 @@ export default class ascendex extends Exchange {
3001
3001
  const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
3002
3002
  const toId = this.safeString(accountsByType, toAccount, toAccount);
3003
3003
  if (fromId !== 'cash' && toId !== 'cash') {
3004
- throw new ExchangeError(this.id + ' transfer() only supports direct balance transfer between spot and future, spot and margin');
3004
+ throw new ExchangeError(this.id + ' transfer() only supports direct balance transfer between spot and swap, spot and margin');
3005
3005
  }
3006
3006
  const request = {
3007
3007
  'account-group': accountGroup,
@@ -3050,6 +3050,83 @@ export default class ascendex extends Exchange {
3050
3050
  }
3051
3051
  return 'failed';
3052
3052
  }
3053
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3054
+ /**
3055
+ * @method
3056
+ * @name ascendex#fetchFundingHistory
3057
+ * @description fetch the history of funding payments paid and received on this account
3058
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#funding-payment-history
3059
+ * @param {string} [symbol] unified market symbol
3060
+ * @param {int} [since] the earliest time in ms to fetch funding history for
3061
+ * @param {int} [limit] the maximum number of funding history structures to retrieve
3062
+ * @param {object} [params] extra parameters specific to the ascendex api endpoint
3063
+ * @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)
3064
+ * @returns {object} a [funding history structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-history-structure}
3065
+ */
3066
+ await this.loadMarkets();
3067
+ await this.loadAccounts();
3068
+ let paginate = false;
3069
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingHistory', 'paginate');
3070
+ if (paginate) {
3071
+ return await this.fetchPaginatedCallIncremental('fetchFundingHistory', symbol, since, limit, params, 'page', 25);
3072
+ }
3073
+ const account = this.safeValue(this.accounts, 0, {});
3074
+ const accountGroup = this.safeString(account, 'id');
3075
+ const request = {
3076
+ 'account-group': accountGroup,
3077
+ };
3078
+ let market = undefined;
3079
+ if (symbol !== undefined) {
3080
+ market = this.market(symbol);
3081
+ request['symbol'] = market['id'];
3082
+ }
3083
+ if (limit !== undefined) {
3084
+ request['pageSize'] = limit;
3085
+ }
3086
+ const response = await this.v2PrivateAccountGroupGetFuturesFundingPayments(this.extend(request, params));
3087
+ //
3088
+ // {
3089
+ // "code": 0,
3090
+ // "data": {
3091
+ // "data": [
3092
+ // {
3093
+ // "timestamp": 1640476800000,
3094
+ // "symbol": "BTC-PERP",
3095
+ // "paymentInUSDT": "-0.013991178",
3096
+ // "fundingRate": "0.000173497"
3097
+ // },
3098
+ // ],
3099
+ // "page": 1,
3100
+ // "pageSize": 3,
3101
+ // "hasNext": true
3102
+ // }
3103
+ // }
3104
+ //
3105
+ const data = this.safeValue(response, 'data', {});
3106
+ const rows = this.safeValue(data, 'data', []);
3107
+ return this.parseIncomes(rows, market, since, limit);
3108
+ }
3109
+ parseIncome(income, market = undefined) {
3110
+ //
3111
+ // {
3112
+ // "timestamp": 1640476800000,
3113
+ // "symbol": "BTC-PERP",
3114
+ // "paymentInUSDT": "-0.013991178",
3115
+ // "fundingRate": "0.000173497"
3116
+ // }
3117
+ //
3118
+ const marketId = this.safeString(income, 'symbol');
3119
+ const timestamp = this.safeInteger(income, 'timestamp');
3120
+ return {
3121
+ 'info': income,
3122
+ 'symbol': this.safeSymbol(marketId, market, '-', 'swap'),
3123
+ 'code': 'USDT',
3124
+ 'timestamp': timestamp,
3125
+ 'datetime': this.iso8601(timestamp),
3126
+ 'id': undefined,
3127
+ 'amount': this.safeNumber(income, 'paymentInUSDT'),
3128
+ };
3129
+ }
3053
3130
  sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3054
3131
  const version = api[0];
3055
3132
  const access = api[1];
@@ -4,8 +4,8 @@ ExchangeError, AuthenticationError, DDoSProtection, RequestTimeout, ExchangeNotA
4
4
  import WsClient from './ws/WsClient.js';
5
5
  import { Future } from './ws/Future.js';
6
6
  import { OrderBook as WsOrderBook, IndexedOrderBook, CountedOrderBook } from './ws/OrderBook.js';
7
- import { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRateHistory, OpenInterest, Liquidation, OrderRequest } from './types.js';
8
- export { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRateHistory, Liquidation } from './types.js';
7
+ import { Market, Trade, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRateHistory, OpenInterest, Liquidation, OrderRequest, FundingHistory } from './types.js';
8
+ export { Market, Trade, Fee, Ticker, OHLCV, OHLCVC, Order, OrderBook, Balance, Balances, Dictionary, Transaction, DepositAddressResponse, Currency, MinMax, IndexType, Int, OrderType, OrderSide, Position, FundingRateHistory, Liquidation, FundingHistory } from './types.js';
9
9
  /**
10
10
  * @class Exchange
11
11
  */
@@ -95,6 +95,7 @@ export default class Exchange {
95
95
  last_http_response: any;
96
96
  last_json_response: any;
97
97
  last_response_headers: any;
98
+ last_request_headers: any;
98
99
  id: string;
99
100
  markets: Dictionary<any>;
100
101
  has: Dictionary<boolean | 'emulated'>;
@@ -740,6 +741,7 @@ export default class Exchange {
740
741
  fetchWithdrawals(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
741
742
  fetchOpenInterest(symbol: string, params?: {}): Promise<OpenInterest>;
742
743
  fetchFundingRateHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<FundingRateHistory[]>;
744
+ fetchFundingHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
743
745
  parseLastPrice(price: any, market?: any): any;
744
746
  fetchDepositAddress(code: string, params?: {}): Promise<any>;
745
747
  account(): Balance;
@@ -806,7 +808,7 @@ export default class Exchange {
806
808
  depositWithdrawFee(info: any): any;
807
809
  assignDefaultDepositWithdrawFees(fee: any, currency?: any): any;
808
810
  parseIncome(info: any, market?: any): void;
809
- parseIncomes(incomes: any, market?: any, since?: Int, limit?: Int): any;
811
+ parseIncomes(incomes: any, market?: any, since?: Int, limit?: Int): FundingHistory[];
810
812
  getMarketFromSymbols(symbols?: string[]): any;
811
813
  parseWsOHLCVs(ohlcvs: object[], market?: any, timeframe?: string, since?: Int, limit?: Int): any[];
812
814
  fetchTransactions(code?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
@@ -64,6 +64,7 @@ export default class Exchange {
64
64
  this.last_http_response = undefined;
65
65
  this.last_json_response = undefined;
66
66
  this.last_response_headers = undefined;
67
+ this.last_request_headers = undefined;
67
68
  this.id = undefined;
68
69
  this.markets = undefined;
69
70
  this.status = undefined;
@@ -258,6 +259,7 @@ export default class Exchange {
258
259
  this.last_http_response = undefined;
259
260
  this.last_json_response = undefined;
260
261
  this.last_response_headers = undefined;
262
+ this.last_request_headers = undefined;
261
263
  // camelCase and snake_notation support
262
264
  const unCamelCaseProperties = (obj = this) => {
263
265
  if (obj !== null) {
@@ -2824,6 +2826,7 @@ export default class Exchange {
2824
2826
  }
2825
2827
  this.lastRestRequestTimestamp = this.milliseconds();
2826
2828
  const request = this.sign(path, api, method, params, headers, body);
2829
+ this.last_request_headers = request['headers'];
2827
2830
  return await this.fetch(request['url'], request['method'], request['headers'], request['body']);
2828
2831
  }
2829
2832
  async request(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined, config = {}) {
@@ -3408,6 +3411,9 @@ export default class Exchange {
3408
3411
  async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3409
3412
  throw new NotSupported(this.id + ' fetchFundingRateHistory() is not supported yet');
3410
3413
  }
3414
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3415
+ throw new NotSupported(this.id + ' fetchFundingHistory() is not supported yet');
3416
+ }
3411
3417
  parseLastPrice(price, market = undefined) {
3412
3418
  throw new NotSupported(this.id + ' parseLastPrice() is not supported yet');
3413
3419
  }
@@ -238,6 +238,15 @@ export interface OrderRequest {
238
238
  price?: number | undefined;
239
239
  params?: any;
240
240
  }
241
+ export interface FundingHistory {
242
+ info: any;
243
+ symbol: string;
244
+ code: string;
245
+ timestamp?: number;
246
+ datetime?: string;
247
+ id: string;
248
+ amount: number;
249
+ }
241
250
  /** [ timestamp, open, high, low, close, volume ] */
242
251
  export declare type OHLCV = [number, number, number, number, number, number];
243
252
  /** [ timestamp, open, high, low, close, volume, count ] */
@@ -375,7 +375,7 @@ export default class binance extends Exchange {
375
375
  fetchPositions(symbols?: string[], params?: {}): Promise<import("./base/types.js").Position[]>;
376
376
  fetchAccountPositions(symbols?: string[], params?: {}): Promise<import("./base/types.js").Position[]>;
377
377
  fetchPositionsRisk(symbols?: string[], params?: {}): Promise<import("./base/types.js").Position[]>;
378
- fetchFundingHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
378
+ fetchFundingHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<import("./base/types.js").FundingHistory[]>;
379
379
  setLeverage(leverage: any, symbol?: string, params?: {}): Promise<any>;
380
380
  setMarginMode(marginMode: string, symbol?: string, params?: {}): Promise<any>;
381
381
  setPositionMode(hedged: any, symbol?: string, params?: {}): Promise<any>;
@@ -1,5 +1,5 @@
1
1
  import Exchange from './abstract/bitget.js';
2
- import { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest } from './base/types.js';
2
+ import { Int, OrderSide, OrderType, Trade, OHLCV, Order, FundingRateHistory, OrderRequest, FundingHistory } from './base/types.js';
3
3
  /**
4
4
  * @class bitget
5
5
  * @extends Exchange
@@ -224,7 +224,7 @@ export default class bitget extends Exchange {
224
224
  previousFundingTimestamp: any;
225
225
  previousFundingDatetime: any;
226
226
  };
227
- fetchFundingHistory(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<any>;
227
+ fetchFundingHistory(symbol?: string, since?: Int, limit?: Int, params?: {}): Promise<FundingHistory[]>;
228
228
  parseFundingHistory(contract: any, market?: any): {
229
229
  info: any;
230
230
  symbol: any;
@@ -234,7 +234,7 @@ export default class bitget extends Exchange {
234
234
  amount: number;
235
235
  id: string;
236
236
  };
237
- parseFundingHistories(contracts: any, market?: any, since?: Int, limit?: Int): any;
237
+ parseFundingHistories(contracts: any, market?: any, since?: Int, limit?: Int): FundingHistory[];
238
238
  modifyMarginHelper(symbol: string, amount: any, type: any, params?: {}): Promise<any>;
239
239
  parseMarginModification(data: any, market?: any): {
240
240
  info: any;
package/js/src/bitget.js CHANGED
@@ -1306,11 +1306,16 @@ export default class bitget extends Exchange {
1306
1306
  };
1307
1307
  }
1308
1308
  async fetchMarketsByType(type, params = {}) {
1309
- const method = this.getSupportedMapping(type, {
1310
- 'spot': 'publicSpotGetPublicProducts',
1311
- 'swap': 'publicMixGetMarketContracts',
1312
- });
1313
- const response = await this[method](params);
1309
+ let response = undefined;
1310
+ if (type === 'spot') {
1311
+ response = await this.publicSpotGetPublicProducts(params);
1312
+ }
1313
+ else if (type === 'swap') {
1314
+ response = await this.publicMixGetMarketContracts(params);
1315
+ }
1316
+ else {
1317
+ throw new NotSupported(this.id + ' does not support ' + type + ' market');
1318
+ }
1314
1319
  //
1315
1320
  // spot
1316
1321
  //
@@ -3568,11 +3573,6 @@ export default class bitget extends Exchange {
3568
3573
  if (!isStopOrder && !isTriggerOrder) {
3569
3574
  throw new InvalidOrder(this.id + ' editOrder() only support plan orders');
3570
3575
  }
3571
- let method = this.getSupportedMapping(marketType, {
3572
- 'spot': 'privateSpotPostPlanModifyPlan',
3573
- 'swap': 'privateMixPostPlanModifyPlan',
3574
- 'future': 'privateMixPostPlanModifyPlan',
3575
- });
3576
3576
  if (triggerPrice !== undefined) {
3577
3577
  // default triggerType to market price for unification
3578
3578
  const triggerType = this.safeString(params, 'triggerType', 'market_price');
@@ -3580,6 +3580,8 @@ export default class bitget extends Exchange {
3580
3580
  request['triggerPrice'] = this.priceToPrecision(symbol, triggerPrice);
3581
3581
  request['executePrice'] = this.priceToPrecision(symbol, price);
3582
3582
  }
3583
+ const omitted = this.omit(query, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice']);
3584
+ let response = undefined;
3583
3585
  if (marketType === 'spot') {
3584
3586
  if (isStopOrder) {
3585
3587
  throw new InvalidOrder(this.id + ' editOrder() does not support stop orders on spot markets, only swap markets');
@@ -3599,10 +3601,15 @@ export default class bitget extends Exchange {
3599
3601
  else {
3600
3602
  request['size'] = this.amountToPrecision(symbol, amount);
3601
3603
  }
3604
+ response = await this.privateSpotPostPlanModifyPlan(this.extend(request, omitted));
3602
3605
  }
3603
3606
  else {
3604
3607
  request['symbol'] = market['id'];
3605
3608
  request['size'] = this.amountToPrecision(symbol, amount);
3609
+ if ((marketType !== 'swap') && (marketType !== 'future')) {
3610
+ throw new NotSupported(this.id + ' editOrder() does not support ' + marketType + ' market');
3611
+ }
3612
+ request['marginCoin'] = market['settleId'];
3606
3613
  if (isStopOrder) {
3607
3614
  if (!isMarketOrder) {
3608
3615
  throw new ExchangeError(this.id + ' editOrder() bitget stopLoss or takeProfit orders must be market orders');
@@ -3615,12 +3622,12 @@ export default class bitget extends Exchange {
3615
3622
  request['triggerPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
3616
3623
  request['planType'] = 'profit_plan';
3617
3624
  }
3618
- method = 'privateMixPostPlanModifyTPSLPlan';
3625
+ response = await this.privateMixPostPlanModifyTPSLPlan(this.extend(request, omitted));
3626
+ }
3627
+ else {
3628
+ response = await this.privateMixPostPlanModifyPlan(this.extend(request, omitted));
3619
3629
  }
3620
- request['marginCoin'] = market['settleId'];
3621
3630
  }
3622
- const omitted = this.omit(query, ['stopPrice', 'triggerType', 'stopLossPrice', 'takeProfitPrice']);
3623
- const response = await this[method](this.extend(request, omitted));
3624
3631
  //
3625
3632
  // spot
3626
3633
  // {
@@ -3950,16 +3957,20 @@ export default class bitget extends Exchange {
3950
3957
  await this.loadMarkets();
3951
3958
  const market = this.market(symbol);
3952
3959
  const [marketType, query] = this.handleMarketTypeAndParams('fetchOrder', market, params);
3953
- const method = this.getSupportedMapping(marketType, {
3954
- 'spot': 'privateSpotPostTradeOrderInfo',
3955
- 'swap': 'privateMixGetOrderDetail',
3956
- 'future': 'privateMixGetOrderDetail',
3957
- });
3958
3960
  const request = {
3959
3961
  'symbol': market['id'],
3960
3962
  'orderId': id,
3961
3963
  };
3962
- let response = await this[method](this.extend(request, query));
3964
+ let response = undefined;
3965
+ if (marketType === 'spot') {
3966
+ response = await this.privateSpotPostTradeOrderInfo(this.extend(request, query));
3967
+ }
3968
+ else if ((marketType === 'swap') || (marketType === 'future')) {
3969
+ response = await this.privateMixGetOrderDetail(this.extend(request, query));
3970
+ }
3971
+ else {
3972
+ throw new NotSupported(this.id + ' fetchOrder() does not support ' + marketType + ' market');
3973
+ }
3963
3974
  // spot
3964
3975
  // {
3965
3976
  // code: '00000',
@@ -4885,16 +4896,20 @@ export default class bitget extends Exchange {
4885
4896
  await this.loadMarkets();
4886
4897
  const market = this.market(symbol);
4887
4898
  const [marketType, query] = this.handleMarketTypeAndParams('fetchOrderTrades', market, params);
4888
- const method = this.getSupportedMapping(marketType, {
4889
- 'spot': 'privateSpotPostTradeFills',
4890
- 'swap': 'privateMixGetOrderFills',
4891
- 'future': 'privateMixGetOrderFills',
4892
- });
4893
4899
  const request = {
4894
4900
  'symbol': market['id'],
4895
4901
  'orderId': id,
4896
4902
  };
4897
- const response = await this[method](this.extend(request, query));
4903
+ let response = undefined;
4904
+ if (marketType === 'spot') {
4905
+ response = await this.privateSpotPostTradeFills(this.extend(request, query));
4906
+ }
4907
+ else if ((marketType === 'swap') || (marketType === 'future')) {
4908
+ response = await this.privateMixGetOrderFills(this.extend(request, query));
4909
+ }
4910
+ else {
4911
+ throw new NotSupported(this.id + ' fetchOrderTrades() does not support ' + marketType + ' market');
4912
+ }
4898
4913
  // spot
4899
4914
  //
4900
4915
  // swap
@@ -5358,7 +5373,7 @@ export default class bitget extends Exchange {
5358
5373
  'previousFundingDatetime': undefined,
5359
5374
  };
5360
5375
  }
5361
- async fetchFundingHistory(symbol, since = undefined, limit = undefined, params = {}) {
5376
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
5362
5377
  /**
5363
5378
  * @method
5364
5379
  * @name bitget#fetchFundingHistory
@@ -5371,6 +5386,7 @@ export default class bitget extends Exchange {
5371
5386
  * @returns {object[]} a list of [funding history structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#funding-history-structure}
5372
5387
  */
5373
5388
  await this.loadMarkets();
5389
+ this.checkRequiredSymbol('fetchFundingHistory', symbol);
5374
5390
  const market = this.market(symbol);
5375
5391
  if (!market['swap']) {
5376
5392
  throw new BadSymbol(this.id + ' fetchFundingHistory() supports swap contracts only');