Add loading order_types from config file

This commit is contained in:
Matthias 2018-11-17 10:14:18 +01:00
parent e6baa9ccf2
commit 24ed9a8b7d
3 changed files with 40 additions and 0 deletions

View File

@ -33,6 +33,11 @@
"order_book_min": 1, "order_book_min": 1,
"order_book_max": 9 "order_book_max": 9
}, },
"order_types": {
"buy": "limit",
"sell": "limit",
"stoploss": "market"
},
"exchange": { "exchange": {
"name": "bittrex", "name": "bittrex",
"key": "your_exchange_key", "key": "your_exchange_key",

View File

@ -75,6 +75,15 @@ class StrategyResolver(object):
else: else:
config['process_only_new_candles'] = self.strategy.process_only_new_candles config['process_only_new_candles'] = self.strategy.process_only_new_candles
if 'order_types' in config:
self.strategy.order_types = config['order_types']
logger.info(
"Override strategy 'order_types' with value in config file: %s.",
config['order_types']
)
else:
config['order_types'] = self.strategy.order_types
# Sort and apply type conversions # Sort and apply type conversions
self.strategy.minimal_roi = OrderedDict(sorted( self.strategy.minimal_roi = OrderedDict(sorted(
{int(key): value for (key, value) in self.strategy.minimal_roi.items()}.items(), {int(key): value for (key, value) in self.strategy.minimal_roi.items()}.items(),

View File

@ -182,6 +182,32 @@ def test_strategy_override_process_only_new_candles(caplog):
) in caplog.record_tuples ) in caplog.record_tuples
def test_strategy_override_order_types(caplog):
caplog.set_level(logging.INFO)
order_types = {
'buy': 'market',
'sell': 'limit',
'stoploss': 'limit'
}
config = {
'strategy': 'DefaultStrategy',
'order_types': order_types
}
resolver = StrategyResolver(config)
assert resolver.strategy.order_types
for method in ['buy', 'sell', 'stoploss']:
assert resolver.strategy.order_types[method] == order_types[method]
assert ('freqtrade.strategy.resolver',
logging.INFO,
"Override strategy 'order_types' with value in config file:"
" {'buy': 'market', 'sell': 'limit', 'stoploss': 'limit'}."
) in caplog.record_tuples
def test_deprecate_populate_indicators(result): def test_deprecate_populate_indicators(result):
default_location = path.join(path.dirname(path.realpath(__file__))) default_location = path.join(path.dirname(path.realpath(__file__)))
resolver = StrategyResolver({'strategy': 'TestStrategyLegacy', resolver = StrategyResolver({'strategy': 'TestStrategyLegacy',