iterativv / NostalgiaForInfinity

Trading strategy for the Freqtrade crypto bot
GNU General Public License v3.0
1.97k stars 487 forks source link

Issue with Trading Bot in dry-run Mode and Connected Real Accounts Bots #369

Open Va1b0rt opened 8 months ago

Va1b0rt commented 8 months ago

Problem Description

I have encountered an interesting situation with a trading bot. One instance of the bot is trading in dry-run mode and entering trades with the leverage specified in the strategy. Two additional bots are connected to it via the producer/consumer mode, and they are trading on real accounts. Despite all bots entering the same trades as the main account, they are using different leverages.

Questions

  1. Is it possible that this situation is part of the strategy's mechanics?
  2. What could be the reasons for this behavior?
  3. How can one disable this strategy mechanic if it is causing issues?

Reproduction Steps

  1. Launch the bot in dry-run mode with the specified leverage.
  2. Connect your bots through the producer/consumer mode on real accounts.
  3. Observe differences in leverage when entering the same trades.

Expected Behavior

It was expected that all bots, including the one running in dry-run mode, would use the same leverage when entering the same trades.

Environment Information

iterativv commented 8 months ago

Could you verify on exchange that 5x (and 3x leverage for signal 61) is allowed ? I assume the leverage is 1x instead, right ?

Va1b0rt commented 8 months ago

I've confirmed that trading with leverage works as expected by running the bot with my custom strategy, which trades with the specified leverage. However, it seems to be an issue specific to this particular strategy, as other strategies are functioning correctly. That's why I suspect the problem lies within this strategy.

As for "Signal 61," could you provide more details about it? What does it represent or signify in the context of the strategy? Understanding the specifics of Signal 61 could help in troubleshooting the issue more effectively.

If You was referring to the "rebuy" mode, the configuration in the strategy is as follows:

is_futures_mode = True futures_mode_leverage = 6.0 futures_mode_leverage_rebuy_mode = 3.0

These settings indicate that the strategy is set to futures mode with a leverage of 6.0, and in "rebuy" mode, the leverage is adjusted to 3.0.

iterativv commented 8 months ago

It's with 5x. That still is too high, if you ask me. Signal 61 is the so called "rebuy mode", it's going to buy 20% of the normal stake, then more if there are dips. This is 3x.

Va1b0rt commented 8 months ago

Well, yes. But this does not explain the behavior described above at all. In dry-run mode, it is included at 6x, but on real accounts, it is included in most deals at 1x, and in some at 20x. Where do these numbers come from? They are not specified in the strategy

iterativv commented 8 months ago

Yes, it should get it from leverage() function, that is 5x, unless signals 61, that is 3x ... 1x it can happen, in case that 5x is not possible for the pair in question. But 20x ?

Va1b0rt commented 8 months ago

Well, exactly, 20x. I myself can't understand where this number comes from. In the leverage() method, only futures_mode_leverage and futures_mode_leverage_rebuy_mode are used, the values of which I've provided earlier. And the most interesting thing is that this behavior occurs only with a real account; in dry-run mode, we enter trades with 6x leverage as specified in the strategy. I'm puzzled.

Screenshot_4

The screenshot shows two real accounts "Vladislav" and "Valbort" and one in the dry-run mode "freqtrade" with absolutely identical strategy settings (except for the DRY-RUN mode) and connected to the same strategy. In the strategy, only those parameters that I changed above have been changed. The rest remains unchanged.

iterativv commented 8 months ago

Is there anything in the logs ? Maybe don't change the value to 6, leave the default 5.

Va1b0rt commented 8 months ago

There are similar messages in the logs: 2024-01-28 06:11:24 - freqtrade.strategy.interface - WARNING - Outdated history for pair XVS/USDT:USDT. Last tick is 16 minutes old 2024-01-28 06:11:24 - freqtrade.strategy.interface - WARNING - Outdated history for pair YFI/USDT:USDT. Last tick is 16 minutes old 2024-01-28 06:11:24 - freqtrade.strategy.interface - WARNING - Outdated history for pair ZEC/USDT:USDT. Last tick is 16 minutes old 2024-01-28 06:11:24 - freqtrade.strategy.interface - WARNING - Outdated history for pair ZEN/USDT:USDT. Last tick is 16 minutes old 2024-01-28 06:11:24 - freqtrade.strategy.interface - WARNING - Outdated history for pair ZIL/USDT:USDT. Last tick is 16 minutes old 2024-01-28 06:11:24 - freqtrade.strategy.interface - WARNING - Outdated history for pair ZRX/USDT:USDT. Last tick is 16 minutes old 2024-01-28 06:11:24 - freqtrade.worker - INFO - Bot heartbeat. PID=603961, version='2023.8.dev, strategy_version: v14.0.719', state='RUNNING'

