Skip to content

Commit

Permalink
Merge pull request ccxt#12354 from samgermain/gateio-lev fix ccxt#12257
Browse files Browse the repository at this point in the history
ccxt#11756

Gateio.setLeverage cross leverage
  • Loading branch information
kroitor authored Mar 16, 2022
2 parents bf2b970 + dd0bc27 commit 43f864b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions js/gateio.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ module.exports = class gateio extends Exchange {
'delivery': 'delivery',
},
'defaultType': 'spot',
'defaultMarginType': 'isolated',
'swap': {
'fetchMarkets': {
'settlementCurrencies': [ 'usdt', 'btc' ],
Expand Down Expand Up @@ -3334,15 +3335,22 @@ module.exports = class gateio extends Exchange {
'future': 'privateDeliveryPostSettlePositionsContractLeverage',
});
const request = this.prepareRequest (market);
request['query'] = {
'leverage': leverage.toString (),
};
if ('cross_leverage_limit' in params) {
if (leverage !== 0) {
throw new BadRequest (this.id + ' cross margin leverage(valid only when leverage is 0)');
}
request['cross_leverage_limit'] = params['cross_leverage_limit'].toString ();
params = this.omit (params, 'cross_leverage_limit');
const defaultMarginType = this.safeString (this.options, 'marginType', 'defaultMarginType');
const crossLeverageLimit = this.safeString (params, 'cross_leverage_limit');
let marginType = this.safeString (params, 'marginType', defaultMarginType);
if (crossLeverageLimit !== undefined) {
marginType = 'cross';
leverage = crossLeverageLimit;
}
if (marginType === 'cross') {
request['query'] = {
'cross_leverage_limit': leverage.toString (),
'leverage': '0',
};
} else {
request['query'] = {
'leverage': leverage.toString (),
};
}
const response = await this[method] (this.extend (request, params));
//
Expand Down

0 comments on commit 43f864b

Please sign in to comment.