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.

How to execute Bybit futures trades?

See original GitHub issue

I’m having trouble finding details on how to execute bybit futures trades. Can someone provide some examples of buying/selling longs and shorts on bybit?

I have this code to get into a long position with ‘buy’ and I can get into a short position using ‘sell’, but I don’t know how to close the positions:

exchange_id = 'bybit'
exchange_class = getattr(ccxt, exchange_id)
log.info(f"exchange id: {exchange_id}, api_key: {api_key[:5]}, api_secret: {api_secret[:5]}")
exchange = exchange_class({
    'apiKey': api_key,
    'secret': api_secret,
    'enableRateLimit': True, 
    'options': {
        'defaultType': 'future',
        'adjustForTimeDifference': True
    },
})

# go long
exchange.create_order('BTC/USDT', 'market', 'buy', 0.05)

# go short
exchange.create_order('BTC/USDT', 'market', 'sell', 0.05)

I’ve also tried adding the options for ‘reduce_only’ and ‘close_on_trigger’ but it won’t close the long/short positions:

    params = {
        'reduce_only': True,
        'close_on_trigger': True,
        'time_in_force': 'GTC'
    }
    # order = exchange.create_order('BTC/USDT', 'market', 'buy', 0.05, params)
    order = exchange.create_order('BTC/USDT', 'market', 'sell', 0.05, params)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kroitorcommented, Oct 20, 2021

@freegab the fifth argument of createOrder must be the price (None for market orders), not params. The params overrides must be the sixth argument.

1reaction
joomongcommented, Oct 1, 2021

add params 'side':Sell

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contract Rules & Platform Answers | Bybit Terms of Service
Bybit may charge a trading fee when an order is executed. The trading fee is incurred upon execution of an order. It is...
Read more >
What Is Futures Trading in Crypto and How Does It Work?
Higher potential profits. When trading crypto futures with leverage, the gains are typically more substantial. On Bybit, you can set the ...
Read more >
How to Use Bybit Futures Grid Bot
You may also create your Futures Trading Bot via the main Derivatives page. Choose USDT Perpetual from the top menu, and then select...
Read more >
Bybit Trading Bot | A Smarter Way To Automate Trade
Your trusted automation tools & trading bots for crypto trading 24/7. Customize trades with Bybit Grid ... Futures Grid Bot. Multiply your earnings...
Read more >
How to Get Started Derivatives Copy Trading on Bybit (Master ...
On Desktop · Contract: Select derivatives trading pair · Trade Direction: Long or Short · Order Type: Limit or Market · Enter the...
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