How to execute Bybit futures trades?
See original GitHub issueI’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:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@freegab the fifth argument of
createOrder
must be theprice
(None
for market orders), notparams
. Theparams
overrides must be the sixth argument.add params
'side':Sell