Va1b0rt commented 8 months ago

corrected the leverage value to 5. Only changed is_futures_mode = True I'll see what comes of it. but still there are doubts that this can help.

Here is the part in the log where the purchase is made with 20x leverage:

trade.freqtradebot - INFO - Long signal found: about create a new trade for PYTH/USDT:USDT with stake_amount: 5.54078282802 ... trade.freqtradebot - INFO - Order #423633325 was created for PYTH/USDT:USDT and status is closed. trade.wallets - INFO - Wallets synced. trade.rpc.rpc_manager - INFO - Sending rpc message: {'trade_id': 30, 'type': entry, 'buy_tag': '61 ', 'enter_tag': '61 ', 'exchange': 'Binance', 'pair': 'PYTH/USDT:USDT', 'leverage': 20.0, 'direction': 'Long', 'limit': 0.3178, 'open_rate': 0.3178, 'order_type': 'market', 'stake_amount': 5.529719999999999, 'stake_currency': 'USDT', 'base_currency': 'PYTH', 'fiat_currency': 'USD', 'amount': 348.0, 'open_date': datetime.datetime(2024, 1, 19, 16, 18, 47, 293918, tzinfo=datetime.timezone.utc), 'current_rate': 0.3178, 'sub_trade': False} trade.freqtradebot - INFO - Found open order for Trade(id=30, pair=PYTH/USDT:USDT, amount=348.00000000, is_short=False, leverage=20.0, open_rate=0.31780000, open_since=2024-01-19 16:18:47) trade.persistence.trade_model - INFO - Updating trade (id=30) ... trade.persistence.trade_model - INFO - MARKET_BUY has been fulfilled for Trade(id=30, pair=PYTH/USDT:USDT, amount=348.00000000, is_short=False, leverage=20.0, open_rate=0.31780000, open_since=2024-01-19 16:18:47).

Nothing seems unusual. Except that the leverage of 20x came from somewhere.

iterativv commented 8 months ago

No need to change the mode, it's going to read it from your config. Is this something to do with the producer/consumer I wonder ? I have to look into it.

Va1b0rt commented 8 months ago

Changing the variable futures_mode_leverage back to its original value of 5 resolved the issue. Now, both on the demo account and on the real accounts, the bot enters trades with a leverage of 5. However, I still can't understand why such a bug occurs with other leverage values, as I haven't noticed this variable being changed in the code in any way. To me, the situation seems quite strange. I would like to understand why this is happening. Can you suggest which direction to investigate? From what I understand, the problem lies specifically within the strategy, not in the bot itself. Please advise where exactly in your strategy the leverage value could be modified, if possible.

godshades commented 8 months ago

hi @Va1b0rt , may i ask why you run 3 bot like this, any benefit ?

Va1b0rt commented 8 months ago

hi @Va1b0rt , may i ask why you run 3 bot like this, any benefit ?

Running three bots like this doesn't provide me with any additional benefits. The idea is as follows: I have one bot running in dry-run mode, and I connect my real exchange accounts to it via producer/consumer. As I understand it, this is a less resource-intensive way to run multiple bots on a single machine. If I'm mistaken, please correct me.

Moreover, if at any point I'm unsure about the strategy (for example, during certain market conditions), I can disconnect the real accounts but still continue monitoring the strategy's performance in dry-run mode.

Va1b0rt commented 7 months ago

I had some errors like 'Outdated history...'. I thought maybe it was affecting the fact that producers and consumers enter different deals, but after resolving these errors, it didn't affect the situation with the inputs at all. I noticed that consumers enter the same deals and do not enter deals that the producer enters. But sometimes one of the consumers enters the same deal as the producer. Very strange behavior... Perhaps the computer cannot process three accounts simultaneously?