2017-09-09 11:48:49 +00:00
|
|
|
# pragma pylint: disable=missing-docstring
|
2017-10-26 13:50:31 +00:00
|
|
|
import json
|
2017-10-01 08:02:47 +00:00
|
|
|
import pytest
|
2017-09-09 11:48:49 +00:00
|
|
|
import arrow
|
2017-09-28 21:26:28 +00:00
|
|
|
from pandas import DataFrame
|
|
|
|
|
|
|
|
from freqtrade.analyze import parse_ticker_dataframe, populate_buy_trend, populate_indicators, \
|
|
|
|
get_buy_signal
|
2017-09-09 11:48:49 +00:00
|
|
|
|
2017-10-01 08:02:47 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def result():
|
2017-10-26 13:50:31 +00:00
|
|
|
with open('freqtrade/tests/testdata/btc-eth.json') as data_file:
|
|
|
|
data = json.load(data_file)
|
|
|
|
|
|
|
|
return parse_ticker_dataframe(data['result'], arrow.get('2017-08-30T10:00:00'))
|
2017-10-01 08:02:47 +00:00
|
|
|
|
2017-10-01 08:11:20 +00:00
|
|
|
def test_dataframe_has_correct_columns(result):
|
2017-10-01 08:02:47 +00:00
|
|
|
assert result.columns.tolist() == \
|
|
|
|
['close', 'high', 'low', 'open', 'date', 'volume']
|
|
|
|
|
2017-10-26 13:50:31 +00:00
|
|
|
def test_dataframe_has_correct_length(result):
|
|
|
|
assert len(result.index) == 5751
|
2017-10-01 08:02:47 +00:00
|
|
|
|
2017-10-01 08:11:20 +00:00
|
|
|
def test_populates_buy_trend(result):
|
2017-10-01 08:02:47 +00:00
|
|
|
dataframe = populate_buy_trend(populate_indicators(result))
|
|
|
|
assert 'buy' in dataframe.columns
|
|
|
|
assert 'buy_price' in dataframe.columns
|
|
|
|
|
2017-10-01 12:25:10 +00:00
|
|
|
def test_returns_latest_buy_signal(mocker):
|
2017-10-01 08:02:47 +00:00
|
|
|
buydf = DataFrame([{'buy': 1, 'date': arrow.utcnow()}])
|
2017-10-01 12:25:10 +00:00
|
|
|
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=buydf)
|
2017-10-01 12:45:21 +00:00
|
|
|
assert get_buy_signal('BTC-ETH')
|
2017-10-01 12:25:10 +00:00
|
|
|
|
2017-10-01 08:02:47 +00:00
|
|
|
buydf = DataFrame([{'buy': 0, 'date': arrow.utcnow()}])
|
2017-10-01 12:25:10 +00:00
|
|
|
mocker.patch('freqtrade.analyze.analyze_ticker', return_value=buydf)
|
2017-10-01 12:45:21 +00:00
|
|
|
assert not get_buy_signal('BTC-ETH')
|