Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pairs trade opening priority #6030

Open
denmoroz opened this issue Dec 7, 2021 · 2 comments
Open

Pairs trade opening priority #6030

denmoroz opened this issue Dec 7, 2021 · 2 comments
Labels
Enhancement Enhancements to the bot. Get lower priority than bugs by default. Pairlist Issues / PR's related to Pairlists / pairlist handling

Comments

@denmoroz
Copy link

denmoroz commented Dec 7, 2021

Describe your environment

(if applicable)

  • Operating system: ____
  • Python Version: _____ (python -V)
  • CCXT version: _____ (pip freeze | grep ccxt)
  • Freqtrade Version: ____ (freqtrade -V or docker-compose run --rm freqtrade -V for Freqtrade running in docker)

Describe the enhancement

Sometimes it could be useful to order pairs after dataframe analysis for each pair is done (probably based on some indicator or whatever).

Let's imagine that target indicator is "probability of profit" for a pair during the following K candles, for instance predicted by some Machine Learning technique. Someone may want to open trades in max-to-min predicted probability order to maximize expected wins / by expected return based on predicted probability and position size to maximize expected capital growth / whatever else.

Currently there is no clear way to provide "priority" information out of the strategy so the bot will know which pair to enter first. One approach I can imagine right now is to override analyze(self, pairs: List[str]) somehow like:

from queue import PriorityQueue

def analyze(self, pairs: List[str]) -> None:
    priority_queue = PriorityQueue()

    while pairs:
        pair = pairs.pop(0)
        pair_priority = 0.0

        self.analyze_pair(pair)
        analyzed_df, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)

        if not analyzed_df.empty:
            latest_candle = analyzed_df.iloc[-1].squeeze()
            pair_priority = latest_candle[PRIORITY_SIGNAL_COLUMN]

        priority_queue.put((pair_priority, pair))

    while not priority_queue.empty():
        best_priority, best_pair = priority_queue.get()
        pairs.append(best_pair)

or just simply .sort() pairs list inplace based on some column calculated in populate_indicators. But is definitely not a straightforward and potentially dangerous approach as it is based on knowledge of bot cycle internals.

What I imagine could be useful is change the IStrategy interface so there will be a point to explicitly provide priorities for the bot cycle and order pairs before enter_positions. This method could be optional to override with default return value of 0.0 so by default there will not be any specific ordering and everything will work exactly how it works right now.

@xmatthias xmatthias added the Pairlist Issues / PR's related to Pairlists / pairlist handling label Dec 15, 2021
@xmatthias
Copy link
Member

xmatthias commented Dec 15, 2021

This is definitely not a supported way, and i'd discourage you (or any future reader) from pursuing it, as it can break your strategy in subtle ways during updates (or completely ...).

It will also not work as you think it does - as you're modifying the order the pairs are analyzed (which is irrelevant anyway, and cannot be guaranteed on "candle time switches")- but not the order of the pairlist itself.


Unfortunately however, messing with the pairlist (in a proper way) is not an easy task / approach.
What you're proposing does only fit your particular need, but from a framework perspective, would not make much sense as it'd be quite limiting (and we'd need to have quite strict / complex logic in place to ensure that the pairlist is not modified in a breaking manner).

if we would want to enable this, then it would need to be called at the level of pairlists (where pairlists are populated) - also allowing users to provide new pairs from within the strategy.
If that were the case however, then you could not use any technical indicators (freqtrade can't provide the dataframe, and users can't rely on the dataframe being available through dataprovider).

As such, i think this task is better left to dedicated pairlists plugin.
It might be possible to simplify adding pairlist plugins (#4477) - but for the moment, i certainly don't see us having a callback in the strategy to sort the pairlist.

@denmoroz
Copy link
Author

denmoroz commented Dec 29, 2021

@xmatthias Thanks for the answer.

I certainly don't see us having a callback in the strategy to sort the pairlist.

It worth to say that I didn't mean exactly this. I meant that strategy might provide some optional "importance" signal along with "buy" signal. It may be even indicator itself - let's say RSI value (the lower RSI the more oversold the asset assumed to be and presumably more desired to buy for RSI-based strategy). It might be useful when many pairs generate "buy" signal simultaneously but the amount of free stake currency is not enough to enter them all - then it is probably worth to be greedy and enter most "important" / promising first.

And then, the bot will be able to order analyzed pairs based on their importance in bot's main loop (not the strategy). If strategy does not provide any "importance" signal then there is no any preferred ordering for trades opening.

@xmatthias xmatthias added the Enhancement Enhancements to the bot. Get lower priority than bugs by default. label Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Enhancements to the bot. Get lower priority than bugs by default. Pairlist Issues / PR's related to Pairlists / pairlist handling
Projects
None yet
Development

No branches or pull requests

2 participants