Fix review comments

This commit is contained in:
Anton
2018-06-04 01:48:26 +03:00
parent 3427c7eb54
commit daa9c0c026
5 changed files with 54 additions and 5 deletions

View File

@@ -33,10 +33,11 @@ CONF_SCHEMA = {
'max_open_trades': {'type': 'integer', 'minimum': 0},
'ticker_interval': {'type': 'string', 'enum': list(TICKER_INTERVAL_MINUTES.keys())},
'stake_currency': {'type': 'string', 'enum': ['BTC', 'ETH', 'USDT']},
'stake_amount': {'anyOf': [
{'type': 'integer', 'minimum': 0.0005},
{'constant': UNLIMITED_STAKE_AMOUNT}
]},
'stake_amount': {
"type": ["number", "string"],
"minimum": 0.0005,
"pattern": UNLIMITED_STAKE_AMOUNT
},
'fiat_display_currency': {'type': 'string', 'enum': ['AUD', 'BRL', 'CAD', 'CHF',
'CLP', 'CNY', 'CZK', 'DKK',
'EUR', 'GBP', 'HKD', 'HUF',

View File

@@ -3,6 +3,7 @@
import json
import math
import random
import pytest
from copy import deepcopy
from typing import List
from unittest.mock import MagicMock
@@ -11,7 +12,7 @@ import numpy as np
import pandas as pd
from arrow import Arrow
from freqtrade import optimize
from freqtrade import optimize, constants, DependencyException
from freqtrade.analyze import Analyze
from freqtrade.arguments import Arguments
from freqtrade.optimize.backtesting import Backtesting, start, setup_configuration
@@ -261,6 +262,28 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
)
def test_setup_configuration_unlimited_stake_amount(mocker, default_conf, caplog) -> None:
"""
Test setup_configuration() function
"""
conf = deepcopy(default_conf)
conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT
mocker.patch('freqtrade.configuration.open', mocker.mock_open(
read_data=json.dumps(conf)
))
args = [
'--config', 'config.json',
'--strategy', 'DefaultStrategy',
'backtesting'
]
with pytest.raises(DependencyException, match=r'.*stake amount.*'):
setup_configuration(get_args(args))
def test_start(mocker, fee, default_conf, caplog) -> None:
"""
Test start() function

View File

@@ -53,6 +53,18 @@ def test_load_config_missing_attributes(default_conf) -> None:
configuration._validate_config(conf)
def test_load_config_incorrect_stake_amount(default_conf) -> None:
"""
Test the configuration validator with a missing attribute
"""
conf = deepcopy(default_conf)
conf['stake_amount'] = 'fake'
with pytest.raises(ValidationError, match=r'.*\'fake\' does not match \'unlimited\'.*'):
configuration = Configuration([])
configuration._validate_config(conf)
def test_load_config_file(default_conf, mocker, caplog) -> None:
"""
Test Configuration._load_config_file() method

View File

@@ -295,6 +295,12 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf,
result = freqtrade._get_trade_stake_amount()
assert(result == default_conf['stake_amount'] / (conf['max_open_trades'] - 1))
# create 2 trades, order amount should be 0
freqtrade.create_trade()
result = freqtrade._get_trade_stake_amount()
assert(result == 0)
def test_create_trade_no_stake_amount(default_conf, ticker, limit_buy_order, fee, mocker) -> None:
"""