some formatting for flake8
This commit is contained in:
parent
8ea9b3746b
commit
ed24d96a79
@ -49,20 +49,22 @@ def patch_edge(mocker) -> None:
|
|||||||
# "LTC/BTC",
|
# "LTC/BTC",
|
||||||
# "XRP/BTC",
|
# "XRP/BTC",
|
||||||
# "NEO/BTC"
|
# "NEO/BTC"
|
||||||
pair_info = namedtuple('pair_info', 'stoploss, winrate, risk_reward_ratio, required_risk_reward, expectancy')
|
pair_info = namedtuple(
|
||||||
|
'pair_info',
|
||||||
|
'stoploss, winrate, risk_reward_ratio, required_risk_reward, expectancy')
|
||||||
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
|
mocker.patch('freqtrade.edge.Edge._cached_pairs', mocker.PropertyMock(
|
||||||
return_value={
|
return_value={
|
||||||
'NEO/BTC': pair_info(-0.20, 0.66, 3.71, 0.50, 1.71),
|
'NEO/BTC': pair_info(-0.20, 0.66, 3.71, 0.50, 1.71),
|
||||||
'LTC/BTC': pair_info(-0.21, 0.66, 3.71, 0.50, 1.71),
|
'LTC/BTC': pair_info(-0.21, 0.66, 3.71, 0.50, 1.71),
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value = -0.20))
|
mocker.patch('freqtrade.edge.Edge.stoploss', MagicMock(return_value=-0.20))
|
||||||
mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value = True))
|
mocker.patch('freqtrade.edge.Edge.calculate', MagicMock(return_value=True))
|
||||||
|
|
||||||
|
|
||||||
def get_patched_edge(mocker, config) -> Edge:
|
def get_patched_edge(mocker, config) -> Edge:
|
||||||
patch_edge(mocker)
|
patch_edge(mocker)
|
||||||
edge=Edge(config)
|
edge = Edge(config)
|
||||||
return edge
|
return edge
|
||||||
|
|
||||||
# Functions for recurrent object patching
|
# Functions for recurrent object patching
|
||||||
@ -86,15 +88,15 @@ def get_patched_freqtradebot(mocker, config) -> FreqtradeBot:
|
|||||||
return FreqtradeBot(config)
|
return FreqtradeBot(config)
|
||||||
|
|
||||||
|
|
||||||
def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]]=None) -> None:
|
def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]] = None) -> None:
|
||||||
"""
|
"""
|
||||||
Mocker to coinmarketcap to speed up tests
|
Mocker to coinmarketcap to speed up tests
|
||||||
:param mocker: mocker to patch coinmarketcap class
|
:param mocker: mocker to patch coinmarketcap class
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
tickermock=MagicMock(return_value={'price_usd': 12345.0})
|
tickermock = MagicMock(return_value={'price_usd': 12345.0})
|
||||||
listmock=MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
|
listmock = MagicMock(return_value={'data': [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC',
|
||||||
'website_slug': 'bitcoin'},
|
'website_slug': 'bitcoin'},
|
||||||
{'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH',
|
{'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH',
|
||||||
'website_slug': 'ethereum'}
|
'website_slug': 'ethereum'}
|
||||||
@ -110,7 +112,7 @@ def patch_coinmarketcap(mocker, value: Optional[Dict[str, float]]=None) -> None:
|
|||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def default_conf():
|
def default_conf():
|
||||||
""" Returns validated configuration suitable for most tests """
|
""" Returns validated configuration suitable for most tests """
|
||||||
configuration={
|
configuration = {
|
||||||
"max_open_trades": 1,
|
"max_open_trades": 1,
|
||||||
"stake_currency": "BTC",
|
"stake_currency": "BTC",
|
||||||
"stake_amount": 0.001,
|
"stake_amount": 0.001,
|
||||||
|
@ -64,7 +64,7 @@ def _validate_ohlc(buy_ohlc_sell_matrice):
|
|||||||
|
|
||||||
def _build_dataframe(buy_ohlc_sell_matrice):
|
def _build_dataframe(buy_ohlc_sell_matrice):
|
||||||
_validate_ohlc(buy_ohlc_sell_matrice)
|
_validate_ohlc(buy_ohlc_sell_matrice)
|
||||||
tickers= []
|
tickers = []
|
||||||
for ohlc in buy_ohlc_sell_matrice:
|
for ohlc in buy_ohlc_sell_matrice:
|
||||||
ticker = {
|
ticker = {
|
||||||
'date': ticker_start_time.shift(
|
'date': ticker_start_time.shift(
|
||||||
@ -82,9 +82,9 @@ def _build_dataframe(buy_ohlc_sell_matrice):
|
|||||||
|
|
||||||
frame = DataFrame(tickers)
|
frame = DataFrame(tickers)
|
||||||
frame['date'] = to_datetime(frame['date'],
|
frame['date'] = to_datetime(frame['date'],
|
||||||
unit = 'ms',
|
unit='ms',
|
||||||
utc = True,
|
utc=True,
|
||||||
infer_datetime_format = True)
|
infer_datetime_format=True)
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
@ -95,17 +95,17 @@ def _time_on_candle(number):
|
|||||||
|
|
||||||
|
|
||||||
def test_edge_heartbeat_calculate(mocker, default_conf):
|
def test_edge_heartbeat_calculate(mocker, default_conf):
|
||||||
exchange=get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
edge=Edge(default_conf, exchange)
|
edge = Edge(default_conf, exchange)
|
||||||
heartbeat=default_conf['edge']['process_throttle_secs']
|
heartbeat = default_conf['edge']['process_throttle_secs']
|
||||||
|
|
||||||
# should not recalculate if heartbeat not reached
|
# should not recalculate if heartbeat not reached
|
||||||
edge._last_updated=arrow.utcnow().timestamp - heartbeat + 1
|
edge._last_updated = arrow.utcnow().timestamp - heartbeat + 1
|
||||||
|
|
||||||
assert edge.calculate() is False
|
assert edge.calculate() is False
|
||||||
|
|
||||||
|
|
||||||
def mocked_load_data(datadir, pairs = [], ticker_interval = '0m', refresh_pairs = False,
|
def mocked_load_data(datadir, pairs=[], ticker_interval='0m', refresh_pairs=False,
|
||||||
timerange=None, exchange=None):
|
timerange=None, exchange=None):
|
||||||
hz = 0.1
|
hz = 0.1
|
||||||
base = 0.001
|
base = 0.001
|
||||||
@ -213,6 +213,8 @@ def test_process_expectancy(mocker, default_conf):
|
|||||||
assert round(final['TEST/BTC'].expectancy, 10) == 101.5128205128
|
assert round(final['TEST/BTC'].expectancy, 10) == 101.5128205128
|
||||||
|
|
||||||
# 1) Open trade should be removed from the end
|
# 1) Open trade should be removed from the end
|
||||||
|
|
||||||
|
|
||||||
def test_case_1(mocker, default_conf):
|
def test_case_1(mocker, default_conf):
|
||||||
exchange = get_patched_exchange(mocker, default_conf)
|
exchange = get_patched_exchange(mocker, default_conf)
|
||||||
edge = Edge(default_conf, exchange)
|
edge = Edge(default_conf, exchange)
|
||||||
|
Loading…
Reference in New Issue
Block a user