Add mock to improve backtesting tests (#194)
This commit is contained in:
parent
512fcdbcb1
commit
14868615d5
@ -4,7 +4,6 @@ import logging
|
||||
import json
|
||||
import os
|
||||
from typing import Optional, List, Dict
|
||||
import time
|
||||
from freqtrade.exchange import get_ticker_history
|
||||
|
||||
from pandas import DataFrame
|
||||
|
@ -123,3 +123,36 @@ def limit_sell_order():
|
||||
'remaining': 0.0,
|
||||
'closed': datetime.utcnow(),
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ticker_history():
|
||||
return [
|
||||
{
|
||||
"O": 8.794e-05,
|
||||
"H": 8.948e-05,
|
||||
"L": 8.794e-05,
|
||||
"C": 8.88e-05,
|
||||
"V": 991.09056638,
|
||||
"T": "2017-11-26T08:50:00",
|
||||
"BV": 0.0877869
|
||||
},
|
||||
{
|
||||
"O": 8.88e-05,
|
||||
"H": 8.942e-05,
|
||||
"L": 8.88e-05,
|
||||
"C": 8.893e-05,
|
||||
"V": 658.77935965,
|
||||
"T": "2017-11-26T08:55:00",
|
||||
"BV": 0.05874751
|
||||
},
|
||||
{
|
||||
"O": 8.891e-05,
|
||||
"H": 8.893e-05,
|
||||
"L": 8.875e-05,
|
||||
"C": 8.877e-05,
|
||||
"V": 7920.73570705,
|
||||
"T": "2017-11-26T09:00:00",
|
||||
"BV": 0.7039405
|
||||
}
|
||||
]
|
@ -1,5 +1,6 @@
|
||||
# pragma pylint: disable=missing-docstring,W0212
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from freqtrade import exchange, optimize
|
||||
from freqtrade.exchange import Bittrex
|
||||
@ -28,8 +29,10 @@ def test_1min_ticker_interval(default_conf, mocker):
|
||||
results = backtest(default_conf, optimize.preprocess(data), 1, True)
|
||||
assert len(results) > 0
|
||||
|
||||
def test_backtest_with_new_pair(default_conf, mocker):
|
||||
def test_backtest_with_new_pair(default_conf, ticker_history, mocker):
|
||||
mocker.patch('freqtrade.optimize.get_ticker_history', return_value=ticker_history)
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
|
||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||
|
||||
optimize.load_data(ticker_interval=1, pairs=['BTC_MEME'])
|
||||
@ -45,7 +48,8 @@ def test_testdata_path():
|
||||
assert str('freqtrade/optimize/../tests/testdata') in testdata_path()
|
||||
|
||||
|
||||
def test_download_pairs(default_conf, mocker):
|
||||
def test_download_pairs(default_conf, ticker_history, mocker):
|
||||
mocker.patch('freqtrade.optimize.__init__.get_ticker_history', return_value=ticker_history)
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||
|
||||
@ -75,7 +79,8 @@ def test_download_pairs(default_conf, mocker):
|
||||
os.remove(file2_5)
|
||||
|
||||
|
||||
def test_download_backtesting_testdata(default_conf, mocker):
|
||||
def test_download_backtesting_testdata(default_conf, ticker_history, mocker):
|
||||
mocker.patch('freqtrade.optimize.__init__.get_ticker_history', return_value=ticker_history)
|
||||
mocker.patch.dict('freqtrade.main._CONF', default_conf)
|
||||
exchange._API = Bittrex({'key': '', 'secret': ''})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user