define constants.DEFAULT_DB_DRYRUN_URL and fix StaticPool conditions

This commit is contained in:
gcarq 2018-06-07 17:29:43 +02:00
parent c3d0980763
commit 5b1ff6675f
4 changed files with 11 additions and 10 deletions

View File

@ -108,7 +108,7 @@ class Arguments(object):
help='Override trades database URL, this is useful if dry_run is enabled'
' or in custom deployments (default: %(default)s)',
dest='db_url',
default=constants.DEFAULT_DB_URL,
default=constants.DEFAULT_DB_PROD_URL,
type=str,
metavar='PATH',
)

View File

@ -103,12 +103,12 @@ class Configuration(object):
if config.get('dry_run', False):
logger.info('Dry run is enabled')
if config.get('db_url') in [None, constants.DEFAULT_DB_URL]:
if config.get('db_url') in [None, constants.DEFAULT_DB_PROD_URL]:
# Default to in-memory db for dry_run if not specified
config['db_url'] = 'sqlite://'
config['db_url'] = constants.DEFAULT_DB_DRYRUN_URL
else:
if not config.get('db_url', None):
config['db_url'] = constants.DEFAULT_DB_URL
config['db_url'] = constants.DEFAULT_DB_PROD_URL
logger.info('Dry run is disabled')
logger.info('Using DB: "{}"'.format(config['db_url']))

View File

@ -9,7 +9,8 @@ TICKER_INTERVAL = 5 # min
HYPEROPT_EPOCH = 100 # epochs
RETRY_TIMEOUT = 30 # sec
DEFAULT_STRATEGY = 'DefaultStrategy'
DEFAULT_DB_URL = 'sqlite:///tradesv3.sqlite'
DEFAULT_DB_PROD_URL = 'sqlite:///tradesv3.sqlite'
DEFAULT_DB_DRYRUN_URL = 'sqlite://'
TICKER_INTERVAL_MINUTES = {
'1m': 1,

View File

@ -16,6 +16,8 @@ from sqlalchemy.orm.scoping import scoped_session
from sqlalchemy.orm.session import sessionmaker
from sqlalchemy.pool import StaticPool
from freqtrade import constants
logger = logging.getLogger(__name__)
_CONF = {}
@ -35,10 +37,8 @@ def init(config: Dict) -> None:
db_url = _CONF.get('db_url', None)
kwargs = {}
if not db_url and _CONF.get('dry_run', False):
# Default to in-memory db if not specified
# and take care of thread ownership if in-memory db
db_url = 'sqlite://'
if db_url == constants.DEFAULT_DB_DRYRUN_URL:
# Take care of thread ownership if in-memory db
kwargs.update({
'connect_args': {'check_same_thread': False},
'poolclass': StaticPool,
@ -53,7 +53,7 @@ def init(config: Dict) -> None:
check_migrate(engine)
# Clean dry_run DB
if _CONF.get('dry_run', False) and db_url != 'sqlite://':
if _CONF.get('dry_run', False) and db_url != constants.DEFAULT_DB_DRYRUN_URL:
clean_dry_run_db()