Add deep_merge for _ft_has and test

This commit is contained in:
Matthias
2019-06-09 14:05:36 +02:00
parent 9c497bf15c
commit 7108a2e57d
2 changed files with 47 additions and 11 deletions

View File

@@ -2,23 +2,24 @@
"""
Cryptocurrency Exchanges support
"""
import logging
import asyncio
import inspect
from random import randint
from typing import List, Dict, Tuple, Any, Optional
import logging
from copy import deepcopy
from datetime import datetime
from math import floor, ceil
from math import ceil, floor
from random import randint
from typing import Any, Dict, List, Optional, Tuple
import arrow
import asyncio
import ccxt
import ccxt.async_support as ccxt_async
from pandas import DataFrame
from freqtrade import (constants, DependencyException, OperationalException,
TemporaryError, InvalidOrderException)
from freqtrade import (DependencyException, InvalidOrderException,
OperationalException, TemporaryError, constants)
from freqtrade.data.converter import parse_ticker_dataframe
from freqtrade.misc import deep_merge_dicts
logger = logging.getLogger(__name__)
@@ -68,12 +69,13 @@ class Exchange(object):
_params: Dict = {}
# Dict to specify which options each exchange implements
# TODO: this should be merged with attributes from subclasses
# To avoid having to copy/paste this to all subclasses.
_ft_has: Dict = {
# This defines defaults, which can be selectively overridden by subclasses using _ft_has
# or by specifying them in the configuration.
_ft_has_default: Dict = {
"stoploss_on_exchange": False,
"order_time_in_force": ["gtc"],
}
_ft_has: Dict = {}
def __init__(self, config: dict) -> None:
"""
@@ -100,6 +102,13 @@ class Exchange(object):
logger.info('Instance is running with dry_run enabled')
exchange_config = config['exchange']
# Deep merge ft_has with default ft_has options
self._ft_has = deep_merge_dicts(self._ft_has, deepcopy(self._ft_has_default))
if exchange_config.get("_ft_has_params"):
self._ft_has = deep_merge_dicts(exchange_config.get("_ft_has_params"),
self._ft_has)
self._api: ccxt.Exchange = self._init_ccxt(
exchange_config, ccxt_kwargs=exchange_config.get('ccxt_config'))
self._api_async: ccxt_async.Exchange = self._init_ccxt(