robswc / tradingview-webhooks-bot

a framework 🏗 for trading with tradingview webhooks!
http://tvwb.robswc.me
GNU General Public License v3.0
591 stars 180 forks source link

How to get reduce_only to work on bybit #38

Closed DutchTowel closed 1 year ago

DutchTowel commented 1 year ago

Hello, first of all thanks for all the time and effort you put in to creating this. I have the following issue: i am not familiar with python. And after trying all sorts of things for a week with changing tradingview alerts and the actions.py to get my problem solved. i just cant get it to work.

So i use bybit in hedge mode (both shorts and longs can be open at same time). To close a position the extra parameter reduce_only is needed, with values true or false. I also wanted to add a stop loss which i thought should also be added through params. I added them in actions.py as follows

print('Sending:', data['symbol'], data['type'], data['side'], data['amount'], data['reduce_only'], data['stop_loss'])
order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], params={'reduce_only': data['reduce_only'], 'stop_loss': data['stop_loss']})

i keep getting the error: NameError: name 'reduce_only' is not defined NameError: name 'stop_loss' is not defined

Any help would be greatly appreciated.. Thank you

DutchTowel commented 1 year ago

Got it to work like this: print('Sending:', data['symbol'], data['type'], data['side'], data['amount'], data['reduce_only']) order = exchange.create_order(data['symbol'], data['type'], data['side'], data['amount'], params={'reduce_only': data['reduce_only'], 'stop_loss': data['stop_loss']})