From 2bf7705f2c0c46a9d38a087ced290a59f90f4bae Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 12 Jul 2021 23:05:35 -0600 Subject: [PATCH 01/14] Renamed example config files so they are .json so that syntax highlighting is all correct. Explicitly listed each one in .gitignore to prevent a real config file from being uploaded accidently --- .gitignore | 5 +++++ .../config_binance.example.json | 0 .../config_bittrex.example.json | 0 .../config_ftx.example.json | 0 .../config_full.example.json | 0 .../config_kraken.example.json | 0 6 files changed, 5 insertions(+) rename config_binance.json.example => config_examples/config_binance.example.json (100%) rename config_bittrex.json.example => config_examples/config_bittrex.example.json (100%) rename config_ftx.json.example => config_examples/config_ftx.example.json (100%) rename config_full.json.example => config_examples/config_full.example.json (100%) rename config_kraken.json.example => config_examples/config_kraken.example.json (100%) diff --git a/.gitignore b/.gitignore index 4720ff5cb..16df71194 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,8 @@ target/ #exceptions !*.gitkeep +!config_examples/config_binance.example.json +!config_examples/config_bittrex.example.json +!config_examples/config_ftx.example.json +!config_examples/config_full.example.json +!config_examples/config_kraken.example.json diff --git a/config_binance.json.example b/config_examples/config_binance.example.json similarity index 100% rename from config_binance.json.example rename to config_examples/config_binance.example.json diff --git a/config_bittrex.json.example b/config_examples/config_bittrex.example.json similarity index 100% rename from config_bittrex.json.example rename to config_examples/config_bittrex.example.json diff --git a/config_ftx.json.example b/config_examples/config_ftx.example.json similarity index 100% rename from config_ftx.json.example rename to config_examples/config_ftx.example.json diff --git a/config_full.json.example b/config_examples/config_full.example.json similarity index 100% rename from config_full.json.example rename to config_examples/config_full.example.json diff --git a/config_kraken.json.example b/config_examples/config_kraken.example.json similarity index 100% rename from config_kraken.json.example rename to config_examples/config_kraken.example.json From 362436f7d23c8b4ebb7bec942c3bf2a259192a34 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 12 Jul 2021 23:05:35 -0600 Subject: [PATCH 02/14] Renamed example config files so they are .json so that syntax highlighting is all correct. Explicitly listed each one in .gitignore to prevent a real config file from being uploaded accidently --- .github/workflows/ci.yml | 12 ++--- .gitignore | 5 ++ .travis.yml | 4 +- build_helpers/publish_docker_multi.sh | 2 +- .../config_binance.example.json | 0 .../config_bittrex.example.json | 0 .../config_ftx.example.json | 0 .../config_full.example.json | 0 .../config_kraken.example.json | 0 docs/configuration.md | 2 +- tests/commands/test_commands.py | 54 +++++++++---------- tests/test_arguments.py | 2 +- tests/test_configuration.py | 2 +- tests/test_main.py | 20 +++---- tests/test_plotting.py | 4 +- 15 files changed, 56 insertions(+), 51 deletions(-) rename config_binance.json.example => config_examples/config_binance.example.json (100%) rename config_bittrex.json.example => config_examples/config_bittrex.example.json (100%) rename config_ftx.json.example => config_examples/config_ftx.example.json (100%) rename config_full.json.example => config_examples/config_full.example.json (100%) rename config_kraken.json.example => config_examples/config_kraken.example.json (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 42959c3b5..5890f56a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,13 +79,13 @@ jobs: - name: Backtesting run: | - cp config_bittrex.json.example config.json + cp config_examples/config_bittrex.example.json config.json freqtrade create-userdir --userdir user_data freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy - name: Hyperopt run: | - cp config_bittrex.json.example config.json + cp config_examples/config_bittrex.example.json config.json freqtrade create-userdir --userdir user_data freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily --print-all @@ -172,13 +172,13 @@ jobs: - name: Backtesting run: | - cp config_bittrex.json.example config.json + cp config_examples/config_bittrex.example.json config.json freqtrade create-userdir --userdir user_data freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy - name: Hyperopt run: | - cp config_bittrex.json.example config.json + cp config_examples/config_bittrex.example.json config.json freqtrade create-userdir --userdir user_data freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily --print-all @@ -239,13 +239,13 @@ jobs: - name: Backtesting run: | - cp config_bittrex.json.example config.json + cp config_examples/config_bittrex.example.json config.json freqtrade create-userdir --userdir user_data freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy - name: Hyperopt run: | - cp config_bittrex.json.example config.json + cp config_examples/config_bittrex.example.json config.json freqtrade create-userdir --userdir user_data freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily --print-all diff --git a/.gitignore b/.gitignore index 4720ff5cb..16df71194 100644 --- a/.gitignore +++ b/.gitignore @@ -95,3 +95,8 @@ target/ #exceptions !*.gitkeep +!config_examples/config_binance.example.json +!config_examples/config_bittrex.example.json +!config_examples/config_ftx.example.json +!config_examples/config_full.example.json +!config_examples/config_kraken.example.json diff --git a/.travis.yml b/.travis.yml index 4535c44cb..f2a6d508d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,12 +26,12 @@ jobs: # - coveralls || true name: pytest - script: - - cp config_bittrex.json.example config.json + - cp config_examples/config_bittrex.example.json config.json - freqtrade create-userdir --userdir user_data - freqtrade backtesting --datadir tests/testdata --strategy SampleStrategy name: backtest - script: - - cp config_bittrex.json.example config.json + - cp config_examples/config_bittrex.example.json config.json - freqtrade create-userdir --userdir user_data - freqtrade hyperopt --datadir tests/testdata -e 5 --strategy SampleStrategy --hyperopt SampleHyperOpt --hyperopt-loss SharpeHyperOptLossDaily name: hyperopt diff --git a/build_helpers/publish_docker_multi.sh b/build_helpers/publish_docker_multi.sh index a6b06ce7d..057ecbbf2 100755 --- a/build_helpers/publish_docker_multi.sh +++ b/build_helpers/publish_docker_multi.sh @@ -52,7 +52,7 @@ docker build --cache-from freqtrade:${TAG} --build-arg sourceimage=${TAG} -t fre docker tag freqtrade:$TAG_PLOT ${IMAGE_NAME}:$TAG_PLOT # Run backtest -docker run --rm -v $(pwd)/config_bittrex.json.example:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} backtesting --datadir /tests/testdata --strategy-path /tests/strategy/strats/ --strategy DefaultStrategy +docker run --rm -v $(pwd)/config_examples/config_bittrex.example.json:/freqtrade/config.json:ro -v $(pwd)/tests:/tests freqtrade:${TAG} backtesting --datadir /tests/testdata --strategy-path /tests/strategy/strats/ --strategy DefaultStrategy if [ $? -ne 0 ]; then echo "failed running backtest" diff --git a/config_binance.json.example b/config_examples/config_binance.example.json similarity index 100% rename from config_binance.json.example rename to config_examples/config_binance.example.json diff --git a/config_bittrex.json.example b/config_examples/config_bittrex.example.json similarity index 100% rename from config_bittrex.json.example rename to config_examples/config_bittrex.example.json diff --git a/config_ftx.json.example b/config_examples/config_ftx.example.json similarity index 100% rename from config_ftx.json.example rename to config_examples/config_ftx.example.json diff --git a/config_full.json.example b/config_examples/config_full.example.json similarity index 100% rename from config_full.json.example rename to config_examples/config_full.example.json diff --git a/config_kraken.json.example b/config_examples/config_kraken.example.json similarity index 100% rename from config_kraken.json.example rename to config_examples/config_kraken.example.json diff --git a/docs/configuration.md b/docs/configuration.md index 5c6236e58..c84a0ac34 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -556,7 +556,7 @@ You should also make sure to read the [Exchanges](exchanges.md) section of the d To use a proxy with freqtrade, add the kwarg `"aiohttp_trust_env"=true` to the `"ccxt_async_kwargs"` dict in the exchange section of the configuration. -An example for this can be found in `config_full.json.example` +An example for this can be found in `config_examples/config_full.example.json` ``` json "ccxt_async_config": { diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index dcceb3ea1..de0cb80e4 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -26,7 +26,7 @@ from tests.conftest_trades import MOCK_TRADE_COUNT def test_setup_utils_configuration(): args = [ - 'list-exchanges', '--config', 'config_bittrex.json.example', + 'list-exchanges', '--config', 'config_examples/config_bittrex.example.json', ] config = setup_utils_configuration(get_args(args), RunMode.OTHER) @@ -45,7 +45,7 @@ def test_start_trading_fail(mocker, caplog): exitmock = mocker.patch("freqtrade.worker.Worker.exit", MagicMock()) args = [ 'trade', - '-c', 'config_bittrex.json.example' + '-c', 'config_examples/config_bittrex.example.json' ] start_trading(get_args(args)) assert exitmock.call_count == 1 @@ -127,10 +127,10 @@ def test_list_timeframes(mocker, capsys): match=r"This command requires a configured exchange.*"): start_list_timeframes(pargs) - # Test with --config config_bittrex.json.example + # Test with --config config_examples/config_bittrex.example.json args = [ "list-timeframes", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', ] start_list_timeframes(get_args(args)) captured = capsys.readouterr() @@ -174,7 +174,7 @@ def test_list_timeframes(mocker, capsys): # Test with --one-column args = [ "list-timeframes", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--one-column", ] start_list_timeframes(get_args(args)) @@ -214,10 +214,10 @@ def test_list_markets(mocker, markets, capsys): match=r"This command requires a configured exchange.*"): start_list_markets(pargs, False) - # Test with --config config_bittrex.json.example + # Test with --config config_examples/config_bittrex.example.json args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--print-list", ] start_list_markets(get_args(args), False) @@ -244,7 +244,7 @@ def test_list_markets(mocker, markets, capsys): # Test with --all: all markets args = [ "list-markets", "--all", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--print-list", ] start_list_markets(get_args(args), False) @@ -257,7 +257,7 @@ def test_list_markets(mocker, markets, capsys): # Test list-pairs subcommand: active pairs args = [ "list-pairs", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--print-list", ] start_list_markets(get_args(args), True) @@ -269,7 +269,7 @@ def test_list_markets(mocker, markets, capsys): # Test list-pairs subcommand with --all: all pairs args = [ "list-pairs", "--all", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--print-list", ] start_list_markets(get_args(args), True) @@ -282,7 +282,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, base=ETH, LTC args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "ETH", "LTC", "--print-list", ] @@ -295,7 +295,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, base=LTC args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "LTC", "--print-list", ] @@ -308,7 +308,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, quote=USDT, USD args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--quote", "USDT", "USD", "--print-list", ] @@ -321,7 +321,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, quote=USDT args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--quote", "USDT", "--print-list", ] @@ -334,7 +334,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, base=LTC, quote=USDT args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "LTC", "--quote", "USDT", "--print-list", ] @@ -347,7 +347,7 @@ def test_list_markets(mocker, markets, capsys): # active pairs, base=LTC, quote=USDT args = [ "list-pairs", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "LTC", "--quote", "USD", "--print-list", ] @@ -360,7 +360,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, base=LTC, quote=USDT, NONEXISTENT args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "LTC", "--quote", "USDT", "NONEXISTENT", "--print-list", ] @@ -373,7 +373,7 @@ def test_list_markets(mocker, markets, capsys): # active markets, base=LTC, quote=NONEXISTENT args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "LTC", "--quote", "NONEXISTENT", "--print-list", ] @@ -386,7 +386,7 @@ def test_list_markets(mocker, markets, capsys): # Test tabular output args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', ] start_list_markets(get_args(args), False) captured = capsys.readouterr() @@ -396,7 +396,7 @@ def test_list_markets(mocker, markets, capsys): # Test tabular output, no markets found args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--base", "LTC", "--quote", "NONEXISTENT", ] start_list_markets(get_args(args), False) @@ -408,7 +408,7 @@ def test_list_markets(mocker, markets, capsys): # Test --print-json args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--print-json" ] start_list_markets(get_args(args), False) @@ -420,7 +420,7 @@ def test_list_markets(mocker, markets, capsys): # Test --print-csv args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--print-csv" ] start_list_markets(get_args(args), False) @@ -432,7 +432,7 @@ def test_list_markets(mocker, markets, capsys): # Test --one-column args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--one-column" ] start_list_markets(get_args(args), False) @@ -444,7 +444,7 @@ def test_list_markets(mocker, markets, capsys): # Test --one-column args = [ "list-markets", - '--config', 'config_bittrex.json.example', + '--config', 'config_examples/config_bittrex.example.json', "--one-column" ] with pytest.raises(OperationalException, match=r"Cannot get markets.*"): @@ -887,7 +887,7 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys): patched_configuration_load_config_file(mocker, default_conf) args = [ 'test-pairlist', - '-c', 'config_bittrex.json.example' + '-c', 'config_examples/config_bittrex.example.json' ] start_test_pairlist(get_args(args)) @@ -901,7 +901,7 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys): args = [ 'test-pairlist', - '-c', 'config_bittrex.json.example', + '-c', 'config_examples/config_bittrex.example.json', '--one-column', ] start_test_pairlist(get_args(args)) @@ -910,7 +910,7 @@ def test_start_test_pairlist(mocker, caplog, tickers, default_conf, capsys): args = [ 'test-pairlist', - '-c', 'config_bittrex.json.example', + '-c', 'config_examples/config_bittrex.example.json', '--print-json', ] start_test_pairlist(get_args(args)) diff --git a/tests/test_arguments.py b/tests/test_arguments.py index 0d81dea28..fd6f162fd 100644 --- a/tests/test_arguments.py +++ b/tests/test_arguments.py @@ -172,7 +172,7 @@ def test_download_data_options() -> None: def test_plot_dataframe_options() -> None: args = [ 'plot-dataframe', - '-c', 'config_bittrex.json.example', + '-c', 'config_examples/config_bittrex.example.json', '--indicators1', 'sma10', 'sma100', '--indicators2', 'macd', 'fastd', 'fastk', '--plot-limit', '30', diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 8edd09c5a..34db892b2 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -28,7 +28,7 @@ from tests.conftest import log_has, log_has_re, patched_configuration_load_confi @pytest.fixture(scope="function") def all_conf(): - config_file = Path(__file__).parents[1] / "config_full.json.example" + config_file = Path(__file__).parents[1] / "config_examples/config_full.example.json" conf = load_config_file(str(config_file)) return conf diff --git a/tests/test_main.py b/tests/test_main.py index 3546a3bab..4f769ca30 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -67,12 +67,12 @@ def test_main_fatal_exception(mocker, default_conf, caplog) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = ['trade', '-c', 'config_bittrex.json.example'] + args = ['trade', '-c', 'config_examples/config_bittrex.example.json'] # Test Main + the KeyboardInterrupt exception with pytest.raises(SystemExit): main(args) - assert log_has('Using config: config_bittrex.json.example ...', caplog) + assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog) assert log_has('Fatal exception!', caplog) @@ -85,12 +85,12 @@ def test_main_keyboard_interrupt(mocker, default_conf, caplog) -> None: mocker.patch('freqtrade.wallets.Wallets.update', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = ['trade', '-c', 'config_bittrex.json.example'] + args = ['trade', '-c', 'config_examples/config_bittrex.example.json'] # Test Main + the KeyboardInterrupt exception with pytest.raises(SystemExit): main(args) - assert log_has('Using config: config_bittrex.json.example ...', caplog) + assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog) assert log_has('SIGINT received, aborting ...', caplog) @@ -106,12 +106,12 @@ def test_main_operational_exception(mocker, default_conf, caplog) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = ['trade', '-c', 'config_bittrex.json.example'] + args = ['trade', '-c', 'config_examples/config_bittrex.example.json'] # Test Main + the KeyboardInterrupt exception with pytest.raises(SystemExit): main(args) - assert log_has('Using config: config_bittrex.json.example ...', caplog) + assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog) assert log_has('Oh snap!', caplog) @@ -157,12 +157,12 @@ def test_main_reload_config(mocker, default_conf, caplog) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = Arguments(['trade', '-c', 'config_bittrex.json.example']).get_parsed_arg() + args = Arguments(['trade', '-c', 'config_examples/config_bittrex.example.json']).get_parsed_arg() worker = Worker(args=args, config=default_conf) with pytest.raises(SystemExit): - main(['trade', '-c', 'config_bittrex.json.example']) + main(['trade', '-c', 'config_examples/config_bittrex.example.json']) - assert log_has('Using config: config_bittrex.json.example ...', caplog) + assert log_has('Using config: config_examples/config_bittrex.example.json ...', caplog) assert worker_mock.call_count == 4 assert reconfigure_mock.call_count == 1 assert isinstance(worker.freqtrade, FreqtradeBot) @@ -180,7 +180,7 @@ def test_reconfigure(mocker, default_conf) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = Arguments(['trade', '-c', 'config_bittrex.json.example']).get_parsed_arg() + args = Arguments(['trade', '-c', 'config_examples/config_bittrex.example.json']).get_parsed_arg() worker = Worker(args=args, config=default_conf) freqtrade = worker.freqtrade diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 20f159e3a..ecadc3f8b 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -364,7 +364,7 @@ def test_start_plot_dataframe(mocker): aup = mocker.patch("freqtrade.plot.plotting.load_and_plot_trades", MagicMock()) args = [ "plot-dataframe", - "--config", "config_bittrex.json.example", + "--config", "config_examples/config_bittrex.example.json", "--pairs", "ETH/BTC" ] start_plot_dataframe(get_args(args)) @@ -408,7 +408,7 @@ def test_start_plot_profit(mocker): aup = mocker.patch("freqtrade.plot.plotting.plot_profit", MagicMock()) args = [ "plot-profit", - "--config", "config_bittrex.json.example", + "--config", "config_examples/config_bittrex.example.json", "--pairs", "ETH/BTC" ] start_plot_profit(get_args(args)) From f5c47767cb509836ab7fcd1fd87d629172d21bbb Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 14 Jul 2021 20:51:42 +0200 Subject: [PATCH 03/14] Provide available capital to api --- freqtrade/rpc/api_server/api_schemas.py | 1 + freqtrade/rpc/rpc.py | 1 + 2 files changed, 2 insertions(+) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index a0f1c05a6..40101e609 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -115,6 +115,7 @@ class ShowConfig(BaseModel): dry_run: bool stake_currency: str stake_amount: Union[float, str] + available_capital: Optional[float] stake_currency_decimals: int max_open_trades: int minimal_roi: Dict[str, Any] diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index e0aaefe50..e173673be 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -106,6 +106,7 @@ class RPC: 'stake_currency': config['stake_currency'], 'stake_currency_decimals': decimals_per_coin(config['stake_currency']), 'stake_amount': config['stake_amount'], + 'available_capital': config.get('available_capital'), 'max_open_trades': (config['max_open_trades'] if config['max_open_trades'] != float('inf') else -1), 'minimal_roi': config['minimal_roi'].copy() if 'minimal_roi' in config else {}, From c9c7f84e8c2726b2d423f70ca1e569b21487a084 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 14 Jul 2021 20:55:11 +0200 Subject: [PATCH 04/14] Calculate relative profit based on assumed starting balance --- freqtrade/rpc/api_server/api_schemas.py | 4 ++++ freqtrade/rpc/rpc.py | 17 +++++++++++++---- freqtrade/rpc/telegram.py | 8 ++++---- freqtrade/wallets.py | 13 +++++++++++++ 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index 40101e609..d3eec9be6 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -67,12 +67,16 @@ class Profit(BaseModel): profit_closed_ratio_mean: float profit_closed_percent_sum: float profit_closed_ratio_sum: float + profit_closed_percent: float + profit_closed_ratio: float profit_closed_fiat: float profit_all_coin: float profit_all_percent_mean: float profit_all_ratio_mean: float profit_all_percent_sum: float profit_all_ratio_sum: float + profit_all_percent: float + profit_all_ratio: float profit_all_fiat: float trade_count: int closed_trade_count: int diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index e173673be..d6eaf7ca6 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -397,7 +397,12 @@ class RPC: profit_all_coin_sum = round(sum(profit_all_coin), 8) profit_all_ratio_mean = float(mean(profit_all_ratio) if profit_all_ratio else 0.0) + # Doing the sum is not right - overall profit needs to be based on initial capital profit_all_ratio_sum = sum(profit_all_ratio) if profit_all_ratio else 0.0 + starting_balance = self._freqtrade.wallets.get_starting_balance() + profit_closed_ratio_fromstart = profit_closed_coin_sum / starting_balance + profit_all_ratio_fromstart = profit_all_coin_sum / starting_balance + profit_all_fiat = self._fiat_converter.convert_amount( profit_all_coin_sum, stake_currency, @@ -411,14 +416,18 @@ class RPC: 'profit_closed_coin': profit_closed_coin_sum, 'profit_closed_percent_mean': round(profit_closed_ratio_mean * 100, 2), 'profit_closed_ratio_mean': profit_closed_ratio_mean, - 'profit_closed_percent_sum': round(profit_closed_ratio_sum * 100, 2), - 'profit_closed_ratio_sum': profit_closed_ratio_sum, + 'profit_closed_percent_sum': round(profit_closed_ratio_sum * 100, 2), # Deprecated + 'profit_closed_ratio_sum': profit_closed_ratio_sum, # Deprecated + 'profit_closed_ratio': profit_closed_ratio_fromstart, + 'profit_closed_percent': round(profit_closed_ratio_fromstart * 100, 2), 'profit_closed_fiat': profit_closed_fiat, 'profit_all_coin': profit_all_coin_sum, 'profit_all_percent_mean': round(profit_all_ratio_mean * 100, 2), 'profit_all_ratio_mean': profit_all_ratio_mean, - 'profit_all_percent_sum': round(profit_all_ratio_sum * 100, 2), - 'profit_all_ratio_sum': profit_all_ratio_sum, + 'profit_all_percent_sum': round(profit_all_ratio_sum * 100, 2), # Deprecated + 'profit_all_ratio_sum': profit_all_ratio_sum, # Deprecated + 'profit_all_ratio': profit_all_ratio_fromstart, + 'profit_all_percent': round(profit_all_ratio_fromstart * 100, 2), 'profit_all_fiat': profit_all_fiat, 'trade_count': len(trades), 'closed_trade_count': len([t for t in trades if not t.is_open]), diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 319a6c9c0..263a3fc6d 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -494,11 +494,11 @@ class Telegram(RPCHandler): start_date) profit_closed_coin = stats['profit_closed_coin'] profit_closed_percent_mean = stats['profit_closed_percent_mean'] - profit_closed_percent_sum = stats['profit_closed_percent_sum'] + profit_closed_percent = stats['profit_closed_percent'] profit_closed_fiat = stats['profit_closed_fiat'] profit_all_coin = stats['profit_all_coin'] profit_all_percent_mean = stats['profit_all_percent_mean'] - profit_all_percent_sum = stats['profit_all_percent_sum'] + profit_all_percent = stats['profit_all_percent'] profit_all_fiat = stats['profit_all_fiat'] trade_count = stats['trade_count'] first_trade_date = stats['first_trade_date'] @@ -514,7 +514,7 @@ class Telegram(RPCHandler): markdown_msg = ("*ROI:* Closed trades\n" f"∙ `{round_coin_value(profit_closed_coin, stake_cur)} " f"({profit_closed_percent_mean:.2f}%) " - f"({profit_closed_percent_sum} \N{GREEK CAPITAL LETTER SIGMA}%)`\n" + f"({profit_closed_percent} \N{GREEK CAPITAL LETTER SIGMA}%)`\n" f"∙ `{round_coin_value(profit_closed_fiat, fiat_disp_cur)}`\n") else: markdown_msg = "`No closed trade` \n" @@ -523,7 +523,7 @@ class Telegram(RPCHandler): f"*ROI:* All trades\n" f"∙ `{round_coin_value(profit_all_coin, stake_cur)} " f"({profit_all_percent_mean:.2f}%) " - f"({profit_all_percent_sum} \N{GREEK CAPITAL LETTER SIGMA}%)`\n" + f"({profit_all_percent} \N{GREEK CAPITAL LETTER SIGMA}%)`\n" f"∙ `{round_coin_value(profit_all_fiat, fiat_disp_cur)}`\n" f"*Total Trade Count:* `{trade_count}`\n" f"*{'First Trade opened' if not timescale else 'Showing Profit since'}:* " diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index 0048dbf48..e51a01afc 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -129,6 +129,19 @@ class Wallets: def get_all_balances(self) -> Dict[str, Any]: return self._wallets + def get_starting_balance(self) -> float: + """ + Retrieves starting balance - based on either available capital, + or by using current balance subtracting + """ + if "available_capital" in self._config: + return self._config['available_capital'] + else: + tot_profit = Trade.get_total_closed_profit() + open_stakes = Trade.total_open_trades_stakes() + available_balance = self.get_free(self._config['stake_currency']) + return available_balance - tot_profit + open_stakes + def get_total_stake_amount(self): """ Return the total currently available balance in stake currency, including tied up stake and From 02d716a8be1963d7741a20d0c435a307793ba006 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 14 Jul 2021 20:59:47 +0200 Subject: [PATCH 05/14] Fix api test --- tests/rpc/test_rpc_apiserver.py | 4 ++++ tests/rpc/test_rpc_telegram.py | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 89da68da7..4dea2bbfa 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -677,12 +677,16 @@ def test_api_profit(botclient, mocker, ticker, fee, markets): 'profit_all_ratio_mean': -0.6641100666666667, 'profit_all_percent_sum': -398.47, 'profit_all_ratio_sum': -3.9846604, + 'profit_all_percent': -4.41, + 'profit_all_ratio': -0.044063014216106644, 'profit_closed_coin': 0.00073913, 'profit_closed_fiat': 9.124559849999999, 'profit_closed_ratio_mean': 0.0075, 'profit_closed_percent_mean': 0.75, 'profit_closed_ratio_sum': 0.015, 'profit_closed_percent_sum': 1.5, + 'profit_closed_ratio': 7.391275897987988e-07, + 'profit_closed_percent': 0.0, 'trade_count': 6, 'closed_trade_count': 2, 'winning_trades': 2, diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 4784f1172..cccc78117 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -452,7 +452,8 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee, assert msg_mock.call_count == 1 assert 'No closed trade' in msg_mock.call_args_list[-1][0][0] assert '*ROI:* All trades' in msg_mock.call_args_list[-1][0][0] - assert ('∙ `-0.00000500 BTC (-0.50%) (-0.5 \N{GREEK CAPITAL LETTER SIGMA}%)`' + mocker.patch('freqtrade.wallets.Wallets.get_starting_balance', return_value=0.01) + assert ('∙ `-0.00000500 BTC (-0.50%) (-0.0 \N{GREEK CAPITAL LETTER SIGMA}%)`' in msg_mock.call_args_list[-1][0][0]) msg_mock.reset_mock() @@ -466,11 +467,11 @@ def test_profit_handle(default_conf, update, ticker, ticker_sell_up, fee, telegram._profit(update=update, context=MagicMock()) assert msg_mock.call_count == 1 assert '*ROI:* Closed trades' in msg_mock.call_args_list[-1][0][0] - assert ('∙ `0.00006217 BTC (6.20%) (6.2 \N{GREEK CAPITAL LETTER SIGMA}%)`' + assert ('∙ `0.00006217 BTC (6.20%) (0.62 \N{GREEK CAPITAL LETTER SIGMA}%)`' in msg_mock.call_args_list[-1][0][0]) assert '∙ `0.933 USD`' in msg_mock.call_args_list[-1][0][0] assert '*ROI:* All trades' in msg_mock.call_args_list[-1][0][0] - assert ('∙ `0.00006217 BTC (6.20%) (6.2 \N{GREEK CAPITAL LETTER SIGMA}%)`' + assert ('∙ `0.00006217 BTC (6.20%) (0.62 \N{GREEK CAPITAL LETTER SIGMA}%)`' in msg_mock.call_args_list[-1][0][0]) assert '∙ `0.933 USD`' in msg_mock.call_args_list[-1][0][0] From 697bf92f6f10d6419982e8e45a1c83039be6a4cd Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 14 Jul 2021 21:10:25 +0200 Subject: [PATCH 06/14] Add test for get_starting_balance method --- tests/test_wallets.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/test_wallets.py b/tests/test_wallets.py index a44ca243b..25f2ad89f 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -197,3 +197,28 @@ def test__validate_stake_amount(mocker, default_conf, return_value=max_stake_amount) res = freqtrade.wallets._validate_stake_amount('XRP/USDT', stake_amount, min_stake_amount) assert res == expected + + +@pytest.mark.parametrize('available_capital,closed_profit,open_stakes,free,expected', [ + (None, 10, 100, 910, 1000), + (None, 0, 0, 2500, 2500), + (None, 500, 0, 2500, 2000), + (None, 500, 0, 2500, 2000), + # Only available balance matters when it's set. + (100, 0, 0, 0, 100), + (1000, 0, 2, 5, 1000), + (1235, 2250, 2, 5, 1235), +]) +def test_get_starting_balance(mocker, default_conf, available_capital, closed_profit, + open_stakes, free, expected): + if available_capital: + default_conf['available_capital'] = available_capital + mocker.patch("freqtrade.persistence.models.Trade.get_total_closed_profit", + return_value=closed_profit) + mocker.patch("freqtrade.persistence.models.Trade.total_open_trades_stakes", + return_value=open_stakes) + mocker.patch("freqtrade.wallets.Wallets.get_free", return_value=free) + + freqtrade = get_patched_freqtradebot(mocker, default_conf) + + assert freqtrade.wallets.get_starting_balance() == expected From cde041f7024fcac948418cd3b1d87adad7f3435a Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 14 Jul 2021 19:20:12 -0600 Subject: [PATCH 07/14] install hdf5 and c-blosc on mac if using python3.9 --- setup.sh | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/setup.sh b/setup.sh index 631c31df2..ee3fee0a3 100755 --- a/setup.sh +++ b/setup.sh @@ -17,6 +17,15 @@ function check_installed_python() { exit 2 fi + which python3.9 + if [ $? -eq 0 ]; then + echo "using Python 3.9" + PYTHON=python3.9 + check_installed_pip + return + fi + + which python3.8 if [ $? -eq 0 ]; then echo "using Python 3.8" @@ -25,13 +34,6 @@ function check_installed_python() { return fi - which python3.9 - if [ $? -eq 0 ]; then - echo "using Python 3.9" - PYTHON=python3.9 - check_installed_pip - return - fi which python3.7 if [ $? -eq 0 ]; then @@ -122,6 +124,25 @@ function install_talib() { cd .. } +function install_mac_newer_python_dependencies() { + + if [ ! $(brew --prefix --installed hdf5 2>/dev/null) ] + then + echo "-------------------------" + echo "Installing hdf5" + echo "-------------------------" + brew install hdf5 + fi + + if [ ! $(brew --prefix --installed c-blosc 2>/dev/null) ] + then + echo "-------------------------" + echo "Installing c-blosc" + echo "-------------------------" + brew install c-blosc + fi +} + # Install bot MacOS function install_macos() { if [ ! -x "$(command -v brew)" ] @@ -131,6 +152,12 @@ function install_macos() { echo "-------------------------" /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" fi + #Gets number after decimal in python version + version=$(egrep -o 3.\[0-9\]+ <<< $PYTHON | sed 's/3.//g' ) + + if [[ $version -ge 9 ]]; then #Checks if python version >= 3.9 + install_mac_newer_python_dependencies + fi install_talib test_and_fix_python_on_mac } From 74d7497a47b3fe9ddc40895a3b3eb8b54d97f153 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 14 Jul 2021 19:25:51 -0600 Subject: [PATCH 08/14] Setup script tries to install python3.9 instead of 3.8 with this fix, python versions are also checked for in a loop instead of copy and pasted code --- setup.sh | 40 ++++++++++------------------------------ 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/setup.sh b/setup.sh index ee3fee0a3..1393b012a 100755 --- a/setup.sh +++ b/setup.sh @@ -17,37 +17,17 @@ function check_installed_python() { exit 2 fi - which python3.9 - if [ $? -eq 0 ]; then - echo "using Python 3.9" - PYTHON=python3.9 - check_installed_pip - return - fi + for v in {9..7}; do + PYTHON="python3.${v}" + which $PYTHON + if [ $? -eq 0 ]; then + check_installed_pip + return + fi + done - - which python3.8 - if [ $? -eq 0 ]; then - echo "using Python 3.8" - PYTHON=python3.8 - check_installed_pip - return - fi - - - which python3.7 - if [ $? -eq 0 ]; then - echo "using Python 3.7" - PYTHON=python3.7 - check_installed_pip - return - fi - - - if [ -z ${PYTHON} ]; then - echo "No usable python found. Please make sure to have python3.7 or newer installed" - exit 1 - fi + echo "No usable python found. Please make sure to have python3.7 or newer installed" + exit 1 } function updateenv() { From 65ce7c983888b43b9a871125f2f33987bd181724 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 14 Jul 2021 20:01:43 -0600 Subject: [PATCH 09/14] Added echo python3.* line back in --- setup.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.sh b/setup.sh index 1393b012a..78cb499a8 100755 --- a/setup.sh +++ b/setup.sh @@ -21,6 +21,8 @@ function check_installed_python() { PYTHON="python3.${v}" which $PYTHON if [ $? -eq 0 ]; then + echo "using ${PYTHON}" + check_installed_pip return fi From 07e3f824006be83a83fa37c29cf05a72ba3b353a Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Thu, 15 Jul 2021 01:03:32 -0600 Subject: [PATCH 10/14] Changed to python3.8 installing first, removed test_and_fix_python_on_mac --- setup.sh | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/setup.sh b/setup.sh index 78cb499a8..3bcbfc48d 100755 --- a/setup.sh +++ b/setup.sh @@ -17,7 +17,8 @@ function check_installed_python() { exit 2 fi - for v in {9..7}; do + for v in 8 9 7 + do PYTHON="python3.${v}" which $PYTHON if [ $? -eq 0 ]; then @@ -141,7 +142,6 @@ function install_macos() { install_mac_newer_python_dependencies fi install_talib - test_and_fix_python_on_mac } # Install bot Debian_ubuntu @@ -198,19 +198,6 @@ function reset() { updateenv } -function test_and_fix_python_on_mac() { - - if ! [ -x "$(command -v python3.6)" ] - then - echo "-------------------------" - echo "Fixing Python" - echo "-------------------------" - echo "Python 3.6 is not linked in your system. Fixing it..." - brew link --overwrite python - echo - fi -} - function config() { echo "-------------------------" From 2928ee22ce4bc4dc8b81107fb00d537ac7924c54 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 15 Jul 2021 14:32:23 +0000 Subject: [PATCH 11/14] Remove compose file for devcontainer --- .devcontainer/devcontainer.json | 33 ++++++++++++++------------------ .devcontainer/docker-compose.yml | 24 ----------------------- 2 files changed, 14 insertions(+), 43 deletions(-) delete mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1882e3bdf..41b8475ec 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,11 +1,20 @@ { "name": "freqtrade Develop", - - "dockerComposeFile": [ - "docker-compose.yml" + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ + 8080 ], + "mounts": [ + "source=freqtrade-bashhistory,target=/home/ftuser/commandhistory,type=volume" + ], + // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "ftuser", - "service": "ft_vscode", + "postCreateCommand": "freqtrade create-userdir --userdir user_data/", "workspaceFolder": "/freqtrade/", @@ -25,20 +34,6 @@ "ms-python.vscode-pylance", "davidanson.vscode-markdownlint", "ms-azuretools.vscode-docker", + "vscode-icons-team.vscode-icons", ], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Uncomment the next line if you want start specific services in your Docker Compose config. - // "runServices": [], - - // Uncomment the next line if you want to keep your containers running after VS Code shuts down. - // "shutdownAction": "none", - - // Uncomment the next line to run commands after the container is created - for example installing curl. - // "postCreateCommand": "sudo apt-get update && apt-get install -y git", - - // Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "ftuser" } diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml deleted file mode 100644 index 20ec247d1..000000000 --- a/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -version: '3' -services: - ft_vscode: - build: - context: .. - dockerfile: ".devcontainer/Dockerfile" - volumes: - # Allow git usage within container - - "${HOME}/.ssh:/home/ftuser/.ssh:ro" - - "${HOME}/.gitconfig:/home/ftuser/.gitconfig:ro" - - ..:/freqtrade:cached - # Persist bash-history - - freqtrade-vscode-server:/home/ftuser/.vscode-server - - freqtrade-bashhistory:/home/ftuser/commandhistory - # Expose API port - ports: - - "127.0.0.1:8080:8080" - command: /bin/sh -c "while sleep 1000; do :; done" - - -volumes: - freqtrade-vscode-server: - freqtrade-bashhistory: From 2e95df4d8dde6ff7ff4be9ed41af9da742ba3b18 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 15 Jul 2021 07:11:44 +0200 Subject: [PATCH 12/14] Update docs for /profit output --- docs/telegram-usage.md | 8 ++++++-- freqtrade/rpc/rpc.py | 8 ++++---- tests/test_wallets.py | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index f5d9744b4..b020b00db 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -245,10 +245,10 @@ current max Return a summary of your profit/loss and performance. > **ROI:** Close trades -> ∙ `0.00485701 BTC (258.45%)` +> ∙ `0.00485701 BTC (2.2%) (15.2 Σ%)` > ∙ `62.968 USD` > **ROI:** All trades -> ∙ `0.00255280 BTC (143.43%)` +> ∙ `0.00255280 BTC (1.5%) (6.43 Σ%)` > ∙ `33.095 EUR` > > **Total Trade Count:** `138` @@ -257,6 +257,10 @@ Return a summary of your profit/loss and performance. > **Avg. Duration:** `2:33:45` > **Best Performing:** `PAY/BTC: 50.23%` +The relative profit of `1.2%` is the average profit per trade. +The relative profit of `15.2 Σ%` is be based on the starting capital - so in this case, the starting capital was `0.00485701 * 1.152 = 0.00738 BTC`. +Starting capital is either taken from the `available_capital` setting, or calculated by using current wallet size - profits. + ### /forcesell > **BITTREX:** Selling BTC/LTC with limit `0.01650000 (profit: ~-4.07%, -0.00008168)` diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index d6eaf7ca6..db89443bf 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -416,16 +416,16 @@ class RPC: 'profit_closed_coin': profit_closed_coin_sum, 'profit_closed_percent_mean': round(profit_closed_ratio_mean * 100, 2), 'profit_closed_ratio_mean': profit_closed_ratio_mean, - 'profit_closed_percent_sum': round(profit_closed_ratio_sum * 100, 2), # Deprecated - 'profit_closed_ratio_sum': profit_closed_ratio_sum, # Deprecated + 'profit_closed_percent_sum': round(profit_closed_ratio_sum * 100, 2), + 'profit_closed_ratio_sum': profit_closed_ratio_sum, 'profit_closed_ratio': profit_closed_ratio_fromstart, 'profit_closed_percent': round(profit_closed_ratio_fromstart * 100, 2), 'profit_closed_fiat': profit_closed_fiat, 'profit_all_coin': profit_all_coin_sum, 'profit_all_percent_mean': round(profit_all_ratio_mean * 100, 2), 'profit_all_ratio_mean': profit_all_ratio_mean, - 'profit_all_percent_sum': round(profit_all_ratio_sum * 100, 2), # Deprecated - 'profit_all_ratio_sum': profit_all_ratio_sum, # Deprecated + 'profit_all_percent_sum': round(profit_all_ratio_sum * 100, 2), + 'profit_all_ratio_sum': profit_all_ratio_sum, 'profit_all_ratio': profit_all_ratio_fromstart, 'profit_all_percent': round(profit_all_ratio_fromstart * 100, 2), 'profit_all_fiat': profit_all_fiat, diff --git a/tests/test_wallets.py b/tests/test_wallets.py index 25f2ad89f..64db3b9cd 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -204,10 +204,12 @@ def test__validate_stake_amount(mocker, default_conf, (None, 0, 0, 2500, 2500), (None, 500, 0, 2500, 2000), (None, 500, 0, 2500, 2000), + (None, -70, 0, 1930, 2000), # Only available balance matters when it's set. (100, 0, 0, 0, 100), (1000, 0, 2, 5, 1000), (1235, 2250, 2, 5, 1235), + (1235, -2250, 2, 5, 1235), ]) def test_get_starting_balance(mocker, default_conf, available_capital, closed_profit, open_stakes, free, expected): From b7dc2989e70588c988360fd7c345ba6b9afa8721 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Fri, 16 Jul 2021 02:03:25 -0600 Subject: [PATCH 13/14] flake8 adjustments --- tests/test_main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 4f769ca30..59a5bb0f7 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -157,7 +157,11 @@ def test_main_reload_config(mocker, default_conf, caplog) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = Arguments(['trade', '-c', 'config_examples/config_bittrex.example.json']).get_parsed_arg() + args = Arguments([ + 'trade', + '-c', + 'config_examples/config_bittrex.example.json' + ]).get_parsed_arg() worker = Worker(args=args, config=default_conf) with pytest.raises(SystemExit): main(['trade', '-c', 'config_examples/config_bittrex.example.json']) @@ -180,7 +184,11 @@ def test_reconfigure(mocker, default_conf) -> None: mocker.patch('freqtrade.freqtradebot.RPCManager', MagicMock()) mocker.patch('freqtrade.freqtradebot.init_db', MagicMock()) - args = Arguments(['trade', '-c', 'config_examples/config_bittrex.example.json']).get_parsed_arg() + args = Arguments([ + 'trade', + '-c', + 'config_examples/config_bittrex.example.json' + ]).get_parsed_arg() worker = Worker(args=args, config=default_conf) freqtrade = worker.freqtrade From d652e6fcc45ef7cac219f1e9275b16e5ede65e02 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 16 Jul 2021 19:57:39 +0200 Subject: [PATCH 14/14] Don't log from wallet in backtest mode --- freqtrade/wallets.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index e51a01afc..237c1dc2c 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -246,18 +246,21 @@ class Wallets: max_stake_amount = self.get_available_stake_amount() if min_stake_amount > max_stake_amount: - logger.warning("Minimum stake amount > available balance.") + if self._log: + logger.warning("Minimum stake amount > available balance.") return 0 if min_stake_amount is not None and stake_amount < min_stake_amount: stake_amount = min_stake_amount - logger.info( - f"Stake amount for pair {pair} is too small ({stake_amount} < {min_stake_amount}), " - f"adjusting to {min_stake_amount}." - ) + if self._log: + logger.info( + f"Stake amount for pair {pair} is too small " + f"({stake_amount} < {min_stake_amount}), adjusting to {min_stake_amount}." + ) if stake_amount > max_stake_amount: stake_amount = max_stake_amount - logger.info( - f"Stake amount for pair {pair} is too big ({stake_amount} > {max_stake_amount}), " - f"adjusting to {max_stake_amount}." - ) + if self._log: + logger.info( + f"Stake amount for pair {pair} is too big " + f"({stake_amount} > {max_stake_amount}), adjusting to {max_stake_amount}." + ) return stake_amount