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.

[OKX PERP Swaps]: Cannot set leverage in the code.

See original GitHub issue

I am trying to set leverage=1 for all perp swaps in the code. However, when I ran the code, the position is always opened with default leverage setting. It seems I can only manually set leverage in web browser.

Someone raised a similar question , but I dont think it has been answered properly.

OS: Mac OS Programming Language version: Python CCXT version: 1.84.70

exchange = ccxt.okx({
    'subName' : config.OKX_SUB_NAME,
    'apiKey': config.OKX_API_KEY,
    'secret': config.OKX_API_SECRET,
    'password': config.OKX_PASS_PHRASE,
    "options": {'defaultType': 'swap'}
})
markets = exchange.load_markets()


qty = 10
inst = 'CHZ/USDT:USDT'
params = {"mgnMode" : "isolated", "posSide": "net" }
exchange.set_leverage(1, inst, params)
order = exchange.create_order(inst, type='market', side='sell', amount=qty)

Then I can see ‘CHZ/USDT:USDT’ short position opened with 2X leverage. Can anyone advise ? Thanks

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
YuxinSUN89commented, Nov 27, 2022

@carlosmiei Thank you for solving my question !

1reaction
carlosmieicommented, Nov 27, 2022

Hello @YuxinSUN89 in the screenshot I see a cross margin position, but your code sets the leverage for the isolated mode. I think that might be the problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I. Perpetual swaps – Help center - OKX
Traders can take a long/short position on cryptocurrencies with up to 125x leverage to make a profit when the price goes up/down.
Read more >
How to trade perpetual swaps on OKX
Step 4: Choose the type of leverage for swap trading. After funding your swaps account, you can select the margin mode (either “Isolated”...
Read more >
Overview – OKX API guide | OKX technical support
Welcome to the OKX API guide, OKEx technical support. OKX is a leading BTC exchange with highly secure SSL encryption and cold storage...
Read more >
II. What is margin in Perpetual swaps? – Help center - OKX
Isolated Margin is the margin balance allocated to an individual position, allowing traders to manage their risk on each position. For crypto- ...
Read more >
OKX's solution for spot, margin and perpetual swap ...
So far, OKX supports spot, margin, and perpetual swap trading — as well ... the actual leverage multiples or closing positions in advance....
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