diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a23181c37..759ac0a6a 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -15,9 +15,9 @@ repos:
additional_dependencies:
- types-cachetools==5.2.1
- types-filelock==3.2.7
- - types-requests==2.28.1
+ - types-requests==2.28.3
- types-tabulate==0.8.11
- - types-python-dateutil==2.8.18
+ - types-python-dateutil==2.8.19
# stages: [push]
- repo: https://github.com/pycqa/isort
diff --git a/docs/configuration.md b/docs/configuration.md
index 0f3069478..412571674 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -116,6 +116,9 @@ This is similar to using multiple `--config` parameters, but simpler in usage as
The table below will list all configuration parameters available.
Freqtrade can also load many options via command line (CLI) arguments (check out the commands `--help` output for details).
+
+### Configuration option prevalence
+
The prevalence for all Options is as follows:
- CLI arguments override any other option
@@ -123,6 +126,8 @@ The prevalence for all Options is as follows:
- Configuration files are used in sequence (the last file wins) and override Strategy configurations.
- Strategy configurations are only used if they are not set via configuration or command-line arguments. These options are marked with [Strategy Override](#parameters-in-the-strategy) in the below table.
+### Parameters table
+
Mandatory parameters are marked as **Required**, which means that they are required to be set in one of the possible ways.
| Parameter | Description |
@@ -135,7 +140,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `amend_last_stake_amount` | Use reduced last stake amount if necessary. [More information below](#configuring-amount-per-trade).
*Defaults to `false`.*
**Datatype:** Boolean
| `last_stake_amount_min_ratio` | Defines minimum stake amount that has to be left and executed. Applies only to the last stake amount when it's amended to a reduced value (i.e. if `amend_last_stake_amount` is set to `true`). [More information below](#configuring-amount-per-trade).
*Defaults to `0.5`.*
**Datatype:** Float (as ratio)
| `amount_reserve_percent` | Reserve some amount in min pair stake amount. The bot will reserve `amount_reserve_percent` + stoploss value when calculating min pair stake amount in order to avoid possible trade refusals.
*Defaults to `0.05` (5%).*
**Datatype:** Positive Float as ratio.
-| `timeframe` | The timeframe to use (e.g `1m`, `5m`, `15m`, `30m`, `1h` ...). [Strategy Override](#parameters-in-the-strategy).
**Datatype:** String
+| `timeframe` | The timeframe to use (e.g `1m`, `5m`, `15m`, `30m`, `1h` ...). Usually missing in configuration, and specified in the strategy. [Strategy Override](#parameters-in-the-strategy).
**Datatype:** String
| `fiat_display_currency` | Fiat currency used to show your profits. [More information below](#what-values-can-be-used-for-fiat_display_currency).
**Datatype:** String
| `dry_run` | **Required.** Define if the bot must be in Dry Run or production mode.
*Defaults to `true`.*
**Datatype:** Boolean
| `dry_run_wallet` | Define the starting amount in stake currency for the simulated wallet used by the bot running in Dry Run mode.
*Defaults to `1000`.*
**Datatype:** Float
@@ -148,13 +153,16 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `trailing_stop_positive_offset` | Offset on when to apply `trailing_stop_positive`. Percentage value which should be positive. More details in the [stoploss documentation](stoploss.md#trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset). [Strategy Override](#parameters-in-the-strategy).
*Defaults to `0.0` (no offset).*
**Datatype:** Float
| `trailing_only_offset_is_reached` | Only apply trailing stoploss when the offset is reached. [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean
| `fee` | Fee used during backtesting / dry-runs. Should normally not be configured, which has freqtrade fall back to the exchange default fee. Set as ratio (e.g. 0.001 = 0.1%). Fee is applied twice for each trade, once when buying, once when selling.
**Datatype:** Float (as ratio)
+| `futures_funding_rate` | User-specified funding rate to be used when historical funding rates are not available from the exchange. This does not overwrite real historical rates. It is recommended that this be set to 0 unless you are testing a specific coin and you understand how the funding rate will affect freqtrade's profit calculations. [More information here](leverage.md#unavailable-funding-rates)
*Defaults to None.*
**Datatype:** Float
| `trading_mode` | Specifies if you want to trade regularly, trade with leverage, or trade contracts whose prices are derived from matching cryptocurrency prices. [leverage documentation](leverage.md).
*Defaults to `"spot"`.*
**Datatype:** String
| `margin_mode` | When trading with leverage, this determines if the collateral owned by the trader will be shared or isolated to each trading pair [leverage documentation](leverage.md).
**Datatype:** String
| `liquidation_buffer` | A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price [leverage documentation](leverage.md).
*Defaults to `0.05`.*
**Datatype:** Float
+| | **Unfilled timeout**
| `unfilledtimeout.entry` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled entry order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).
**Datatype:** Integer
| `unfilledtimeout.exit` | **Required.** How long (in minutes or seconds) the bot will wait for an unfilled exit order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. [Strategy Override](#parameters-in-the-strategy).
**Datatype:** Integer
| `unfilledtimeout.unit` | Unit to use in unfilledtimeout setting. Note: If you set unfilledtimeout.unit to "seconds", "internals.process_throttle_secs" must be inferior or equal to timeout [Strategy Override](#parameters-in-the-strategy).
*Defaults to `minutes`.*
**Datatype:** String
| `unfilledtimeout.exit_timeout_count` | How many times can exit orders time out. Once this number of timeouts is reached, an emergency exit is triggered. 0 to disable and allow unlimited order cancels. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `0`.*
**Datatype:** Integer
+| | **Pricing**
| `entry_pricing.price_side` | Select the side of the spread the bot should look at to get the entry rate. [More information below](#buy-price-side).
*Defaults to `same`.*
**Datatype:** String (either `ask`, `bid`, `same` or `other`).
| `entry_pricing.price_last_balance` | **Required.** Interpolate the bidding price. More information [below](#entry-price-without-orderbook-enabled).
| `entry_pricing.use_order_book` | Enable entering using the rates in [Order Book Entry](#entry-price-with-orderbook-enabled).
*Defaults to `True`.*
**Datatype:** Boolean
@@ -165,6 +173,8 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `exit_pricing.price_last_balance` | Interpolate the exiting price. More information [below](#exit-price-without-orderbook-enabled).
| `exit_pricing.use_order_book` | Enable exiting of open trades using [Order Book Exit](#exit-price-with-orderbook-enabled).
*Defaults to `True`.*
**Datatype:** Boolean
| `exit_pricing.order_book_top` | Bot will use the top N rate in Order Book "price_side" to exit. I.e. a value of 2 will allow the bot to pick the 2nd ask rate in [Order Book Exit](#exit-price-with-orderbook-enabled)
*Defaults to `1`.*
**Datatype:** Positive Integer
+| `custom_price_max_distance_ratio` | Configure maximum distance ratio between current and custom entry or exit price.
*Defaults to `0.02` 2%).*
**Datatype:** Positive float
+| | **TODO**
| `use_exit_signal` | Use exit signals produced by the strategy in addition to the `minimal_roi`. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `true`.*
**Datatype:** Boolean
| `exit_profit_only` | Wait until the bot reaches `exit_profit_offset` before taking an exit decision. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean
| `exit_profit_offset` | Exit-signal is only active above this value. Only active in combination with `exit_profit_only=True`. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `0.0`.*
**Datatype:** Float (as ratio)
@@ -172,8 +182,9 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `ignore_buying_expired_candle_after` | Specifies the number of seconds until a buy signal is no longer used.
**Datatype:** Integer
| `order_types` | Configure order-types depending on the action (`"entry"`, `"exit"`, `"stoploss"`, `"stoploss_on_exchange"`). [More information below](#understand-order_types). [Strategy Override](#parameters-in-the-strategy).
**Datatype:** Dict
| `order_time_in_force` | Configure time in force for entry and exit orders. [More information below](#understand-order_time_in_force). [Strategy Override](#parameters-in-the-strategy).
**Datatype:** Dict
-| `custom_price_max_distance_ratio` | Configure maximum distance ratio between current and custom entry or exit price.
*Defaults to `0.02` 2%).*
**Datatype:** Positive float
-| `recursive_strategy_search` | Set to `true` to recursively search sub-directories inside `user_data/strategies` for a strategy.
**Datatype:** Boolean
+| `position_adjustment_enable` | Enables the strategy to use position adjustments (additional buys or sells). [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean
+| `max_entry_position_adjustment` | Maximum additional order(s) for each open trade on top of the first entry Order. Set it to `-1` for unlimited additional orders. [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `-1`.*
**Datatype:** Positive Integer or -1
+| | **Exchange**
| `exchange.name` | **Required.** Name of the exchange class to use. [List below](#user-content-what-values-for-exchangename).
**Datatype:** String
| `exchange.sandbox` | Use the 'sandbox' version of the exchange, where the exchange provides a sandbox for risk-free integration. See [here](sandbox-testing.md) in more details.
**Datatype:** Boolean
| `exchange.key` | API key to use for the exchange. Only required when you are in production mode.
**Keep it in secret, do not disclose publicly.**
**Datatype:** String
@@ -190,14 +201,19 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `exchange.skip_open_order_update` | Skips open order updates on startup should the exchange cause problems. Only relevant in live conditions.
*Defaults to `false`
**Datatype:** Boolean
| `exchange.unknown_fee_rate` | Fallback value to use when calculating trading fees. This can be useful for exchanges which have fees in non-tradable currencies. The value provided here will be multiplied with the "fee cost".
*Defaults to `None`
**Datatype:** float
| `exchange.log_responses` | Log relevant exchange responses. For debug mode only - use with care.
*Defaults to `false`
**Datatype:** Boolean
-| `edge.*` | Please refer to [edge configuration document](edge.md) for detailed explanation.
| `experimental.block_bad_exchanges` | Block exchanges known to not work with freqtrade. Leave on default unless you want to test if that exchange works now.
*Defaults to `true`.*
**Datatype:** Boolean
+| | **Plugins**
+| `edge.*` | Please refer to [edge configuration document](edge.md) for detailed explanation of all possible configuration options.
| `pairlists` | Define one or more pairlists to be used. [More information](plugins.md#pairlists-and-pairlist-handlers).
*Defaults to `StaticPairList`.*
**Datatype:** List of Dicts
| `protections` | Define one or more protections to be used. [More information](plugins.md#protections).
**Datatype:** List of Dicts
+| | **Telegram**
| `telegram.enabled` | Enable the usage of Telegram.
**Datatype:** Boolean
| `telegram.token` | Your Telegram bot token. Only required if `telegram.enabled` is `true`.
**Keep it in secret, do not disclose publicly.**
**Datatype:** String
| `telegram.chat_id` | Your personal Telegram account id. Only required if `telegram.enabled` is `true`.
**Keep it in secret, do not disclose publicly.**
**Datatype:** String
| `telegram.balance_dust_level` | Dust-level (in stake currency) - currencies with a balance below this will not be shown by `/balance`.
**Datatype:** float
+| `telegram.reload` | Allow "reload" buttons on telegram messages.
*Defaults to `True`.
**Datatype:** boolean
+| `telegram.notification_settings.*` | Detailed notification settings. Refer to the [telegram documentation](telegram-usage.md) for details.
**Datatype:** dictionary
+| | **Webhook**
| `webhook.enabled` | Enable usage of Webhook notifications
**Datatype:** Boolean
| `webhook.url` | URL for the webhook. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String
| `webhook.webhookentry` | Payload to send on entry. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String
@@ -207,6 +223,7 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `webhook.webhookexitcancel` | Payload to send on exit order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String
| `webhook.webhookexitfill` | Payload to send on exit order filled. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String
| `webhook.webhookstatus` | Payload to send on status calls. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String
+| | **Rest API / FreqUI**
| `api_server.enabled` | Enable usage of API Server. See the [API Server documentation](rest-api.md) for more details.
**Datatype:** Boolean
| `api_server.listen_ip_address` | Bind IP address. See the [API Server documentation](rest-api.md) for more details.
**Datatype:** IPv4
| `api_server.listen_port` | Bind Port. See the [API Server documentation](rest-api.md) for more details.
**Datatype:** Integer between 1024 and 65535
@@ -214,23 +231,22 @@ Mandatory parameters are marked as **Required**, which means that they are requi
| `api_server.username` | Username for API server. See the [API Server documentation](rest-api.md) for more details.
**Keep it in secret, do not disclose publicly.**
**Datatype:** String
| `api_server.password` | Password for API server. See the [API Server documentation](rest-api.md) for more details.
**Keep it in secret, do not disclose publicly.**
**Datatype:** String
| `bot_name` | Name of the bot. Passed via API to a client - can be shown to distinguish / name bots.
*Defaults to `freqtrade`*
**Datatype:** String
-| `db_url` | Declares database URL to use. NOTE: This defaults to `sqlite:///tradesv3.dryrun.sqlite` if `dry_run` is `true`, and to `sqlite:///tradesv3.sqlite` for production instances.
**Datatype:** String, SQLAlchemy connect string
+| | **Other**
| `initial_state` | Defines the initial application state. If set to stopped, then the bot has to be explicitly started via `/start` RPC command.
*Defaults to `stopped`.*
**Datatype:** Enum, either `stopped` or `running`
| `force_entry_enable` | Enables the RPC Commands to force a Trade entry. More information below.
**Datatype:** Boolean
| `disable_dataframe_checks` | Disable checking the OHLCV dataframe returned from the strategy methods for correctness. Only use when intentionally changing the dataframe and understand what you are doing. [Strategy Override](#parameters-in-the-strategy).
*Defaults to `False`*.
**Datatype:** Boolean
-| `strategy` | **Required** Defines Strategy class to use. Recommended to be set via `--strategy NAME`.
**Datatype:** ClassName
-| `strategy_path` | Adds an additional strategy lookup path (must be a directory).
**Datatype:** String
| `internals.process_throttle_secs` | Set the process throttle, or minimum loop duration for one bot iteration loop. Value in second.
*Defaults to `5` seconds.*
**Datatype:** Positive Integer
| `internals.heartbeat_interval` | Print heartbeat message every N seconds. Set to 0 to disable heartbeat messages.
*Defaults to `60` seconds.*
**Datatype:** Positive Integer or 0
| `internals.sd_notify` | Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See [here](installation.md#7-optional-configure-freqtrade-as-a-systemd-service) for more details.
**Datatype:** Boolean
-| `logfile` | Specifies logfile name. Uses a rolling strategy for log file rotation for 10 files with the 1MB limit per file.
**Datatype:** String
+| `strategy` | **Required** Defines Strategy class to use. Recommended to be set via `--strategy NAME`.
**Datatype:** ClassName
+| `strategy_path` | Adds an additional strategy lookup path (must be a directory).
**Datatype:** String
+| `recursive_strategy_search` | Set to `true` to recursively search sub-directories inside `user_data/strategies` for a strategy.
**Datatype:** Boolean
| `user_data_dir` | Directory containing user data.
*Defaults to `./user_data/`*.
**Datatype:** String
+| `db_url` | Declares database URL to use. NOTE: This defaults to `sqlite:///tradesv3.dryrun.sqlite` if `dry_run` is `true`, and to `sqlite:///tradesv3.sqlite` for production instances.
**Datatype:** String, SQLAlchemy connect string
+| `logfile` | Specifies logfile name. Uses a rolling strategy for log file rotation for 10 files with the 1MB limit per file.
**Datatype:** String
| `add_config_files` | Additional config files. These files will be loaded and merged with the current config file. The files are resolved relative to the initial file.
*Defaults to `[]`*.
**Datatype:** List of strings
| `dataformat_ohlcv` | Data format to use to store historical candle (OHLCV) data.
*Defaults to `json`*.
**Datatype:** String
| `dataformat_trades` | Data format to use to store historical trades data.
*Defaults to `jsongz`*.
**Datatype:** String
-| `position_adjustment_enable` | Enables the strategy to use position adjustments (additional buys or sells). [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `false`.*
**Datatype:** Boolean
-| `max_entry_position_adjustment` | Maximum additional order(s) for each open trade on top of the first entry Order. Set it to `-1` for unlimited additional orders. [More information here](strategy-callbacks.md#adjust-trade-position).
[Strategy Override](#parameters-in-the-strategy).
*Defaults to `-1`.*
**Datatype:** Positive Integer or -1
-| `futures_funding_rate` | User-specified funding rate to be used when historical funding rates are not available from the exchange. This does not overwrite real historical rates. It is recommended that this be set to 0 unless you are testing a specific coin and you understand how the funding rate will affect freqtrade's profit calculations. [More information here](leverage.md#unavailable-funding-rates)
*Defaults to None.*
**Datatype:** Float
### Parameters in the strategy
diff --git a/docs/hyperopt.md b/docs/hyperopt.md
index 55fe8f008..c9ec30056 100644
--- a/docs/hyperopt.md
+++ b/docs/hyperopt.md
@@ -40,13 +40,15 @@ pip install -r requirements-hyperopt.txt
```
usage: freqtrade hyperopt [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]
[--userdir PATH] [-s NAME] [--strategy-path PATH]
- [-i TIMEFRAME] [--timerange TIMERANGE]
+ [--recursive-strategy-search] [-i TIMEFRAME]
+ [--timerange TIMERANGE]
[--data-format-ohlcv {json,jsongz,hdf5}]
[--max-open-trades INT]
[--stake-amount STAKE_AMOUNT] [--fee FLOAT]
[-p PAIRS [PAIRS ...]] [--hyperopt-path PATH]
[--eps] [--dmmp] [--enable-protections]
- [--dry-run-wallet DRY_RUN_WALLET] [-e INT]
+ [--dry-run-wallet DRY_RUN_WALLET]
+ [--timeframe-detail TIMEFRAME_DETAIL] [-e INT]
[--spaces {all,buy,sell,roi,stoploss,trailing,protection,default} [{all,buy,sell,roi,stoploss,trailing,protection,default} ...]]
[--print-all] [--no-color] [--print-json] [-j JOBS]
[--random-state INT] [--min-trades INT]
@@ -89,6 +91,9 @@ optional arguments:
--dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET
Starting balance, used for backtesting / hyperopt and
dry-runs.
+ --timeframe-detail TIMEFRAME_DETAIL
+ Specify detail timeframe for backtesting (`1m`, `5m`,
+ `30m`, `1h`, `1d`).
-e INT, --epochs INT Specify number of epochs (default: 100).
--spaces {all,buy,sell,roi,stoploss,trailing,protection,default} [{all,buy,sell,roi,stoploss,trailing,protection,default} ...]
Specify which parameters to hyperopt. Space-separated
@@ -146,7 +151,9 @@ Strategy arguments:
Specify strategy class name which will be used by the
bot.
--strategy-path PATH Specify additional strategy lookup path.
-
+ --recursive-strategy-search
+ Recursively search for a strategy in the strategies
+ folder.
```
### Hyperopt checklist
@@ -867,10 +874,12 @@ You can also enable position stacking in the configuration file by explicitly se
As hyperopt consumes a lot of memory (the complete data needs to be in memory once per parallel backtesting process), it's likely that you run into "out of memory" errors.
To combat these, you have multiple options:
-* reduce the amount of pairs
-* reduce the timerange used (`--timerange `)
-* reduce the number of parallel processes (`-j `)
-* Increase the memory of your machine
+* Reduce the amount of pairs.
+* Reduce the timerange used (`--timerange `).
+* Avoid using `--timeframe-detail` (this loads a lot of additional data into memory).
+* Reduce the number of parallel processes (`-j `).
+* Increase the memory of your machine.
+
## The objective has been evaluated at this point before.
diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt
index a07f4f944..205516d6d 100644
--- a/docs/requirements-docs.txt
+++ b/docs/requirements-docs.txt
@@ -1,5 +1,5 @@
-markdown==3.4.1
-mkdocs==1.3.0
+markdown==3.3.7
+mkdocs==1.3.1
mkdocs-material==8.3.9
mdx_truly_sane_lists==1.3
pymdown-extensions==9.5
diff --git a/docs/stoploss.md b/docs/stoploss.md
index 6ddb485a4..249c40109 100644
--- a/docs/stoploss.md
+++ b/docs/stoploss.md
@@ -175,8 +175,8 @@ Before this, `stoploss` is used for the trailing stoploss.
* assuming the asset now increases to 102$
* the stoploss will now be at 91.8$ - 10% below the highest observed rate
* assuming the asset now increases to 103.5$ (above the offset configured)
- * the stop loss will now be -2% of 103$ = 101.42$
- * now the asset drops in value to 102\$, the stop loss will still be 101.42$ and would trigger once price breaks below 101.42$
+ * the stop loss will now be -2% of 103.5$ = 101.43$
+ * now the asset drops in value to 102\$, the stop loss will still be 101.43$ and would trigger once price breaks below 101.43$
### Trailing stop loss only once the trade has reached a certain offset
diff --git a/freqtrade/commands/arguments.py b/freqtrade/commands/arguments.py
index 1e3e2845a..fc3eda14d 100644
--- a/freqtrade/commands/arguments.py
+++ b/freqtrade/commands/arguments.py
@@ -28,7 +28,7 @@ ARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + ["position_stacking", "use_max_market_pos
ARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + ["hyperopt", "hyperopt_path",
"position_stacking", "use_max_market_positions",
- "enable_protections", "dry_run_wallet",
+ "enable_protections", "dry_run_wallet", "timeframe_detail",
"epochs", "spaces", "print_all",
"print_colorized", "print_json", "hyperopt_jobs",
"hyperopt_random_state", "hyperopt_min_trades",
diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py
index a430cdac5..11e37b953 100644
--- a/freqtrade/exchange/exchange.py
+++ b/freqtrade/exchange/exchange.py
@@ -88,7 +88,8 @@ class Exchange:
# TradingMode.SPOT always supported and not required in this list
]
- def __init__(self, config: Dict[str, Any], validate: bool = True) -> None:
+ def __init__(self, config: Dict[str, Any], validate: bool = True,
+ load_leverage_tiers: bool = False) -> None:
"""
Initializes this module with the given config,
it does basic validation whether the specified exchange and pairs are valid.
@@ -186,7 +187,7 @@ class Exchange:
self.markets_refresh_interval: int = exchange_config.get(
"markets_refresh_interval", 60) * 60
- if self.trading_mode != TradingMode.SPOT:
+ if self.trading_mode != TradingMode.SPOT and load_leverage_tiers:
self.fill_leverage_tiers()
self.additional_exchange_init()
diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py
index 2007f9b4e..43608cae7 100644
--- a/freqtrade/freqtradebot.py
+++ b/freqtrade/freqtradebot.py
@@ -65,7 +65,8 @@ class FreqtradeBot(LoggingMixin):
# Check config consistency here since strategies can set certain options
validate_config_consistency(config)
- self.exchange = ExchangeResolver.load_exchange(self.config['exchange']['name'], self.config)
+ self.exchange = ExchangeResolver.load_exchange(
+ self.config['exchange']['name'], self.config, load_leverage_tiers=True)
init_db(self.config['db_url'])
diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py
index da28a8d93..4d16dc0f1 100755
--- a/freqtrade/optimize/backtesting.py
+++ b/freqtrade/optimize/backtesting.py
@@ -84,7 +84,8 @@ class Backtesting:
self.processed_dfs: Dict[str, Dict] = {}
self._exchange_name = self.config['exchange']['name']
- self.exchange = ExchangeResolver.load_exchange(self._exchange_name, self.config)
+ self.exchange = ExchangeResolver.load_exchange(
+ self._exchange_name, self.config, load_leverage_tiers=True)
self.dataprovider = DataProvider(self.config, self.exchange)
if self.config.get('strategy_list'):
diff --git a/freqtrade/resolvers/exchange_resolver.py b/freqtrade/resolvers/exchange_resolver.py
index 4dfbf445b..a2f572ff2 100644
--- a/freqtrade/resolvers/exchange_resolver.py
+++ b/freqtrade/resolvers/exchange_resolver.py
@@ -18,7 +18,8 @@ class ExchangeResolver(IResolver):
object_type = Exchange
@staticmethod
- def load_exchange(exchange_name: str, config: dict, validate: bool = True) -> Exchange:
+ def load_exchange(exchange_name: str, config: dict, validate: bool = True,
+ load_leverage_tiers: bool = False) -> Exchange:
"""
Load the custom class from config parameter
:param exchange_name: name of the Exchange to load
@@ -29,9 +30,13 @@ class ExchangeResolver(IResolver):
exchange_name = exchange_name.title()
exchange = None
try:
- exchange = ExchangeResolver._load_exchange(exchange_name,
- kwargs={'config': config,
- 'validate': validate})
+ exchange = ExchangeResolver._load_exchange(
+ exchange_name,
+ kwargs={
+ 'config': config,
+ 'validate': validate,
+ 'load_leverage_tiers': load_leverage_tiers}
+ )
except ImportError:
logger.info(
f"No {exchange_name} specific subclass found. Using the generic class instead.")
diff --git a/freqtrade/rpc/api_server/deps.py b/freqtrade/rpc/api_server/deps.py
index f5e61602e..81c013efa 100644
--- a/freqtrade/rpc/api_server/deps.py
+++ b/freqtrade/rpc/api_server/deps.py
@@ -37,7 +37,7 @@ def get_exchange(config=Depends(get_config)):
if not ApiServer._exchange:
from freqtrade.resolvers import ExchangeResolver
ApiServer._exchange = ExchangeResolver.load_exchange(
- config['exchange']['name'], config)
+ config['exchange']['name'], config, load_leverage_tiers=False)
return ApiServer._exchange
diff --git a/requirements-dev.txt b/requirements-dev.txt
index 3d91f29fd..3b98e20db 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -7,7 +7,7 @@
coveralls==3.3.1
flake8==4.0.1
flake8-tidy-imports==4.8.0
-mypy==0.961
+mypy==0.971
pre-commit==2.20.0
pytest==7.1.2
pytest-asyncio==0.19.0
@@ -24,6 +24,6 @@ nbconvert==6.5.0
# mypy types
types-cachetools==5.2.1
types-filelock==3.2.7
-types-requests==2.28.1
+types-requests==2.28.3
types-tabulate==0.8.11
-types-python-dateutil==2.8.18
+types-python-dateutil==2.8.19
diff --git a/requirements.txt b/requirements.txt
index b27c8f559..411827b62 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,7 +2,7 @@ numpy==1.23.1
pandas==1.4.3
pandas-ta==0.3.14b
-ccxt==1.90.89
+ccxt==1.91.22
# Pin cryptography for now due to rust build errors with piwheels
cryptography==37.0.4
aiohttp==3.8.1
@@ -28,7 +28,7 @@ py_find_1st==1.1.5
# Load ticker files 30% faster
python-rapidjson==1.8
# Properly format api responses
-orjson==3.7.7
+orjson==3.7.8
# Notify systemd
sdnotify==0.3.2
diff --git a/tests/conftest.py b/tests/conftest.py
index 3158e9ede..ff3e1007f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -148,7 +148,7 @@ def get_patched_exchange(mocker, config, api_mock=None, id='binance',
patch_exchange(mocker, api_mock, id, mock_markets, mock_supported_modes)
config['exchange']['name'] = id
try:
- exchange = ExchangeResolver.load_exchange(id, config)
+ exchange = ExchangeResolver.load_exchange(id, config, load_leverage_tiers=True)
except ImportError:
exchange = Exchange(config)
return exchange
@@ -2609,7 +2609,7 @@ def open_trade_usdt():
pair='ADA/USDT',
open_rate=2.0,
exchange='binance',
- open_order_id='123456789',
+ open_order_id='123456789_exit',
amount=30.0,
fee_open=0.0,
fee_close=0.0,
@@ -2634,6 +2634,23 @@ def open_trade_usdt():
cost=trade.open_rate * trade.amount,
order_date=trade.open_date,
order_filled_date=trade.open_date,
+ ),
+ Order(
+ ft_order_side='exit',
+ ft_pair=trade.pair,
+ ft_is_open=True,
+ order_id='123456789_exit',
+ status="open",
+ symbol=trade.pair,
+ order_type="limit",
+ side="sell",
+ price=trade.open_rate,
+ average=trade.open_rate,
+ filled=trade.amount,
+ remaining=0,
+ cost=trade.open_rate * trade.amount,
+ order_date=trade.open_date,
+ order_filled_date=trade.open_date,
)
]
return trade
diff --git a/tests/exchange/test_ccxt_compat.py b/tests/exchange/test_ccxt_compat.py
index 74106f28b..7bb52ccaf 100644
--- a/tests/exchange/test_ccxt_compat.py
+++ b/tests/exchange/test_ccxt_compat.py
@@ -137,7 +137,8 @@ def exchange_futures(request, exchange_conf, class_mocker):
'freqtrade.exchange.binance.Binance.fill_leverage_tiers')
class_mocker.patch('freqtrade.exchange.exchange.Exchange.fetch_trading_fees')
class_mocker.patch('freqtrade.exchange.okx.Okx.additional_exchange_init')
- exchange = ExchangeResolver.load_exchange(request.param, exchange_conf, validate=True)
+ exchange = ExchangeResolver.load_exchange(
+ request.param, exchange_conf, validate=True, load_leverage_tiers=True)
yield exchange, request.param
diff --git a/tests/plugins/test_protections.py b/tests/plugins/test_protections.py
index 172e1f077..3c333200c 100644
--- a/tests/plugins/test_protections.py
+++ b/tests/plugins/test_protections.py
@@ -6,6 +6,7 @@ import pytest
from freqtrade import constants
from freqtrade.enums import ExitType
from freqtrade.persistence import PairLocks, Trade
+from freqtrade.persistence.trade_model import Order
from freqtrade.plugins.protectionmanager import ProtectionManager
from tests.conftest import get_patched_freqtradebot, log_has_re
@@ -30,7 +31,37 @@ def generate_mock_trade(pair: str, fee: float, is_open: bool,
amount=0.01 / open_rate,
exchange='binance',
is_short=is_short,
+ leverage=1,
)
+
+ trade.orders.append(Order(
+ ft_order_side=trade.entry_side,
+ order_id=f'{pair}-{trade.entry_side}-{trade.open_date}',
+ ft_pair=pair,
+ amount=trade.amount,
+ filled=trade.amount,
+ remaining=0,
+ price=open_rate,
+ average=open_rate,
+ status="closed",
+ order_type="market",
+ side=trade.entry_side,
+ ))
+ if not is_open:
+ trade.orders.append(Order(
+ ft_order_side=trade.exit_side,
+ order_id=f'{pair}-{trade.exit_side}-{trade.close_date}',
+ ft_pair=pair,
+ amount=trade.amount,
+ filled=trade.amount,
+ remaining=0,
+ price=open_rate * (2 - profit_rate if is_short else profit_rate),
+ average=open_rate * (2 - profit_rate if is_short else profit_rate),
+ status="closed",
+ order_type="market",
+ side=trade.exit_side,
+ ))
+
trade.recalc_open_trade_value()
if not is_open:
trade.close(open_rate * (2 - profit_rate if is_short else profit_rate))
diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py
index d20646e60..6e19fcaf3 100644
--- a/tests/rpc/test_rpc.py
+++ b/tests/rpc/test_rpc.py
@@ -830,6 +830,8 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None:
assert cancel_order_mock.call_count == 2
assert trade.amount == amount
+ trade = Trade.query.filter(Trade.id == '3').first()
+
# make an limit-sell open trade
mocker.patch(
'freqtrade.exchange.Exchange.fetch_order',
diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py
index 91ee92fd7..f69b7e878 100644
--- a/tests/rpc/test_rpc_telegram.py
+++ b/tests/rpc/test_rpc_telegram.py
@@ -686,6 +686,7 @@ def test_profit_handle(default_conf_usdt, update, ticker_usdt, ticker_sell_up, f
# Simulate fulfilled LIMIT_SELL order for trade
oobj = Order.parse_from_ccxt_object(
limit_sell_order_usdt, limit_sell_order_usdt['symbol'], 'sell')
+ trade.orders.append(oobj)
trade.update_trade(oobj)
trade.close_date = datetime.now(timezone.utc)
@@ -707,7 +708,7 @@ def test_profit_handle(default_conf_usdt, update, ticker_usdt, ticker_sell_up, f
assert '*Best Performing:* `ETH/USDT: 9.45%`' in msg_mock.call_args_list[-1][0][0]
assert '*Max Drawdown:*' in msg_mock.call_args_list[-1][0][0]
assert '*Profit factor:*' in msg_mock.call_args_list[-1][0][0]
- assert '*Trading volume:* `60 USDT`' in msg_mock.call_args_list[-1][0][0]
+ assert '*Trading volume:* `126 USDT`' in msg_mock.call_args_list[-1][0][0]
@pytest.mark.parametrize('is_short', [True, False])
diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py
index e431e7ac3..66cbd7d9b 100644
--- a/tests/test_freqtradebot.py
+++ b/tests/test_freqtradebot.py
@@ -2139,8 +2139,6 @@ def test_handle_trade(
assert trade
time.sleep(0.01) # Race condition fix
- oobj = Order.parse_from_ccxt_object(enter_order, enter_order['symbol'], entry_side(is_short))
- trade.update_trade(oobj)
assert trade.is_open is True
freqtrade.wallets.update()
@@ -2150,11 +2148,15 @@ def test_handle_trade(
assert trade.open_order_id == exit_order['id']
# Simulate fulfilled LIMIT_SELL order for trade
- oobj = Order.parse_from_ccxt_object(exit_order, exit_order['symbol'], exit_side(is_short))
- trade.update_trade(oobj)
+ trade.orders[-1].ft_is_open = False
+ trade.orders[-1].status = 'closed'
+ trade.orders[-1].filled = trade.orders[-1].remaining
+ trade.orders[-1].remaining = 0.0
- assert trade.close_rate == 2.0 if is_short else 2.2
- assert trade.close_profit == close_profit
+ trade.update_trade(trade.orders[-1])
+
+ assert trade.close_rate == (2.0 if is_short else 2.2)
+ assert pytest.approx(trade.close_profit) == close_profit
assert trade.calc_profit(trade.close_rate) == 5.685
assert trade.close_date is not None
assert trade.exit_reason == 'sell_signal1'
@@ -2757,6 +2759,8 @@ def test_check_handle_cancelled_exit(
cancel_order_mock = MagicMock()
limit_sell_order_old.update({"status": "canceled", 'filled': 0.0})
limit_sell_order_old['side'] = 'buy' if is_short else 'sell'
+ limit_sell_order_old['id'] = open_trade_usdt.open_order_id
+
patch_exchange(mocker)
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
@@ -3096,7 +3100,27 @@ def test_handle_cancel_exit_limit(mocker, default_conf_usdt, fee) -> None:
close_date=arrow.utcnow().datetime,
exit_reason="sell_reason_whatever",
)
- order = {'remaining': 1,
+ trade.orders = [
+ Order(
+ ft_order_side='buy',
+ ft_pair=trade.pair,
+ ft_is_open=True,
+ order_id='123456',
+ status="closed",
+ symbol=trade.pair,
+ order_type="market",
+ side="buy",
+ price=trade.open_rate,
+ average=trade.open_rate,
+ filled=trade.amount,
+ remaining=0,
+ cost=trade.open_rate * trade.amount,
+ order_date=trade.open_date,
+ order_filled_date=trade.open_date,
+ ),
+ ]
+ order = {'id': "123456",
+ 'remaining': 1,
'amount': 1,
'status': "open"}
reason = CANCEL_REASON['TIMEOUT']
diff --git a/tests/test_persistence.py b/tests/test_persistence.py
index a09711048..838c4c22a 100644
--- a/tests/test_persistence.py
+++ b/tests/test_persistence.py
@@ -481,6 +481,7 @@ def test_update_limit_order(fee, caplog, limit_buy_order_usdt, limit_sell_order_
trade.open_order_id = 'something'
oobj = Order.parse_from_ccxt_object(enter_order, 'ADA/USDT', entry_side)
+ trade.orders.append(oobj)
trade.update_trade(oobj)
assert trade.open_order_id is None
assert trade.open_rate == open_rate
@@ -496,11 +497,12 @@ def test_update_limit_order(fee, caplog, limit_buy_order_usdt, limit_sell_order_
trade.open_order_id = 'something'
time_machine.move_to("2022-03-31 21:45:05 +00:00")
oobj = Order.parse_from_ccxt_object(exit_order, 'ADA/USDT', exit_side)
+ trade.orders.append(oobj)
trade.update_trade(oobj)
assert trade.open_order_id is None
assert trade.close_rate == close_rate
- assert trade.close_profit == profit
+ assert pytest.approx(trade.close_profit) == profit
assert trade.close_date is not None
assert log_has_re(f"LIMIT_{exit_side.upper()} has been fulfilled for "
r"Trade\(id=2, pair=ADA/USDT, amount=30.00000000, "
@@ -529,6 +531,7 @@ def test_update_market_order(market_buy_order_usdt, market_sell_order_usdt, fee,
trade.open_order_id = 'something'
oobj = Order.parse_from_ccxt_object(market_buy_order_usdt, 'ADA/USDT', 'buy')
+ trade.orders.append(oobj)
trade.update_trade(oobj)
assert trade.open_order_id is None
assert trade.open_rate == 2.0
@@ -543,10 +546,11 @@ def test_update_market_order(market_buy_order_usdt, market_sell_order_usdt, fee,
trade.is_open = True
trade.open_order_id = 'something'
oobj = Order.parse_from_ccxt_object(market_sell_order_usdt, 'ADA/USDT', 'sell')
+ trade.orders.append(oobj)
trade.update_trade(oobj)
assert trade.open_order_id is None
assert trade.close_rate == 2.2
- assert trade.close_profit == round(0.0945137157107232, 8)
+ assert pytest.approx(trade.close_profit) == 0.094513715710723
assert trade.close_date is not None
assert log_has_re(r"MARKET_SELL has been fulfilled for Trade\(id=1, "
r"pair=ADA/USDT, amount=30.00000000, is_short=False, leverage=1.0, "
@@ -624,14 +628,41 @@ def test_trade_close(limit_buy_order_usdt, limit_sell_order_usdt, fee):
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=10),
interest_rate=0.0005,
exchange='binance',
- trading_mode=margin
+ trading_mode=margin,
+ leverage=1.0,
)
+ trade.orders.append(Order(
+ ft_order_side=trade.entry_side,
+ order_id=f'{trade.pair}-{trade.entry_side}-{trade.open_date}',
+ ft_pair=trade.pair,
+ amount=trade.amount,
+ filled=trade.amount,
+ remaining=0,
+ price=trade.open_rate,
+ average=trade.open_rate,
+ status="closed",
+ order_type="limit",
+ side=trade.entry_side,
+ ))
+ trade.orders.append(Order(
+ ft_order_side=trade.exit_side,
+ order_id=f'{trade.pair}-{trade.exit_side}-{trade.open_date}',
+ ft_pair=trade.pair,
+ amount=trade.amount,
+ filled=trade.amount,
+ remaining=0,
+ price=2.2,
+ average=2.2,
+ status="closed",
+ order_type="limit",
+ side=trade.exit_side,
+ ))
assert trade.close_profit is None
assert trade.close_date is None
assert trade.is_open is True
trade.close(2.2)
assert trade.is_open is False
- assert trade.close_profit == round(0.0945137157107232, 8)
+ assert pytest.approx(trade.close_profit) == 0.094513715
assert trade.close_date is not None
new_date = arrow.Arrow(2020, 2, 2, 15, 6, 1).datetime,