Bug wih opening position on MEXC Futures
See original GitHub issueTHIS
mexc_futures = ccxt.mexc({
"apiKey": config.MEXC_API_KEY,
"secret": config.MEXC_SECRET_KEY,
"options": {'defaultType': 'swap' }
})
symbol = 'LINK/USDT:USDT'
balance = float(mexc_futures.fetch_balance()["USDT"]["free"]) - float(mexc_futures.fetch_balance()["USDT"]["free"])/100*5
price = float(mexc_futures.fetch_ticker("LINK/USDT:USDT")["last"])
leverage = 0
for elem in mexc_futures.fetch_contract_markets():
if elem["symbol"] == "LINK/USDT:USDT":
leverage = int(elem["info"]["maxLeverage"])
amount = (math.floor((balance/price)*10*leverage)*0.98)
params = {'openType': 1, "positionType":1, "leverage": leverage}
mexc_futures.create_swap_order(symbol, 1, 1, amount, price*1.01, params)
gets error
ccxt.base.errors.ExchangeError: mexc {"success":false,"code":2021,"message":"Leverage ratio is inconsistent with the existing position leverage ratio!"}
If i pass params by hand, for example
symbol = 'LINK/USDT:USDT' balance = float(mexc_futures.fetch_balance()["USDT"]["free"]) - float(mexc_futures.fetch_balance()["USDT"]["free"])/100*5 price = float(mexc_futures.fetch_ticker("LINK/USDT:USDT")["last"]) params = {'openType': 1, "positionType":1, "leverage": 50} mexc_futures.create_swap_order(symbol, 1, 1, 2, price*1.01, params)
It will still say to me ccxt.base.errors.ExchangeError: mexc {"success":false,"code":2021,"message":"Leverage ratio is inconsistent with the existing position leverage ratio!"}
Looks like another bug, because this contract HAS 50x leverage, but ccxt doesnt see this
If i try params = {'openType': 1, "positionType":1, "leverage": 1} mexc_futures.create_swap_order(symbol, 1, 1, 3, price*1.01, params)
- it works, with the leverage MORE than 1 - IT DOESNT
params = {'openType': 1, "positionType":1, "leverage": 2}
mexc_futures.create_swap_order(symbol, 1, 1, 3, price*1.01, params)
ccxt.base.errors.ExchangeError: mexc {"success":false,"code":2021,"message":"Leverage ratio is inconsistent with the existing position leverage ratio!"}
My dear sweat devs, who saves me all these days, can you please check it and fix it?
Issue Analytics
- State:
- Created a year ago
- Comments:9 (4 by maintainers)
Thank you very much, it works
thanks!