Add is_pair_locked
This commit is contained in:
parent
c042d08bb7
commit
200b6ea10f
@ -4,7 +4,7 @@ This module defines the interface to apply for strategies
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Dict, List, NamedTuple, Optional, Tuple
|
from typing import Dict, List, NamedTuple, Optional, Tuple
|
||||||
import warnings
|
import warnings
|
||||||
@ -159,8 +159,19 @@ class IStrategy(ABC):
|
|||||||
"""
|
"""
|
||||||
Locks pair until a given timestamp happens.
|
Locks pair until a given timestamp happens.
|
||||||
Locked pairs are not analyzed, and are prevented from opening new trades.
|
Locked pairs are not analyzed, and are prevented from opening new trades.
|
||||||
|
:param pair: Pair to lock
|
||||||
|
:param until: datetime in UTC until the pair should be blocked from opening new trades.
|
||||||
|
Needs to be timezone aware `datetime.now(timezone.utc)`
|
||||||
"""
|
"""
|
||||||
self._pair_locked_until['pair'] = until
|
self._pair_locked_until[pair] = until
|
||||||
|
|
||||||
|
def is_pair_locked(self, pair: str) -> bool:
|
||||||
|
"""
|
||||||
|
Checks if a pair is currently locked
|
||||||
|
"""
|
||||||
|
if pair not in self._pair_locked_until:
|
||||||
|
return False
|
||||||
|
return self._pair_locked_until[pair] >= datetime.now(timezone.utc)
|
||||||
|
|
||||||
def analyze_ticker(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def analyze_ticker(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
@ -268,8 +279,8 @@ class IStrategy(ABC):
|
|||||||
sell: bool, low: float = None, high: float = None,
|
sell: bool, low: float = None, high: float = None,
|
||||||
force_stoploss: float = 0) -> SellCheckTuple:
|
force_stoploss: float = 0) -> SellCheckTuple:
|
||||||
"""
|
"""
|
||||||
This function evaluate if on the condition required to trigger a sell has been reached
|
This function evaluate if one of the conditions required to trigger a sell
|
||||||
if the threshold is reached and updates the trade record.
|
has been reached, which can either be a stop-loss, ROI or sell-signal.
|
||||||
:param low: Only used during backtesting to simulate stoploss
|
:param low: Only used during backtesting to simulate stoploss
|
||||||
:param high: Only used during backtesting, to simulate ROI
|
:param high: Only used during backtesting, to simulate ROI
|
||||||
:param force_stoploss: Externally provided stoploss
|
:param force_stoploss: Externally provided stoploss
|
||||||
|
@ -286,3 +286,19 @@ def test__analyze_ticker_internal_skip_analyze(ticker_history, mocker, caplog) -
|
|||||||
assert ret['sell'].sum() == 0
|
assert ret['sell'].sum() == 0
|
||||||
assert not log_has('TA Analysis Launched', caplog)
|
assert not log_has('TA Analysis Launched', caplog)
|
||||||
assert log_has('Skipping TA Analysis for already analyzed candle', caplog)
|
assert log_has('Skipping TA Analysis for already analyzed candle', caplog)
|
||||||
|
|
||||||
|
|
||||||
|
def test_is_pair_locked(default_conf):
|
||||||
|
strategy = DefaultStrategy(default_conf)
|
||||||
|
# dict should be empty
|
||||||
|
assert not strategy._pair_locked_until
|
||||||
|
|
||||||
|
pair = 'ETH/BTC'
|
||||||
|
assert not strategy.is_pair_locked(pair)
|
||||||
|
strategy.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime)
|
||||||
|
# ETH/BTC locked for 4 minutes
|
||||||
|
assert strategy.is_pair_locked(pair)
|
||||||
|
|
||||||
|
# XRP/BTC should not be locked now
|
||||||
|
pair = 'XRP/BTC'
|
||||||
|
assert not strategy.is_pair_locked(pair)
|
||||||
|
Loading…
Reference in New Issue
Block a user