donewiththedollar / directionalscalper

CCXT based algorithmic trading framework for Bybit and other CCXT supported exchanges

Home Page:https://quantumvoid.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unterminated string JSON, and string indices need to be int not str.

dasbts opened this issue · comments

commented

Hi,

Great work with this bot. I'm running with the default example config, and have a position of 0.001 from before I initiated the bot. The wallet exposure I set to 0.1 as I have some passivbot positions open in other symbols (I believe it would clash to have both on same symbol).

The bot did a short successfully, and it took the profit quite soon, but after that it did not record the profit, and it instead still showed the following:
│ Short take profit │ None │
│ Short expected profit │ 0.07 USDT

After this, I noticed it seemingly stopped placing more hedge positions, and I had the following:
JSON decode error: Unterminated string starting at: line 1 column 109255 (char 109254)
string indices must be integers, not 'str'
string indices must be integers, not 'str'
string indices must be integers, not 'str'

Seemingly, no stack trace or such. I also noticed some anomalies in general. Initial trade qty and max trade qty I think would be at least 0.001 as my position sizes are (which is the same size which it opened as short during a bear trend):
Exchange name: bybit
Strategy name: bybit_auto_hedge
Symbol: BTCUSDT
Futures balance: 438.44973666
Initial max trade qty set to 0.0
Initial trade qty set to 0.0
Leverage: 0.001x, Trade Quantity: 0.0
Leverage: 0.01x, Trade Quantity: 0.0
Leverage: 0.1x, Trade Quantity: 0.0
Leverage: 1x, Trade Quantity: 0.0
Leverage: 2.5x, Trade Quantity: 0.0
Leverage: 5x, Trade Quantity: 0.0

I also noticed that in the table of the current stats, it showed a different leverage than what was chosen in the Bybit derivatives positions, is this because the bot calculates differently than what it places on the exchange? In Bybit it shows 100x, and in the bot terminal (in Debian 11):
│ Long pos. lev. │ 2.0 │
│ Short pos. lev. │ 2.0 │

Hope you're able to help figure this out. Let me know if there's anything I can help with in terms of development (even if my vacation ends next week), and let me know if there's any more details I should provide.

Regards
dasbts

commented

Full log of current bot.

   Directional Scalper 2.0.6        

┌───────────────────────┬──────────────┐
│ Symbol │ BTCUSDT │
│ Price │ 28888.05 │
│ Balance │ 441.41607115 │
│ Available bal. │ 251.89438037 │
│ Long MAX QTY │ 0.0 │
│ Short MAX QTY │ 0.0 │
│ Long entry QTY │ 0.001 │
│ Short entry QTY │ 0.001 │
│ Long pos. QTY │ 0.001 │
│ Short pos. QTY │ 0.001 │
│ Long uPNL │ -0.3453 │
│ Short uPNL │ -0.0504 │
│ Long cum. uPNL │ 4.9295 │
│ Short cum. uPNL │ 0.0632 │
│ Long pos. price │ 29231.6 │
│ Long take profit │ 29396.6 │
│ Long expected profit │ 0.17 USDT │
│ Short pos. price │ 28835.9 │
│ Short take profit │ 28672.4 │
│ Short expected profit │ 0.16 USDT │
│ Long pos. lev. │ 2.0 │
│ Short pos. lev. │ 2.0 │
│ Long liq price │ 0.0 │
│ Short liq price │ 0.0 │
│ 1m Vol │ 8595807 │
│ 5m Spread: │ 0.2745 │
│ Trend │ short │
│ ERI Trend │ bullish │
│ Long condition │ False │
│ Add long cond. │ False │
│ Short condition │ False │
│ Add short cond. │ True │
│ Min. volume │ 15000 │
│ Min. spread │ 0.15 │
│ Min. qty │ 0.001 │
└───────────────────────┴──────────────┘

Also, I'm running bybit_auto_hedge, is that the one that was recommended, or was it some other like bybit_hedge_mfirsi_maker?

Hm this is very interesting, well one thing to note is that the

Long pos lev. and Short pos lev. are as they should be based on the math of total equity and 0.001x size being the automatic entry quantity initially. However, by the way things look it seems there sounds like there is a bug in the auto hedge strategy. Along with that bug, there may be an issue with reading from the JSON that is causing that bug.

I want to try to reproduce this error myself, if you can have the error happen again that would be a good thing (ironically) so we can get more information as to if it was the old position that caused this or something else. The order IDs should be processed regardless - meaning if you had placed an order prior to starting the bot, the bot should see that order and handle the order ID as normal wether it be take profit or entry.

However, it sounds like there is something going on here with the JSON decode error - and it was not just a fluke incident in my opinion. Looking into it now 😊

Edit: Oh, and I use bybit_hedge_mfirsi_maker mostly

commented

Interesting. I will try that strategy as well.

Regarding reproducing it, I had a 0.001 BTC long position open, then it opened and closed a short position meanwhile. We'll see if it does it again, I will keep monitoring and let you know ASAP on anything similar. I would be glad to look into further error handling in the near future to help debug where it occurs, so far I haven't read a line of the code actually.

Interesting regarding the 100x leverage, but if that is fine in the backend even tho it looks a bit scary, then I guess it's fine.

P.s. I also enabled Webhook with Discord, but haven't yet seen any messages to my server. I suppose it would send any opened/closed positions. When I get time I might do a PR with Slack support, that's what I use in other bots.

This should be good now with the way the manager handles the API but will leave open for a bit longer to see if any more reports about this come in. Many have switched to the rotator which automatically selects symbols from a whitelist based on volume and spread; which also is not encountering this issue from previous strategies.