question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug wih opening position on MEXC Futures

See original GitHub issue

THIS

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:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
KindSpideycommented, May 18, 2022

Thank you very much, it works

1reaction
KindSpideycommented, May 18, 2022

thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial: Futures Trading on the MEXC Application
You may open a short position by selling contracts in anticipation of a market downturn. Here's how you can trade Futures on MEXC....
Read more >
How to View Positions and Funds in Futures Account - MEXC
You can view your current position information below the futures trading interface, such as the current position, estimated liquidation price, ...
Read more >
Learn & Earn. Season 2. Futures Trading - MEXC Blog
In this video our YouTube Host Mark will guide you through principles of futures trading, how to perform such orders and what MEXC...
Read more >
How to View Positions and Funds in Futures Account
MEXC Learn solely provides information, but not financial advice. You should ensure that you fully understand the risk involved before investing ...
Read more >
1006786 - Harassment and signal squelchening Description
Description is a hacker and stalker. She has stalked me for at least 12 years. She has hacked me for at least 10...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found