move parse_ticker_dataframe outside Analyze class

This commit is contained in:
Janne Sinivirta 2018-07-10 13:04:37 +03:00
parent 85e6c9585a
commit f6b8c2b40f
5 changed files with 37 additions and 37 deletions

View File

@ -17,29 +17,7 @@ from freqtrade.strategy.resolver import IStrategy
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class SignalType(Enum): def parse_ticker_dataframe(ticker: list) -> DataFrame:
"""
Enum to distinguish between buy and sell signals
"""
BUY = "buy"
SELL = "sell"
class Analyze(object):
"""
Analyze class contains everything the bot need to determine if the situation is good for
buying or selling.
"""
def __init__(self, config: dict, strategy: IStrategy) -> None:
"""
Init Analyze
:param config: Bot configuration (use the one from Configuration())
"""
self.config = config
self.strategy = strategy
@staticmethod
def parse_ticker_dataframe(ticker: list) -> DataFrame:
""" """
Analyses the trend for the given ticker history Analyses the trend for the given ticker history
:param ticker: See exchange.get_ticker_history :param ticker: See exchange.get_ticker_history
@ -64,13 +42,35 @@ class Analyze(object):
frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle frame.drop(frame.tail(1).index, inplace=True) # eliminate partial candle
return frame return frame
class SignalType(Enum):
"""
Enum to distinguish between buy and sell signals
"""
BUY = "buy"
SELL = "sell"
class Analyze(object):
"""
Analyze class contains everything the bot need to determine if the situation is good for
buying or selling.
"""
def __init__(self, config: dict, strategy: IStrategy) -> None:
"""
Init Analyze
:param config: Bot configuration (use the one from Configuration())
"""
self.config = config
self.strategy = strategy
def analyze_ticker(self, ticker_history: List[Dict]) -> DataFrame: def analyze_ticker(self, ticker_history: List[Dict]) -> DataFrame:
""" """
Parses the given ticker history and returns a populated DataFrame Parses the given ticker history and returns a populated DataFrame
add several TA indicators and buy signal to it add several TA indicators and buy signal to it
:return DataFrame with ticker data and indicator data :return DataFrame with ticker data and indicator data
""" """
dataframe = self.parse_ticker_dataframe(ticker_history) dataframe = parse_ticker_dataframe(ticker_history)
dataframe = self.strategy.populate_indicators(dataframe) dataframe = self.strategy.populate_indicators(dataframe)
dataframe = self.strategy.populate_buy_trend(dataframe) dataframe = self.strategy.populate_buy_trend(dataframe)
dataframe = self.strategy.populate_sell_trend(dataframe) dataframe = self.strategy.populate_sell_trend(dataframe)
@ -227,5 +227,5 @@ class Analyze(object):
""" """
Creates a dataframe and populates indicators for given ticker data Creates a dataframe and populates indicators for given ticker data
""" """
return {pair: self.strategy.populate_indicators(self.parse_ticker_dataframe(pair_data)) return {pair: self.strategy.populate_indicators(parse_ticker_dataframe(pair_data))
for pair, pair_data in tickerdata.items()} for pair, pair_data in tickerdata.items()}

View File

@ -12,7 +12,7 @@ from jsonschema import validate
from telegram import Chat, Message, Update from telegram import Chat, Message, Update
from freqtrade import constants from freqtrade import constants
from freqtrade.analyze import Analyze from freqtrade.analyze import parse_ticker_dataframe
from freqtrade.exchange import Exchange from freqtrade.exchange import Exchange
from freqtrade.freqtradebot import FreqtradeBot from freqtrade.freqtradebot import FreqtradeBot
@ -616,7 +616,7 @@ def tickers():
@pytest.fixture @pytest.fixture
def result(): def result():
with open('freqtrade/tests/testdata/UNITTEST_BTC-1m.json') as data_file: with open('freqtrade/tests/testdata/UNITTEST_BTC-1m.json') as data_file:
return Analyze.parse_ticker_dataframe(json.load(data_file)) return parse_ticker_dataframe(json.load(data_file))
# FIX: # FIX:
# Create an fixture/function # Create an fixture/function

View File

@ -3,14 +3,14 @@ import json
import pytest import pytest
from pandas import DataFrame from pandas import DataFrame
from freqtrade.analyze import Analyze from freqtrade.analyze import parse_ticker_dataframe
from freqtrade.strategy.default_strategy import DefaultStrategy from freqtrade.strategy.default_strategy import DefaultStrategy
@pytest.fixture @pytest.fixture
def result(): def result():
with open('freqtrade/tests/testdata/ETH_BTC-1m.json') as data_file: with open('freqtrade/tests/testdata/ETH_BTC-1m.json') as data_file:
return Analyze.parse_ticker_dataframe(json.load(data_file)) return parse_ticker_dataframe(json.load(data_file))
def test_default_strategy_structure(): def test_default_strategy_structure():

View File

@ -10,7 +10,7 @@ from unittest.mock import MagicMock
import arrow import arrow
from pandas import DataFrame from pandas import DataFrame
from freqtrade.analyze import Analyze from freqtrade.analyze import Analyze, parse_ticker_dataframe
from freqtrade.arguments import TimeRange from freqtrade.arguments import TimeRange
from freqtrade.optimize.__init__ import load_tickerdata_file from freqtrade.optimize.__init__ import load_tickerdata_file
from freqtrade.tests.conftest import get_patched_exchange, log_has from freqtrade.tests.conftest import get_patched_exchange, log_has
@ -21,7 +21,7 @@ _ANALYZE = Analyze({}, DefaultStrategy())
def test_dataframe_correct_length(result): def test_dataframe_correct_length(result):
dataframe = Analyze.parse_ticker_dataframe(result) dataframe = parse_ticker_dataframe(result)
assert len(result.index) - 1 == len(dataframe.index) # last partial candle removed assert len(result.index) - 1 == len(dataframe.index) # last partial candle removed
@ -145,7 +145,7 @@ def test_parse_ticker_dataframe(ticker_history):
columns = ['date', 'open', 'high', 'low', 'close', 'volume'] columns = ['date', 'open', 'high', 'low', 'close', 'volume']
# Test file with BV data # Test file with BV data
dataframe = Analyze.parse_ticker_dataframe(ticker_history) dataframe = parse_ticker_dataframe(ticker_history)
assert dataframe.columns.tolist() == columns assert dataframe.columns.tolist() == columns

View File

@ -7,7 +7,7 @@ Unit test file for misc.py
import datetime import datetime
from unittest.mock import MagicMock from unittest.mock import MagicMock
from freqtrade.analyze import Analyze from freqtrade.analyze import Analyze, parse_ticker_dataframe
from freqtrade.misc import (common_datearray, datesarray_to_datetimearray, from freqtrade.misc import (common_datearray, datesarray_to_datetimearray,
file_dump_json, format_ms_time, shorten_date) file_dump_json, format_ms_time, shorten_date)
from freqtrade.optimize.__init__ import load_tickerdata_file from freqtrade.optimize.__init__ import load_tickerdata_file
@ -29,7 +29,7 @@ def test_datesarray_to_datetimearray(ticker_history):
Test datesarray_to_datetimearray() function Test datesarray_to_datetimearray() function
:return: None :return: None
""" """
dataframes = Analyze.parse_ticker_dataframe(ticker_history) dataframes = parse_ticker_dataframe(ticker_history)
dates = datesarray_to_datetimearray(dataframes['date']) dates = datesarray_to_datetimearray(dataframes['date'])
assert isinstance(dates[0], datetime.datetime) assert isinstance(dates[0], datetime.datetime)