ccxt 4.1.89 → 4.1.91
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.
- package/README.md +3 -3
- package/dist/ccxt.browser.js +936 -358
- package/dist/ccxt.browser.min.js +3 -3
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/base/Exchange.js +2 -2
- package/dist/cjs/src/binance.js +61 -0
- package/dist/cjs/src/bitforex.js +2 -0
- package/dist/cjs/src/bitget.js +11 -4
- package/dist/cjs/src/bitmex.js +2 -0
- package/dist/cjs/src/blockchaincom.js +0 -41
- package/dist/cjs/src/bybit.js +29 -14
- package/dist/cjs/src/coinlist.js +2 -0
- package/dist/cjs/src/coinsph.js +2 -0
- package/dist/cjs/src/cryptocom.js +2 -0
- package/dist/cjs/src/gate.js +276 -11
- package/dist/cjs/src/htx.js +264 -219
- package/dist/cjs/src/kucoin.js +1 -0
- package/dist/cjs/src/kucoinfutures.js +37 -0
- package/dist/cjs/src/kuna.js +2 -0
- package/dist/cjs/src/mexc.js +2 -0
- package/dist/cjs/src/okcoin.js +4 -1
- package/dist/cjs/src/phemex.js +160 -26
- package/dist/cjs/src/poloniex.js +28 -2
- package/dist/cjs/src/pro/binance.js +6 -6
- package/dist/cjs/src/pro/bitmart.js +19 -18
- package/dist/cjs/src/pro/poloniex.js +15 -10
- package/dist/cjs/src/tokocrypto.js +2 -0
- package/dist/cjs/src/wazirx.js +2 -0
- package/dist/cjs/src/whitebit.js +2 -0
- package/dist/cjs/src/zaif.js +2 -3
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/base/Exchange.js +2 -2
- package/js/src/binance.d.ts +3 -0
- package/js/src/binance.js +61 -0
- package/js/src/bitforex.js +2 -0
- package/js/src/bitget.js +11 -4
- package/js/src/bitmex.js +2 -0
- package/js/src/blockchaincom.d.ts +0 -2
- package/js/src/blockchaincom.js +0 -41
- package/js/src/bybit.js +29 -14
- package/js/src/coinlist.js +2 -0
- package/js/src/coinsph.js +2 -0
- package/js/src/cryptocom.js +2 -0
- package/js/src/gate.d.ts +47 -0
- package/js/src/gate.js +276 -11
- package/js/src/htx.js +264 -219
- package/js/src/kucoin.js +1 -0
- package/js/src/kucoinfutures.d.ts +1 -0
- package/js/src/kucoinfutures.js +37 -0
- package/js/src/kuna.js +2 -0
- package/js/src/mexc.js +2 -0
- package/js/src/okcoin.js +4 -1
- package/js/src/phemex.d.ts +1 -0
- package/js/src/phemex.js +160 -26
- package/js/src/poloniex.js +28 -2
- package/js/src/pro/binance.js +6 -6
- package/js/src/pro/bitmart.d.ts +1 -1
- package/js/src/pro/bitmart.js +19 -18
- package/js/src/pro/poloniex.js +16 -11
- package/js/src/tokocrypto.js +2 -0
- package/js/src/wazirx.js +2 -0
- package/js/src/whitebit.js +2 -0
- package/js/src/zaif.js +2 -3
- package/package.json +1 -1
package/dist/cjs/ccxt.js
CHANGED
|
@@ -168,7 +168,7 @@ var woo$1 = require('./src/pro/woo.js');
|
|
|
168
168
|
|
|
169
169
|
//-----------------------------------------------------------------------------
|
|
170
170
|
// this is updated by vss.js when building
|
|
171
|
-
const version = '4.1.
|
|
171
|
+
const version = '4.1.91';
|
|
172
172
|
Exchange["default"].ccxtVersion = version;
|
|
173
173
|
const exchanges = {
|
|
174
174
|
'ace': ace,
|
|
@@ -3697,7 +3697,7 @@ class Exchange {
|
|
|
3697
3697
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
3698
3698
|
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
3699
3699
|
*/
|
|
3700
|
-
if (this.
|
|
3700
|
+
if (this.has['createMarketOrderWithCost'] || (this.has['createMarketBuyOrderWithCost'] && this.has['createMarketSellOrderWithCost'])) {
|
|
3701
3701
|
return await this.createOrder(symbol, 'market', side, cost, 1, params);
|
|
3702
3702
|
}
|
|
3703
3703
|
throw new errors.NotSupported(this.id + ' createMarketOrderWithCost() is not supported yet');
|
|
@@ -3712,7 +3712,7 @@ class Exchange {
|
|
|
3712
3712
|
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
3713
3713
|
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
3714
3714
|
*/
|
|
3715
|
-
if (this.options['createMarketBuyOrderRequiresPrice'] || this.
|
|
3715
|
+
if (this.options['createMarketBuyOrderRequiresPrice'] || this.has['createMarketBuyOrderWithCost']) {
|
|
3716
3716
|
return await this.createOrder(symbol, 'market', 'buy', cost, 1, params);
|
|
3717
3717
|
}
|
|
3718
3718
|
throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() is not supported yet');
|
package/dist/cjs/src/binance.js
CHANGED
|
@@ -41,6 +41,9 @@ class binance extends binance$1 {
|
|
|
41
41
|
'closeAllPositions': false,
|
|
42
42
|
'closePosition': false,
|
|
43
43
|
'createDepositAddress': false,
|
|
44
|
+
'createMarketBuyOrderWithCost': true,
|
|
45
|
+
'createMarketOrderWithCost': true,
|
|
46
|
+
'createMarketSellOrderWithCost': true,
|
|
44
47
|
'createOrder': true,
|
|
45
48
|
'createOrders': true,
|
|
46
49
|
'createPostOnlyOrder': true,
|
|
@@ -4654,6 +4657,64 @@ class binance extends binance$1 {
|
|
|
4654
4657
|
const requestParams = this.omit(params, ['quoteOrderQty', 'cost', 'stopPrice', 'test', 'type', 'newClientOrderId', 'clientOrderId', 'postOnly']);
|
|
4655
4658
|
return this.extend(request, requestParams);
|
|
4656
4659
|
}
|
|
4660
|
+
async createMarketOrderWithCost(symbol, side, cost, params = {}) {
|
|
4661
|
+
/**
|
|
4662
|
+
* @method
|
|
4663
|
+
* @name binance#createMarketOrderWithCost
|
|
4664
|
+
* @description create a market order by providing the symbol, side and cost
|
|
4665
|
+
* @see https://binance-docs.github.io/apidocs/spot/en/#new-order-trade
|
|
4666
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
4667
|
+
* @param {string} side 'buy' or 'sell'
|
|
4668
|
+
* @param {float} cost how much you want to trade in units of the quote currency
|
|
4669
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4670
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
4671
|
+
*/
|
|
4672
|
+
await this.loadMarkets();
|
|
4673
|
+
const market = this.market(symbol);
|
|
4674
|
+
if (!market['spot']) {
|
|
4675
|
+
throw new errors.NotSupported(this.id + ' createMarketOrderWithCost() supports spot orders only');
|
|
4676
|
+
}
|
|
4677
|
+
params['quoteOrderQty'] = cost;
|
|
4678
|
+
return await this.createOrder(symbol, 'market', side, cost, undefined, params);
|
|
4679
|
+
}
|
|
4680
|
+
async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
|
|
4681
|
+
/**
|
|
4682
|
+
* @method
|
|
4683
|
+
* @name binance#createMarketBuyOrderWithCost
|
|
4684
|
+
* @description create a market buy order by providing the symbol and cost
|
|
4685
|
+
* @see https://binance-docs.github.io/apidocs/spot/en/#new-order-trade
|
|
4686
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
4687
|
+
* @param {float} cost how much you want to trade in units of the quote currency
|
|
4688
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4689
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
4690
|
+
*/
|
|
4691
|
+
await this.loadMarkets();
|
|
4692
|
+
const market = this.market(symbol);
|
|
4693
|
+
if (!market['spot']) {
|
|
4694
|
+
throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
|
|
4695
|
+
}
|
|
4696
|
+
params['quoteOrderQty'] = cost;
|
|
4697
|
+
return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
|
|
4698
|
+
}
|
|
4699
|
+
async createMarketSellOrderWithCost(symbol, cost, params = {}) {
|
|
4700
|
+
/**
|
|
4701
|
+
* @method
|
|
4702
|
+
* @name binance#createMarketSellOrderWithCost
|
|
4703
|
+
* @description create a market sell order by providing the symbol and cost
|
|
4704
|
+
* @see https://binance-docs.github.io/apidocs/spot/en/#new-order-trade
|
|
4705
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
4706
|
+
* @param {float} cost how much you want to trade in units of the quote currency
|
|
4707
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4708
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
4709
|
+
*/
|
|
4710
|
+
await this.loadMarkets();
|
|
4711
|
+
const market = this.market(symbol);
|
|
4712
|
+
if (!market['spot']) {
|
|
4713
|
+
throw new errors.NotSupported(this.id + ' createMarketSellOrderWithCost() supports spot orders only');
|
|
4714
|
+
}
|
|
4715
|
+
params['quoteOrderQty'] = cost;
|
|
4716
|
+
return await this.createOrder(symbol, 'market', 'sell', cost, undefined, params);
|
|
4717
|
+
}
|
|
4657
4718
|
async fetchOrder(id, symbol = undefined, params = {}) {
|
|
4658
4719
|
/**
|
|
4659
4720
|
* @method
|
package/dist/cjs/src/bitforex.js
CHANGED
package/dist/cjs/src/bitget.js
CHANGED
|
@@ -3855,7 +3855,7 @@ class bitget extends bitget$1 {
|
|
|
3855
3855
|
if (feeCostString !== undefined) {
|
|
3856
3856
|
// swap
|
|
3857
3857
|
fee = {
|
|
3858
|
-
'cost': feeCostString,
|
|
3858
|
+
'cost': this.parseNumber(Precise["default"].stringAbs(feeCostString)),
|
|
3859
3859
|
'currency': market['settle'],
|
|
3860
3860
|
};
|
|
3861
3861
|
}
|
|
@@ -3863,10 +3863,17 @@ class bitget extends bitget$1 {
|
|
|
3863
3863
|
if (feeDetail !== undefined) {
|
|
3864
3864
|
const parsedFeeDetail = JSON.parse(feeDetail);
|
|
3865
3865
|
const feeValues = Object.values(parsedFeeDetail);
|
|
3866
|
-
|
|
3866
|
+
let feeObject = undefined;
|
|
3867
|
+
for (let i = 0; i < feeValues.length; i++) {
|
|
3868
|
+
const feeValue = feeValues[i];
|
|
3869
|
+
if (this.safeValue(feeValue, 'feeCoinCode') !== undefined) {
|
|
3870
|
+
feeObject = feeValue;
|
|
3871
|
+
break;
|
|
3872
|
+
}
|
|
3873
|
+
}
|
|
3867
3874
|
fee = {
|
|
3868
|
-
'cost': this.safeString(
|
|
3869
|
-
'currency': this.safeCurrencyCode(this.safeString(
|
|
3875
|
+
'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString(feeObject, 'totalFee'))),
|
|
3876
|
+
'currency': this.safeCurrencyCode(this.safeString(feeObject, 'feeCoinCode')),
|
|
3870
3877
|
};
|
|
3871
3878
|
}
|
|
3872
3879
|
let postOnly = undefined;
|
package/dist/cjs/src/bitmex.js
CHANGED
|
@@ -906,47 +906,6 @@ class blockchaincom extends blockchaincom$1 {
|
|
|
906
906
|
'fee': fee,
|
|
907
907
|
};
|
|
908
908
|
}
|
|
909
|
-
async fetchWithdrawalWhitelist(params = {}) {
|
|
910
|
-
/**
|
|
911
|
-
* @method
|
|
912
|
-
* @name blockchaincom#fetchWithdrawalWhitelist
|
|
913
|
-
* @description fetch the list of withdrawal addresses on the whitelist
|
|
914
|
-
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
915
|
-
* @returns {object} dictionary with keys beneficiaryId, name, currency
|
|
916
|
-
*/
|
|
917
|
-
await this.loadMarkets();
|
|
918
|
-
const response = await this.privateGetWhitelist();
|
|
919
|
-
const result = [];
|
|
920
|
-
for (let i = 0; i < response.length; i++) {
|
|
921
|
-
const entry = response[i];
|
|
922
|
-
result.push({
|
|
923
|
-
'beneficiaryId': this.safeString(entry, 'whitelistId'),
|
|
924
|
-
'name': this.safeString(entry, 'name'),
|
|
925
|
-
'currency': this.safeString(entry, 'currency'),
|
|
926
|
-
'info': entry,
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
return result;
|
|
930
|
-
}
|
|
931
|
-
async fetchWithdrawalWhitelistByCurrency(code, params = {}) {
|
|
932
|
-
await this.loadMarkets();
|
|
933
|
-
const currency = this.currency(code);
|
|
934
|
-
const request = {
|
|
935
|
-
'currency': currency['id'],
|
|
936
|
-
};
|
|
937
|
-
const response = await this.privateGetWhitelistCurrency(this.extend(request, params));
|
|
938
|
-
const result = [];
|
|
939
|
-
for (let i = 0; i < response.length; i++) {
|
|
940
|
-
const entry = response[i];
|
|
941
|
-
result.push({
|
|
942
|
-
'beneficiaryId': this.safeString(entry, 'whitelistId'),
|
|
943
|
-
'name': this.safeString(entry, 'name'),
|
|
944
|
-
'currency': this.safeString(entry, 'currency'),
|
|
945
|
-
'info': entry,
|
|
946
|
-
});
|
|
947
|
-
}
|
|
948
|
-
return result;
|
|
949
|
-
}
|
|
950
909
|
async withdraw(code, amount, address, tag = undefined, params = {}) {
|
|
951
910
|
/**
|
|
952
911
|
* @method
|
package/dist/cjs/src/bybit.js
CHANGED
|
@@ -944,6 +944,7 @@ class bybit extends bybit$1 {
|
|
|
944
944
|
},
|
|
945
945
|
'precisionMode': number.TICK_SIZE,
|
|
946
946
|
'options': {
|
|
947
|
+
'fetchMarkets': ['spot', 'linear', 'inverse', 'option'],
|
|
947
948
|
'enableUnifiedMargin': undefined,
|
|
948
949
|
'enableUnifiedAccount': undefined,
|
|
949
950
|
'createMarketBuyOrderRequiresPrice': true,
|
|
@@ -1449,21 +1450,35 @@ class bybit extends bybit$1 {
|
|
|
1449
1450
|
if (this.options['adjustForTimeDifference']) {
|
|
1450
1451
|
await this.loadTimeDifference();
|
|
1451
1452
|
}
|
|
1452
|
-
const promisesUnresolved = [
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1453
|
+
const promisesUnresolved = [];
|
|
1454
|
+
const fetchMarkets = this.safeValue(this.options, 'fetchMarkets', ['spot', 'linear', 'inverse']);
|
|
1455
|
+
for (let i = 0; i < fetchMarkets.length; i++) {
|
|
1456
|
+
const marketType = fetchMarkets[i];
|
|
1457
|
+
if (marketType === 'spot') {
|
|
1458
|
+
promisesUnresolved.push(this.fetchSpotMarkets(params));
|
|
1459
|
+
}
|
|
1460
|
+
else if (marketType === 'linear') {
|
|
1461
|
+
promisesUnresolved.push(this.fetchFutureMarkets({ 'category': 'linear' }));
|
|
1462
|
+
}
|
|
1463
|
+
else if (marketType === 'inverse') {
|
|
1464
|
+
promisesUnresolved.push(this.fetchFutureMarkets({ 'category': 'inverse' }));
|
|
1465
|
+
}
|
|
1466
|
+
else if (marketType === 'option') {
|
|
1467
|
+
promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'BTC' }));
|
|
1468
|
+
promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'ETH' }));
|
|
1469
|
+
promisesUnresolved.push(this.fetchOptionMarkets({ 'baseCoin': 'SOL' }));
|
|
1470
|
+
}
|
|
1471
|
+
else {
|
|
1472
|
+
throw new errors.ExchangeError(this.id + ' fetchMarkets() this.options fetchMarkets "' + marketType + '" is not a supported market type');
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1460
1475
|
const promises = await Promise.all(promisesUnresolved);
|
|
1461
|
-
const spotMarkets = promises[
|
|
1462
|
-
const linearMarkets = promises[
|
|
1463
|
-
const inverseMarkets = promises[
|
|
1464
|
-
const btcOptionMarkets = promises[
|
|
1465
|
-
const ethOptionMarkets = promises[
|
|
1466
|
-
const solOptionMarkets = promises[
|
|
1476
|
+
const spotMarkets = this.safeValue(promises, 0, []);
|
|
1477
|
+
const linearMarkets = this.safeValue(promises, 1, []);
|
|
1478
|
+
const inverseMarkets = this.safeValue(promises, 2, []);
|
|
1479
|
+
const btcOptionMarkets = this.safeValue(promises, 3, []);
|
|
1480
|
+
const ethOptionMarkets = this.safeValue(promises, 4, []);
|
|
1481
|
+
const solOptionMarkets = this.safeValue(promises, 5, []);
|
|
1467
1482
|
const futureMarkets = this.arrayConcat(linearMarkets, inverseMarkets);
|
|
1468
1483
|
let optionMarkets = this.arrayConcat(btcOptionMarkets, ethOptionMarkets);
|
|
1469
1484
|
optionMarkets = this.arrayConcat(optionMarkets, solOptionMarkets);
|
package/dist/cjs/src/coinlist.js
CHANGED
|
@@ -106,6 +106,8 @@ class coinlist extends coinlist$1 {
|
|
|
106
106
|
'fetchWithdrawals': false,
|
|
107
107
|
'fetchWithdrawalWhitelist': false,
|
|
108
108
|
'reduceMargin': false,
|
|
109
|
+
'repayCrossMargin': false,
|
|
110
|
+
'repayIsolatedMargin': false,
|
|
109
111
|
'setLeverage': false,
|
|
110
112
|
'setMargin': false,
|
|
111
113
|
'setMarginMode': false,
|
package/dist/cjs/src/coinsph.js
CHANGED
|
@@ -108,6 +108,8 @@ class coinsph extends coinsph$1 {
|
|
|
108
108
|
'fetchWithdrawals': true,
|
|
109
109
|
'fetchWithdrawalWhitelist': false,
|
|
110
110
|
'reduceMargin': false,
|
|
111
|
+
'repayCrossMargin': false,
|
|
112
|
+
'repayIsolatedMargin': false,
|
|
111
113
|
'setLeverage': false,
|
|
112
114
|
'setMargin': false,
|
|
113
115
|
'setMarginMode': false,
|
|
@@ -96,6 +96,8 @@ class cryptocom extends cryptocom$1 {
|
|
|
96
96
|
'fetchVolatilityHistory': false,
|
|
97
97
|
'fetchWithdrawals': true,
|
|
98
98
|
'reduceMargin': false,
|
|
99
|
+
'repayCrossMargin': false,
|
|
100
|
+
'repayIsolatedMargin': false,
|
|
99
101
|
'setLeverage': false,
|
|
100
102
|
'setMarginMode': false,
|
|
101
103
|
'setPositionMode': false,
|
package/dist/cjs/src/gate.js
CHANGED
|
@@ -76,9 +76,14 @@ class gate extends gate$1 {
|
|
|
76
76
|
'future': true,
|
|
77
77
|
'option': true,
|
|
78
78
|
'addMargin': true,
|
|
79
|
+
'borrowCrossMargin': true,
|
|
80
|
+
'borrowIsolatedMargin': true,
|
|
79
81
|
'cancelAllOrders': true,
|
|
80
82
|
'cancelOrder': true,
|
|
83
|
+
'createMarketBuyOrderWithCost': true,
|
|
81
84
|
'createMarketOrder': true,
|
|
85
|
+
'createMarketOrderWithCost': false,
|
|
86
|
+
'createMarketSellOrderWithCost': false,
|
|
82
87
|
'createOrder': true,
|
|
83
88
|
'createOrders': true,
|
|
84
89
|
'createPostOnlyOrder': true,
|
|
@@ -140,6 +145,8 @@ class gate extends gate$1 {
|
|
|
140
145
|
'fetchVolatilityHistory': false,
|
|
141
146
|
'fetchWithdrawals': true,
|
|
142
147
|
'reduceMargin': true,
|
|
148
|
+
'repayCrossMargin': true,
|
|
149
|
+
'repayIsolatedMargin': true,
|
|
143
150
|
'setLeverage': true,
|
|
144
151
|
'setMarginMode': false,
|
|
145
152
|
'setPositionMode': true,
|
|
@@ -3758,6 +3765,7 @@ class gate extends gate$1 {
|
|
|
3758
3765
|
* @param {bool} [params.close] *contract only* Set as true to close the position, with size set to 0
|
|
3759
3766
|
* @param {bool} [params.auto_size] *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
|
|
3760
3767
|
* @param {int} [params.price_type] *contract only* 0 latest deal price, 1 mark price, 2 index price
|
|
3768
|
+
* @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
|
|
3761
3769
|
* @returns {object|undefined} [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
3762
3770
|
*/
|
|
3763
3771
|
await this.loadMarkets();
|
|
@@ -3955,9 +3963,15 @@ class gate extends gate$1 {
|
|
|
3955
3963
|
}
|
|
3956
3964
|
}
|
|
3957
3965
|
if (contract) {
|
|
3958
|
-
const
|
|
3959
|
-
|
|
3960
|
-
|
|
3966
|
+
const isClose = this.safeValue(params, 'close');
|
|
3967
|
+
if (isClose) {
|
|
3968
|
+
amount = 0;
|
|
3969
|
+
}
|
|
3970
|
+
else {
|
|
3971
|
+
const amountToPrecision = this.amountToPrecision(symbol, amount);
|
|
3972
|
+
const signedAmount = (side === 'sell') ? Precise["default"].stringNeg(amountToPrecision) : amountToPrecision;
|
|
3973
|
+
amount = parseInt(signedAmount);
|
|
3974
|
+
}
|
|
3961
3975
|
}
|
|
3962
3976
|
let request = undefined;
|
|
3963
3977
|
const nonTriggerOrder = !isStopOrder && (trigger === undefined);
|
|
@@ -4005,24 +4019,30 @@ class gate extends gate$1 {
|
|
|
4005
4019
|
// 'auto_borrow': false, // used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
|
|
4006
4020
|
// 'auto_repay': false, // automatic repayment for automatic borrow loan generated by cross margin order, diabled by default
|
|
4007
4021
|
};
|
|
4008
|
-
const createMarketBuyOrderRequiresPrice = this.safeValue(this.options, 'createMarketBuyOrderRequiresPrice', true);
|
|
4009
4022
|
if (isMarketOrder && (side === 'buy')) {
|
|
4010
|
-
|
|
4023
|
+
let quoteAmount = undefined;
|
|
4024
|
+
let createMarketBuyOrderRequiresPrice = true;
|
|
4025
|
+
[createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
|
|
4026
|
+
const cost = this.safeNumber(params, 'cost');
|
|
4027
|
+
params = this.omit(params, 'cost');
|
|
4028
|
+
if (cost !== undefined) {
|
|
4029
|
+
quoteAmount = this.costToPrecision(symbol, cost);
|
|
4030
|
+
}
|
|
4031
|
+
else if (createMarketBuyOrderRequiresPrice) {
|
|
4011
4032
|
if (price === undefined) {
|
|
4012
|
-
throw new errors.InvalidOrder(this.id + ' createOrder() requires price argument for market buy orders
|
|
4033
|
+
throw new errors.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');
|
|
4013
4034
|
}
|
|
4014
4035
|
else {
|
|
4015
4036
|
const amountString = this.numberToString(amount);
|
|
4016
4037
|
const priceString = this.numberToString(price);
|
|
4017
|
-
const
|
|
4018
|
-
|
|
4038
|
+
const costRequest = Precise["default"].stringMul(amountString, priceString);
|
|
4039
|
+
quoteAmount = this.costToPrecision(symbol, costRequest);
|
|
4019
4040
|
}
|
|
4020
4041
|
}
|
|
4021
4042
|
else {
|
|
4022
|
-
|
|
4023
|
-
params = this.omit(params, 'cost');
|
|
4024
|
-
request['amount'] = this.costToPrecision(symbol, cost);
|
|
4043
|
+
quoteAmount = this.costToPrecision(symbol, amount);
|
|
4025
4044
|
}
|
|
4045
|
+
request['amount'] = quoteAmount;
|
|
4026
4046
|
}
|
|
4027
4047
|
else {
|
|
4028
4048
|
request['amount'] = this.amountToPrecision(symbol, amount);
|
|
@@ -4152,6 +4172,25 @@ class gate extends gate$1 {
|
|
|
4152
4172
|
}
|
|
4153
4173
|
return this.extend(request, params);
|
|
4154
4174
|
}
|
|
4175
|
+
async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
|
|
4176
|
+
/**
|
|
4177
|
+
* @method
|
|
4178
|
+
* @name gate#createMarketBuyOrderWithCost
|
|
4179
|
+
* @description create a market buy order by providing the symbol and cost
|
|
4180
|
+
* @see https://www.gate.io/docs/developers/apiv4/en/#create-an-order
|
|
4181
|
+
* @param {string} symbol unified symbol of the market to create an order in
|
|
4182
|
+
* @param {float} cost how much you want to trade in units of the quote currency
|
|
4183
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
4184
|
+
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
|
|
4185
|
+
*/
|
|
4186
|
+
await this.loadMarkets();
|
|
4187
|
+
const market = this.market(symbol);
|
|
4188
|
+
if (!market['spot']) {
|
|
4189
|
+
throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
|
|
4190
|
+
}
|
|
4191
|
+
params['createMarketBuyOrderRequiresPrice'] = false;
|
|
4192
|
+
return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
|
|
4193
|
+
}
|
|
4155
4194
|
async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
|
|
4156
4195
|
/**
|
|
4157
4196
|
* @method
|
|
@@ -5737,6 +5776,210 @@ class gate extends gate$1 {
|
|
|
5737
5776
|
}
|
|
5738
5777
|
return tiers;
|
|
5739
5778
|
}
|
|
5779
|
+
async repayIsolatedMargin(symbol, code, amount, params = {}) {
|
|
5780
|
+
/**
|
|
5781
|
+
* @method
|
|
5782
|
+
* @name gate#repayMargin
|
|
5783
|
+
* @description repay borrowed margin and interest
|
|
5784
|
+
* @see https://www.gate.io/docs/apiv4/en/#repay-a-loan
|
|
5785
|
+
* @param {string} symbol unified market symbol
|
|
5786
|
+
* @param {string} code unified currency code of the currency to repay
|
|
5787
|
+
* @param {float} amount the amount to repay
|
|
5788
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
5789
|
+
* @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
|
|
5790
|
+
* @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
|
|
5791
|
+
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
|
|
5792
|
+
*/
|
|
5793
|
+
await this.loadMarkets();
|
|
5794
|
+
const currency = this.currency(code);
|
|
5795
|
+
const request = {
|
|
5796
|
+
'currency': currency['id'].toUpperCase(),
|
|
5797
|
+
'amount': this.currencyToPrecision(code, amount),
|
|
5798
|
+
};
|
|
5799
|
+
const market = this.market(symbol);
|
|
5800
|
+
request['currency_pair'] = market['id'];
|
|
5801
|
+
request['type'] = 'repay';
|
|
5802
|
+
const response = await this.privateMarginPostUniLoans(this.extend(request, params));
|
|
5803
|
+
//
|
|
5804
|
+
// empty response
|
|
5805
|
+
//
|
|
5806
|
+
return this.parseMarginLoan(response, currency);
|
|
5807
|
+
}
|
|
5808
|
+
async repayCrossMargin(code, amount, params = {}) {
|
|
5809
|
+
/**
|
|
5810
|
+
* @method
|
|
5811
|
+
* @name gate#repayCrossMargin
|
|
5812
|
+
* @description repay cross margin borrowed margin and interest
|
|
5813
|
+
* @see https://www.gate.io/docs/developers/apiv4/en/#cross-margin-repayments
|
|
5814
|
+
* @param {string} code unified currency code of the currency to repay
|
|
5815
|
+
* @param {float} amount the amount to repay
|
|
5816
|
+
* @param {string} symbol unified market symbol, required for isolated margin
|
|
5817
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
5818
|
+
* @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
|
|
5819
|
+
* @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
|
|
5820
|
+
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
|
|
5821
|
+
*/
|
|
5822
|
+
await this.loadMarkets();
|
|
5823
|
+
const currency = this.currency(code);
|
|
5824
|
+
const request = {
|
|
5825
|
+
'currency': currency['id'].toUpperCase(),
|
|
5826
|
+
'amount': this.currencyToPrecision(code, amount),
|
|
5827
|
+
};
|
|
5828
|
+
let response = await this.privateMarginPostCrossRepayments(this.extend(request, params));
|
|
5829
|
+
//
|
|
5830
|
+
// [
|
|
5831
|
+
// {
|
|
5832
|
+
// "id": "17",
|
|
5833
|
+
// "create_time": 1620381696159,
|
|
5834
|
+
// "update_time": 1620381696159,
|
|
5835
|
+
// "currency": "EOS",
|
|
5836
|
+
// "amount": "110.553635",
|
|
5837
|
+
// "text": "web",
|
|
5838
|
+
// "status": 2,
|
|
5839
|
+
// "repaid": "110.506649705159",
|
|
5840
|
+
// "repaid_interest": "0.046985294841",
|
|
5841
|
+
// "unpaid_interest": "0.0000074393366667"
|
|
5842
|
+
// }
|
|
5843
|
+
// ]
|
|
5844
|
+
//
|
|
5845
|
+
response = this.safeValue(response, 0);
|
|
5846
|
+
return this.parseMarginLoan(response, currency);
|
|
5847
|
+
}
|
|
5848
|
+
async borrowIsolatedMargin(symbol, code, amount, params = {}) {
|
|
5849
|
+
/**
|
|
5850
|
+
* @method
|
|
5851
|
+
* @name gate#borrowMargin
|
|
5852
|
+
* @description create a loan to borrow margin
|
|
5853
|
+
* @see https://www.gate.io/docs/developers/apiv4/en/#marginuni
|
|
5854
|
+
* @param {string} code unified currency code of the currency to borrow
|
|
5855
|
+
* @param {float} amount the amount to borrow
|
|
5856
|
+
* @param {string} symbol unified market symbol, required for isolated margin
|
|
5857
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
5858
|
+
* @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
|
|
5859
|
+
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
|
|
5860
|
+
*/
|
|
5861
|
+
await this.loadMarkets();
|
|
5862
|
+
const currency = this.currency(code);
|
|
5863
|
+
const request = {
|
|
5864
|
+
'currency': currency['id'].toUpperCase(),
|
|
5865
|
+
'amount': this.currencyToPrecision(code, amount),
|
|
5866
|
+
};
|
|
5867
|
+
let response = undefined;
|
|
5868
|
+
const market = this.market(symbol);
|
|
5869
|
+
request['currency_pair'] = market['id'];
|
|
5870
|
+
request['type'] = 'borrow';
|
|
5871
|
+
response = await this.privateMarginPostUniLoans(this.extend(request, params));
|
|
5872
|
+
//
|
|
5873
|
+
// {
|
|
5874
|
+
// "id": "34267567",
|
|
5875
|
+
// "create_time": "1656394778",
|
|
5876
|
+
// "expire_time": "1657258778",
|
|
5877
|
+
// "status": "loaned",
|
|
5878
|
+
// "side": "borrow",
|
|
5879
|
+
// "currency": "USDT",
|
|
5880
|
+
// "rate": "0.0002",
|
|
5881
|
+
// "amount": "100",
|
|
5882
|
+
// "days": 10,
|
|
5883
|
+
// "auto_renew": false,
|
|
5884
|
+
// "currency_pair": "LTC_USDT",
|
|
5885
|
+
// "left": "0",
|
|
5886
|
+
// "repaid": "0",
|
|
5887
|
+
// "paid_interest": "0",
|
|
5888
|
+
// "unpaid_interest": "0.003333333333"
|
|
5889
|
+
// }
|
|
5890
|
+
//
|
|
5891
|
+
return this.parseMarginLoan(response, currency);
|
|
5892
|
+
}
|
|
5893
|
+
async borrowCrossMargin(code, amount, params = {}) {
|
|
5894
|
+
/**
|
|
5895
|
+
* @method
|
|
5896
|
+
* @name gate#borrowMargin
|
|
5897
|
+
* @description create a loan to borrow margin
|
|
5898
|
+
* @see https://www.gate.io/docs/apiv4/en/#create-a-cross-margin-borrow-loan
|
|
5899
|
+
* @param {string} code unified currency code of the currency to borrow
|
|
5900
|
+
* @param {float} amount the amount to borrow
|
|
5901
|
+
* @param {string} symbol unified market symbol, required for isolated margin
|
|
5902
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
5903
|
+
* @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
|
|
5904
|
+
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
|
|
5905
|
+
*/
|
|
5906
|
+
await this.loadMarkets();
|
|
5907
|
+
const currency = this.currency(code);
|
|
5908
|
+
const request = {
|
|
5909
|
+
'currency': currency['id'].toUpperCase(),
|
|
5910
|
+
'amount': this.currencyToPrecision(code, amount),
|
|
5911
|
+
};
|
|
5912
|
+
const response = await this.privateMarginPostCrossLoans(this.extend(request, params));
|
|
5913
|
+
//
|
|
5914
|
+
// {
|
|
5915
|
+
// "id": "17",
|
|
5916
|
+
// "create_time": 1620381696159,
|
|
5917
|
+
// "update_time": 1620381696159,
|
|
5918
|
+
// "currency": "EOS",
|
|
5919
|
+
// "amount": "110.553635",
|
|
5920
|
+
// "text": "web",
|
|
5921
|
+
// "status": 2,
|
|
5922
|
+
// "repaid": "110.506649705159",
|
|
5923
|
+
// "repaid_interest": "0.046985294841",
|
|
5924
|
+
// "unpaid_interest": "0.0000074393366667"
|
|
5925
|
+
// }
|
|
5926
|
+
//
|
|
5927
|
+
return this.parseMarginLoan(response, currency);
|
|
5928
|
+
}
|
|
5929
|
+
parseMarginLoan(info, currency = undefined) {
|
|
5930
|
+
//
|
|
5931
|
+
// Cross
|
|
5932
|
+
//
|
|
5933
|
+
// {
|
|
5934
|
+
// "id": "17",
|
|
5935
|
+
// "create_time": 1620381696159,
|
|
5936
|
+
// "update_time": 1620381696159,
|
|
5937
|
+
// "currency": "EOS",
|
|
5938
|
+
// "amount": "110.553635",
|
|
5939
|
+
// "text": "web",
|
|
5940
|
+
// "status": 2,
|
|
5941
|
+
// "repaid": "110.506649705159",
|
|
5942
|
+
// "repaid_interest": "0.046985294841",
|
|
5943
|
+
// "unpaid_interest": "0.0000074393366667"
|
|
5944
|
+
// }
|
|
5945
|
+
//
|
|
5946
|
+
// Isolated
|
|
5947
|
+
//
|
|
5948
|
+
// {
|
|
5949
|
+
// "id": "34267567",
|
|
5950
|
+
// "create_time": "1656394778",
|
|
5951
|
+
// "expire_time": "1657258778",
|
|
5952
|
+
// "status": "loaned",
|
|
5953
|
+
// "side": "borrow",
|
|
5954
|
+
// "currency": "USDT",
|
|
5955
|
+
// "rate": "0.0002",
|
|
5956
|
+
// "amount": "100",
|
|
5957
|
+
// "days": 10,
|
|
5958
|
+
// "auto_renew": false,
|
|
5959
|
+
// "currency_pair": "LTC_USDT",
|
|
5960
|
+
// "left": "0",
|
|
5961
|
+
// "repaid": "0",
|
|
5962
|
+
// "paid_interest": "0",
|
|
5963
|
+
// "unpaid_interest": "0.003333333333"
|
|
5964
|
+
// }
|
|
5965
|
+
//
|
|
5966
|
+
const marginMode = this.safeString2(this.options, 'defaultMarginMode', 'marginMode', 'cross');
|
|
5967
|
+
let timestamp = this.safeInteger(info, 'create_time');
|
|
5968
|
+
if (marginMode === 'isolated') {
|
|
5969
|
+
timestamp = this.safeTimestamp(info, 'create_time');
|
|
5970
|
+
}
|
|
5971
|
+
const currencyId = this.safeString(info, 'currency');
|
|
5972
|
+
const marketId = this.safeString(info, 'currency_pair');
|
|
5973
|
+
return {
|
|
5974
|
+
'id': this.safeInteger(info, 'id'),
|
|
5975
|
+
'currency': this.safeCurrencyCode(currencyId, currency),
|
|
5976
|
+
'amount': this.safeNumber(info, 'amount'),
|
|
5977
|
+
'symbol': this.safeSymbol(marketId, undefined, '_', 'margin'),
|
|
5978
|
+
'timestamp': timestamp,
|
|
5979
|
+
'datetime': this.iso8601(timestamp),
|
|
5980
|
+
'info': info,
|
|
5981
|
+
};
|
|
5982
|
+
}
|
|
5740
5983
|
sign(path, api = [], method = 'GET', params = {}, headers = undefined, body = undefined) {
|
|
5741
5984
|
const authentication = api[0]; // public, private
|
|
5742
5985
|
const type = api[1]; // spot, margin, future, delivery
|
|
@@ -6746,6 +6989,28 @@ class gate extends gate$1 {
|
|
|
6746
6989
|
'info': greeks,
|
|
6747
6990
|
};
|
|
6748
6991
|
}
|
|
6992
|
+
async closePosition(symbol, side = undefined, params = {}) {
|
|
6993
|
+
/**
|
|
6994
|
+
* @method
|
|
6995
|
+
* @name gate#closePositions
|
|
6996
|
+
* @description closes open positions for a market
|
|
6997
|
+
* @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order
|
|
6998
|
+
* @see https://www.gate.io/docs/developers/apiv4/en/#create-a-futures-order-2
|
|
6999
|
+
* @see https://www.gate.io/docs/developers/apiv4/en/#create-an-options-order
|
|
7000
|
+
* @param {string} symbol Unified CCXT market symbol
|
|
7001
|
+
* @param {string} side 'buy' or 'sell'
|
|
7002
|
+
* @param {object} [params] extra parameters specific to the okx api endpoint
|
|
7003
|
+
* @returns {[object]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
|
|
7004
|
+
*/
|
|
7005
|
+
const request = {
|
|
7006
|
+
'close': true,
|
|
7007
|
+
};
|
|
7008
|
+
params = this.extend(request, params);
|
|
7009
|
+
if (side === undefined) {
|
|
7010
|
+
side = ''; // side is not used but needs to be present, otherwise crashes in php
|
|
7011
|
+
}
|
|
7012
|
+
return await this.createOrder(symbol, 'market', side, 0, undefined, params);
|
|
7013
|
+
}
|
|
6749
7014
|
handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
|
|
6750
7015
|
if (response === undefined) {
|
|
6751
7016
|
return undefined;
|