From 179947fa727e8c501941560e644cb04abeff257c Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Wed, 2 Feb 2022 07:46:44 -0600 Subject: [PATCH] New config (#6333) * updated new-config to add trading_mode and margin_mode * added trading_mode and margin_mode to config examples * added okex config example * new file: config_examples/config_binance_futures.example.json * removed trading_mode and margin_mode from base_config and binance and okex example * deleted okex and futures config files * updated full config file * updated new-config command to add trading_mode and margin_mode to config * new file: config_examples/config_okex_futures.example.json * removed config_okex_futures.example.json * added trading_mode to test_start_new_config * new-config asks exchange before asking futures * Simplify trading_mode selection * margin_mode is empty string for spot new configs * build_config_commands sorted exchanges * isort Co-authored-by: Matthias --- config_examples/config_full.example.json | 2 ++ freqtrade/commands/build_config_commands.py | 22 ++++++++++++++++----- freqtrade/exchange/okex.py | 3 ++- freqtrade/templates/base_config.json.j2 | 2 ++ tests/commands/test_build_config.py | 2 ++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/config_examples/config_full.example.json b/config_examples/config_full.example.json index 5202954f4..f0e467f07 100644 --- a/config_examples/config_full.example.json +++ b/config_examples/config_full.example.json @@ -19,6 +19,8 @@ "sell_profit_offset": 0.0, "ignore_roi_if_buy_signal": false, "ignore_buying_expired_candle_after": 300, + "trading_mode": "futures", + "margin_mode": "isolated", "minimal_roi": { "40": 0.0, "30": 0.01, diff --git a/freqtrade/commands/build_config_commands.py b/freqtrade/commands/build_config_commands.py index 9e95cc455..a8cd99892 100644 --- a/freqtrade/commands/build_config_commands.py +++ b/freqtrade/commands/build_config_commands.py @@ -107,19 +107,27 @@ def ask_user_config() -> Dict[str, Any]: "type": "select", "name": "exchange_name", "message": "Select exchange", - "choices": [ + "choices": lambda x: [ "binance", "binanceus", "bittrex", - "kraken", "ftx", - "kucoin", "gateio", + "kraken", + "kucoin", "okex", - Separator(), + Separator("-----------------------------------------------"), "other", ], }, + { + "type": "confirm", + "name": "trading_mode", + "message": "Do you want to trade Perpetual Swaps (perpetual futures)?", + "default": False, + "filter": lambda val: 'futures' if val else 'spot', + "when": lambda x: x["exchange_name"] in ['binance', 'gateio'], + }, { "type": "autocomplete", "name": "exchange_name", @@ -196,7 +204,11 @@ def ask_user_config() -> Dict[str, Any]: if not answers: # Interrupted questionary sessions return an empty dict. raise OperationalException("User interrupted interactive questions.") - + answers['margin_mode'] = ( + 'isolated' + if answers.get('trading_mode') == 'futures' + else '' + ) # Force JWT token to be a random string answers['api_server_jwt_key'] = secrets.token_hex() diff --git a/freqtrade/exchange/okex.py b/freqtrade/exchange/okex.py index 3c774cc9a..ff440f42c 100644 --- a/freqtrade/exchange/okex.py +++ b/freqtrade/exchange/okex.py @@ -2,8 +2,9 @@ import logging from typing import Dict, List, Tuple from freqtrade.enums import MarginMode, TradingMode -from freqtrade.exchange import Exchange from freqtrade.exceptions import OperationalException +from freqtrade.exchange import Exchange + logger = logging.getLogger(__name__) diff --git a/freqtrade/templates/base_config.json.j2 b/freqtrade/templates/base_config.json.j2 index c91715b1f..60f4b4fd7 100644 --- a/freqtrade/templates/base_config.json.j2 +++ b/freqtrade/templates/base_config.json.j2 @@ -13,6 +13,8 @@ "fiat_display_currency": "{{ fiat_display_currency }}",{{ ('\n "timeframe": "' + timeframe + '",') if timeframe else '' }} "dry_run": {{ dry_run | lower }}, "cancel_open_orders_on_exit": false, + "trading_mode": "{{ trading_mode }}", + "margin_mode": "{{ margin_mode }}", "unfilledtimeout": { "buy": 10, "sell": 10, diff --git a/tests/commands/test_build_config.py b/tests/commands/test_build_config.py index 66c750e79..e30d5bf94 100644 --- a/tests/commands/test_build_config.py +++ b/tests/commands/test_build_config.py @@ -44,6 +44,8 @@ def test_start_new_config(mocker, caplog, exchange): 'fiat_display_currency': 'EUR', 'timeframe': '15m', 'dry_run': True, + 'trading_mode': 'spot', + 'margin_mode': '', 'exchange_name': exchange, 'exchange_key': 'sampleKey', 'exchange_secret': 'Samplesecret',