2017-11-07 17:24:51 +00:00
|
|
|
# pragma pylint: disable=missing-docstring
|
2017-11-07 19:12:56 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from unittest.mock import MagicMock
|
2018-01-10 08:09:33 +00:00
|
|
|
from functools import reduce
|
2017-11-07 19:12:56 +00:00
|
|
|
|
2018-01-28 07:38:41 +00:00
|
|
|
import json
|
2018-01-04 14:39:01 +00:00
|
|
|
import arrow
|
2018-01-10 07:51:36 +00:00
|
|
|
import pytest
|
2017-11-07 19:12:56 +00:00
|
|
|
from jsonschema import validate
|
2018-01-10 07:51:36 +00:00
|
|
|
from telegram import Chat, Message, Update
|
2018-01-28 07:38:41 +00:00
|
|
|
from freqtrade.analyze import parse_ticker_dataframe
|
|
|
|
from freqtrade.strategy.strategy import Strategy
|
2017-11-07 19:12:56 +00:00
|
|
|
|
|
|
|
from freqtrade.misc import CONF_SCHEMA
|
2017-11-07 15:18:29 +00:00
|
|
|
|
|
|
|
|
2018-01-10 08:09:33 +00:00
|
|
|
def log_has(line, logs):
|
|
|
|
# caplog mocker returns log as a tuple: ('freqtrade.analyze', logging.WARNING, 'foobar')
|
|
|
|
# and we want to match line against foobar in the tuple
|
|
|
|
return reduce(lambda a, b: a or b,
|
|
|
|
filter(lambda x: x[2] == line, logs),
|
|
|
|
False)
|
|
|
|
|
|
|
|
|
2017-11-07 15:18:29 +00:00
|
|
|
@pytest.fixture(scope="module")
|
2017-11-07 19:12:56 +00:00
|
|
|
def default_conf():
|
|
|
|
""" Returns validated configuration suitable for most tests """
|
|
|
|
configuration = {
|
2017-11-07 21:27:44 +00:00
|
|
|
"max_open_trades": 1,
|
2017-11-07 19:12:56 +00:00
|
|
|
"stake_currency": "BTC",
|
2017-12-17 21:07:56 +00:00
|
|
|
"stake_amount": 0.001,
|
2017-12-25 07:51:41 +00:00
|
|
|
"fiat_display_currency": "USD",
|
2018-01-22 08:39:26 +00:00
|
|
|
"ticker_interval": 5,
|
2017-11-07 19:12:56 +00:00
|
|
|
"dry_run": True,
|
|
|
|
"minimal_roi": {
|
2018-01-10 09:29:41 +00:00
|
|
|
"40": 0.0,
|
|
|
|
"30": 0.01,
|
|
|
|
"20": 0.02,
|
|
|
|
"0": 0.04
|
2017-11-07 19:12:56 +00:00
|
|
|
},
|
2017-11-23 16:43:19 +00:00
|
|
|
"stoploss": -0.10,
|
2018-01-03 23:35:57 +00:00
|
|
|
"unfilledtimeout": 600,
|
2017-11-07 19:12:56 +00:00
|
|
|
"bid_strategy": {
|
|
|
|
"ask_last_balance": 0.0
|
|
|
|
},
|
|
|
|
"exchange": {
|
|
|
|
"name": "bittrex",
|
|
|
|
"enabled": True,
|
|
|
|
"key": "key",
|
|
|
|
"secret": "secret",
|
|
|
|
"pair_whitelist": [
|
2018-03-09 07:24:45 +00:00
|
|
|
"ETH/BTC",
|
|
|
|
"TKN/BTC",
|
|
|
|
"TRST/BTC",
|
|
|
|
"SWT/BTC",
|
|
|
|
"BCC/BTC"
|
2017-11-07 19:12:56 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
"telegram": {
|
|
|
|
"enabled": True,
|
|
|
|
"token": "token",
|
|
|
|
"chat_id": "0"
|
|
|
|
},
|
|
|
|
"initial_state": "running"
|
|
|
|
}
|
|
|
|
validate(configuration, CONF_SCHEMA)
|
|
|
|
return configuration
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def update():
|
|
|
|
_update = Update(0)
|
|
|
|
_update.message = Message(0, 0, datetime.utcnow(), Chat(0, 0))
|
|
|
|
return _update
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def ticker():
|
|
|
|
return MagicMock(return_value={
|
2017-12-17 21:07:56 +00:00
|
|
|
'bid': 0.00001098,
|
|
|
|
'ask': 0.00001099,
|
|
|
|
'last': 0.00001098,
|
2017-11-07 19:12:56 +00:00
|
|
|
})
|
|
|
|
|
2017-12-19 05:58:02 +00:00
|
|
|
|
2017-12-17 21:07:56 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def ticker_sell_up():
|
|
|
|
return MagicMock(return_value={
|
|
|
|
'bid': 0.00001172,
|
|
|
|
'ask': 0.00001173,
|
|
|
|
'last': 0.00001172,
|
|
|
|
})
|
|
|
|
|
2017-12-19 05:58:02 +00:00
|
|
|
|
2017-12-17 21:07:56 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def ticker_sell_down():
|
|
|
|
return MagicMock(return_value={
|
|
|
|
'bid': 0.00001044,
|
|
|
|
'ask': 0.00001043,
|
|
|
|
'last': 0.00001044,
|
|
|
|
})
|
2017-11-07 19:12:56 +00:00
|
|
|
|
|
|
|
|
2017-11-13 20:34:47 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def health():
|
2018-03-04 19:19:00 +00:00
|
|
|
return MagicMock(return_value={
|
|
|
|
'ETH/BTC': {
|
|
|
|
'Currency': 'BTC',
|
|
|
|
'base': 'ETH',
|
|
|
|
'quote': 'BTC',
|
|
|
|
'active': True,
|
|
|
|
'LastChecked': '2017-11-13T20:15:00.00',
|
|
|
|
'Notice': None
|
|
|
|
},
|
|
|
|
'TRST/BTC': {
|
|
|
|
'Currency': 'TRST',
|
|
|
|
'base': 'TRST',
|
|
|
|
'quote': 'BTC',
|
|
|
|
'active': True,
|
|
|
|
'LastChecked': '2017-11-13T20:15:00.00',
|
|
|
|
'Notice': None
|
|
|
|
},
|
|
|
|
'SWT/BTC': {
|
|
|
|
'Currency': 'SWT',
|
|
|
|
'base': 'SWT',
|
|
|
|
'quote': 'BTC',
|
|
|
|
'active': True,
|
|
|
|
'LastChecked': '2017-11-13T20:15:00.00',
|
|
|
|
'Notice': None
|
|
|
|
},
|
|
|
|
'BCC/BTC': {
|
|
|
|
'Currency': 'BCC',
|
|
|
|
'base': 'BCC',
|
|
|
|
'quote': 'BTC',
|
|
|
|
'active': False,
|
|
|
|
'LastChecked': '2017-11-13T20:15:00.00',
|
|
|
|
'Notice': None
|
|
|
|
}
|
|
|
|
})
|
2017-11-13 20:34:47 +00:00
|
|
|
|
|
|
|
|
2017-11-07 19:12:56 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def limit_buy_order():
|
|
|
|
return {
|
|
|
|
'id': 'mocked_limit_buy',
|
|
|
|
'type': 'LIMIT_BUY',
|
|
|
|
'pair': 'mocked',
|
2018-01-05 04:12:13 +00:00
|
|
|
'opened': str(arrow.utcnow().datetime),
|
2017-12-17 21:07:56 +00:00
|
|
|
'rate': 0.00001099,
|
|
|
|
'amount': 90.99181073,
|
2017-11-07 19:12:56 +00:00
|
|
|
'remaining': 0.0,
|
2018-01-05 04:12:13 +00:00
|
|
|
'closed': str(arrow.utcnow().datetime),
|
2018-01-04 14:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def limit_buy_order_old():
|
|
|
|
return {
|
|
|
|
'id': 'mocked_limit_buy_old',
|
|
|
|
'type': 'LIMIT_BUY',
|
2018-03-04 13:55:14 +00:00
|
|
|
'pair': 'ETH/BTC',
|
2018-01-05 04:12:13 +00:00
|
|
|
'opened': str(arrow.utcnow().shift(minutes=-601).datetime),
|
2018-01-04 14:39:01 +00:00
|
|
|
'rate': 0.00001099,
|
|
|
|
'amount': 90.99181073,
|
|
|
|
'remaining': 90.99181073,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def limit_sell_order_old():
|
|
|
|
return {
|
|
|
|
'id': 'mocked_limit_sell_old',
|
|
|
|
'type': 'LIMIT_SELL',
|
2018-03-04 13:55:14 +00:00
|
|
|
'pair': 'ETH/BTC',
|
2018-01-05 04:12:13 +00:00
|
|
|
'opened': str(arrow.utcnow().shift(minutes=-601).datetime),
|
2018-01-04 14:39:01 +00:00
|
|
|
'rate': 0.00001099,
|
|
|
|
'amount': 90.99181073,
|
|
|
|
'remaining': 90.99181073,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def limit_buy_order_old_partial():
|
|
|
|
return {
|
|
|
|
'id': 'mocked_limit_buy_old_partial',
|
|
|
|
'type': 'LIMIT_BUY',
|
2018-03-04 13:55:14 +00:00
|
|
|
'pair': 'ETH/BTC',
|
2018-01-05 04:12:13 +00:00
|
|
|
'opened': str(arrow.utcnow().shift(minutes=-601).datetime),
|
2018-01-04 14:39:01 +00:00
|
|
|
'rate': 0.00001099,
|
|
|
|
'amount': 90.99181073,
|
|
|
|
'remaining': 67.99181073,
|
2017-11-07 19:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def limit_sell_order():
|
|
|
|
return {
|
|
|
|
'id': 'mocked_limit_sell',
|
|
|
|
'type': 'LIMIT_SELL',
|
|
|
|
'pair': 'mocked',
|
2018-01-05 04:12:13 +00:00
|
|
|
'opened': str(arrow.utcnow().datetime),
|
2017-12-17 21:07:56 +00:00
|
|
|
'rate': 0.00001173,
|
|
|
|
'amount': 90.99181073,
|
2017-11-07 19:12:56 +00:00
|
|
|
'remaining': 0.0,
|
2018-01-05 04:12:13 +00:00
|
|
|
'closed': str(arrow.utcnow().datetime),
|
2017-11-07 19:12:56 +00:00
|
|
|
}
|
2017-12-16 23:24:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def ticker_history():
|
|
|
|
return [
|
2017-12-18 16:36:00 +00:00
|
|
|
{
|
2017-12-16 23:24:21 +00:00
|
|
|
"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",
|
2018-01-21 13:25:15 +00:00
|
|
|
"BV": 0.0877869
|
2017-12-16 23:24:21 +00:00
|
|
|
},
|
2017-12-18 16:36:00 +00:00
|
|
|
{
|
2017-12-16 23:24:21 +00:00
|
|
|
"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",
|
2018-01-21 13:25:15 +00:00
|
|
|
"BV": 0.05874751
|
2017-12-16 23:24:21 +00:00
|
|
|
},
|
2017-12-18 16:36:00 +00:00
|
|
|
{
|
2017-12-16 23:24:21 +00:00
|
|
|
"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",
|
2018-01-21 13:25:15 +00:00
|
|
|
"BV": 0.7039405
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def ticker_history_without_bv():
|
|
|
|
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"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"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"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"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"
|
2017-12-16 23:24:21 +00:00
|
|
|
}
|
2017-12-17 21:07:56 +00:00
|
|
|
]
|
2018-01-28 07:38:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def result():
|
|
|
|
with open('freqtrade/tests/testdata/BTC_ETH-1.json') as data_file:
|
|
|
|
return parse_ticker_dataframe(json.load(data_file))
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def default_strategy():
|
|
|
|
strategy = Strategy()
|
|
|
|
strategy.init({'strategy': 'default_strategy'})
|
|
|
|
return strategy
|