From 3427c7eb540ac7b73e7ed52578ec1c281b4b2500 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 25 May 2018 17:04:08 +0300 Subject: [PATCH] Use constants --- docs/configuration.md | 2 +- freqtrade/constants.py | 3 ++- freqtrade/freqtradebot.py | 2 +- freqtrade/optimize/backtesting.py | 7 ++++--- freqtrade/tests/test_freqtradebot.py | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index e75775f3f..5b527ddf7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -16,7 +16,7 @@ The table below will list all configuration parameters. |----------|---------|----------|-------------| | `max_open_trades` | 3 | Yes | Number of trades open your bot will have. | `stake_currency` | BTC | Yes | Crypto-currency used for trading. -| `stake_amount` | 0.05 | Yes | Amount of crypto-currency your bot will use for each trade. Per default, the bot will use (0.05 BTC x 3) = 0.15 BTC in total will be always engaged. 'unlimited' is used to allow a bot to use all avaliable balance. +| `stake_amount` | 0.05 | Yes | Amount of crypto-currency your bot will use for each trade. Per default, the bot will use (0.05 BTC x 3) = 0.15 BTC in total will be always engaged. Set it to 'unlimited' to allow the bot to use all avaliable balance. | `ticker_interval` | [1m, 5m, 30m, 1h, 1d] | No | The ticker interval to use (1min, 5 min, 30 min, 1 hour or 1 day). Default is 5 minutes | `fiat_display_currency` | USD | Yes | Fiat currency used to show your profits. More information below. | `dry_run` | true | Yes | Define if the bot must be in Dry-run or production mode. diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 20c8a2287..1039b9da4 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -9,6 +9,7 @@ TICKER_INTERVAL = 5 # min HYPEROPT_EPOCH = 100 # epochs RETRY_TIMEOUT = 30 # sec DEFAULT_STRATEGY = 'DefaultStrategy' +UNLIMITED_STAKE_AMOUNT = 'unlimited' TICKER_INTERVAL_MINUTES = { '1m': 1, @@ -34,7 +35,7 @@ CONF_SCHEMA = { 'stake_currency': {'type': 'string', 'enum': ['BTC', 'ETH', 'USDT']}, 'stake_amount': {'anyOf': [ {'type': 'integer', 'minimum': 0.0005}, - {'constant': 'unlimited'} + {'constant': UNLIMITED_STAKE_AMOUNT} ]}, 'fiat_display_currency': {'type': 'string', 'enum': ['AUD', 'BRL', 'CAD', 'CHF', 'CLP', 'CNY', 'CZK', 'DKK', diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index af3f9287e..431a146dd 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -259,7 +259,7 @@ class FreqtradeBot(object): stake_amount = self.config['stake_amount'] avaliable_amount = exchange.get_balance(self.config['stake_currency']) - if stake_amount == 'unlimited': + if stake_amount == constants.UNLIMITED_STAKE_AMOUNT: open_trades = len(Trade.query.filter(Trade.is_open.is_(True)).all()) if open_trades == self.config['max_open_trades']: return 0 diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index eb6b25e02..520765853 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -13,7 +13,7 @@ from pandas import DataFrame from tabulate import tabulate import freqtrade.optimize as optimize -from freqtrade import exchange, DependencyException +from freqtrade import exchange, constants, DependencyException from freqtrade.analyze import Analyze from freqtrade.arguments import Arguments from freqtrade.configuration import Configuration @@ -296,8 +296,9 @@ def setup_configuration(args: Namespace) -> Dict[str, Any]: config['exchange']['key'] = '' config['exchange']['secret'] = '' - if config['stake_amount'] == 'unlimited': - raise DependencyException('stake amount could not be "unlimited" for backtesting') + if config['stake_amount'] == constants.UNLIMITED_STAKE_AMOUNT: + raise DependencyException('stake amount could not be "%s" for backtesting' % + constants.UNLIMITED_STAKE_AMOUNT) return config diff --git a/freqtrade/tests/test_freqtradebot.py b/freqtrade/tests/test_freqtradebot.py index e47bfd007..eeab3bf37 100644 --- a/freqtrade/tests/test_freqtradebot.py +++ b/freqtrade/tests/test_freqtradebot.py @@ -15,7 +15,7 @@ import pytest import requests from sqlalchemy import create_engine -from freqtrade import DependencyException, OperationalException, TemporaryError +from freqtrade import constants, DependencyException, OperationalException, TemporaryError from freqtrade.freqtradebot import FreqtradeBot from freqtrade.persistence import Trade from freqtrade.state import State @@ -280,7 +280,7 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ) conf = deepcopy(default_conf) - conf['stake_amount'] = 'unlimited' + conf['stake_amount'] = constants.UNLIMITED_STAKE_AMOUNT conf['max_open_trades'] = 2 freqtrade = FreqtradeBot(conf, create_engine('sqlite://'))