Comments (5)
Can you log or print r
and type of r
right after line 238 and same thing with position
between line 243 and 244. Run and tell me what it returns please, maybe something has changed in bybit's api because position['size'] should return a number but apparently it's not the case here so we should print the whole dictionary and see what's actually inside for debugging.
from tradingview-webhook-trading-bot.
That's exactly what i whent and did yesterday after further testing. The position reports as:
Retrieve positions
{'id': 0, 'position_idx': 0, 'mode': 0, 'user_id': 499713, 'risk_id': 1, 'symbol': 'BTCUSD', 'side': 'Buy', 'size': 3, 'position_value': '0.00007489', 'entry_price': '40058.75283749', 'is_isolated': True, 'auto_add_margin': 0, 'leverage': '1', 'effective_leverage': '1', 'position_margin': '0.00007498', 'liq_price': '20080.5', 'bust_price': '20029.5', 'occ_closing_fee': '0.00000009', 'occ_funding_fee': '0', 'take_profit': '0', 'stop_loss': '39000', 'trailing_stop': '0', 'position_status': 'Normal', 'deleverage_indicator': 3, 'oc_calc_data': '{"blq":0,"slq":3,"slv":"0.00006666","bmp":0,"smp":45004.5005,"bv2c":1.0018,"sv2c":1.0006}', 'order_margin': '0', 'wallet_balance': '0.48751317', 'realised_pnl': '-0.00000006', 'unrealised_pnl': -6.8e-07, 'cum_realised_pnl': '-0.01248683', 'cross_seq': 4984212004, 'position_seq': 0, 'created_at': '2022-04-02T19:55:06.723844426Z', 'updated_at': '2022-04-12T18:43:33.110089552Z', 'tp_sl_mode': 'Full'}
So basically we'r trying to return string but size in the dictionary is integer? That would be my frist guess.
So then if i try and do:
for position in r['result'].values():
open_size = position['size']
i get the error:
TypeError: 'int' object is not subscriptable
That is how far i got yesterday.
from tradingview-webhook-trading-bot.
I have fixed it.
Tested just a couple orders for long and short.
What i did was in the example of the exit position:
for position in r['result']:
open_size = r['result'].get('size')
if open_size > 0:
open_side = r['result'].get('side')
close_side = 'Sell' if open_side == 'Buy' else 'Buy'
so basically get the size and open side with .get to get the value out of the dictionary.
Idk if this is the correct way but it does close the order/s and enters the new position correctly if we'r calling for 'entry' or it just closes the positions if we'r calling for it to 'exit'.
from tradingview-webhook-trading-bot.
Glad you made it work ! I think you can write position.get('key')
instead of r['result'].get('key')
for more legibility and therefore I believe you have to make the change everywhere in the code where a key in a dictionary is called.
But this is still quite surprising because position['key']
and position.get('key')
both do the same thing if the key exists, I really wonder what the problem is. What version of python are you using to run that code ?
from tradingview-webhook-trading-bot.
I'm using Python 3.10.4. It's weird it was not working for me but its okay as its fixed.
from tradingview-webhook-trading-bot.
Related Issues (7)
- launching HOT 1
- ByBit integration broken? HOT 1
- ByBit Timestamp Error HOT 1
- pathlib HOT 1
- Modifications if possible? HOT 8
- Request to support Binance, FTX is no longer available HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tradingview-webhook-trading-bot.