Add documentation for bot_loop_start
This commit is contained in:
parent
77056a3119
commit
bc821c7c20
@ -89,3 +89,30 @@ class Awesomestrategy(IStrategy):
|
||||
return True
|
||||
return False
|
||||
```
|
||||
|
||||
## Bot loop start callback
|
||||
|
||||
A simple callback which is called at the start of every bot iteration.
|
||||
This can be used to perform calculations which are pair independent.
|
||||
|
||||
|
||||
``` python
|
||||
import requests
|
||||
|
||||
class Awesomestrategy(IStrategy):
|
||||
|
||||
# ... populate_* methods
|
||||
|
||||
def bot_loop_start(self, **kwargs) -> None:
|
||||
"""
|
||||
Called at the start of the bot iteration (one loop).
|
||||
Might be used to perform pair-independent tasks
|
||||
(e.g. gather some remote ressource for comparison)
|
||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||
"""
|
||||
if self.config['runmode'].value in ('live', 'dry_run'):
|
||||
# Assign this to the class by using self.*
|
||||
# can then be used by populate_* methods
|
||||
self.remote_data = requests.get('https://some_remote_source.example.com')
|
||||
|
||||
```
|
||||
|
@ -151,6 +151,8 @@ class FreqtradeBot:
|
||||
self.dataprovider.refresh(self.pairlists.create_pair_list(self.active_pair_whitelist),
|
||||
self.strategy.informative_pairs())
|
||||
|
||||
strategy_safe_wrapper(self.strategy.bot_loop_start)()
|
||||
|
||||
self.strategy.analyze(self.active_pair_whitelist)
|
||||
|
||||
with self._sell_lock:
|
||||
|
@ -194,7 +194,7 @@ class IStrategy(ABC):
|
||||
"""
|
||||
Called at the start of the bot iteration (one loop).
|
||||
Might be used to perform pair-independent tasks
|
||||
(e.g. like lock pairs with negative profit in the last hour)
|
||||
(e.g. gather some remote ressource for comparison)
|
||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||
"""
|
||||
pass
|
||||
|
@ -1,4 +1,13 @@
|
||||
|
||||
def bot_loop_start(self, **kwargs) -> None:
|
||||
"""
|
||||
Called at the start of the bot iteration (one loop).
|
||||
Might be used to perform pair-independent tasks
|
||||
(e.g. gather some remote ressource for comparison)
|
||||
:param **kwargs: Ensure to keep this here so updates to this won't break your strategy.
|
||||
"""
|
||||
pass
|
||||
|
||||
def check_buy_timeout(self, pair: str, trade: 'Trade', order: dict, **kwargs) -> bool:
|
||||
"""
|
||||
Check buy timeout function callback.
|
||||
|
@ -57,6 +57,9 @@ def test_returns_latest_signal(mocker, default_conf, ohlcv_history):
|
||||
|
||||
def test_trade_no_dataprovider(default_conf, mocker, caplog):
|
||||
strategy = DefaultStrategy({})
|
||||
# Delete DP for sure (suffers from test leakage, as we update this in the base class)
|
||||
if strategy.dp:
|
||||
del strategy.dp
|
||||
with pytest.raises(OperationalException, match="DataProvider not found."):
|
||||
strategy.get_signal('ETH/BTC', '5m')
|
||||
|
||||
@ -418,6 +421,14 @@ def test_is_pair_locked(default_conf):
|
||||
assert not strategy.is_pair_locked(pair)
|
||||
|
||||
|
||||
def test_is_informative_pairs_callback(default_conf):
|
||||
default_conf.update({'strategy': 'TestStrategyLegacy'})
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
# Should return empty
|
||||
# Uses fallback to base implementation
|
||||
assert [] == strategy.informative_pairs()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('error', [
|
||||
ValueError, KeyError, Exception,
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user