diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9c03e61c..1a87b86cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ "macos-latest", "macos-13", "macos-14" ] + os: [ "macos-12", "macos-13", "macos-14" ] python-version: ["3.9", "3.10", "3.11", "3.12"] exclude: - os: "macos-14" @@ -414,7 +414,7 @@ jobs: pytest --random-order --longrun --durations 20 -n auto - # Notify only once - when CI completes (and after deploy) in case it's successfull + # Notify only once - when CI completes (and after deploy) in case it's successful notify-complete: needs: [ build-linux, diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e3b61b31..f88d94072 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,7 +31,7 @@ repos: - repo: https://github.com/charliermarsh/ruff-pre-commit # Ruff version. - rev: 'v0.3.5' + rev: 'v0.4.1' hooks: - id: ruff @@ -54,3 +54,10 @@ repos: (?x)^( .*\.md )$ + + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + additional_dependencies: + - tomli diff --git a/build_helpers/pre_commit_update.py b/build_helpers/pre_commit_update.py index e6b47d100..7774523d2 100644 --- a/build_helpers/pre_commit_update.py +++ b/build_helpers/pre_commit_update.py @@ -1,4 +1,4 @@ -# File used in CI to ensure pre-commit dependencies are kept uptodate. +# File used in CI to ensure pre-commit dependencies are kept up-to-date. import sys from pathlib import Path diff --git a/build_helpers/pyarrow-15.0.2-cp311-cp311-linux_armv7l.whl b/build_helpers/pyarrow-16.0.0-cp311-cp311-linux_armv7l.whl similarity index 65% rename from build_helpers/pyarrow-15.0.2-cp311-cp311-linux_armv7l.whl rename to build_helpers/pyarrow-16.0.0-cp311-cp311-linux_armv7l.whl index 77545d082..f8022ffbf 100644 Binary files a/build_helpers/pyarrow-15.0.2-cp311-cp311-linux_armv7l.whl and b/build_helpers/pyarrow-16.0.0-cp311-cp311-linux_armv7l.whl differ diff --git a/build_helpers/pyarrow-15.0.2-cp39-cp39-linux_armv7l.whl b/build_helpers/pyarrow-16.0.0-cp39-cp39-linux_armv7l.whl similarity index 65% rename from build_helpers/pyarrow-15.0.2-cp39-cp39-linux_armv7l.whl rename to build_helpers/pyarrow-16.0.0-cp39-cp39-linux_armv7l.whl index 638750fc2..c1cbf19de 100644 Binary files a/build_helpers/pyarrow-15.0.2-cp39-cp39-linux_armv7l.whl and b/build_helpers/pyarrow-16.0.0-cp39-cp39-linux_armv7l.whl differ diff --git a/docs/advanced-backtesting.md b/docs/advanced-backtesting.md index e91842d64..563e5df08 100644 --- a/docs/advanced-backtesting.md +++ b/docs/advanced-backtesting.md @@ -36,7 +36,7 @@ freqtrade backtesting-analysis -c --analysis-groups 0 1 2 3 4 5 ``` This command will read from the last backtesting results. The `--analysis-groups` option is -used to specify the various tabular outputs showing the profit fo each group or trade, +used to specify the various tabular outputs showing the profit of each group or trade, ranging from the simplest (0) to the most detailed per pair, per buy and per sell tag (4): * 0: overall winrate and profit summary by enter_tag diff --git a/docs/backtesting.md b/docs/backtesting.md index 11510dc24..6cfc9597f 100644 --- a/docs/backtesting.md +++ b/docs/backtesting.md @@ -587,7 +587,7 @@ These precision values are based on current exchange limits (as described in the ## Improved backtest accuracy -One big limitation of backtesting is it's inability to know how prices moved intra-candle (was high before close, or viceversa?). +One big limitation of backtesting is it's inability to know how prices moved intra-candle (was high before close, or vice-versa?). So assuming you run backtesting with a 1h timeframe, there will be 4 prices for that candle (Open, High, Low, Close). While backtesting does take some assumptions (read above) about this - this can never be perfect, and will always be biased in one way or the other. diff --git a/docs/configuration.md b/docs/configuration.md index 684c6743c..6a85f445e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -547,7 +547,7 @@ is automatically cancelled by the exchange. **PO (Post only):** Post only order. The order is either placed as a maker order, or it is canceled. -This means the order must be placed on orderbook for at at least time in an unfilled state. +This means the order must be placed on orderbook for at least time in an unfilled state. #### time_in_force config diff --git a/docs/developer.md b/docs/developer.md index d65e807ff..f1218471f 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -261,7 +261,7 @@ For that reason, they must implement the following methods: The `until` portion should be calculated using the provided `calculate_lock_end()` method. -All Protections should use `"stop_duration"` / `"stop_duration_candles"` to define how long a a pair (or all pairs) should be locked. +All Protections should use `"stop_duration"` / `"stop_duration_candles"` to define how long a pair (or all pairs) should be locked. The content of this is made available as `self._stop_duration` to the each Protection. If your protection requires a look-back period, please use `"lookback_period"` / `"lockback_period_candles"` to keep all protections aligned. diff --git a/docs/edge.md b/docs/edge.md index bb702f202..fe33f141b 100644 --- a/docs/edge.md +++ b/docs/edge.md @@ -137,7 +137,7 @@ $$ R = \frac{\text{average_profit}}{\text{average_loss}} = \frac{\mu_{win}}{\mu_ ### Expectancy -By combining the Win Rate $W$ and and the Risk Reward ratio $R$ to create an expectancy ratio $E$. A expectance ratio is the expected return of the investment made in a trade. We can compute the value of $E$ as follows: +By combining the Win Rate $W$ and the Risk Reward ratio $R$ to create an expectancy ratio $E$. A expectance ratio is the expected return of the investment made in a trade. We can compute the value of $E$ as follows: $$E = R * W - L$$ diff --git a/docs/faq.md b/docs/faq.md index 95a9924f9..134765579 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -2,7 +2,7 @@ ## Supported Markets -Freqtrade supports spot trading, as well as (isolated) futures trading for some selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an uptodate list of supported exchanges. +Freqtrade supports spot trading, as well as (isolated) futures trading for some selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an up-to-date list of supported exchanges. ### Can my bot open short positions? @@ -14,7 +14,7 @@ In spot markets, you can in some cases use leveraged spot tokens, which reflect ### Can my bot trade options or futures? -Futures trading is supported for selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an uptodate list of supported exchanges. +Futures trading is supported for selected exchanges. Please refer to the [documentation start page](index.md#supported-futures-exchanges-experimental) for an up-to-date list of supported exchanges. ## Beginner Tips & Tricks diff --git a/docs/freqai-parameter-table.md b/docs/freqai-parameter-table.md index 055b7b45d..56043bb0f 100644 --- a/docs/freqai-parameter-table.md +++ b/docs/freqai-parameter-table.md @@ -31,7 +31,7 @@ Mandatory parameters are marked as **Required** and have to be set in one of the | `feature_parameters` | A dictionary containing the parameters used to engineer the feature set. Details and examples are shown [here](freqai-feature-engineering.md).
**Datatype:** Dictionary. | `include_timeframes` | A list of timeframes that all indicators in `feature_engineering_expand_*()` will be created for. The list is added as features to the base indicators dataset.
**Datatype:** List of timeframes (strings). | `include_corr_pairlist` | A list of correlated coins that FreqAI will add as additional features to all `pair_whitelist` coins. All indicators set in `feature_engineering_expand_*()` during feature engineering (see details [here](freqai-feature-engineering.md)) will be created for each correlated coin. The correlated coins features are added to the base indicators dataset.
**Datatype:** List of assets (strings). -| `label_period_candles` | Number of candles into the future that the labels are created for. This is used in `feature_engineering_expand_all()` (see `templates/FreqaiExampleStrategy.py` for detailed usage). You can create custom labels and choose whether to make use of this parameter or not.
**Datatype:** Positive integer. +| `label_period_candles` | Number of candles into the future that the labels are created for. This can be used in `set_freqai_targets()` (see `templates/FreqaiExampleStrategy.py` for detailed usage). This parameter is not necessarily required, you can create custom labels and choose whether to make use of this parameter or not. Please see `templates/FreqaiExampleStrategy.py` to see the example usage.
**Datatype:** Positive integer. | `include_shifted_candles` | Add features from previous candles to subsequent candles with the intent of adding historical information. If used, FreqAI will duplicate and shift all features from the `include_shifted_candles` previous candles so that the information is available for the subsequent candle.
**Datatype:** Positive integer. | `weight_factor` | Weight training data points according to their recency (see details [here](freqai-feature-engineering.md#weighting-features-for-temporal-importance)).
**Datatype:** Positive float (typically < 1). | `indicator_max_period_candles` | **No longer used (#7325)**. Replaced by `startup_candle_count` which is set in the [strategy](freqai-configuration.md#building-a-freqai-strategy). `startup_candle_count` is timeframe independent and defines the maximum *period* used in `feature_engineering_*()` for indicator creation. FreqAI uses this parameter together with the maximum timeframe in `include_time_frames` to calculate how many data points to download such that the first data point does not include a NaN.
**Datatype:** Positive integer. @@ -55,7 +55,7 @@ Mandatory parameters are marked as **Required** and have to be set in one of the | | **Data split parameters within the `freqai.data_split_parameters` sub dictionary** | `data_split_parameters` | Include any additional parameters available from scikit-learn `test_train_split()`, which are shown [here](https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.train_test_split.html) (external website).
**Datatype:** Dictionary. | `test_size` | The fraction of data that should be used for testing instead of training.
**Datatype:** Positive float < 1. -| `shuffle` | Shuffle the training data points during training. Typically, to not remove the chronological order of data in time-series forecasting, this is set to `False`.
**Datatype:** Boolean.
Defaut: `False`. +| `shuffle` | Shuffle the training data points during training. Typically, to not remove the chronological order of data in time-series forecasting, this is set to `False`.
**Datatype:** Boolean.
Default: `False`. ### Model training parameters diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt index ddc374b35..74be94c1a 100644 --- a/docs/requirements-docs.txt +++ b/docs/requirements-docs.txt @@ -1,6 +1,6 @@ markdown==3.6 mkdocs==1.5.3 -mkdocs-material==9.5.17 +mkdocs-material==9.5.18 mdx_truly_sane_lists==1.3 -pymdown-extensions==10.7.1 +pymdown-extensions==10.8 jinja2==3.1.3 diff --git a/docs/rest-api.md b/docs/rest-api.md index cf196559d..ab5e9db9f 100644 --- a/docs/rest-api.md +++ b/docs/rest-api.md @@ -89,7 +89,8 @@ Make sure that the following 2 lines are available in your docker-compose file: ``` !!! Danger "Security warning" - By using `8080:8080` in the docker port mapping, the API will be available to everyone connecting to the server under the correct port, so others may be able to control your bot. + By using `"8080:8080"` (or `"0.0.0.0:8080:8080"`) in the docker port mapping, the API will be available to everyone connecting to the server under the correct port, so others may be able to control your bot. + This **may** be safe if you're running the bot in a secure environment (like your home network), but it's not recommended to expose the API to the internet. ## Rest API @@ -454,7 +455,7 @@ To properly configure your reverse proxy (securely), please consult it's documen - **Caddy**: Caddy v2 supports websockets out of the box, see the [documentation](https://caddyserver.com/docs/v2-upgrade#proxy) !!! Tip "SSL certificates" - You can use tools like certbot to setup ssl certificates to access your bot's UI through encrypted connection by using any fo the above reverse proxies. + You can use tools like certbot to setup ssl certificates to access your bot's UI through encrypted connection by using any of the above reverse proxies. While this will protect your data in transit, we do not recommend to run the freqtrade API outside of your private network (VPN, SSH tunnel). ### OpenAPI interface diff --git a/docs/stoploss.md b/docs/stoploss.md index 935950d06..19683aadd 100644 --- a/docs/stoploss.md +++ b/docs/stoploss.md @@ -240,7 +240,7 @@ When using leverage, the same principle is applied - with stoploss defining the Therefore, a stoploss of 10% on a 10x trade would trigger on a 1% price move. If your stake amount (own capital) was 100$ - this trade would be 1000$ at 10x (after leverage). -If price moves 1% - you've lost 10$ of your own capital - therfore stoploss will trigger in this case. +If price moves 1% - you've lost 10$ of your own capital - therefore stoploss will trigger in this case. Make sure to be aware of this, and avoid using too tight stoploss (at 10x leverage, 10% risk may be too little to allow the trade to "breath" a little). diff --git a/docs/strategy-advanced.md b/docs/strategy-advanced.md index debd5bc1b..c5a17c364 100644 --- a/docs/strategy-advanced.md +++ b/docs/strategy-advanced.md @@ -326,4 +326,4 @@ for val in self.buy_ema_short.range: dataframe = pd.concat(frames, axis=1) ``` -Freqtrade does however also counter this by running `dataframe.copy()` on the dataframe right after the `populate_indicators()` method - so performance implications of this should be low to non-existant. +Freqtrade does however also counter this by running `dataframe.copy()` on the dataframe right after the `populate_indicators()` method - so performance implications of this should be low to non-existent. diff --git a/docs/strategy-customization.md b/docs/strategy-customization.md index 900dafb33..59efc0e02 100644 --- a/docs/strategy-customization.md +++ b/docs/strategy-customization.md @@ -551,8 +551,8 @@ for more information. # Define BTC/STAKE informative pair. A custom formatter may be specified for formatting # column names. A callable `fmt(**kwargs) -> str` may be specified, to implement custom - # formatting. Available in populate_indicators and other methods as 'rsi_upper'. - @informative('1h', 'BTC/{stake}', '{column}') + # formatting. Available in populate_indicators and other methods as 'rsi_upper_1h'. + @informative('1h', 'BTC/{stake}', '{column}_{timeframe}') def populate_indicators_btc_1h_2(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['rsi_upper'] = ta.RSI(dataframe, timeperiod=14) return dataframe @@ -776,7 +776,7 @@ The orderbook structure is aligned with the order structure from [ccxt](https:// Therefore, using `ob['bids'][0][0]` as demonstrated above will result in using the best bid price. `ob['bids'][0][1]` would look at the amount at this orderbook position. !!! Warning "Warning about backtesting" - The order book is not part of the historic data which means backtesting and hyperopt will not work correctly if this method is used, as the method will return uptodate values. + The order book is not part of the historic data which means backtesting and hyperopt will not work correctly if this method is used, as the method will return up-to-date values. ### *ticker(pair)* diff --git a/docs/trade-object.md b/docs/trade-object.md index 15a8b1938..fa8b2dbb1 100644 --- a/docs/trade-object.md +++ b/docs/trade-object.md @@ -126,7 +126,7 @@ An `Order` object will always be tied to it's corresponding [`Trade`](#trade-obj ### Order - Available attributes an Order object is typically attached to a trade. -Most properties here can be None as they are dependant on the exchange response. +Most properties here can be None as they are dependent on the exchange response. | Attribute | DataType | Description | |------------|-------------|-------------| @@ -141,7 +141,7 @@ Most properties here can be None as they are dependant on the exchange response. `amount` | float | Amount in base currency `filled` | float | Filled amount (in base currency) `remaining` | float | Remaining amount -`cost` | float | Cost of the order - usually average * filled (*Exchange dependant on futures, may contain the cost with or without leverage and may be in contracts.*) +`cost` | float | Cost of the order - usually average * filled (*Exchange dependent on futures, may contain the cost with or without leverage and may be in contracts.*) `stake_amount` | float | Stake amount used for this order. *Added in 2023.7.* `order_date` | datetime | Order creation date **use `order_date_utc` instead** `order_date_utc` | datetime | Order creation date (in UTC) diff --git a/freqtrade/commands/deploy_commands.py b/freqtrade/commands/deploy_commands.py index c87f55e43..8de600c9e 100644 --- a/freqtrade/commands/deploy_commands.py +++ b/freqtrade/commands/deploy_commands.py @@ -16,6 +16,10 @@ from freqtrade.util import render_template, render_template_with_fallback logger = logging.getLogger(__name__) +# Timeout for requests +req_timeout = 30 + + def start_create_userdir(args: Dict[str, Any]) -> None: """ Create "user_data" directory to contain user data strategies, hyperopt, ...) @@ -119,7 +123,7 @@ def download_and_install_ui(dest_folder: Path, dl_url: str, version: str): from zipfile import ZipFile logger.info(f"Downloading {dl_url}") - resp = requests.get(dl_url).content + resp = requests.get(dl_url, timeout=req_timeout).content dest_folder.mkdir(parents=True, exist_ok=True) with ZipFile(BytesIO(resp)) as zf: for fn in zf.filelist: @@ -137,7 +141,7 @@ def get_ui_download_url(version: Optional[str] = None) -> Tuple[str, str]: base_url = 'https://api.github.com/repos/freqtrade/frequi/' # Get base UI Repo path - resp = requests.get(f"{base_url}releases") + resp = requests.get(f"{base_url}releases", timeout=req_timeout) resp.raise_for_status() r = resp.json() @@ -158,7 +162,7 @@ def get_ui_download_url(version: Optional[str] = None) -> Tuple[str, str]: # URL not found - try assets url if not dl_url: assets = r[0]['assets_url'] - resp = requests.get(assets) + resp = requests.get(assets, timeout=req_timeout) r = resp.json() dl_url = r[0]['browser_download_url'] diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 4d945c23e..906d0a544 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -202,7 +202,7 @@ class Configuration: if self.args.get('show_sensitive'): logger.warning( - "Sensitive information will be shown in the upcomming output. " + "Sensitive information will be shown in the upcoming output. " "Please make sure to never share this output without redacting " "the information yourself.") diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index ef92d4db6..07417b27f 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -238,6 +238,16 @@ def update_backtest_metadata(filename: Path, strategy: str, content: Dict[str, A file_dump_json(get_backtest_metadata_filename(filename), metadata) +def get_backtest_market_change(filename: Path, include_ts: bool = True) -> pd.DataFrame: + """ + Read backtest market change file. + """ + df = pd.read_feather(filename) + if include_ts: + df.loc[:, '__date_ts'] = df.loc[:, 'date'].astype(np.int64) // 1000 // 1000 + return df + + def find_existing_backtest_stats(dirname: Union[Path, str], run_ids: Dict[str, str], min_backtest_date: Optional[datetime] = None) -> Dict[str, Any]: """ diff --git a/freqtrade/data/dataprovider.py b/freqtrade/data/dataprovider.py index b737007c4..6fa6e4738 100644 --- a/freqtrade/data/dataprovider.py +++ b/freqtrade/data/dataprovider.py @@ -523,7 +523,7 @@ class DataProvider: Send custom RPC Notifications from your bot. Will not send any bot in modes other than Dry-run or Live. :param message: Message to be sent. Must be below 4096. - :param always_send: If False, will send the message only once per candle, and surpress + :param always_send: If False, will send the message only once per candle, and suppress identical messages. Careful as this can end up spaming your chat. Defaults to False diff --git a/freqtrade/data/history/datahandlers/idatahandler.py b/freqtrade/data/history/datahandlers/idatahandler.py index fbaded640..cff26760f 100644 --- a/freqtrade/data/history/datahandlers/idatahandler.py +++ b/freqtrade/data/history/datahandlers/idatahandler.py @@ -302,8 +302,8 @@ class IDataHandler(ABC): Rebuild pair name from filename Assumes a asset name of max. 7 length to also support BTC-PERP and BTC-PERP:USD names. """ - res = re.sub(r'^(([A-Za-z\d]{1,10})|^([A-Za-z\-]{1,6}))(_)', r'\g<1>/', pair, 1) - res = re.sub('_', ':', res, 1) + res = re.sub(r'^(([A-Za-z\d]{1,10})|^([A-Za-z\-]{1,6}))(_)', r'\g<1>/', pair, count=1) + res = re.sub('_', ':', res, count=1) return res def ohlcv_load(self, pair, timeframe: str, diff --git a/freqtrade/data/metrics.py b/freqtrade/data/metrics.py index 738129939..43a33fa0d 100644 --- a/freqtrade/data/metrics.py +++ b/freqtrade/data/metrics.py @@ -30,8 +30,25 @@ def calculate_market_change(data: Dict[str, pd.DataFrame], column: str = "close" return float(np.mean(tmp_means)) -def combine_dataframes_with_mean(data: Dict[str, pd.DataFrame], - column: str = "close") -> pd.DataFrame: +def combine_dataframes_by_column( + data: Dict[str, pd.DataFrame], column: str = "close") -> pd.DataFrame: + """ + Combine multiple dataframes "column" + :param data: Dict of Dataframes, dict key should be pair. + :param column: Column in the original dataframes to use + :return: DataFrame with the column renamed to the dict key. + :raise: ValueError if no data is provided. + """ + if not data: + raise ValueError("No data provided.") + df_comb = pd.concat([data[pair].set_index('date').rename( + {column: pair}, axis=1)[pair] for pair in data], axis=1) + return df_comb + + +def combined_dataframes_with_rel_mean( + data: Dict[str, pd.DataFrame], fromdt: datetime, todt: datetime, + column: str = "close") -> pd.DataFrame: """ Combine multiple dataframes "column" :param data: Dict of Dataframes, dict key should be pair. @@ -40,8 +57,26 @@ def combine_dataframes_with_mean(data: Dict[str, pd.DataFrame], named mean, containing the mean of all pairs. :raise: ValueError if no data is provided. """ - df_comb = pd.concat([data[pair].set_index('date').rename( - {column: pair}, axis=1)[pair] for pair in data], axis=1) + df_comb = combine_dataframes_by_column(data, column) + # Trim dataframes to the given timeframe + df_comb = df_comb.iloc[(df_comb.index >= fromdt) & (df_comb.index < todt)] + df_comb['count'] = df_comb.count(axis=1) + df_comb['mean'] = df_comb.mean(axis=1) + df_comb['rel_mean'] = df_comb['mean'].pct_change().fillna(0).cumsum() + return df_comb[['mean', 'rel_mean', 'count']] + + +def combine_dataframes_with_mean( + data: Dict[str, pd.DataFrame], column: str = "close") -> pd.DataFrame: + """ + Combine multiple dataframes "column" + :param data: Dict of Dataframes, dict key should be pair. + :param column: Column in the original dataframes to use + :return: DataFrame with the column renamed to the dict key, and a column + named mean, containing the mean of all pairs. + :raise: ValueError if no data is provided. + """ + df_comb = combine_dataframes_by_column(data, column) df_comb['mean'] = df_comb.mean(axis=1) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index 8826b70b5..109f3c1e8 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -25,6 +25,7 @@ from freqtrade.exchange.exchange_utils_timeframe import (timeframe_to_minutes, t from freqtrade.exchange.gate import Gate from freqtrade.exchange.hitbtc import Hitbtc from freqtrade.exchange.htx import Htx +from freqtrade.exchange.idex import Idex from freqtrade.exchange.kraken import Kraken from freqtrade.exchange.kucoin import Kucoin from freqtrade.exchange.okx import Okx diff --git a/freqtrade/exchange/binance_leverage_tiers.json b/freqtrade/exchange/binance_leverage_tiers.json index 8e906d018..abc135395 100644 --- a/freqtrade/exchange/binance_leverage_tiers.json +++ b/freqtrade/exchange/binance_leverage_tiers.json @@ -21,95 +21,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "50000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 50000.0, + "maxNotional": 500000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "500000", + "notionalFloor": "50000", + "maintMarginRatio": "0.05", + "cum": "1400.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 500000.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1000000", + "notionalFloor": "500000", + "maintMarginRatio": "0.1", + "cum": "26400.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1000000.0, + "maxNotional": 1250000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "1250000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.125", + "cum": "51400.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 1250000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "2500000", + "notionalFloor": "1250000", + "maintMarginRatio": "0.25", + "cum": "207650.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 2500000.0, + "maxNotional": 5000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "5000000", + "notionalFloor": "2500000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "832650.0" } } ], @@ -623,95 +639,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "50000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 50000.0, + "maxNotional": 500000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "500000", + "notionalFloor": "50000", + "maintMarginRatio": "0.05", + "cum": "1400.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 500000.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1000000", + "notionalFloor": "500000", + "maintMarginRatio": "0.1", + "cum": "26400.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1000000.0, + "maxNotional": 1250000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "1250000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.125", + "cum": "51400.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 1250000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "2500000", + "notionalFloor": "1250000", + "maintMarginRatio": "0.25", + "cum": "207650.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 2500000.0, + "maxNotional": 5000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "5000000", + "notionalFloor": "2500000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "832650.0" } } ], @@ -1874,96 +1906,112 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", - "notionalCap": "25000", + "initialLeverage": "25", + "notionalCap": "50000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, + "minNotional": 50000.0, "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", + "initialLeverage": "20", "notionalCap": "100000", - "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", + "initialLeverage": "10", + "notionalCap": "1000000", "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "maintMarginRatio": "0.05", + "cum": "2775.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 1000000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "2000000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.1", + "cum": "52775.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 2000000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2500000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.125", + "cum": "102775.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2500000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "5000000", + "notionalFloor": "2500000", + "maintMarginRatio": "0.25", + "cum": "415275.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 5000000.0, + "maxNotional": 10000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "10000000", + "notionalFloor": "5000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1665275.0" } } ], @@ -3595,6 +3643,136 @@ } } ], + "ARB/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.006, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.006", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 5000.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 25.0, + "info": { + "bracket": "2", + "initialLeverage": "25", + "notionalCap": "50000", + "notionalFloor": "5000", + "maintMarginRatio": "0.01", + "cum": "20.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 50000.0, + "maxNotional": 600000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "3", + "initialLeverage": "20", + "notionalCap": "600000", + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "770.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 600000.0, + "maxNotional": 1200000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "4", + "initialLeverage": "10", + "notionalCap": "1200000", + "notionalFloor": "600000", + "maintMarginRatio": "0.05", + "cum": "15770.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 1200000.0, + "maxNotional": 3000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "5", + "initialLeverage": "5", + "notionalCap": "3000000", + "notionalFloor": "1200000", + "maintMarginRatio": "0.1", + "cum": "75770.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 3000000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "6", + "initialLeverage": "4", + "notionalCap": "5000000", + "notionalFloor": "3000000", + "maintMarginRatio": "0.125", + "cum": "150770.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 5000000.0, + "maxNotional": 12000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "12000000", + "notionalFloor": "5000000", + "maintMarginRatio": "0.25", + "cum": "775770.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 12000000.0, + "maxNotional": 20000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "8", + "initialLeverage": "1", + "notionalCap": "20000000", + "notionalFloor": "12000000", + "maintMarginRatio": "0.5", + "cum": "3775770.0" + } + } + ], "ARB/USDT:USDT": [ { "tier": 1.0, @@ -7369,6 +7547,136 @@ } } ], + "BOME/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.01", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 5000.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, + "info": { + "bracket": "2", + "initialLeverage": "25", + "notionalCap": "50000", + "notionalFloor": "5000", + "maintMarginRatio": "0.02", + "cum": "50.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 50000.0, + "maxNotional": 600000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "3", + "initialLeverage": "20", + "notionalCap": "600000", + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "300.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 600000.0, + "maxNotional": 1200000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "4", + "initialLeverage": "10", + "notionalCap": "1200000", + "notionalFloor": "600000", + "maintMarginRatio": "0.05", + "cum": "15300.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 1200000.0, + "maxNotional": 3000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "5", + "initialLeverage": "5", + "notionalCap": "3000000", + "notionalFloor": "1200000", + "maintMarginRatio": "0.1", + "cum": "75300.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 3000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "6", + "initialLeverage": "4", + "notionalCap": "4000000", + "notionalFloor": "3000000", + "maintMarginRatio": "0.125", + "cum": "150300.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 4000000.0, + "maxNotional": 6000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "6000000", + "notionalFloor": "4000000", + "maintMarginRatio": "0.25", + "cum": "650300.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 6000000.0, + "maxNotional": 10000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "8", + "initialLeverage": "1", + "notionalCap": "10000000", + "notionalFloor": "6000000", + "maintMarginRatio": "0.5", + "cum": "2150300.0" + } + } + ], "BOME/USDT:USDT": [ { "tier": 1.0, @@ -7390,96 +7698,112 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", - "notionalCap": "25000", + "initialLeverage": "25", + "notionalCap": "50000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "minNotional": 50000.0, + "maxNotional": 150000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", - "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "initialLeverage": "20", + "notionalCap": "150000", + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 150000.0, + "maxNotional": 1500000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "1500000", + "notionalFloor": "150000", + "maintMarginRatio": "0.05", + "cum": "4025.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 1500000.0, + "maxNotional": 3000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "3000000", + "notionalFloor": "1500000", + "maintMarginRatio": "0.1", + "cum": "79025.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 3000000.0, + "maxNotional": 3750000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "3750000", + "notionalFloor": "3000000", + "maintMarginRatio": "0.125", + "cum": "154025.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 3750000.0, + "maxNotional": 7500000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "7500000", + "notionalFloor": "3750000", + "maintMarginRatio": "0.25", + "cum": "622775.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 7500000.0, + "maxNotional": 15000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "15000000", + "notionalFloor": "7500000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "2497775.0" } } ], @@ -12242,96 +12566,112 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", - "notionalCap": "25000", + "initialLeverage": "25", + "notionalCap": "50000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, + "minNotional": 50000.0, "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", + "initialLeverage": "20", "notionalCap": "100000", - "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", + "initialLeverage": "10", + "notionalCap": "1000000", "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "maintMarginRatio": "0.05", + "cum": "2775.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 1000000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "2000000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.1", + "cum": "52775.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 2000000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2500000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.125", + "cum": "102775.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2500000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "5000000", + "notionalFloor": "2500000", + "maintMarginRatio": "0.25", + "cum": "415275.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 5000000.0, + "maxNotional": 10000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "10000000", + "notionalFloor": "5000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1665275.0" } } ], @@ -13686,96 +14026,112 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", - "notionalCap": "25000", + "initialLeverage": "25", + "notionalCap": "50000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, + "minNotional": 50000.0, "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", + "initialLeverage": "20", "notionalCap": "100000", - "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", + "initialLeverage": "10", + "notionalCap": "1000000", "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "maintMarginRatio": "0.05", + "cum": "2775.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 1000000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "2000000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.1", + "cum": "52775.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 2000000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2500000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.125", + "cum": "102775.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2500000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "5000000", + "notionalFloor": "2500000", + "maintMarginRatio": "0.25", + "cum": "415275.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 5000000.0, + "maxNotional": 10000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "10000000", + "notionalFloor": "5000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1665275.0" } } ], @@ -14007,6 +14363,152 @@ } } ], + "FIL/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.006, + "maxLeverage": 75.0, + "info": { + "bracket": "1", + "initialLeverage": "75", + "notionalCap": "50000", + "notionalFloor": "0", + "maintMarginRatio": "0.006", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 50000.0, + "maxNotional": 250000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 40.0, + "info": { + "bracket": "2", + "initialLeverage": "40", + "notionalCap": "250000", + "notionalFloor": "50000", + "maintMarginRatio": "0.01", + "cum": "200.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 250000.0, + "maxNotional": 600000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 20.0, + "info": { + "bracket": "3", + "initialLeverage": "20", + "notionalCap": "600000", + "notionalFloor": "250000", + "maintMarginRatio": "0.02", + "cum": "2700.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 600000.0, + "maxNotional": 1200000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "4", + "initialLeverage": "10", + "notionalCap": "1200000", + "notionalFloor": "600000", + "maintMarginRatio": "0.05", + "cum": "20700.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 1200000.0, + "maxNotional": 3000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "5", + "initialLeverage": "5", + "notionalCap": "3000000", + "notionalFloor": "1200000", + "maintMarginRatio": "0.1", + "cum": "80700.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 3000000.0, + "maxNotional": 6000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "6", + "initialLeverage": "4", + "notionalCap": "6000000", + "notionalFloor": "3000000", + "maintMarginRatio": "0.125", + "cum": "155700.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 6000000.0, + "maxNotional": 10000000.0, + "maintenanceMarginRate": 0.165, + "maxLeverage": 3.0, + "info": { + "bracket": "7", + "initialLeverage": "3", + "notionalCap": "10000000", + "notionalFloor": "6000000", + "maintMarginRatio": "0.165", + "cum": "395700.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 10000000.0, + "maxNotional": 20000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "8", + "initialLeverage": "2", + "notionalCap": "20000000", + "notionalFloor": "10000000", + "maintMarginRatio": "0.25", + "cum": "1245700.0" + } + }, + { + "tier": 9.0, + "currency": "USDC", + "minNotional": 20000000.0, + "maxNotional": 30000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "9", + "initialLeverage": "1", + "notionalCap": "30000000", + "notionalFloor": "20000000", + "maintMarginRatio": "0.5", + "cum": "6245700.0" + } + } + ], "FIL/USDT:USDT": [ { "tier": 1.0, @@ -17988,96 +18490,112 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", - "notionalCap": "25000", + "initialLeverage": "25", + "notionalCap": "50000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, + "minNotional": 50000.0, "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", + "initialLeverage": "20", "notionalCap": "100000", - "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", + "initialLeverage": "10", + "notionalCap": "1000000", "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "maintMarginRatio": "0.05", + "cum": "2775.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 1000000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "2000000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.1", + "cum": "52775.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 2000000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2500000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.125", + "cum": "102775.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2500000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "5000000", + "notionalFloor": "2500000", + "maintMarginRatio": "0.25", + "cum": "415275.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 5000000.0, + "maxNotional": 10000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "10000000", + "notionalFloor": "5000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1665275.0" } } ], @@ -20149,6 +20667,168 @@ } } ], + "LTC/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.005, + "maxLeverage": 75.0, + "info": { + "bracket": "1", + "initialLeverage": "75", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.005", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 5000.0, + "maxNotional": 10000.0, + "maintenanceMarginRate": 0.006, + "maxLeverage": 50.0, + "info": { + "bracket": "2", + "initialLeverage": "50", + "notionalCap": "10000", + "notionalFloor": "5000", + "maintMarginRatio": "0.006", + "cum": "5.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 10000.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 40.0, + "info": { + "bracket": "3", + "initialLeverage": "40", + "notionalCap": "50000", + "notionalFloor": "10000", + "maintMarginRatio": "0.01", + "cum": "45.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 50000.0, + "maxNotional": 750000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, + "info": { + "bracket": "4", + "initialLeverage": "25", + "notionalCap": "750000", + "notionalFloor": "50000", + "maintMarginRatio": "0.02", + "cum": "545.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 750000.0, + "maxNotional": 3000000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "5", + "initialLeverage": "10", + "notionalCap": "3000000", + "notionalFloor": "750000", + "maintMarginRatio": "0.05", + "cum": "23045.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 3000000.0, + "maxNotional": 10000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "6", + "initialLeverage": "5", + "notionalCap": "10000000", + "notionalFloor": "3000000", + "maintMarginRatio": "0.1", + "cum": "173045.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 10000000.0, + "maxNotional": 12000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "7", + "initialLeverage": "4", + "notionalCap": "12000000", + "notionalFloor": "10000000", + "maintMarginRatio": "0.125", + "cum": "423045.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 12000000.0, + "maxNotional": 20000000.0, + "maintenanceMarginRate": 0.15, + "maxLeverage": 3.0, + "info": { + "bracket": "8", + "initialLeverage": "3", + "notionalCap": "20000000", + "notionalFloor": "12000000", + "maintMarginRatio": "0.15", + "cum": "723045.0" + } + }, + { + "tier": 9.0, + "currency": "USDC", + "minNotional": 20000000.0, + "maxNotional": 30000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "9", + "initialLeverage": "2", + "notionalCap": "30000000", + "notionalFloor": "20000000", + "maintMarginRatio": "0.25", + "cum": "2723045.0" + } + }, + { + "tier": 10.0, + "currency": "USDC", + "minNotional": 30000000.0, + "maxNotional": 50000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "10", + "initialLeverage": "1", + "notionalCap": "50000000", + "notionalFloor": "30000000", + "maintMarginRatio": "0.5", + "cum": "10223045.0" + } + } + ], "LTC/USDT:USDT": [ { "tier": 1.0, @@ -20913,6 +21593,152 @@ } } ], + "MATIC/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 10000.0, + "maintenanceMarginRate": 0.006, + "maxLeverage": 75.0, + "info": { + "bracket": "1", + "initialLeverage": "75", + "notionalCap": "10000", + "notionalFloor": "0", + "maintMarginRatio": "0.006", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 10000.0, + "maxNotional": 25000.0, + "maintenanceMarginRate": 0.007, + "maxLeverage": 50.0, + "info": { + "bracket": "2", + "initialLeverage": "50", + "notionalCap": "25000", + "notionalFloor": "10000", + "maintMarginRatio": "0.007", + "cum": "10.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 25000.0, + "maxNotional": 600000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 25.0, + "info": { + "bracket": "3", + "initialLeverage": "25", + "notionalCap": "600000", + "notionalFloor": "25000", + "maintMarginRatio": "0.01", + "cum": "85.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 600000.0, + "maxNotional": 900000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "4", + "initialLeverage": "20", + "notionalCap": "900000", + "notionalFloor": "600000", + "maintMarginRatio": "0.025", + "cum": "9085.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 900000.0, + "maxNotional": 1800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "5", + "initialLeverage": "10", + "notionalCap": "1800000", + "notionalFloor": "900000", + "maintMarginRatio": "0.05", + "cum": "31585.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 1800000.0, + "maxNotional": 4800000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "6", + "initialLeverage": "5", + "notionalCap": "4800000", + "notionalFloor": "1800000", + "maintMarginRatio": "0.1", + "cum": "121585.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 4800000.0, + "maxNotional": 6000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "7", + "initialLeverage": "4", + "notionalCap": "6000000", + "notionalFloor": "4800000", + "maintMarginRatio": "0.125", + "cum": "241585.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 6000000.0, + "maxNotional": 18000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "8", + "initialLeverage": "2", + "notionalCap": "18000000", + "notionalFloor": "6000000", + "maintMarginRatio": "0.25", + "cum": "991585.0" + } + }, + { + "tier": 9.0, + "currency": "USDC", + "minNotional": 18000000.0, + "maxNotional": 30000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "9", + "initialLeverage": "1", + "notionalCap": "30000000", + "notionalFloor": "18000000", + "maintMarginRatio": "0.5", + "cum": "5491585.0" + } + } + ], "MATIC/USDT:USDT": [ { "tier": 1.0, @@ -22345,6 +23171,136 @@ } } ], + "NEAR/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 10000.0, + "maintenanceMarginRate": 0.015, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "10000", + "notionalFloor": "0", + "maintMarginRatio": "0.015", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 10000.0, + "maxNotional": 250000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "2", + "initialLeverage": "20", + "notionalCap": "250000", + "notionalFloor": "10000", + "maintMarginRatio": "0.025", + "cum": "100.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 250000.0, + "maxNotional": 750000.0, + "maintenanceMarginRate": 0.03, + "maxLeverage": 15.0, + "info": { + "bracket": "3", + "initialLeverage": "15", + "notionalCap": "750000", + "notionalFloor": "250000", + "maintMarginRatio": "0.03", + "cum": "1350.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 750000.0, + "maxNotional": 1500000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "4", + "initialLeverage": "10", + "notionalCap": "1500000", + "notionalFloor": "750000", + "maintMarginRatio": "0.05", + "cum": "16350.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 1500000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "5", + "initialLeverage": "5", + "notionalCap": "4000000", + "notionalFloor": "1500000", + "maintMarginRatio": "0.1", + "cum": "91350.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 4000000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "6", + "initialLeverage": "4", + "notionalCap": "5000000", + "notionalFloor": "4000000", + "maintMarginRatio": "0.125", + "cum": "191350.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 5000000.0, + "maxNotional": 12000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "12000000", + "notionalFloor": "5000000", + "maintMarginRatio": "0.25", + "cum": "816350.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 12000000.0, + "maxNotional": 20000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "8", + "initialLeverage": "1", + "notionalCap": "20000000", + "notionalFloor": "12000000", + "maintMarginRatio": "0.5", + "cum": "3816350.0" + } + } + ], "NEAR/USDT:USDT": [ { "tier": 1.0, @@ -22475,6 +23431,136 @@ } } ], + "NEO/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.006, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.006", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 5000.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 25.0, + "info": { + "bracket": "2", + "initialLeverage": "25", + "notionalCap": "50000", + "notionalFloor": "5000", + "maintMarginRatio": "0.01", + "cum": "20.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 50000.0, + "maxNotional": 400000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "3", + "initialLeverage": "20", + "notionalCap": "400000", + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "770.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 400000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "4", + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "400000", + "maintMarginRatio": "0.05", + "cum": "10770.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 800000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "5", + "initialLeverage": "5", + "notionalCap": "2000000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "50770.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 2000000.0, + "maxNotional": 5000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "6", + "initialLeverage": "4", + "notionalCap": "5000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.125", + "cum": "100770.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 5000000.0, + "maxNotional": 12000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "12000000", + "notionalFloor": "5000000", + "maintMarginRatio": "0.25", + "cum": "725770.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 12000000.0, + "maxNotional": 20000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "8", + "initialLeverage": "1", + "notionalCap": "20000000", + "notionalFloor": "12000000", + "maintMarginRatio": "0.5", + "cum": "3725770.0" + } + } + ], "NEO/USDT:USDT": [ { "tier": 1.0, @@ -23485,7 +24571,7 @@ } } ], - "ONDO/USDT:USDT": [ + "OMNI/USDT:USDT": [ { "tier": 1.0, "currency": "USDT", @@ -23507,12 +24593,126 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "2", + "initialLeverage": "20", + "notionalCap": "25000", + "notionalFloor": "5000", + "maintMarginRatio": "0.025", + "cum": "50.0" + } + }, + { + "tier": 3.0, + "currency": "USDT", + "minNotional": 25000.0, + "maxNotional": 100000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "3", + "initialLeverage": "10", + "notionalCap": "100000", + "notionalFloor": "25000", + "maintMarginRatio": "0.05", + "cum": "675.0" + } + }, + { + "tier": 4.0, + "currency": "USDT", + "minNotional": 100000.0, + "maxNotional": 200000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "4", + "initialLeverage": "5", + "notionalCap": "200000", + "notionalFloor": "100000", + "maintMarginRatio": "0.1", + "cum": "5675.0" + } + }, + { + "tier": 5.0, + "currency": "USDT", + "minNotional": 200000.0, + "maxNotional": 500000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "5", + "initialLeverage": "4", + "notionalCap": "500000", + "notionalFloor": "200000", + "maintMarginRatio": "0.125", + "cum": "10675.0" + } + }, + { + "tier": 6.0, + "currency": "USDT", + "minNotional": 500000.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "6", + "initialLeverage": "2", + "notionalCap": "1000000", + "notionalFloor": "500000", + "maintMarginRatio": "0.25", + "cum": "73175.0" + } + }, + { + "tier": 7.0, + "currency": "USDT", + "minNotional": 1000000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "7", + "initialLeverage": "1", + "notionalCap": "2000000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.5", + "cum": "323175.0" + } + } + ], + "ONDO/USDT:USDT": [ + { + "tier": 1.0, + "currency": "USDT", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.015, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.015", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDT", + "minNotional": 5000.0, + "maxNotional": 50000.0, "maintenanceMarginRate": 0.02, "maxLeverage": 25.0, "info": { "bracket": "2", "initialLeverage": "25", - "notionalCap": "25000", + "notionalCap": "50000", "notionalFloor": "5000", "maintMarginRatio": "0.02", "cum": "25.0" @@ -23521,97 +24721,97 @@ { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, - "maxNotional": 80000.0, + "minNotional": 50000.0, + "maxNotional": 150000.0, "maintenanceMarginRate": 0.025, "maxLeverage": 20.0, "info": { "bracket": "3", "initialLeverage": "20", - "notionalCap": "80000", - "notionalFloor": "25000", + "notionalCap": "150000", + "notionalFloor": "50000", "maintMarginRatio": "0.025", - "cum": "150.0" + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 80000.0, - "maxNotional": 800000.0, + "minNotional": 150000.0, + "maxNotional": 1500000.0, "maintenanceMarginRate": 0.05, "maxLeverage": 10.0, "info": { "bracket": "4", "initialLeverage": "10", - "notionalCap": "800000", - "notionalFloor": "80000", + "notionalCap": "1500000", + "notionalFloor": "150000", "maintMarginRatio": "0.05", - "cum": "2150.0" + "cum": "4025.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 800000.0, - "maxNotional": 1600000.0, + "minNotional": 1500000.0, + "maxNotional": 3000000.0, "maintenanceMarginRate": 0.1, "maxLeverage": 5.0, "info": { "bracket": "5", "initialLeverage": "5", - "notionalCap": "1600000", - "notionalFloor": "800000", + "notionalCap": "3000000", + "notionalFloor": "1500000", "maintMarginRatio": "0.1", - "cum": "42150.0" + "cum": "79025.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 1600000.0, - "maxNotional": 2000000.0, + "minNotional": 3000000.0, + "maxNotional": 3750000.0, "maintenanceMarginRate": 0.125, "maxLeverage": 4.0, "info": { "bracket": "6", "initialLeverage": "4", - "notionalCap": "2000000", - "notionalFloor": "1600000", + "notionalCap": "3750000", + "notionalFloor": "3000000", "maintMarginRatio": "0.125", - "cum": "82150.0" + "cum": "154025.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 2000000.0, - "maxNotional": 4000000.0, + "minNotional": 3750000.0, + "maxNotional": 7500000.0, "maintenanceMarginRate": 0.25, "maxLeverage": 2.0, "info": { "bracket": "7", "initialLeverage": "2", - "notionalCap": "4000000", - "notionalFloor": "2000000", + "notionalCap": "7500000", + "notionalFloor": "3750000", "maintMarginRatio": "0.25", - "cum": "332150.0" + "cum": "622775.0" } }, { "tier": 8.0, "currency": "USDT", - "minNotional": 4000000.0, - "maxNotional": 8000000.0, + "minNotional": 7500000.0, + "maxNotional": 15000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { "bracket": "8", "initialLeverage": "1", - "notionalCap": "8000000", - "notionalFloor": "4000000", + "notionalCap": "15000000", + "notionalFloor": "7500000", "maintMarginRatio": "0.5", - "cum": "1332150.0" + "cum": "2497775.0" } } ], @@ -24629,14 +25829,14 @@ "currency": "USDT", "minNotional": 0.0, "maxNotional": 5000.0, - "maintenanceMarginRate": 0.02, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.015, + "maxLeverage": 50.0, "info": { "bracket": "1", - "initialLeverage": "20", + "initialLeverage": "50", "notionalCap": "5000", "notionalFloor": "0", - "maintMarginRatio": "0.02", + "maintMarginRatio": "0.015", "cum": "0.0" } }, @@ -24645,14 +25845,14 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 15.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "15", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", + "maintMarginRatio": "0.02", "cum": "25.0" } }, @@ -24660,80 +25860,96 @@ "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 80000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "200000", + "initialLeverage": "20", + "notionalCap": "80000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "650.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 80000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.1", - "cum": "10650.0" + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "80000", + "maintMarginRatio": "0.05", + "cum": "2150.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 800000.0, + "maxNotional": 1600000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.125", - "cum": "23150.0" + "initialLeverage": "5", + "notionalCap": "1600000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "42150.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 3000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1600000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "3000000", - "notionalFloor": "1000000", - "maintMarginRatio": "0.25", - "cum": "148150.0" + "initialLeverage": "4", + "notionalCap": "2000000", + "notionalFloor": "1600000", + "maintMarginRatio": "0.125", + "cum": "82150.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 3000000.0, - "maxNotional": 5000000.0, + "minNotional": 2000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "4000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.25", + "cum": "332150.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 4000000.0, + "maxNotional": 8000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "5000000", - "notionalFloor": "3000000", + "notionalCap": "8000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.5", - "cum": "898150.0" + "cum": "1332150.0" } } ], @@ -25215,95 +26431,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 80000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "80000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 80000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "80000", + "maintMarginRatio": "0.05", + "cum": "2150.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 800000.0, + "maxNotional": 1600000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1600000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "42150.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1600000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2000000", + "notionalFloor": "1600000", + "maintMarginRatio": "0.125", + "cum": "82150.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "4000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.25", + "cum": "332150.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 4000000.0, + "maxNotional": 8000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "8000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1332150.0" } } ], @@ -25557,95 +26789,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 80000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "80000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 80000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "80000", + "maintMarginRatio": "0.05", + "cum": "2150.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 800000.0, + "maxNotional": 1600000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1600000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "42150.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1600000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2000000", + "notionalFloor": "1600000", + "maintMarginRatio": "0.125", + "cum": "82150.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "4000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.25", + "cum": "332150.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 4000000.0, + "maxNotional": 8000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "8000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1332150.0" } } ], @@ -26633,14 +27881,14 @@ "currency": "USDT", "minNotional": 0.0, "maxNotional": 5000.0, - "maintenanceMarginRate": 0.02, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.015, + "maxLeverage": 50.0, "info": { "bracket": "1", - "initialLeverage": "20", + "initialLeverage": "50", "notionalCap": "5000", "notionalFloor": "0", - "maintMarginRatio": "0.02", + "maintMarginRatio": "0.015", "cum": "0.0" } }, @@ -26648,96 +27896,112 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 50000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 15.0, + "maxNotional": 25000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "15", - "notionalCap": "50000", + "initialLeverage": "25", + "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", + "maintMarginRatio": "0.02", "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", - "minNotional": 50000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "minNotional": 25000.0, + "maxNotional": 80000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "200000", - "notionalFloor": "50000", - "maintMarginRatio": "0.05", - "cum": "1275.0" + "initialLeverage": "20", + "notionalCap": "80000", + "notionalFloor": "25000", + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 80000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.1", - "cum": "11275.0" + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "80000", + "maintMarginRatio": "0.05", + "cum": "2150.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 800000.0, + "maxNotional": 1600000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.125", - "cum": "23775.0" + "initialLeverage": "5", + "notionalCap": "1600000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "42150.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 1000000.0, + "minNotional": 1600000.0, "maxNotional": 2000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", + "initialLeverage": "4", "notionalCap": "2000000", - "notionalFloor": "1000000", - "maintMarginRatio": "0.25", - "cum": "148775.0" + "notionalFloor": "1600000", + "maintMarginRatio": "0.125", + "cum": "82150.0" } }, { "tier": 7.0, "currency": "USDT", "minNotional": 2000000.0, - "maxNotional": 5000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "4000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.25", + "cum": "332150.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 4000000.0, + "maxNotional": 8000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "5000000", - "notionalFloor": "2000000", + "notionalCap": "8000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.5", - "cum": "648775.0" + "cum": "1332150.0" } } ], @@ -27317,95 +28581,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "50000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 50000.0, + "maxNotional": 500000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "500000", + "notionalFloor": "50000", + "maintMarginRatio": "0.05", + "cum": "1400.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 500000.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1000000", + "notionalFloor": "500000", + "maintMarginRatio": "0.1", + "cum": "26400.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1000000.0, + "maxNotional": 1250000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "1250000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.125", + "cum": "51400.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 1250000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "2500000", + "notionalFloor": "1250000", + "maintMarginRatio": "0.25", + "cum": "207650.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 2500000.0, + "maxNotional": 5000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "5000000", + "notionalFloor": "2500000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "832650.0" } } ], @@ -29629,95 +30909,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 80000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "80000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 80000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "80000", + "maintMarginRatio": "0.05", + "cum": "2150.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 800000.0, + "maxNotional": 1600000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1600000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "42150.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1600000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2000000", + "notionalFloor": "1600000", + "maintMarginRatio": "0.125", + "cum": "82150.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "4000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.25", + "cum": "332150.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 4000000.0, + "maxNotional": 8000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "8000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1332150.0" } } ], @@ -30535,6 +31831,120 @@ } } ], + "TAO/USDT:USDT": [ + { + "tier": 1.0, + "currency": "USDT", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.015, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.015", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDT", + "minNotional": 5000.0, + "maxNotional": 25000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "2", + "initialLeverage": "20", + "notionalCap": "25000", + "notionalFloor": "5000", + "maintMarginRatio": "0.025", + "cum": "50.0" + } + }, + { + "tier": 3.0, + "currency": "USDT", + "minNotional": 25000.0, + "maxNotional": 100000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "3", + "initialLeverage": "10", + "notionalCap": "100000", + "notionalFloor": "25000", + "maintMarginRatio": "0.05", + "cum": "675.0" + } + }, + { + "tier": 4.0, + "currency": "USDT", + "minNotional": 100000.0, + "maxNotional": 200000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "4", + "initialLeverage": "5", + "notionalCap": "200000", + "notionalFloor": "100000", + "maintMarginRatio": "0.1", + "cum": "5675.0" + } + }, + { + "tier": 5.0, + "currency": "USDT", + "minNotional": 200000.0, + "maxNotional": 500000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "5", + "initialLeverage": "4", + "notionalCap": "500000", + "notionalFloor": "200000", + "maintMarginRatio": "0.125", + "cum": "10675.0" + } + }, + { + "tier": 6.0, + "currency": "USDT", + "minNotional": 500000.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "6", + "initialLeverage": "2", + "notionalCap": "1000000", + "notionalFloor": "500000", + "maintMarginRatio": "0.25", + "cum": "73175.0" + } + }, + { + "tier": 7.0, + "currency": "USDT", + "minNotional": 1000000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "7", + "initialLeverage": "1", + "notionalCap": "2000000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.5", + "cum": "323175.0" + } + } + ], "THETA/USDT:USDT": [ { "tier": 1.0, @@ -30665,6 +32075,136 @@ } } ], + "TIA/USDC:USDC": [ + { + "tier": 1.0, + "currency": "USDC", + "minNotional": 0.0, + "maxNotional": 5000.0, + "maintenanceMarginRate": 0.01, + "maxLeverage": 50.0, + "info": { + "bracket": "1", + "initialLeverage": "50", + "notionalCap": "5000", + "notionalFloor": "0", + "maintMarginRatio": "0.01", + "cum": "0.0" + } + }, + { + "tier": 2.0, + "currency": "USDC", + "minNotional": 5000.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, + "info": { + "bracket": "2", + "initialLeverage": "25", + "notionalCap": "50000", + "notionalFloor": "5000", + "maintMarginRatio": "0.02", + "cum": "50.0" + } + }, + { + "tier": 3.0, + "currency": "USDC", + "minNotional": 50000.0, + "maxNotional": 600000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, + "info": { + "bracket": "3", + "initialLeverage": "20", + "notionalCap": "600000", + "notionalFloor": "50000", + "maintMarginRatio": "0.025", + "cum": "300.0" + } + }, + { + "tier": 4.0, + "currency": "USDC", + "minNotional": 600000.0, + "maxNotional": 1200000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, + "info": { + "bracket": "4", + "initialLeverage": "10", + "notionalCap": "1200000", + "notionalFloor": "600000", + "maintMarginRatio": "0.05", + "cum": "15300.0" + } + }, + { + "tier": 5.0, + "currency": "USDC", + "minNotional": 1200000.0, + "maxNotional": 3000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, + "info": { + "bracket": "5", + "initialLeverage": "5", + "notionalCap": "3000000", + "notionalFloor": "1200000", + "maintMarginRatio": "0.1", + "cum": "75300.0" + } + }, + { + "tier": 6.0, + "currency": "USDC", + "minNotional": 3000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, + "info": { + "bracket": "6", + "initialLeverage": "4", + "notionalCap": "4000000", + "notionalFloor": "3000000", + "maintMarginRatio": "0.125", + "cum": "150300.0" + } + }, + { + "tier": 7.0, + "currency": "USDC", + "minNotional": 4000000.0, + "maxNotional": 6000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "6000000", + "notionalFloor": "4000000", + "maintMarginRatio": "0.25", + "cum": "650300.0" + } + }, + { + "tier": 8.0, + "currency": "USDC", + "minNotional": 6000000.0, + "maxNotional": 10000000.0, + "maintenanceMarginRate": 0.5, + "maxLeverage": 1.0, + "info": { + "bracket": "8", + "initialLeverage": "1", + "notionalCap": "10000000", + "notionalFloor": "6000000", + "maintMarginRatio": "0.5", + "cum": "2150300.0" + } + } + ], "TIA/USDT:USDT": [ { "tier": 1.0, @@ -31257,95 +32797,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 80000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "80000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 80000.0, + "maxNotional": 800000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "800000", + "notionalFloor": "80000", + "maintMarginRatio": "0.05", + "cum": "2150.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 800000.0, + "maxNotional": 1600000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1600000", + "notionalFloor": "800000", + "maintMarginRatio": "0.1", + "cum": "42150.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1600000.0, + "maxNotional": 2000000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "2000000", + "notionalFloor": "1600000", + "maintMarginRatio": "0.125", + "cum": "82150.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 2000000.0, + "maxNotional": 4000000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "4000000", + "notionalFloor": "2000000", + "maintMarginRatio": "0.25", + "cum": "332150.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 4000000.0, + "maxNotional": 8000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "8000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "1332150.0" } } ], @@ -32721,95 +34277,111 @@ "currency": "USDT", "minNotional": 5000.0, "maxNotional": 25000.0, - "maintenanceMarginRate": 0.025, - "maxLeverage": 20.0, + "maintenanceMarginRate": 0.02, + "maxLeverage": 25.0, "info": { "bracket": "2", - "initialLeverage": "20", + "initialLeverage": "25", "notionalCap": "25000", "notionalFloor": "5000", - "maintMarginRatio": "0.025", - "cum": "50.0" + "maintMarginRatio": "0.02", + "cum": "25.0" } }, { "tier": 3.0, "currency": "USDT", "minNotional": 25000.0, - "maxNotional": 100000.0, - "maintenanceMarginRate": 0.05, - "maxLeverage": 10.0, + "maxNotional": 50000.0, + "maintenanceMarginRate": 0.025, + "maxLeverage": 20.0, "info": { "bracket": "3", - "initialLeverage": "10", - "notionalCap": "100000", + "initialLeverage": "20", + "notionalCap": "50000", "notionalFloor": "25000", - "maintMarginRatio": "0.05", - "cum": "675.0" + "maintMarginRatio": "0.025", + "cum": "150.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 100000.0, - "maxNotional": 200000.0, - "maintenanceMarginRate": 0.1, - "maxLeverage": 5.0, + "minNotional": 50000.0, + "maxNotional": 500000.0, + "maintenanceMarginRate": 0.05, + "maxLeverage": 10.0, "info": { "bracket": "4", - "initialLeverage": "5", - "notionalCap": "200000", - "notionalFloor": "100000", - "maintMarginRatio": "0.1", - "cum": "5675.0" + "initialLeverage": "10", + "notionalCap": "500000", + "notionalFloor": "50000", + "maintMarginRatio": "0.05", + "cum": "1400.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 200000.0, - "maxNotional": 500000.0, - "maintenanceMarginRate": 0.125, - "maxLeverage": 4.0, + "minNotional": 500000.0, + "maxNotional": 1000000.0, + "maintenanceMarginRate": 0.1, + "maxLeverage": 5.0, "info": { "bracket": "5", - "initialLeverage": "4", - "notionalCap": "500000", - "notionalFloor": "200000", - "maintMarginRatio": "0.125", - "cum": "10675.0" + "initialLeverage": "5", + "notionalCap": "1000000", + "notionalFloor": "500000", + "maintMarginRatio": "0.1", + "cum": "26400.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 500000.0, - "maxNotional": 1000000.0, - "maintenanceMarginRate": 0.25, - "maxLeverage": 2.0, + "minNotional": 1000000.0, + "maxNotional": 1250000.0, + "maintenanceMarginRate": 0.125, + "maxLeverage": 4.0, "info": { "bracket": "6", - "initialLeverage": "2", - "notionalCap": "1000000", - "notionalFloor": "500000", - "maintMarginRatio": "0.25", - "cum": "73175.0" + "initialLeverage": "4", + "notionalCap": "1250000", + "notionalFloor": "1000000", + "maintMarginRatio": "0.125", + "cum": "51400.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 1000000.0, - "maxNotional": 2000000.0, + "minNotional": 1250000.0, + "maxNotional": 2500000.0, + "maintenanceMarginRate": 0.25, + "maxLeverage": 2.0, + "info": { + "bracket": "7", + "initialLeverage": "2", + "notionalCap": "2500000", + "notionalFloor": "1250000", + "maintMarginRatio": "0.25", + "cum": "207650.0" + } + }, + { + "tier": 8.0, + "currency": "USDT", + "minNotional": 2500000.0, + "maxNotional": 5000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { - "bracket": "7", + "bracket": "8", "initialLeverage": "1", - "notionalCap": "2000000", - "notionalFloor": "1000000", + "notionalCap": "5000000", + "notionalFloor": "2500000", "maintMarginRatio": "0.5", - "cum": "323175.0" + "cum": "832650.0" } } ], @@ -33192,13 +34764,13 @@ "tier": 2.0, "currency": "USDT", "minNotional": 5000.0, - "maxNotional": 25000.0, + "maxNotional": 50000.0, "maintenanceMarginRate": 0.02, "maxLeverage": 25.0, "info": { "bracket": "2", "initialLeverage": "25", - "notionalCap": "25000", + "notionalCap": "50000", "notionalFloor": "5000", "maintMarginRatio": "0.02", "cum": "25.0" @@ -33207,97 +34779,97 @@ { "tier": 3.0, "currency": "USDT", - "minNotional": 25000.0, - "maxNotional": 80000.0, + "minNotional": 50000.0, + "maxNotional": 200000.0, "maintenanceMarginRate": 0.025, "maxLeverage": 20.0, "info": { "bracket": "3", "initialLeverage": "20", - "notionalCap": "80000", - "notionalFloor": "25000", + "notionalCap": "200000", + "notionalFloor": "50000", "maintMarginRatio": "0.025", - "cum": "150.0" + "cum": "275.0" } }, { "tier": 4.0, "currency": "USDT", - "minNotional": 80000.0, - "maxNotional": 800000.0, + "minNotional": 200000.0, + "maxNotional": 2000000.0, "maintenanceMarginRate": 0.05, "maxLeverage": 10.0, "info": { "bracket": "4", "initialLeverage": "10", - "notionalCap": "800000", - "notionalFloor": "80000", + "notionalCap": "2000000", + "notionalFloor": "200000", "maintMarginRatio": "0.05", - "cum": "2150.0" + "cum": "5275.0" } }, { "tier": 5.0, "currency": "USDT", - "minNotional": 800000.0, - "maxNotional": 1600000.0, + "minNotional": 2000000.0, + "maxNotional": 4000000.0, "maintenanceMarginRate": 0.1, "maxLeverage": 5.0, "info": { "bracket": "5", "initialLeverage": "5", - "notionalCap": "1600000", - "notionalFloor": "800000", + "notionalCap": "4000000", + "notionalFloor": "2000000", "maintMarginRatio": "0.1", - "cum": "42150.0" + "cum": "105275.0" } }, { "tier": 6.0, "currency": "USDT", - "minNotional": 1600000.0, - "maxNotional": 2000000.0, + "minNotional": 4000000.0, + "maxNotional": 5000000.0, "maintenanceMarginRate": 0.125, "maxLeverage": 4.0, "info": { "bracket": "6", "initialLeverage": "4", - "notionalCap": "2000000", - "notionalFloor": "1600000", + "notionalCap": "5000000", + "notionalFloor": "4000000", "maintMarginRatio": "0.125", - "cum": "82150.0" + "cum": "205275.0" } }, { "tier": 7.0, "currency": "USDT", - "minNotional": 2000000.0, - "maxNotional": 4000000.0, + "minNotional": 5000000.0, + "maxNotional": 10000000.0, "maintenanceMarginRate": 0.25, "maxLeverage": 2.0, "info": { "bracket": "7", "initialLeverage": "2", - "notionalCap": "4000000", - "notionalFloor": "2000000", + "notionalCap": "10000000", + "notionalFloor": "5000000", "maintMarginRatio": "0.25", - "cum": "332150.0" + "cum": "830275.0" } }, { "tier": 8.0, "currency": "USDT", - "minNotional": 4000000.0, - "maxNotional": 8000000.0, + "minNotional": 10000000.0, + "maxNotional": 20000000.0, "maintenanceMarginRate": 0.5, "maxLeverage": 1.0, "info": { "bracket": "8", "initialLeverage": "1", - "notionalCap": "8000000", - "notionalFloor": "4000000", + "notionalCap": "20000000", + "notionalFloor": "10000000", "maintMarginRatio": "0.5", - "cum": "1332150.0" + "cum": "3330275.0" } } ], diff --git a/freqtrade/exchange/bybit.py b/freqtrade/exchange/bybit.py index 3fc52b502..1891902f5 100644 --- a/freqtrade/exchange/bybit.py +++ b/freqtrade/exchange/bybit.py @@ -239,7 +239,7 @@ class Bybit(Exchange): return orders - def fetch_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def fetch_order(self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: order = super().fetch_order(order_id, pair, params) if ( order.get('status') == 'canceled' diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index fbb9028c1..eed852e7c 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -44,7 +44,7 @@ from freqtrade.misc import (chunks, deep_merge_dicts, file_dump_json, file_load_ safe_value_fallback2) from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist from freqtrade.util import dt_from_ts, dt_now -from freqtrade.util.datetime_helpers import dt_humanize, dt_ts +from freqtrade.util.datetime_helpers import dt_humanize_delta, dt_ts from freqtrade.util.periodic_cache import PeriodicCache @@ -239,8 +239,8 @@ class Exchange: self.validate_pricing(config['exit_pricing']) self.validate_pricing(config['entry_pricing']) - def _init_ccxt(self, exchange_config: Dict[str, Any], ccxt_module: CcxtModuleType = ccxt, - ccxt_kwargs: Dict = {}) -> ccxt.Exchange: + def _init_ccxt(self, exchange_config: Dict[str, Any], ccxt_module: CcxtModuleType = ccxt, *, + ccxt_kwargs: Dict) -> ccxt.Exchange: """ Initialize ccxt with given config and return valid ccxt instance. @@ -348,10 +348,13 @@ class Exchange: return int(self._ft_has.get('ohlcv_candle_limit_per_timeframe', {}).get( timeframe, self._ft_has.get('ohlcv_candle_limit'))) - def get_markets(self, base_currencies: List[str] = [], quote_currencies: List[str] = [], - spot_only: bool = False, margin_only: bool = False, futures_only: bool = False, - tradable_only: bool = True, - active_only: bool = False) -> Dict[str, Any]: + def get_markets( + self, + base_currencies: Optional[List[str]] = None, + quote_currencies: Optional[List[str]] = None, + spot_only: bool = False, margin_only: bool = False, futures_only: bool = False, + tradable_only: bool = True, + active_only: bool = False) -> Dict[str, Any]: """ Return exchange ccxt markets, filtered out by base currency and quote currency if this was requested in parameters. @@ -758,7 +761,7 @@ class Exchange: def price_get_one_pip(self, pair: str, price: float) -> float: """ - Get's the "1 pip" value for this pair. + Gets the "1 pip" value for this pair. Used in PriceFilter to calculate the 1pip movements. """ precision = self.markets[pair]['precision']['price'] @@ -848,7 +851,7 @@ class Exchange: # Dry-run methods def create_dry_run_order(self, pair: str, ordertype: str, side: str, amount: float, - rate: float, leverage: float, params: Dict = {}, + rate: float, leverage: float, params: Optional[Dict] = None, stop_loss: bool = False) -> Dict[str, Any]: now = dt_now() order_id = f'dry_run_{side}_{pair}_{now.timestamp()}' @@ -1297,9 +1300,11 @@ class Exchange: raise OperationalException(e) from e @retrier(retries=API_FETCH_ORDER_RETRY_COUNT) - def fetch_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def fetch_order(self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: if self._config['dry_run']: return self.fetch_dry_run_order(order_id) + if params is None: + params = {} try: if not self.exchange_has('fetchOrder'): return self.fetch_order_emulated(order_id, pair, params) @@ -1321,7 +1326,7 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(e) from e - def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def fetch_stoploss_order(self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: return self.fetch_order(order_id, pair, params) def fetch_order_or_stoploss_order(self, order_id: str, pair: str, @@ -1347,7 +1352,7 @@ class Exchange: and order.get('filled') == 0.0) @retrier - def cancel_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def cancel_order(self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: if self._config['dry_run']: try: order = self.fetch_dry_run_order(order_id) @@ -1357,6 +1362,8 @@ class Exchange: except InvalidOrderException: return {} + if params is None: + params = {} try: order = self._api.cancel_order(order_id, pair, params=params) self._log_exchange_response('cancel_order', order) @@ -1373,7 +1380,8 @@ class Exchange: except ccxt.BaseError as e: raise OperationalException(e) from e - def cancel_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def cancel_stoploss_order( + self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: return self.cancel_order(order_id, pair, params) def is_cancel_order_result_suitable(self, corder) -> bool: @@ -2000,14 +2008,14 @@ class Exchange: logger.debug( "one_call: %s msecs (%s)", one_call, - dt_humanize(dt_now() - timedelta(milliseconds=one_call), only_distance=True) + dt_humanize_delta(dt_now() - timedelta(milliseconds=one_call)) ) input_coroutines = [self._async_get_candle_history( pair, timeframe, candle_type, since) for since in range(since_ms, until_ms or dt_ts(), one_call)] data: List = [] - # Chunk requests into batches of 100 to avoid overwelming ccxt Throttling + # Chunk requests into batches of 100 to avoid overwhelming ccxt Throttling for input_coro in chunks(input_coroutines, 100): results = await asyncio.gather(*input_coro, return_exceptions=True) @@ -2124,7 +2132,7 @@ class Exchange: Only used in the dataprovider.refresh() method. :param pair_list: List of 2 element tuples containing pair, interval to refresh :param since_ms: time since when to download, in milliseconds - :param cache: Assign result to _klines. Usefull for one-off downloads like for pairlists + :param cache: Assign result to _klines. Useful for one-off downloads like for pairlists :param drop_incomplete: Control candle dropping. Specifying None defaults to _ohlcv_partial_candle :return: Dict of [{(pair, timeframe): Dataframe}] @@ -2135,7 +2143,7 @@ class Exchange: input_coroutines, cached_pairs = self._build_ohlcv_dl_jobs(pair_list, since_ms, cache) results_df = {} - # Chunk requests into batches of 100 to avoid overwelming ccxt Throttling + # Chunk requests into batches of 100 to avoid overwhelming ccxt Throttling for input_coro in chunks(input_coroutines, 100): async def gather_stuff(): return await asyncio.gather(*input_coro, return_exceptions=True) @@ -2295,7 +2303,7 @@ class Exchange: since: Optional[int] = None, params: Optional[dict] = None) -> Tuple[List[List], Any]: """ - Asyncronously gets trade history using fetch_trades. + Asynchronously gets trade history using fetch_trades. Handles exchange errors, does one call to the exchange. :param pair: Pair to fetch trade data for :param since: Since as integer timestamp in milliseconds @@ -2352,7 +2360,7 @@ class Exchange: since: Optional[int] = None, from_id: Optional[str] = None) -> Tuple[str, List[List]]: """ - Asyncronously gets trade history using fetch_trades + Asynchronously gets trade history using fetch_trades use this when exchange uses id-based iteration (check `self._trades_pagination`) :param pair: Pair to fetch trade data for :param since: Since as integer timestamp in milliseconds @@ -2403,7 +2411,7 @@ class Exchange: async def _async_get_trade_history_time(self, pair: str, until: int, since: Optional[int] = None) -> Tuple[str, List[List]]: """ - Asyncronously gets trade history using fetch_trades, + Asynchronously gets trade history using fetch_trades, when the exchange uses time-based iteration (check `self._trades_pagination`) :param pair: Pair to fetch trade data for :param since: Since as integer timestamp in milliseconds @@ -2786,7 +2794,7 @@ class Exchange: @retrier def set_margin_mode(self, pair: str, margin_mode: MarginMode, accept_fail: bool = False, - params: dict = {}): + params: Optional[Dict] = None): """ Set's the margin mode on the exchange to cross or isolated for a specific pair :param pair: base/quote currency pair (e.g. "ADA/USDT") @@ -2795,6 +2803,8 @@ class Exchange: # Some exchanges only support one margin_mode type return + if params is None: + params = {} try: res = self._api.set_margin_mode(margin_mode.value, pair, params) self._log_exchange_response('set_margin_mode', res) diff --git a/freqtrade/exchange/gate.py b/freqtrade/exchange/gate.py index cb749cb66..1d25e2df3 100644 --- a/freqtrade/exchange/gate.py +++ b/freqtrade/exchange/gate.py @@ -79,7 +79,7 @@ class Gate(Exchange): # As such, futures orders on gate will not contain a fee, which causes # a repeated "update fee" cycle and wrong calculations. # Therefore we patch the response with fees if it's not available. - # An alternative also contianing fees would be + # An alternative also containing fees would be # privateFuturesGetSettleAccountBook({"settle": "usdt"}) pair_fees = self._trading_fees.get(pair, {}) if pair_fees: @@ -98,7 +98,7 @@ class Gate(Exchange): def get_order_id_conditional(self, order: Dict[str, Any]) -> str: return safe_value_fallback2(order, order, 'id_stop', 'id') - def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def fetch_stoploss_order(self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: order = self.fetch_order( order_id=order_id, pair=pair, @@ -119,7 +119,8 @@ class Gate(Exchange): return order1 return order - def cancel_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def cancel_stoploss_order( + self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: return self.cancel_order( order_id=order_id, pair=pair, diff --git a/freqtrade/exchange/idex.py b/freqtrade/exchange/idex.py new file mode 100644 index 000000000..eae5ad155 --- /dev/null +++ b/freqtrade/exchange/idex.py @@ -0,0 +1,19 @@ +""" Idex exchange subclass """ +import logging +from typing import Dict + +from freqtrade.exchange import Exchange + + +logger = logging.getLogger(__name__) + + +class Idex(Exchange): + """ + Idex exchange class. Contains adjustments needed for Freqtrade to work + with this exchange. + """ + + _ft_has: Dict = { + "ohlcv_candle_limit": 1000, + } diff --git a/freqtrade/exchange/okx.py b/freqtrade/exchange/okx.py index 6f1c46215..d919a73cc 100644 --- a/freqtrade/exchange/okx.py +++ b/freqtrade/exchange/okx.py @@ -56,7 +56,7 @@ class Okx(Exchange): """ Exchange ohlcv candle limit OKX has the following behaviour: - * 300 candles for uptodate data + * 300 candles for up-to-date data * 100 candles for historic data * 100 candles for additional candles (not futures or spot). :param timeframe: Timeframe to check @@ -202,7 +202,7 @@ class Okx(Exchange): order['type'] = 'stoploss' return order - def fetch_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def fetch_stoploss_order(self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: if self._config['dry_run']: return self.fetch_dry_run_order(order_id) @@ -232,7 +232,8 @@ class Okx(Exchange): return safe_value_fallback2(order, order, 'id_stop', 'id') return order['id'] - def cancel_stoploss_order(self, order_id: str, pair: str, params: Dict = {}) -> Dict: + def cancel_stoploss_order( + self, order_id: str, pair: str, params: Optional[Dict] = None) -> Dict: params1 = {'stop': True} # 'ordType': 'conditional' # diff --git a/freqtrade/freqai/RL/BaseEnvironment.py b/freqtrade/freqai/RL/BaseEnvironment.py index b8548dd16..f53ab9d27 100644 --- a/freqtrade/freqai/RL/BaseEnvironment.py +++ b/freqtrade/freqai/RL/BaseEnvironment.py @@ -222,7 +222,7 @@ class BaseEnvironment(gym.Env): @abstractmethod def step(self, action: int): """ - Step depeneds on action types, this must be inherited. + Step depends on action types, this must be inherited. """ return @@ -326,7 +326,7 @@ class BaseEnvironment(gym.Env): def _update_unrealized_total_profit(self): """ - Update the unrealized total profit incase of episode end. + Update the unrealized total profit in case of episode end. """ if self._position in (Positions.Long, Positions.Short): pnl = self.get_unrealized_profit() @@ -357,7 +357,7 @@ class BaseEnvironment(gym.Env): """ return self.actions - # Keeping around incase we want to start building more complex environment + # Keeping around in case we want to start building more complex environment # templates in the future. # def most_recent_return(self): # """ diff --git a/freqtrade/freqai/RL/BaseReinforcementLearningModel.py b/freqtrade/freqai/RL/BaseReinforcementLearningModel.py index 5b98efb49..71fd9c28c 100644 --- a/freqtrade/freqai/RL/BaseReinforcementLearningModel.py +++ b/freqtrade/freqai/RL/BaseReinforcementLearningModel.py @@ -311,7 +311,7 @@ class BaseReinforcementLearningModel(IFreqaiModel): if not prices_train_old.empty: prices_train = prices_train_old rename_dict = rename_dict_old - logger.warning('Reinforcement learning module didnt find the correct raw prices ' + logger.warning('Reinforcement learning module didn\'t find the correct raw prices ' 'assigned in feature_engineering_standard(). ' 'Please assign them with:\n' 'dataframe["%-raw_close"] = dataframe["close"]\n' @@ -458,7 +458,7 @@ def make_env(MyRLEnv: Type[BaseEnvironment], env_id: str, rank: int, :param env_id: (str) the environment ID :param num_env: (int) the number of environment you wish to have in subprocesses - :param seed: (int) the inital seed for RNG + :param seed: (int) the initial seed for RNG :param rank: (int) index of the subprocess :param env_info: (dict) all required arguments to instantiate the environment. :return: (Callable) diff --git a/freqtrade/freqai/data_drawer.py b/freqtrade/freqai/data_drawer.py index e04535928..77462f311 100644 --- a/freqtrade/freqai/data_drawer.py +++ b/freqtrade/freqai/data_drawer.py @@ -280,7 +280,7 @@ class FreqaiDataDrawer: new_pred = pred_df.copy() # set new_pred values to nans (we want to signal to user that there was nothing - # historically made during downtime. The newest pred will get appeneded later in + # historically made during downtime. The newest pred will get appended later in # append_model_predictions) new_pred["date_pred"] = dataframe["date"] diff --git a/freqtrade/freqai/data_kitchen.py b/freqtrade/freqai/data_kitchen.py index 3b4c5d817..834399390 100644 --- a/freqtrade/freqai/data_kitchen.py +++ b/freqtrade/freqai/data_kitchen.py @@ -612,7 +612,7 @@ class FreqaiDataKitchen: pairs = self.freqai_config["feature_parameters"].get("include_corr_pairlist", []) for pair in pairs: - pair = pair.replace(':', '') # lightgbm doesnt like colons + pair = pair.replace(':', '') # lightgbm does not like colons pair_cols = [col for col in dataframe.columns if col.startswith("%") and f"{pair}_" in col] @@ -638,7 +638,7 @@ class FreqaiDataKitchen: pairs = self.freqai_config["feature_parameters"].get("include_corr_pairlist", []) current_pair = current_pair.replace(':', '') for pair in pairs: - pair = pair.replace(':', '') # lightgbm doesnt work with colons + pair = pair.replace(':', '') # lightgbm does not work with colons if current_pair != pair: dataframe = dataframe.merge(corr_dataframes[pair], how='left', on='date') @@ -841,7 +841,7 @@ class FreqaiDataKitchen: f = spy.stats.norm.fit(self.data_dictionary["train_labels"][label]) self.data["labels_mean"][label], self.data["labels_std"][label] = f[0], f[1] - # incase targets are classifications + # in case targets are classifications for label in self.unique_class_list: self.data["labels_mean"][label], self.data["labels_std"][label] = 0, 0 diff --git a/freqtrade/freqai/freqai_interface.py b/freqtrade/freqai/freqai_interface.py index ca80cfa64..0972c2c26 100644 --- a/freqtrade/freqai/freqai_interface.py +++ b/freqtrade/freqai/freqai_interface.py @@ -221,7 +221,7 @@ class IFreqaiModel(ABC): time.sleep(1) pair = self.train_queue[0] - # ensure pair is avaialble in dp + # ensure pair is available in dp if pair not in strategy.dp.current_whitelist(): self.train_queue.popleft() logger.warning(f'{pair} not in current whitelist, removing from train queue.') @@ -722,9 +722,6 @@ class IFreqaiModel(ABC): if self.pair_it == self.total_pairs: logger.info( f'Total time spent inferencing pairlist {self.inference_time:.2f} seconds') - if self.inference_time > 0.25 * self.base_tf_seconds: - logger.warning("Inference took over 25% of the candle time. Reduce pairlist to" - " avoid blinding open trades and degrading performance.") self.pair_it = 0 self.inference_time = 0 return diff --git a/freqtrade/freqai/prediction_models/PyTorchMLPClassifier.py b/freqtrade/freqai/prediction_models/PyTorchMLPClassifier.py index 9aabdf7ad..a03a0c742 100644 --- a/freqtrade/freqai/prediction_models/PyTorchMLPClassifier.py +++ b/freqtrade/freqai/prediction_models/PyTorchMLPClassifier.py @@ -74,7 +74,7 @@ class PyTorchMLPClassifier(BasePyTorchClassifier): model.to(self.device) optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate) criterion = torch.nn.CrossEntropyLoss() - # check if continual_learning is activated, and retreive the model to continue training + # check if continual_learning is activated, and retrieve the model to continue training trainer = self.get_init_model(dk.pair) if trainer is None: trainer = PyTorchModelTrainer( diff --git a/freqtrade/freqai/prediction_models/PyTorchMLPRegressor.py b/freqtrade/freqai/prediction_models/PyTorchMLPRegressor.py index dc8dc4b61..ec5c0ba81 100644 --- a/freqtrade/freqai/prediction_models/PyTorchMLPRegressor.py +++ b/freqtrade/freqai/prediction_models/PyTorchMLPRegressor.py @@ -69,7 +69,7 @@ class PyTorchMLPRegressor(BasePyTorchRegressor): model.to(self.device) optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate) criterion = torch.nn.MSELoss() - # check if continual_learning is activated, and retreive the model to continue training + # check if continual_learning is activated, and retrieve the model to continue training trainer = self.get_init_model(dk.pair) if trainer is None: trainer = PyTorchModelTrainer( diff --git a/freqtrade/freqai/prediction_models/PyTorchTransformerRegressor.py b/freqtrade/freqai/prediction_models/PyTorchTransformerRegressor.py index b1f2eecc6..8f245ed83 100644 --- a/freqtrade/freqai/prediction_models/PyTorchTransformerRegressor.py +++ b/freqtrade/freqai/prediction_models/PyTorchTransformerRegressor.py @@ -80,7 +80,7 @@ class PyTorchTransformerRegressor(BasePyTorchRegressor): model.to(self.device) optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate) criterion = torch.nn.MSELoss() - # check if continual_learning is activated, and retreive the model to continue training + # check if continual_learning is activated, and retrieve the model to continue training trainer = self.get_init_model(dk.pair) if trainer is None: trainer = PyTorchTransformerTrainer( diff --git a/freqtrade/freqai/prediction_models/ReinforcementLearner_multiproc.py b/freqtrade/freqai/prediction_models/ReinforcementLearner_multiproc.py index f014da602..3fab83cff 100644 --- a/freqtrade/freqai/prediction_models/ReinforcementLearner_multiproc.py +++ b/freqtrade/freqai/prediction_models/ReinforcementLearner_multiproc.py @@ -63,6 +63,6 @@ class ReinforcementLearner_multiproc(ReinforcementLearner): is_masking_supported(self.eval_env))) # TENSORBOARD CALLBACK DOES NOT RECOMMENDED TO USE WITH MULTIPLE ENVS, - # IT WILL RETURN FALSE INFORMATIONS, NEVERTHLESS NOT THREAD SAFE WITH SB3!!! + # IT WILL RETURN FALSE INFORMATION, NEVERTHELESS NOT THREAD SAFE WITH SB3!!! actions = self.train_env.env_method("get_actions")[0] self.tensorboard_callback = TensorboardCallback(verbose=1, actions=actions) diff --git a/freqtrade/freqai/torch/PyTorchModelTrainer.py b/freqtrade/freqai/torch/PyTorchModelTrainer.py index a91513dcb..5c1db3c65 100644 --- a/freqtrade/freqai/torch/PyTorchModelTrainer.py +++ b/freqtrade/freqai/torch/PyTorchModelTrainer.py @@ -38,7 +38,7 @@ class PyTorchModelTrainer(PyTorchTrainerInterface): :param init_model: A dictionary containing the initial model/optimizer state_dict and model_meta_data saved by self.save() method. :param model_meta_data: Additional metadata about the model (optional). - :param data_convertor: convertor from pd.DataFrame to torch.tensor. + :param data_convertor: converter from pd.DataFrame to torch.tensor. :param n_steps: used to calculate n_epochs. The number of training iterations to run. iteration here refers to the number of times optimizer.step() is called. ignored if n_epochs is set. diff --git a/freqtrade/freqai/utils.py b/freqtrade/freqai/utils.py index 22d75bc16..8ac175e4d 100644 --- a/freqtrade/freqai/utils.py +++ b/freqtrade/freqai/utils.py @@ -178,7 +178,7 @@ def record_params(config: Dict[str, Any], full_path: Path) -> None: def get_timerange_backtest_live_models(config: Config) -> str: """ - Returns a formated timerange for backtest live/ready models + Returns a formatted timerange for backtest live/ready models :param config: Configuration dictionary :return: a string timerange (format example: '20220801-20220822') diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 0184741ff..244095ca7 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -37,6 +37,7 @@ from freqtrade.rpc.rpc_types import (ProfitLossStr, RPCCancelMsg, RPCEntryMsg, R RPCExitMsg, RPCProtectionMsg) from freqtrade.strategy.interface import IStrategy from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper +from freqtrade.util import MeasureTime from freqtrade.util.migrations import migrate_binance_futures_names from freqtrade.wallets import Wallets @@ -64,7 +65,7 @@ class FreqtradeBot(LoggingMixin): # Init objects self.config = config exchange_config: ExchangeConfig = deepcopy(config['exchange']) - # Remove credentials from original exchange config to avoid accidental credentail exposure + # Remove credentials from original exchange config to avoid accidental credential exposure remove_exchange_credentials(config['exchange'], True) self.strategy: IStrategy = StrategyResolver.load_strategy(self.config) @@ -117,7 +118,8 @@ class FreqtradeBot(LoggingMixin): # Protect exit-logic from forcesell and vice versa self._exit_lock = Lock() - LoggingMixin.__init__(self, logger, timeframe_to_seconds(self.strategy.timeframe)) + timeframe_secs = timeframe_to_seconds(self.strategy.timeframe) + LoggingMixin.__init__(self, logger, timeframe_secs) self._schedule = Scheduler() @@ -139,6 +141,16 @@ class FreqtradeBot(LoggingMixin): # Initialize protections AFTER bot start - otherwise parameters are not loaded. self.protections = ProtectionManager(self.config, self.strategy.protections) + def log_took_too_long(duration: float, time_limit: float): + logger.warning( + f"Strategy analysis took {duration:.2f}, which is 25% of the timeframe. " + "This can lead to delayed orders and missed signals." + "Consider either reducing the amount of work your strategy performs " + "or reduce the amount of pairs in the Pairlist." + ) + + self._measure_execution = MeasureTime(log_took_too_long, timeframe_secs * 0.25) + def notify_status(self, msg: str, msg_type=RPCMessageType.STATUS) -> None: """ Public method for users of this class (worker, etc.) to send notifications @@ -175,7 +187,7 @@ class FreqtradeBot(LoggingMixin): try: Trade.commit() except Exception: - # Exeptions here will be happening if the db disappeared. + # Exceptions here will be happening if the db disappeared. # At which point we can no longer commit anyway. pass @@ -223,10 +235,11 @@ class FreqtradeBot(LoggingMixin): strategy_safe_wrapper(self.strategy.bot_loop_start, supress_error=True)( current_time=datetime.now(timezone.utc)) - self.strategy.analyze(self.active_pair_whitelist) + with self._measure_execution: + self.strategy.analyze(self.active_pair_whitelist) with self._exit_lock: - # Check for exchange cancelations, timeouts and user requested replace + # Check for exchange cancellations, timeouts and user requested replace self.manage_open_orders() # Protect from collisions with force_exit. @@ -277,7 +290,7 @@ class FreqtradeBot(LoggingMixin): } self.rpc.send_msg(msg) - def _refresh_active_whitelist(self, trades: List[Trade] = []) -> List[str]: + def _refresh_active_whitelist(self, trades: Optional[List[Trade]] = None) -> List[str]: """ Refresh active whitelist from pairlist or edge and extend it with pairs that have open trades. @@ -449,6 +462,7 @@ class FreqtradeBot(LoggingMixin): trade.pair, trade.open_date_utc - timedelta(seconds=10)) prev_exit_reason = trade.exit_reason prev_trade_state = trade.is_open + prev_trade_amount = trade.amount for order in orders: trade_order = [o for o in trade.orders if o.order_id == order['id']] @@ -480,6 +494,26 @@ class FreqtradeBot(LoggingMixin): send_msg=prev_trade_state != trade.is_open) else: trade.exit_reason = prev_exit_reason + total = self.wallets.get_total(trade.base_currency) + if total < trade.amount: + if total > trade.amount * 0.98: + logger.warning( + f"{trade} has a total of {trade.amount} {trade.base_currency}, " + f"but the Wallet shows a total of {total} {trade.base_currency}. " + f"Adjusting trade amount to {total}." + "This may however lead to further issues." + ) + trade.amount = total + else: + logger.warning( + f"{trade} has a total of {trade.amount} {trade.base_currency}, " + f"but the Wallet shows a total of {total} {trade.base_currency}. " + "Refusing to adjust as the difference is too large." + "This may however lead to further issues." + ) + if prev_trade_amount != trade.amount: + # Cancel stoploss on exchange if the amount changed + trade = self.cancel_stoploss_on_exchange(trade) Trade.commit() except ExchangeError: @@ -1290,12 +1324,12 @@ class FreqtradeBot(LoggingMixin): def manage_trade_stoploss_orders(self, trade: Trade, stoploss_orders: List[Dict]): """ - Perform required actions acording to existing stoploss orders of trade + Perform required actions according to existing stoploss orders of trade :param trade: Corresponding Trade :param stoploss_orders: Current on exchange stoploss orders :return: None """ - # If all stoploss orderd are canceled for some reason we add it again + # If all stoploss ordered are canceled for some reason we add it again canceled_sl_orders = [o for o in stoploss_orders if o['status'] in ('canceled', 'cancelled')] if ( @@ -1935,21 +1969,23 @@ class FreqtradeBot(LoggingMixin): trade.update_trade(order_obj, not send_msg) - trade = self._update_trade_after_fill(trade, order_obj) + trade = self._update_trade_after_fill(trade, order_obj, send_msg) Trade.commit() self.order_close_notify(trade, order_obj, stoploss_order, send_msg) return False - def _update_trade_after_fill(self, trade: Trade, order: Order) -> Trade: + def _update_trade_after_fill(self, trade: Trade, order: Order, send_msg: bool) -> Trade: if order.status in constants.NON_OPEN_EXCHANGE_STATES: strategy_safe_wrapper( self.strategy.order_filled, default_retval=None)( pair=trade.pair, trade=trade, order=order, current_time=datetime.now(timezone.utc)) # If a entry order was closed, force update on stoploss on exchange if order.ft_order_side == trade.entry_side: - trade = self.cancel_stoploss_on_exchange(trade) + if send_msg: + # Don't cancel stoploss in recovery modes immediately + trade = self.cancel_stoploss_on_exchange(trade) if not self.edge: # TODO: should shorting/leverage be supported by Edge, # then this will need to be fixed. diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index fea7a56ef..1952c4fe7 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -19,6 +19,7 @@ from freqtrade.data import history from freqtrade.data.btanalysis import find_existing_backtest_stats, trade_list_to_dataframe from freqtrade.data.converter import trim_dataframe, trim_dataframes from freqtrade.data.dataprovider import DataProvider +from freqtrade.data.metrics import combined_dataframes_with_rel_mean from freqtrade.enums import (BacktestState, CandleType, ExitCheckTuple, ExitType, RunMode, TradingMode) from freqtrade.exceptions import DependencyException, OperationalException @@ -296,7 +297,7 @@ class Backtesting: candle_type=CandleType.FUNDING_RATE ) - # For simplicity, assign to CandleType.Mark (might contian index candles!) + # For simplicity, assign to CandleType.Mark (might contain index candles!) mark_rates_dict = history.load_data( datadir=self.config['datadir'], pairs=self.pairlists.whitelist, @@ -1216,7 +1217,7 @@ class Backtesting: :return: DataFrame with trades (results of backtesting) """ self.prepare_backtest(self.enable_protections) - # Ensure wallets are uptodate (important for --strategy-list) + # Ensure wallets are up-to-date (important for --strategy-list) self.wallets.update() # Use dict of lists with data for performance # (looping lists is a lot faster than pandas DataFrames) @@ -1394,7 +1395,7 @@ class Backtesting: """ Run backtesting end-to-end """ - data: Dict[str, Any] = {} + data: Dict[str, DataFrame] = {} data, timerange = self.load_bt_data() self.load_bt_data_detail() @@ -1421,7 +1422,9 @@ class Backtesting: self.results = results dt_appendix = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") if self.config.get('export', 'none') in ('trades', 'signals'): - store_backtest_stats(self.config['exportfilename'], self.results, dt_appendix) + combined_res = combined_dataframes_with_rel_mean(data, min_date, max_date) + store_backtest_stats(self.config['exportfilename'], self.results, dt_appendix, + market_change_data=combined_res) if (self.config.get('export', 'none') == 'signals' and self.dataprovider.runmode == RunMode.BACKTEST): diff --git a/freqtrade/optimize/hyperopt_tools.py b/freqtrade/optimize/hyperopt_tools.py index 763fed747..5a09d92b5 100644 --- a/freqtrade/optimize/hyperopt_tools.py +++ b/freqtrade/optimize/hyperopt_tools.py @@ -237,8 +237,10 @@ class HyperoptTools: result_dict.update(all_space_params) @staticmethod - def _params_pretty_print(params, space: str, header: str, non_optimized={}) -> None: - if space in params or space in non_optimized: + def _params_pretty_print( + params, space: str, header: str, non_optimized: Optional[Dict] = None) -> None: + + if space in params or (non_optimized and space in non_optimized): space_params = HyperoptTools._space_params(params, space, 5) no_params = HyperoptTools._space_params(non_optimized, space, 5) appendix = '' diff --git a/freqtrade/optimize/optimize_reports/bt_output.py b/freqtrade/optimize/optimize_reports/bt_output.py index ed90cb945..f90a35469 100644 --- a/freqtrade/optimize/optimize_reports/bt_output.py +++ b/freqtrade/optimize/optimize_reports/bt_output.py @@ -278,7 +278,7 @@ def text_table_add_metrics(strat_results: Dict) -> str: def show_backtest_result(strategy: str, results: Dict[str, Any], stake_currency: str, - backtest_breakdown=[]): + backtest_breakdown: List[str]): """ Print results for one strategy """ diff --git a/freqtrade/optimize/optimize_reports/bt_storage.py b/freqtrade/optimize/optimize_reports/bt_storage.py index 6b50412b3..a8a8bf7f2 100644 --- a/freqtrade/optimize/optimize_reports/bt_storage.py +++ b/freqtrade/optimize/optimize_reports/bt_storage.py @@ -1,6 +1,8 @@ import logging from pathlib import Path -from typing import Dict +from typing import Dict, Optional + +from pandas import DataFrame from freqtrade.constants import LAST_BT_RESULT_FN from freqtrade.misc import file_dump_joblib, file_dump_json @@ -11,8 +13,26 @@ from freqtrade.types import BacktestResultType logger = logging.getLogger(__name__) +def _generate_filename(recordfilename: Path, appendix: str, suffix: str) -> Path: + """ + Generates a filename based on the provided parameters. + :param recordfilename: Path object, which can either be a filename or a directory. + :param appendix: use for the filename. e.g. backtest-result- + :param suffix: Suffix to use for the file, e.g. .json, .pkl + :return: Generated filename as a Path object + """ + if recordfilename.is_dir(): + filename = (recordfilename / f'backtest-result-{appendix}').with_suffix(suffix) + else: + filename = Path.joinpath( + recordfilename.parent, f'{recordfilename.stem}-{appendix}' + ).with_suffix(suffix) + return filename + + def store_backtest_stats( - recordfilename: Path, stats: BacktestResultType, dtappendix: str) -> Path: + recordfilename: Path, stats: BacktestResultType, dtappendix: str, *, + market_change_data: Optional[DataFrame] = None) -> Path: """ Stores backtest results :param recordfilename: Path object, which can either be a filename or a directory. @@ -21,12 +41,7 @@ def store_backtest_stats( :param stats: Dataframe containing the backtesting statistics :param dtappendix: Datetime to use for the filename """ - if recordfilename.is_dir(): - filename = (recordfilename / f'backtest-result-{dtappendix}.json') - else: - filename = Path.joinpath( - recordfilename.parent, f'{recordfilename.stem}-{dtappendix}' - ).with_suffix(recordfilename.suffix) + filename = _generate_filename(recordfilename, dtappendix, '.json') # Store metadata separately. file_dump_json(get_backtest_metadata_filename(filename), stats['metadata']) @@ -41,6 +56,11 @@ def store_backtest_stats( latest_filename = Path.joinpath(filename.parent, LAST_BT_RESULT_FN) file_dump_json(latest_filename, {'latest_backtest': str(filename.name)}) + if market_change_data is not None: + filename_mc = _generate_filename(recordfilename, f"{dtappendix}_market_change", '.feather') + market_change_data.reset_index().to_feather( + filename_mc, compression_level=9, compression='lz4') + return filename @@ -57,12 +77,7 @@ def _store_backtest_analysis_data( :param dtappendix: Datetime to use for the filename :param name: Name to use for the file, e.g. signals, rejected """ - if recordfilename.is_dir(): - filename = (recordfilename / f'backtest-result-{dtappendix}_{name}.pkl') - else: - filename = Path.joinpath( - recordfilename.parent, f'{recordfilename.stem}-{dtappendix}_{name}.pkl' - ) + filename = _generate_filename(recordfilename, f"{dtappendix}_{name}", '.pkl') file_dump_joblib(filename, data) diff --git a/freqtrade/persistence/custom_data.py b/freqtrade/persistence/custom_data.py index 81a9e7ad6..4d3bd5218 100644 --- a/freqtrade/persistence/custom_data.py +++ b/freqtrade/persistence/custom_data.py @@ -18,7 +18,7 @@ class _CustomData(ModelBase): """ CustomData database model Keeps records of metadata as key/value store - for trades or global persistant values + for trades or global persistent values One to many relationship with Trades: - One trade can have many metadata entries - One metadata entry can only be associated with one Trade diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index defeb0e3f..1421666ea 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -847,7 +847,7 @@ class LocalTrade: isclose(order.safe_amount_after_fee, amount_tr, abs_tol=MATH_CLOSE_PREC) or (not recalculating and order.safe_amount_after_fee > amount_tr) ): - # When recalculating a trade, only comming out to 0 can force a close + # When recalculating a trade, only coming out to 0 can force a close self.close(order.safe_price) else: self.recalc_trade_from_orders() @@ -1125,7 +1125,7 @@ class LocalTrade: prof = self.calculate_profit(exit_rate, exit_amount, float(avg_price)) close_profit_abs += prof.profit_abs if total_stake > 0: - # This needs to be calculated based on the last occuring exit to be aligned + # This needs to be calculated based on the last occurring exit to be aligned # with realized_profit. close_profit = (close_profit_abs / total_stake) * self.leverage else: @@ -1538,7 +1538,7 @@ class Trade(ModelBase, LocalTrade): amount: Mapped[float] = mapped_column(Float()) # type: ignore amount_requested: Mapped[Optional[float]] = mapped_column(Float()) # type: ignore open_date: Mapped[datetime] = mapped_column( - nullable=False, default=datetime.utcnow) # type: ignore + nullable=False, default=datetime.now) # type: ignore close_date: Mapped[Optional[datetime]] = mapped_column() # type: ignore # absolute value of the stop loss stop_loss: Mapped[float] = mapped_column(Float(), nullable=True, default=0.0) # type: ignore diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index e0aa2437a..4d29337a7 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -440,12 +440,12 @@ def create_scatter( def generate_candlestick_graph( pair: str, data: pd.DataFrame, trades: Optional[pd.DataFrame] = None, *, - indicators1: List[str] = [], indicators2: List[str] = [], - plot_config: Dict[str, Dict] = {}, + indicators1: Optional[List[str]] = None, indicators2: Optional[List[str]] = None, + plot_config: Optional[Dict[str, Dict]] = None, ) -> go.Figure: """ Generate the graph from the data generated by Backtesting or from DB - Volume will always be ploted in row2, so Row 1 and 3 are to our disposal for custom indicators + Volume will always be plotted in row2, so Row 1 and 3 are to our disposal for custom indicators :param pair: Pair to Display on the graph :param data: OHLCV DataFrame containing indicators and entry/exit signals :param trades: All trades created @@ -454,7 +454,11 @@ def generate_candlestick_graph( :param plot_config: Dict of Dicts containing advanced plot configuration :return: Plotly figure """ - plot_config = create_plotconfig(indicators1, indicators2, plot_config) + plot_config = create_plotconfig( + indicators1 or [], + indicators2 or [], + plot_config or {}, + ) rows = 2 + len(plot_config['subplots']) row_widths = [1 for _ in plot_config['subplots']] # Define the graph @@ -673,7 +677,7 @@ def plot_profit(config: Config) -> None: """ Plots the total profit for all pairs. Note, the profit calculation isn't realistic. - But should be somewhat proportional, and therefor useful + But should be somewhat proportional, and therefore useful in helping out to find a good algorithm. """ if 'timeframe' not in config: diff --git a/freqtrade/plugins/pairlist/MarketCapPairList.py b/freqtrade/plugins/pairlist/MarketCapPairList.py index a618f72d2..0c968f988 100644 --- a/freqtrade/plugins/pairlist/MarketCapPairList.py +++ b/freqtrade/plugins/pairlist/MarketCapPairList.py @@ -38,7 +38,7 @@ class MarketCapPairList(IPairList): self._refresh_period = self._pairlistconfig.get('refresh_period', 86400) self._marketcap_cache: TTLCache = TTLCache(maxsize=1, ttl=self._refresh_period) self._def_candletype = self._config['candle_type_def'] - self._coingekko: CoinGeckoAPI = CoinGeckoAPI() + self._coingecko: CoinGeckoAPI = CoinGeckoAPI() if self._max_rank > 250: raise OperationalException( @@ -127,7 +127,7 @@ class MarketCapPairList(IPairList): marketcap_list = self._marketcap_cache.get('marketcap') if marketcap_list is None: - data = self._coingekko.get_coins_markets(vs_currency='usd', order='market_cap_desc', + data = self._coingecko.get_coins_markets(vs_currency='usd', order='market_cap_desc', per_page='250', page='1', sparkline='false', locale='en') if data: diff --git a/freqtrade/plugins/pairlist/PriceFilter.py b/freqtrade/plugins/pairlist/PriceFilter.py index 4c8781184..f27fe035a 100644 --- a/freqtrade/plugins/pairlist/PriceFilter.py +++ b/freqtrade/plugins/pairlist/PriceFilter.py @@ -101,7 +101,7 @@ class PriceFilter(IPairList): def _validate_pair(self, pair: str, ticker: Optional[Ticker]) -> bool: """ - Check if if one price-step (pip) is > than a certain barrier. + Check if one price-step (pip) is > than a certain barrier. :param pair: Pair that's currently validated :param ticker: ticker dict as returned from ccxt.fetch_ticker :return: True if the pair can stay, false if it should be removed diff --git a/freqtrade/plugins/pairlist/RemotePairList.py b/freqtrade/plugins/pairlist/RemotePairList.py index 78e3c8351..0fe67968f 100644 --- a/freqtrade/plugins/pairlist/RemotePairList.py +++ b/freqtrade/plugins/pairlist/RemotePairList.py @@ -116,7 +116,7 @@ class RemotePairList(IPairList): "default": "filter", "options": ["filter", "append"], "description": "Processing mode", - "help": "Append pairs to incomming pairlist or filter them?", + "help": "Append pairs to incoming pairlist or filter them?", }, **IPairList.refresh_period_parameter(), "keep_pairlist_on_failure": { diff --git a/freqtrade/plugins/pairlist/VolumePairList.py b/freqtrade/plugins/pairlist/VolumePairList.py index 25e0a855d..acc6ad7e1 100644 --- a/freqtrade/plugins/pairlist/VolumePairList.py +++ b/freqtrade/plugins/pairlist/VolumePairList.py @@ -65,7 +65,7 @@ class VolumePairList(IPairList): self._tf_in_min = timeframe_to_minutes(self._lookback_timeframe) _tf_in_sec = self._tf_in_min * 60 - # wether to use range lookback or not + # whether to use range lookback or not self._use_range = (self._tf_in_min > 0) & (self._lookback_period > 0) if self._use_range & (self._refresh_period < _tf_in_sec): diff --git a/freqtrade/plugins/protections/iprotection.py b/freqtrade/plugins/protections/iprotection.py index 6057cbc29..378eccfef 100644 --- a/freqtrade/plugins/protections/iprotection.py +++ b/freqtrade/plugins/protections/iprotection.py @@ -110,7 +110,7 @@ class IProtection(LoggingMixin, ABC): Get lock end time """ max_date: datetime = max([trade.close_date for trade in trades if trade.close_date]) - # comming from Database, tzinfo is not set. + # coming from Database, tzinfo is not set. if max_date.tzinfo is None: max_date = max_date.replace(tzinfo=timezone.utc) diff --git a/freqtrade/resolvers/iresolver.py b/freqtrade/resolvers/iresolver.py index 1557f0f35..bcbb5704b 100644 --- a/freqtrade/resolvers/iresolver.py +++ b/freqtrade/resolvers/iresolver.py @@ -47,7 +47,7 @@ class IResolver: @classmethod def build_search_paths(cls, config: Config, user_subdir: Optional[str] = None, - extra_dirs: List[str] = []) -> List[Path]: + extra_dirs: Optional[List[str]] = None) -> List[Path]: abs_paths: List[Path] = [] if cls.initial_search_path: @@ -57,8 +57,9 @@ class IResolver: abs_paths.insert(0, config['user_data_dir'].joinpath(user_subdir)) # Add extra directory to the top of the search paths - for dir in extra_dirs: - abs_paths.insert(0, Path(dir).resolve()) + if extra_dirs: + for dir in extra_dirs: + abs_paths.insert(0, Path(dir).resolve()) if cls.extra_path and (extra := config.get(cls.extra_path)): abs_paths.insert(0, Path(extra).resolve()) @@ -139,7 +140,7 @@ class IResolver: @classmethod def _load_object(cls, paths: List[Path], *, object_name: str, add_source: bool = False, - kwargs: dict = {}) -> Optional[Any]: + kwargs: Dict) -> Optional[Any]: """ Try to load object from path list. """ @@ -163,7 +164,7 @@ class IResolver: def load_object(cls, object_name: str, config: Config, *, kwargs: dict, extra_dir: Optional[str] = None) -> Any: """ - Search and loads the specified object as configured in hte child class. + Search and loads the specified object as configured in the child class. :param object_name: name of the module to import :param config: configuration dictionary :param extra_dir: additional directory to search for the given pairlist diff --git a/freqtrade/rpc/api_server/api_auth.py b/freqtrade/rpc/api_server/api_auth.py index dd4749100..257c1cc24 100644 --- a/freqtrade/rpc/api_server/api_auth.py +++ b/freqtrade/rpc/api_server/api_auth.py @@ -26,6 +26,7 @@ def verify_auth(api_config, username: str, password: str): httpbasic = HTTPBasic(auto_error=False) +security = HTTPBasic() oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token", auto_error=False) @@ -117,7 +118,7 @@ def http_basic_or_jwt_token(form_data: HTTPBasicCredentials = Depends(httpbasic) @router_login.post('/token/login', response_model=AccessAndRefreshToken) -def token_login(form_data: HTTPBasicCredentials = Depends(HTTPBasic()), +def token_login(form_data: HTTPBasicCredentials = Depends(security), api_config=Depends(get_api_config)): if verify_auth(api_config, form_data.username, form_data.password): diff --git a/freqtrade/rpc/api_server/api_backtest.py b/freqtrade/rpc/api_server/api_backtest.py index 814dcf8da..345f835a4 100644 --- a/freqtrade/rpc/api_server/api_backtest.py +++ b/freqtrade/rpc/api_server/api_backtest.py @@ -10,15 +10,16 @@ from fastapi.exceptions import HTTPException from freqtrade.configuration.config_validation import validate_config_consistency from freqtrade.constants import Config -from freqtrade.data.btanalysis import (delete_backtest_result, get_backtest_result, - get_backtest_resultlist, load_and_merge_backtest_result, - update_backtest_metadata) +from freqtrade.data.btanalysis import (delete_backtest_result, get_backtest_market_change, + get_backtest_result, get_backtest_resultlist, + load_and_merge_backtest_result, update_backtest_metadata) from freqtrade.enums import BacktestState from freqtrade.exceptions import ConfigurationError, DependencyException, OperationalException from freqtrade.exchange.common import remove_exchange_credentials from freqtrade.misc import deep_merge_dicts, is_file_in_dir -from freqtrade.rpc.api_server.api_schemas import (BacktestHistoryEntry, BacktestMetadataUpdate, - BacktestRequest, BacktestResponse) +from freqtrade.rpc.api_server.api_schemas import (BacktestHistoryEntry, BacktestMarketChange, + BacktestMetadataUpdate, BacktestRequest, + BacktestResponse) from freqtrade.rpc.api_server.deps import get_config from freqtrade.rpc.api_server.webserver_bgwork import ApiBG from freqtrade.rpc.rpc import RPCException @@ -32,8 +33,10 @@ router = APIRouter() def __run_backtest_bg(btconfig: Config): + from freqtrade.data.metrics import combined_dataframes_with_rel_mean from freqtrade.optimize.optimize_reports import generate_backtest_stats, store_backtest_stats from freqtrade.resolvers import StrategyResolver + asyncio.set_event_loop(asyncio.new_event_loop()) try: # Reload strategy @@ -89,11 +92,14 @@ def __run_backtest_bg(btconfig: Config): min_date=min_date, max_date=max_date) if btconfig.get('export', 'none') == 'trades': + combined_res = combined_dataframes_with_rel_mean(ApiBG.bt['data'], min_date, max_date) fn = store_backtest_stats( - btconfig['exportfilename'], ApiBG.bt['bt'].results, - datetime.now().strftime("%Y-%m-%d_%H-%M-%S") + btconfig['exportfilename'], + ApiBG.bt['bt'].results, + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"), + market_change_data=combined_res ) - ApiBG.bt['bt'].results['metadata'][strategy_name]['filename'] = str(fn.name) + ApiBG.bt['bt'].results['metadata'][strategy_name]['filename'] = str(fn.stem) ApiBG.bt['bt'].results['metadata'][strategy_name]['strategy'] = strategy_name logger.info("Backtest finished.") @@ -308,3 +314,20 @@ def api_update_backtest_history_entry(file: str, body: BacktestMetadataUpdate, raise HTTPException(status_code=400, detail=str(e)) return get_backtest_result(file_abs) + + +@router.get('/backtest/history/{file}/market_change', response_model=BacktestMarketChange, + tags=['webserver', 'backtest']) +def api_get_backtest_market_change(file: str, config=Depends(get_config)): + bt_results_base: Path = config['user_data_dir'] / 'backtest_results' + file_abs = (bt_results_base / f"{file}_market_change").with_suffix('.feather') + # Ensure file is in backtest_results directory + if not is_file_in_dir(file_abs, bt_results_base): + raise HTTPException(status_code=404, detail="File not found.") + df = get_backtest_market_change(file_abs) + + return { + 'columns': df.columns.tolist(), + 'data': df.values.tolist(), + 'length': len(df), + } diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index 6d2c8a13d..97f851b1d 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -558,6 +558,12 @@ class BacktestMetadataUpdate(BaseModel): notes: str = '' +class BacktestMarketChange(BaseModel): + columns: List[str] + length: int + data: List[List[Any]] + + class SysInfo(BaseModel): cpu_pct: List[float] ram_pct: float diff --git a/freqtrade/rpc/api_server/ws/channel.py b/freqtrade/rpc/api_server/ws/channel.py index 3c0a833d8..01bc7d276 100644 --- a/freqtrade/rpc/api_server/ws/channel.py +++ b/freqtrade/rpc/api_server/ws/channel.py @@ -152,7 +152,7 @@ class WebSocketChannel: """ return self._closed.is_set() - def set_subscriptions(self, subscriptions: List[str] = []) -> None: + def set_subscriptions(self, subscriptions: List[str]) -> None: """ Set which subscriptions this channel is subscribed to diff --git a/freqtrade/rpc/external_message_consumer.py b/freqtrade/rpc/external_message_consumer.py index 200d408e6..bb0b3139f 100644 --- a/freqtrade/rpc/external_message_consumer.py +++ b/freqtrade/rpc/external_message_consumer.py @@ -237,7 +237,7 @@ class ExternalMessageConsumer: continue except Exception as e: - # An unforseen error has occurred, log and continue + # An unforeseen error has occurred, log and continue logger.error("Unexpected error has occurred:") logger.exception(e) await asyncio.sleep(self.sleep_time) @@ -387,7 +387,7 @@ class ExternalMessageConsumer: ) if not did_append: - # We want an overlap in candles incase some data has changed + # We want an overlap in candles in case some data has changed n_missing += 1 # Set to None for all candles if we missed a full df's worth of candles n_missing = n_missing if n_missing < FULL_DATAFRAME_THRESHOLD else 1500 diff --git a/freqtrade/rpc/fiat_convert.py b/freqtrade/rpc/fiat_convert.py index d01596cfc..2b44d0546 100644 --- a/freqtrade/rpc/fiat_convert.py +++ b/freqtrade/rpc/fiat_convert.py @@ -39,7 +39,7 @@ class CryptoToFiatConverter(LoggingMixin): This object is also a Singleton """ __instance = None - _coingekko: CoinGeckoAPI = None + _coingecko: CoinGeckoAPI = None _coinlistings: List[Dict] = [] _backoff: float = 0.0 @@ -52,9 +52,9 @@ class CryptoToFiatConverter(LoggingMixin): try: # Limit retires to 1 (0 and 1) # otherwise we risk bot impact if coingecko is down. - CryptoToFiatConverter._coingekko = CoinGeckoAPI(retries=1) + CryptoToFiatConverter._coingecko = CoinGeckoAPI(retries=1) except BaseException: - CryptoToFiatConverter._coingekko = None + CryptoToFiatConverter._coingecko = None return CryptoToFiatConverter.__instance def __init__(self) -> None: @@ -67,7 +67,7 @@ class CryptoToFiatConverter(LoggingMixin): def _load_cryptomap(self) -> None: try: # Use list-comprehension to ensure we get a list. - self._coinlistings = [x for x in self._coingekko.get_coins_list()] + self._coinlistings = [x for x in self._coingecko.get_coins_list()] except RequestException as request_exception: if "429" in str(request_exception): logger.warning( @@ -84,7 +84,7 @@ class CryptoToFiatConverter(LoggingMixin): logger.error( f"Could not load FIAT Cryptocurrency map for the following problem: {exception}") - def _get_gekko_id(self, crypto_symbol): + def _get_gecko_id(self, crypto_symbol): if not self._coinlistings: if self._backoff <= datetime.now().timestamp(): self._load_cryptomap() @@ -180,9 +180,9 @@ class CryptoToFiatConverter(LoggingMixin): if crypto_symbol == fiat_symbol: return 1.0 - _gekko_id = self._get_gekko_id(crypto_symbol) + _gecko_id = self._get_gecko_id(crypto_symbol) - if not _gekko_id: + if not _gecko_id: # return 0 for unsupported stake currencies (fiat-convert should not break the bot) self.log_once( f"unsupported crypto-symbol {crypto_symbol.upper()} - returning 0.0", @@ -191,10 +191,10 @@ class CryptoToFiatConverter(LoggingMixin): try: return float( - self._coingekko.get_price( - ids=_gekko_id, + self._coingecko.get_price( + ids=_gecko_id, vs_currencies=fiat_symbol - )[_gekko_id][fiat_symbol] + )[_gecko_id][fiat_symbol] ) except Exception as exception: logger.error("Error in _find_price: %s", exception) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index a2a02cc68..43be0fd94 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -30,8 +30,8 @@ from freqtrade.persistence.models import PairLock from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist from freqtrade.rpc.fiat_convert import CryptoToFiatConverter from freqtrade.rpc.rpc_types import RPCSendMsg -from freqtrade.util import (decimals_per_coin, dt_humanize, dt_now, dt_ts_def, format_date, - shorten_date) +from freqtrade.util import decimals_per_coin, dt_now, dt_ts_def, format_date, shorten_date +from freqtrade.util.datetime_helpers import dt_humanize_delta from freqtrade.wallets import PositionWallet, Wallet @@ -155,7 +155,7 @@ class RPC: } return val - def _rpc_trade_status(self, trade_ids: List[int] = []) -> List[Dict[str, Any]]: + def _rpc_trade_status(self, trade_ids: Optional[List[int]] = None) -> List[Dict[str, Any]]: """ Below follows the RPC backend it is prefixed with rpc_ to raise awareness that it is a remotely exposed function @@ -301,13 +301,13 @@ class RPC: for oo in trade.open_orders ] - # exemple: '*.**.**' trying to enter, exit and exit with 3 different orders + # example: '*.**.**' trying to enter, exit and exit with 3 different orders active_attempt_side_symbols_str = '.'.join(active_attempt_side_symbols) detail_trade = [ f'{trade.id} {direction_str}', trade.pair + active_attempt_side_symbols_str, - shorten_date(dt_humanize(trade.open_date, only_distance=True)), + shorten_date(dt_humanize_delta(trade.open_date_utc)), profit_str ] @@ -460,8 +460,11 @@ class RPC: def _rpc_trade_statistics( self, stake_currency: str, fiat_display_currency: str, - start_date: datetime = datetime.fromtimestamp(0)) -> Dict[str, Any]: + start_date: Optional[datetime] = None) -> Dict[str, Any]: """ Returns cumulative profit statistics """ + + start_date = datetime.fromtimestamp(0) if start_date is None else start_date + trade_filter = ((Trade.is_open.is_(False) & (Trade.close_date >= start_date)) | Trade.is_open.is_(True)) trades: Sequence[Trade] = Trade.session.scalars(Trade.get_trades_query( @@ -596,10 +599,10 @@ class RPC: 'trade_count': len(trades), 'closed_trade_count': closed_trade_count, 'first_trade_date': format_date(first_date), - 'first_trade_humanized': dt_humanize(first_date) if first_date else '', + 'first_trade_humanized': dt_humanize_delta(first_date) if first_date else '', 'first_trade_timestamp': dt_ts_def(first_date, 0), 'latest_trade_date': format_date(last_date), - 'latest_trade_humanized': dt_humanize(last_date) if last_date else '', + 'latest_trade_humanized': dt_humanize_delta(last_date) if last_date else '', 'latest_trade_timestamp': dt_ts_def(last_date, 0), 'avg_duration': str(timedelta(seconds=sum(durations) / num)).split('.')[0], 'best_pair': best_pair[0] if best_pair else '', diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 94fe8c22f..030075c64 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -33,7 +33,7 @@ from freqtrade.misc import chunks, plural from freqtrade.persistence import Trade from freqtrade.rpc import RPC, RPCException, RPCHandler from freqtrade.rpc.rpc_types import RPCEntryMsg, RPCExitMsg, RPCOrderMsg, RPCSendMsg -from freqtrade.util import dt_humanize, fmt_coin, format_date, round_value +from freqtrade.util import dt_from_ts, dt_humanize_delta, fmt_coin, format_date, round_value MAX_MESSAGE_LENGTH = MessageLimit.MAX_TEXT_LENGTH @@ -488,7 +488,7 @@ class Telegram(RPCHandler): elif msg['type'] == RPCMessageType.WARNING: message = f"\N{WARNING SIGN} *Warning:* `{msg['status']}`" elif msg['type'] == RPCMessageType.EXCEPTION: - # Errors will contain exceptions, which are wrapped in tripple ticks. + # Errors will contain exceptions, which are wrapped in triple ticks. message = f"\N{WARNING SIGN} *ERROR:* \n {msg['status']}" elif msg['type'] == RPCMessageType.STARTUP: @@ -573,8 +573,7 @@ class Telegram(RPCHandler): # TODO: This calculation ignores fees. price_to_1st_entry = ((cur_entry_average - first_avg) / first_avg) if is_open: - lines.append("({})".format(dt_humanize(order["order_filled_date"], - granularity=["day", "hour", "minute"]))) + lines.append("({})".format(dt_humanize_delta(order["order_filled_date"]))) lines.append(f"*Amount:* {round_value(cur_entry_amount, 8)} " f"({fmt_coin(order['cost'], quote_currency)})") lines.append(f"*Average {wording} Price:* {round_value(cur_entry_average, 8)} " @@ -657,7 +656,7 @@ class Telegram(RPCHandler): position_adjust = self._config.get('position_adjustment_enable', False) max_entries = self._config.get('max_entry_position_adjustment', -1) for r in results: - r['open_date_hum'] = dt_humanize(r['open_date']) + r['open_date_hum'] = dt_humanize_delta(r['open_date']) r['num_entries'] = len([o for o in r['orders'] if o['ft_is_entry']]) r['num_exits'] = len([o for o in r['orders'] if not o['ft_is_entry'] and not o['ft_order_side'] == 'stoploss']) @@ -1289,7 +1288,7 @@ class Telegram(RPCHandler): nrecent ) trades_tab = tabulate( - [[dt_humanize(trade['close_date']), + [[dt_humanize_delta(dt_from_ts(trade['close_timestamp'])), trade['pair'] + " (#" + str(trade['trade_id']) + ")", f"{(trade['close_profit']):.2%} ({trade['close_profit_abs']})"] for trade in trades['trades']], @@ -1549,7 +1548,7 @@ class Telegram(RPCHandler): async def send_blacklist_msg(self, blacklist: Dict): errmsgs = [] - for pair, error in blacklist['errors'].items(): + for _, error in blacklist['errors'].items(): errmsgs.append(f"Error: {error['error_msg']}") if errmsgs: await self._send_msg('\n'.join(errmsgs)) diff --git a/freqtrade/strategy/informative_decorator.py b/freqtrade/strategy/informative_decorator.py index e83d9433d..6e44a7e20 100644 --- a/freqtrade/strategy/informative_decorator.py +++ b/freqtrade/strategy/informative_decorator.py @@ -64,7 +64,7 @@ def informative(timeframe: str, asset: str = '', def decorator(fn: PopulateIndicators): informative_pairs = getattr(fn, '_ft_informative', []) informative_pairs.append(InformativeData(_asset, _timeframe, _fmt, _ffill, _candle_type)) - setattr(fn, '_ft_informative', informative_pairs) + setattr(fn, '_ft_informative', informative_pairs) # noqa: B010 return fn return decorator diff --git a/freqtrade/strategy/strategy_helper.py b/freqtrade/strategy/strategy_helper.py index b0fc538ca..5085063a3 100644 --- a/freqtrade/strategy/strategy_helper.py +++ b/freqtrade/strategy/strategy_helper.py @@ -78,7 +78,7 @@ def merge_informative_pair(dataframe: pd.DataFrame, informative: pd.DataFrame, # all indicators on the informative sample MUST be calculated before this point if ffill: # https://pandas.pydata.org/docs/user_guide/merging.html#timeseries-friendly-merging - # merge_ordered - ffill method is 2.5x faster than seperate ffill() + # merge_ordered - ffill method is 2.5x faster than separate ffill() dataframe = pd.merge_ordered(dataframe, informative, fill_method="ffill", left_on='date', right_on=date_merge, how='left') else: diff --git a/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 b/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 index 541c26e87..1783e818c 100644 --- a/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 +++ b/freqtrade/templates/strategy_subtemplates/strategy_methods_advanced.j2 @@ -3,7 +3,7 @@ def bot_loop_start(self, current_time: datetime, **kwargs) -> None: """ Called at the start of the bot iteration (one loop). Might be used to perform pair-independent tasks - (e.g. gather some remote ressource for comparison) + (e.g. gather some remote resource for comparison) For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/ diff --git a/freqtrade/util/__init__.py b/freqtrade/util/__init__.py index f7e63d9d3..6f523cd8e 100644 --- a/freqtrade/util/__init__.py +++ b/freqtrade/util/__init__.py @@ -1,8 +1,9 @@ -from freqtrade.util.datetime_helpers import (dt_floor_day, dt_from_ts, dt_humanize, dt_now, dt_ts, - dt_ts_def, dt_ts_none, dt_utc, format_date, +from freqtrade.util.datetime_helpers import (dt_floor_day, dt_from_ts, dt_humanize_delta, dt_now, + dt_ts, dt_ts_def, dt_ts_none, dt_utc, format_date, format_ms_time, shorten_date) from freqtrade.util.formatters import decimals_per_coin, fmt_coin, round_value from freqtrade.util.ft_precise import FtPrecise +from freqtrade.util.measure_time import MeasureTime from freqtrade.util.periodic_cache import PeriodicCache from freqtrade.util.template_renderer import render_template, render_template_with_fallback # noqa @@ -10,7 +11,7 @@ from freqtrade.util.template_renderer import render_template, render_template_wi __all__ = [ 'dt_floor_day', 'dt_from_ts', - 'dt_humanize', + 'dt_humanize_delta', 'dt_now', 'dt_ts', 'dt_ts_def', @@ -24,4 +25,5 @@ __all__ = [ 'decimals_per_coin', 'round_value', 'fmt_coin', + 'MeasureTime', ] diff --git a/freqtrade/util/datetime_helpers.py b/freqtrade/util/datetime_helpers.py index 66b738e8d..64733721b 100644 --- a/freqtrade/util/datetime_helpers.py +++ b/freqtrade/util/datetime_helpers.py @@ -1,8 +1,8 @@ import re from datetime import datetime, timezone -from typing import Optional +from typing import Optional, Union -import arrow +import humanize from freqtrade.constants import DATETIME_PRINT_FORMAT @@ -76,13 +76,11 @@ def shorten_date(_date: str) -> str: return new_date -def dt_humanize(dt: datetime, **kwargs) -> str: +def dt_humanize_delta(dt: datetime): """ - Return a humanized string for the given datetime. - :param dt: datetime to humanize - :param kwargs: kwargs to pass to arrow's humanize() + Return a humanized string for the given timedelta. """ - return arrow.get(dt).humanize(**kwargs) + return humanize.naturaltime(dt) def format_date(date: Optional[datetime]) -> str: @@ -96,9 +94,9 @@ def format_date(date: Optional[datetime]) -> str: return '' -def format_ms_time(date: int) -> str: +def format_ms_time(date: Union[int, float]) -> str: """ convert MS date to readable format. : epoch-string in ms """ - return datetime.fromtimestamp(date / 1000.0).strftime('%Y-%m-%dT%H:%M:%S') + return dt_from_ts(date).strftime('%Y-%m-%dT%H:%M:%S') diff --git a/freqtrade/util/measure_time.py b/freqtrade/util/measure_time.py new file mode 100644 index 000000000..8266adfc0 --- /dev/null +++ b/freqtrade/util/measure_time.py @@ -0,0 +1,43 @@ +import logging +import time +from typing import Callable + +from cachetools import TTLCache + + +logger = logging.getLogger(__name__) + + +class MeasureTime: + """ + Measure the time of a block of code and call a callback if the time limit is exceeded. + """ + def __init__( + self, callback: Callable[[float, float], None], time_limit: float, ttl: int = 3600 * 4): + """ + :param callback: The callback to call if the time limit is exceeded. + This callback will be called once every "ttl" seconds, + with the parameters "duration" (in seconds) and + "time limit" - representing the passed in time limit. + :param time_limit: The time limit in seconds. + :param ttl: The time to live of the cache in seconds. + defaults to 4 hours. + """ + self._callback = callback + self._time_limit = time_limit + self.__cache: TTLCache = TTLCache(maxsize=1, ttl=ttl) + + def __enter__(self): + self._start = time.time() + + def __exit__(self, *args): + end = time.time() + if self.__cache.get('value'): + return + duration = end - self._start + + if duration < self._time_limit: + return + self._callback(duration, self._time_limit) + + self.__cache['value'] = True diff --git a/freqtrade/util/template_renderer.py b/freqtrade/util/template_renderer.py index 362d0f875..a875818bf 100644 --- a/freqtrade/util/template_renderer.py +++ b/freqtrade/util/template_renderer.py @@ -3,7 +3,10 @@ Jinja2 rendering utils, used to generate new strategy and configurations. """ -def render_template(templatefile: str, arguments: dict = {}) -> str: +from typing import Dict, Optional + + +def render_template(templatefile: str, arguments: Dict) -> str: from jinja2 import Environment, PackageLoader, select_autoescape @@ -16,11 +19,13 @@ def render_template(templatefile: str, arguments: dict = {}) -> str: def render_template_with_fallback(templatefile: str, templatefallbackfile: str, - arguments: dict = {}) -> str: + arguments: Optional[Dict] = None) -> str: """ Use templatefile if possible, otherwise fall back to templatefallbackfile """ from jinja2.exceptions import TemplateNotFound + if arguments is None: + arguments = {} try: return render_template(templatefile, arguments) except TemplateNotFound: diff --git a/freqtrade/wallets.py b/freqtrade/wallets.py index 0d22feb36..96274e7fc 100644 --- a/freqtrade/wallets.py +++ b/freqtrade/wallets.py @@ -306,7 +306,7 @@ class Wallets: :raise: DependencyException if the available stake amount is too low """ stake_amount: float - # Ensure wallets are uptodate. + # Ensure wallets are up-to-date. if update: self.update() val_tied_up = Trade.total_open_trades_stakes() diff --git a/freqtrade/worker.py b/freqtrade/worker.py index fb89e7a2d..e9dbfa74b 100644 --- a/freqtrade/worker.py +++ b/freqtrade/worker.py @@ -137,7 +137,7 @@ class Worker: Throttles the given callable that it takes at least `min_secs` to finish execution. :param func: Any callable - :param throttle_secs: throttling interation execution time limit in seconds + :param throttle_secs: throttling iteration execution time limit in seconds :param timeframe: ensure iteration is executed at the beginning of the next candle. :param timeframe_offset: offset in seconds to apply to the next candle time. :return: Any (result of execution of func) diff --git a/ft_client/freqtrade_client/ft_client.py b/ft_client/freqtrade_client/ft_client.py index 96a7510ff..14bb47bc5 100644 --- a/ft_client/freqtrade_client/ft_client.py +++ b/ft_client/freqtrade_client/ft_client.py @@ -67,7 +67,7 @@ def print_commands(): # Print dynamic help for the different commands using the commands doc-strings client = FtRestClient(None) print("Possible commands:\n") - for x, y in inspect.getmembers(client): + for x, _ in inspect.getmembers(client): if not x.startswith('_'): doc = re.sub(':return:.*', '', getattr(client, x).__doc__, flags=re.MULTILINE).rstrip() print(f"{x}\n\t{doc}\n") diff --git a/pyproject.toml b/pyproject.toml index 6c5252c59..5e02079a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -122,6 +122,7 @@ target-version = "py38" # Exclude UP036 as it's causing the "exit if < 3.9" to fail. extend-select = [ "C90", # mccabe + # "B", # bugbear # "N", # pep8-naming "F", # pyflakes "E", # pycodestyle @@ -129,6 +130,7 @@ extend-select = [ "UP", # pyupgrade "TID", # flake8-tidy-imports # "EXE", # flake8-executable + # "C4", # flake8-comprehensions "YTT", # flake8-2020 # "S", # flake8-bandit # "DTZ", # flake8-datetimez @@ -141,6 +143,7 @@ extend-ignore = [ "E241", # Multiple spaces after comma "E272", # Multiple spaces before keyword "E221", # Multiple spaces before operator + "B007", # Loop control variable not used ] [tool.ruff.lint.mccabe] @@ -149,6 +152,10 @@ max-complexity = 12 [tool.ruff.lint.per-file-ignores] "tests/*" = ["S"] +[tool.ruff.lint.flake8-bugbear] +# Allow default arguments like, e.g., `data: List[str] = fastapi.Query(None)`. +extend-immutable-calls = ["fastapi.Depends", "fastapi.Query"] + [tool.flake8] # Default from https://flake8.pycqa.org/en/latest/user/options.html#cmdoption-flake8-ignore # minus E226 @@ -163,3 +170,7 @@ exclude = [ ".venv", ".env", ] + +[tool.codespell] +ignore-words-list = "coo,fo,strat,zar,selectin" +skip="*.svg,./user_data,./freqtrade/rpc/api_server/ui/installed" diff --git a/requirements-dev.txt b/requirements-dev.txt index a5abb3955..ee6715225 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -7,7 +7,7 @@ -r docs/requirements-docs.txt coveralls==3.3.1 -ruff==0.3.7 +ruff==0.4.1 mypy==1.9.0 pre-commit==3.7.0 pytest==8.1.1 diff --git a/requirements-freqai.txt b/requirements-freqai.txt index df4be7d3b..6bab60ddc 100644 --- a/requirements-freqai.txt +++ b/requirements-freqai.txt @@ -5,7 +5,7 @@ # Required for freqai scikit-learn==1.4.2 joblib==1.4.0 -catboost==1.2.3; 'arm' not in platform_machine +catboost==1.2.5; 'arm' not in platform_machine lightgbm==4.3.0 xgboost==2.0.3 tensorboard==2.16.2 diff --git a/requirements-plot.txt b/requirements-plot.txt index 0d3c404f5..2ef738372 100644 --- a/requirements-plot.txt +++ b/requirements-plot.txt @@ -1,4 +1,4 @@ # Include all requirements to run the bot. -r requirements.txt -plotly==5.20.0 +plotly==5.21.0 diff --git a/requirements.txt b/requirements.txt index 65964d79a..303e2405e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,14 +2,14 @@ numpy==1.26.4 pandas==2.2.2 pandas-ta==0.3.14b -ccxt==4.2.97 +ccxt==4.3.4 cryptography==42.0.5 -aiohttp==3.9.4 +aiohttp==3.9.5 SQLAlchemy==2.0.29 -python-telegram-bot==21.1 +python-telegram-bot==21.1.1 # can't be hard-pinned due to telegram-bot pinning httpx with ~ httpx>=0.24.1 -arrow==1.3.0 +humanize==4.9.0 cachetools==5.3.3 requests==2.31.0 urllib3==2.2.1 @@ -22,7 +22,7 @@ jinja2==3.1.3 tables==3.9.1 joblib==1.4.0 rich==13.7.1 -pyarrow==15.0.2; platform_machine != 'armv7l' +pyarrow==16.0.0; platform_machine != 'armv7l' # find first, C search in arrays py_find_1st==1.1.6 @@ -30,13 +30,13 @@ py_find_1st==1.1.6 # Load ticker files 30% faster python-rapidjson==1.16 # Properly format api responses -orjson==3.10.0 +orjson==3.10.1 # Notify systemd sdnotify==0.3.2 # API Server -fastapi==0.110.1 +fastapi==0.110.2 pydantic==2.7.0 uvicorn==0.29.0 pyjwt==2.8.0 diff --git a/scripts/ws_client.py b/scripts/ws_client.py index 5d27f512e..818426da2 100755 --- a/scripts/ws_client.py +++ b/scripts/ws_client.py @@ -191,7 +191,7 @@ class ClientProtocol: self.logger.info("Empty DataFrame") async def _handle_default(self, name, type, data): - self.logger.info("Unkown message of type {type} received...") + self.logger.info("Unknown message of type {type} received...") self.logger.info(data) @@ -201,7 +201,7 @@ async def create_client( token, scheme='ws', name='default', - protocol=ClientProtocol(), + protocol=None, sleep_time=10, ping_timeout=10, wait_timeout=30, @@ -216,6 +216,8 @@ async def create_client( :param name: The name of the producer :param **kwargs: Any extra kwargs passed to websockets.connect """ + if not protocol: + protocol = ClientProtocol() while 1: try: @@ -277,7 +279,7 @@ async def create_client( continue except Exception as e: - # An unforseen error has occurred, log and try reconnecting again + # An unforeseen error has occurred, log and try reconnecting again logger.error("Unexpected error has occurred:") logger.exception(e) diff --git a/setup.py b/setup.py index 3caf74694..504d3b2b7 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ setup( 'ccxt>=4.2.47', 'SQLAlchemy>=2.0.6', 'python-telegram-bot>=20.1', - 'arrow>=1.0.0', + 'humanize>=4.0.0', 'cachetools', 'requests', 'httpx>=0.24.1', diff --git a/tests/commands/test_commands.py b/tests/commands/test_commands.py index 789535a46..630950c81 100644 --- a/tests/commands/test_commands.py +++ b/tests/commands/test_commands.py @@ -1609,4 +1609,4 @@ def test_start_show_config(capsys, caplog): assert "Your combined configuration is:" in captured.out assert '"max_open_trades":' in captured.out assert '"secret": "REDACTED"' not in captured.out - assert log_has_re(r'Sensitive information will be shown in the upcomming output.*', caplog) + assert log_has_re(r'Sensitive information will be shown in the upcoming output.*', caplog) diff --git a/tests/conftest.py b/tests/conftest.py index d894a7908..b46f30f8f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -49,10 +49,10 @@ def pytest_addoption(parser): def pytest_configure(config): config.addinivalue_line( - "markers", "longrun: mark test that is running slowly and should not be run regularily" + "markers", "longrun: mark test that is running slowly and should not be run regularly" ) if not config.option.longrun: - setattr(config.option, 'markexpr', 'not longrun') + config.option.markexpr = 'not longrun' class FixtureScheduler(LoadScopeScheduling): @@ -490,10 +490,10 @@ def user_dir(mocker, tmp_path) -> Path: @pytest.fixture(autouse=True) -def patch_coingekko(mocker) -> None: +def patch_coingecko(mocker) -> None: """ - Mocker to coingekko to speed up tests - :param mocker: mocker to patch coingekko class + Mocker to coingecko to speed up tests + :param mocker: mocker to patch coingecko class :return: None """ diff --git a/tests/data/test_btanalysis.py b/tests/data/test_btanalysis.py index 554ee261a..7d7a97331 100644 --- a/tests/data/test_btanalysis.py +++ b/tests/data/test_btanalysis.py @@ -16,7 +16,7 @@ from freqtrade.data.metrics import (calculate_cagr, calculate_calmar, calculate_ calculate_expectancy, calculate_market_change, calculate_max_drawdown, calculate_sharpe, calculate_sortino, calculate_underwater, combine_dataframes_with_mean, - create_cum_profit) + combined_dataframes_with_rel_mean, create_cum_profit) from freqtrade.exceptions import OperationalException from freqtrade.util import dt_utc from tests.conftest import CURRENT_TEST_STRATEGY, create_mock_trades @@ -251,10 +251,29 @@ def test_combine_dataframes_with_mean(testdatadir): assert "mean" in df.columns +def test_combined_dataframes_with_rel_mean(testdatadir): + pairs = ["ETH/BTC", "ADA/BTC"] + data = load_data(datadir=testdatadir, pairs=pairs, timeframe='5m') + df = combined_dataframes_with_rel_mean( + data, + datetime(2018, 1, 12, tzinfo=timezone.utc), + datetime(2018, 1, 28, tzinfo=timezone.utc) + ) + assert isinstance(df, DataFrame) + assert "ETH/BTC" not in df.columns + assert "ADA/BTC" not in df.columns + assert "mean" in df.columns + assert "rel_mean" in df.columns + assert "count" in df.columns + assert df.iloc[0]['count'] == 2 + assert df.iloc[-1]['count'] == 2 + assert len(df) < len(data['ETH/BTC']) + + def test_combine_dataframes_with_mean_no_data(testdatadir): pairs = ["ETH/BTC", "ADA/BTC"] data = load_data(datadir=testdatadir, pairs=pairs, timeframe='6m') - with pytest.raises(ValueError, match=r"No objects to concatenate"): + with pytest.raises(ValueError, match=r"No data provided\."): combine_dataframes_with_mean(data) @@ -463,12 +482,12 @@ def test_calculate_max_drawdown2(): assert drawdown == 0.043965 -@pytest.mark.parametrize('profits,relative,highd,lowd,result,result_rel', [ +@pytest.mark.parametrize('profits,relative,highd,lowdays,result,result_rel', [ ([0.0, -500.0, 500.0, 10000.0, -1000.0], False, 3, 4, 1000.0, 0.090909), ([0.0, -500.0, 500.0, 10000.0, -1000.0], True, 0, 1, 500.0, 0.5), ]) -def test_calculate_max_drawdown_abs(profits, relative, highd, lowd, result, result_rel): +def test_calculate_max_drawdown_abs(profits, relative, highd, lowdays, result, result_rel): """ Test case from issue https://github.com/freqtrade/freqtrade/issues/6655 [1000, 500, 1000, 11000, 10000] # absolute results @@ -488,7 +507,7 @@ def test_calculate_max_drawdown_abs(profits, relative, highd, lowd, result, resu assert isinstance(drawdown, float) assert isinstance(drawdown_rel, float) assert hdate == init_date + timedelta(days=highd) - assert ldate == init_date + timedelta(days=lowd) + assert ldate == init_date + timedelta(days=lowdays) # High must be before low assert hdate < ldate diff --git a/tests/data/test_datahandler.py b/tests/data/test_datahandler.py index 25854b261..97c9e29ac 100644 --- a/tests/data/test_datahandler.py +++ b/tests/data/test_datahandler.py @@ -251,7 +251,7 @@ def test_datahandler__check_empty_df(testdatadir, caplog): # @pytest.mark.parametrize('datahandler', []) @pytest.mark.skip("All datahandlers currently support trades data.") def test_datahandler_trades_not_supported(datahandler, testdatadir, ): - # Currently disabled. Reenable should a new provider not support trades data. + # Currently disabled. Re-enable should a new provider not support trades data. dh = get_datahandler(testdatadir, datahandler) with pytest.raises(NotImplementedError): dh.trades_load('UNITTEST/ETH') diff --git a/tests/data/test_dataprovider.py b/tests/data/test_dataprovider.py index 575d2903b..f9c56b62b 100644 --- a/tests/data/test_dataprovider.py +++ b/tests/data/test_dataprovider.py @@ -30,7 +30,7 @@ def test_dp_ohlcv(mocker, default_conf, ohlcv_history, candle_type): assert dp.ohlcv("UNITTEST/BTC", timeframe, candle_type=candletype) is not ohlcv_history assert dp.ohlcv("UNITTEST/BTC", timeframe, copy=False, candle_type=candletype) is ohlcv_history assert not dp.ohlcv("UNITTEST/BTC", timeframe, candle_type=candletype).empty - assert dp.ohlcv("NONESENSE/AAA", timeframe, candle_type=candletype).empty + assert dp.ohlcv("NONSENSE/AAA", timeframe, candle_type=candletype).empty # Test with and without parameter assert dp.ohlcv( @@ -114,7 +114,7 @@ def test_get_pair_dataframe(mocker, default_conf, ohlcv_history, candle_type): assert dp.get_pair_dataframe("UNITTEST/BTC", timeframe, candle_type=candle_type) is not ohlcv_history assert not dp.get_pair_dataframe("UNITTEST/BTC", timeframe, candle_type=candle_type).empty - assert dp.get_pair_dataframe("NONESENSE/AAA", timeframe, candle_type=candle_type).empty + assert dp.get_pair_dataframe("NONSENSE/AAA", timeframe, candle_type=candle_type).empty # Test with and without parameter assert dp.get_pair_dataframe("UNITTEST/BTC", timeframe, candle_type=candle_type)\ @@ -125,7 +125,7 @@ def test_get_pair_dataframe(mocker, default_conf, ohlcv_history, candle_type): assert dp.runmode == RunMode.LIVE assert isinstance(dp.get_pair_dataframe( "UNITTEST/BTC", timeframe, candle_type=candle_type), DataFrame) - assert dp.get_pair_dataframe("NONESENSE/AAA", timeframe, candle_type=candle_type).empty + assert dp.get_pair_dataframe("NONSENSE/AAA", timeframe, candle_type=candle_type).empty historymock = MagicMock(return_value=ohlcv_history) mocker.patch("freqtrade.data.dataprovider.load_pair_history", historymock) diff --git a/tests/edge/test_edge.py b/tests/edge/test_edge.py index 4829dd035..53840b190 100644 --- a/tests/edge/test_edge.py +++ b/tests/edge/test_edge.py @@ -226,8 +226,10 @@ def test_edge_heartbeat_calculate(mocker, edge_conf): assert edge.calculate(edge_conf['exchange']['pair_whitelist']) is False -def mocked_load_data(datadir, pairs=[], timeframe='0m', +def mocked_load_data(datadir, pairs=None, timeframe='0m', timerange=None, *args, **kwargs): + if pairs is None: + pairs = [] hz = 0.1 base = 0.001 diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index df2da7a72..c8293965a 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3830,7 +3830,7 @@ def test_ohlcv_candle_limit(default_conf, mocker, exchange_name): [ ("BTC/USDT", 'BTC', 'USDT', "binance", True, False, False, 'spot', {}, True), ("USDT/BTC", 'USDT', 'BTC', "binance", True, False, False, 'spot', {}, True), - # No seperating / + # No separating / ("BTCUSDT", 'BTC', 'USDT', "binance", True, False, False, 'spot', {}, True), ("BTCUSDT", None, "USDT", "binance", True, False, False, 'spot', {}, False), ("USDT/BTC", "BTC", None, "binance", True, False, False, 'spot', {}, False), @@ -4346,7 +4346,7 @@ def test_combine_funding_and_mark( ('binance', 0, 2, "2021-09-01 00:00:01", "2021-09-01 08:00:00", 30.0, -0.00091409999), ('binance', 0, 2, "2021-08-31 23:58:00", "2021-09-01 08:00:00", 30.0, -0.00091409999), ('binance', 0, 2, "2021-09-01 00:10:01", "2021-09-01 08:00:00", 30.0, -0.0002493), - # TODO: Uncoment once _calculate_funding_fees can pas time_in_ratio to exchange._get_funding_fee + # TODO: Uncomment once _calculate_funding_fees can pass time_in_ratio to exchange. # ('kraken', "2021-09-01 00:00:00", "2021-09-01 08:00:00", 30.0, -0.0014937), # ('kraken', "2021-09-01 00:00:15", "2021-09-01 08:00:00", 30.0, -0.0008289), # ('kraken', "2021-09-01 01:00:14", "2021-09-01 08:00:00", 30.0, -0.0008289), @@ -4358,7 +4358,7 @@ def test_combine_funding_and_mark( ('gate', 0, 2, "2021-09-01 00:00:00", "2021-09-01 12:00:00", 30.0, -0.0009140999), ('gate', 1, 2, "2021-09-01 00:00:01", "2021-09-01 08:00:00", 30.0, -0.0002493), ('binance', 0, 2, "2021-09-01 00:00:00", "2021-09-01 08:00:00", 50.0, -0.0015235), - # TODO: Uncoment once _calculate_funding_fees can pas time_in_ratio to exchange._get_funding_fee + # TODO: Uncomment once _calculate_funding_fees can pass time_in_ratio to exchange. # ('kraken', "2021-09-01 00:00:00", "2021-09-01 08:00:00", 50.0, -0.0024895), ]) def test__fetch_and_calculate_funding_fees( @@ -5133,7 +5133,7 @@ def test_get_maintenance_ratio_and_amt( mocker.patch(f'{EXMS}.exchange_has', return_value=True) exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange._leverage_tiers = leverage_tiers - exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt) + assert exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt) def test_get_max_leverage_futures(default_conf, mocker, leverage_tiers): diff --git a/tests/exchange/test_okx.py b/tests/exchange/test_okx.py index 73f87774e..69e7e498b 100644 --- a/tests/exchange/test_okx.py +++ b/tests/exchange/test_okx.py @@ -472,7 +472,7 @@ def test_load_leverage_tiers_okx(default_conf, mocker, markets, tmp_path, caplog exchange.load_leverage_tiers() assert not log_has(logmsg, caplog) - api_mock.fetch_market_leverage_tiers.call_count == 0 + assert api_mock.fetch_market_leverage_tiers.call_count == 0 # 2 day passes ... time_machine.move_to(datetime.now() + timedelta(weeks=5)) exchange.load_leverage_tiers() @@ -500,7 +500,7 @@ def test__set_leverage_okx(mocker, default_conf): 'posSide': 'net'} api_mock.set_leverage = MagicMock(side_effect=ccxt.NetworkError()) exchange._lev_prep('BTC/USDT:USDT', 3.2, 'buy') - api_mock.fetch_leverage.call_count == 1 + assert api_mock.fetch_leverage.call_count == 1 api_mock.fetch_leverage = MagicMock(side_effect=ccxt.NetworkError()) ccxt_exceptionhandlers( diff --git a/tests/freqai/test_freqai_backtesting.py b/tests/freqai/test_freqai_backtesting.py index c65934c4e..808f37ce5 100644 --- a/tests/freqai/test_freqai_backtesting.py +++ b/tests/freqai/test_freqai_backtesting.py @@ -133,6 +133,6 @@ def test_freqai_backtest_consistent_timerange(mocker, freqai_conf): backtesting = Backtesting(deepcopy(freqai_conf)) backtesting.start() - gbs.call_args[1]['min_date'] == datetime(2021, 11, 20, 0, 0, tzinfo=timezone.utc) - gbs.call_args[1]['max_date'] == datetime(2021, 11, 21, 0, 0, tzinfo=timezone.utc) + assert gbs.call_args[1]['min_date'] == datetime(2021, 11, 20, 0, 0, tzinfo=timezone.utc) + assert gbs.call_args[1]['max_date'] == datetime(2021, 11, 21, 0, 0, tzinfo=timezone.utc) Backtesting.cleanup() diff --git a/tests/freqai/test_freqai_datadrawer.py b/tests/freqai/test_freqai_datadrawer.py index 7e1a1c32e..548fad650 100644 --- a/tests/freqai/test_freqai_datadrawer.py +++ b/tests/freqai/test_freqai_datadrawer.py @@ -143,7 +143,7 @@ def test_get_timerange_from_backtesting_live_df_pred_not_found(mocker, freqai_co def test_set_initial_return_values(mocker, freqai_conf): """ Simple test of the set initial return values that ensures - we are concatening and ffilling values properly. + we are concatenating and ffilling values properly. """ strategy = get_patched_freqai_strategy(mocker, freqai_conf) diff --git a/tests/freqai/test_freqai_interface.py b/tests/freqai/test_freqai_interface.py index cd07b913b..178984818 100644 --- a/tests/freqai/test_freqai_interface.py +++ b/tests/freqai/test_freqai_interface.py @@ -403,7 +403,7 @@ def test_backtesting_fit_live_predictions(mocker, freqai_conf, caplog): freqai.dk.get_unique_classes_from_labels(df) freqai.dk.pair = "ADA/BTC" freqai.dk.full_df = df.fillna(0) - freqai.dk.full_df + assert "&-s_close_mean" not in freqai.dk.full_df.columns assert "&-s_close_std" not in freqai.dk.full_df.columns freqai.backtesting_fit_live_predictions(freqai.dk) diff --git a/tests/freqtradebot/test_freqtradebot.py b/tests/freqtradebot/test_freqtradebot.py index 0106e1b77..993091068 100644 --- a/tests/freqtradebot/test_freqtradebot.py +++ b/tests/freqtradebot/test_freqtradebot.py @@ -285,7 +285,7 @@ def test_edge_overrides_stoploss(limit_order, fee, caplog, mocker, 'last': enter_price * buy_price_mult, }) - # stoploss shoud be hit + # stoploss should be hit assert freqtrade.handle_trade(trade) is not ignore_strat_sl if not ignore_strat_sl: assert log_has_re('Exit for NEO/BTC detected. Reason: stop_loss.*', caplog) @@ -1398,7 +1398,7 @@ def test_update_trade_state_sell( assert order.status == 'open' freqtrade.update_trade_state(trade, trade.open_orders_ids[-1], l_order) assert trade.amount == l_order['amount'] - # Wallet needs to be updated after closing a limit-sell order to reenable buying + # Wallet needs to be updated after closing a limit-sell order to re-enable buying assert wallet_mock.call_count == 1 assert not trade.is_open # Order is updated by update_trade_state @@ -3122,7 +3122,7 @@ def test_exit_profit_only( if profit_only: assert freqtrade.handle_trade(trade) is False # Custom-exit is called - freqtrade.strategy.custom_exit.call_count == 1 + assert freqtrade.strategy.custom_exit.call_count == 1 patch_get_signal(freqtrade, enter_long=False, exit_short=is_short, exit_long=not is_short) assert freqtrade.handle_trade(trade) is handle_first @@ -3240,7 +3240,7 @@ def test_locked_pairs(default_conf_usdt, ticker_usdt, fee, ) trade.close(ticker_usdt_sell_down()['bid']) assert freqtrade.strategy.is_pair_locked(trade.pair, side='*') - # Boths sides are locked + # Both sides are locked assert freqtrade.strategy.is_pair_locked(trade.pair, side='long') assert freqtrade.strategy.is_pair_locked(trade.pair, side='short') @@ -4558,6 +4558,67 @@ def test_handle_onexchange_order(mocker, default_conf_usdt, limit_order, is_shor assert trade.exit_reason == ExitType.SOLD_ON_EXCHANGE.value +@pytest.mark.usefixtures("init_persistence") +@pytest.mark.parametrize("is_short", [False, True]) +@pytest.mark.parametrize("factor,adjusts", [ + (0.99, True), + (0.97, False), +]) +def test_handle_onexchange_order_changed_amount( + mocker, default_conf_usdt, limit_order, is_short, caplog, + factor, adjusts, +): + default_conf_usdt['dry_run'] = False + freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt) + mock_uts = mocker.spy(freqtrade, 'update_trade_state') + + entry_order = limit_order[entry_side(is_short)] + mock_fo = mocker.patch(f'{EXMS}.fetch_orders', return_value=[ + entry_order, + ]) + + trade = Trade( + pair='ETH/USDT', + fee_open=0.001, + base_currency='ETH', + fee_close=0.001, + open_rate=entry_order['price'], + open_date=dt_now(), + stake_amount=entry_order['cost'], + amount=entry_order['amount'], + exchange="binance", + is_short=is_short, + leverage=1, + ) + freqtrade.wallets = MagicMock() + freqtrade.wallets.get_total = MagicMock(return_value=entry_order['amount'] * factor) + + trade.orders.append(Order.parse_from_ccxt_object( + entry_order, 'ADA/USDT', entry_side(is_short)) + ) + Trade.session.add(trade) + + # assert trade.amount > entry_order['amount'] + + freqtrade.handle_onexchange_order(trade) + assert mock_uts.call_count == 1 + assert mock_fo.call_count == 1 + + trade = Trade.session.scalars(select(Trade)).first() + + assert log_has_re(r'.*has a total of .* but the Wallet shows.*', caplog) + if adjusts: + # Trade amount is updated + assert trade.amount == entry_order['amount'] * factor + assert log_has_re(r'.*Adjusting trade amount to.*', caplog) + else: + assert log_has_re(r'.*Refusing to adjust as the difference.*', caplog) + assert trade.amount == entry_order['amount'] + + assert len(trade.orders) == 1 + assert trade.is_open is True + + @pytest.mark.usefixtures("init_persistence") @pytest.mark.parametrize("is_short", [False, True]) def test_handle_onexchange_order_exit(mocker, default_conf_usdt, limit_order, is_short, caplog): @@ -4829,7 +4890,7 @@ def test_update_funding_fees( freqtrade.execute_entry('ETH/USDT', 123, is_short=is_short) freqtrade.execute_entry('LTC/USDT', 2.0, is_short=is_short) freqtrade.execute_entry('XRP/USDT', 123, is_short=is_short) - multipl = 1 if is_short else -1 + multiple = 1 if is_short else -1 trades = Trade.get_open_trades() assert len(trades) == 3 for trade in trades: @@ -4847,7 +4908,7 @@ def test_update_funding_fees( assert trade.funding_fees == pytest.approx(sum( trade.amount * mark_prices[trade.pair].iloc[1:2]['open'] * - funding_rates[trade.pair].iloc[1:2]['open'] * multipl + funding_rates[trade.pair].iloc[1:2]['open'] * multiple )) else: @@ -4859,7 +4920,7 @@ def test_update_funding_fees( trade.amount * mark_prices[trade.pair].iloc[1:2]['open'] * funding_rates[trade.pair].iloc[1:2]['open'] * - multipl + multiple )) diff --git a/tests/optimize/test_backtest_detail.py b/tests/optimize/test_backtest_detail.py index 71cb8ff34..54468910c 100644 --- a/tests/optimize/test_backtest_detail.py +++ b/tests/optimize/test_backtest_detail.py @@ -107,7 +107,7 @@ tc5 = BTContainer(data=[ trades=[BTrade(exit_reason=ExitType.ROI, open_tick=1, close_tick=3)] ) -# Test 6: Drops 3% / Recovers 6% Positive / Closes 1% positve, Stop-Loss triggers 2% Loss +# Test 6: Drops 3% / Recovers 6% Positive / Closes 1% positive, Stop-Loss triggers 2% Loss # stop-loss: 2% ROI: 5% tc6 = BTContainer(data=[ # D O H L C V EL XL ES Xs BT @@ -121,7 +121,7 @@ tc6 = BTContainer(data=[ trades=[BTrade(exit_reason=ExitType.STOP_LOSS, open_tick=1, close_tick=2)] ) -# Test 7: 6% Positive / 1% Negative / Close 1% Positve, ROI Triggers 3% Gain +# Test 7: 6% Positive / 1% Negative / Close 1% Positive, ROI Triggers 3% Gain # stop-loss: 2% ROI: 3% tc7 = BTContainer(data=[ # D O H L C V EL XL ES Xs BT diff --git a/tests/optimize/test_backtesting_adjust_position.py b/tests/optimize/test_backtesting_adjust_position.py index 322b292ff..983e4b47f 100644 --- a/tests/optimize/test_backtesting_adjust_position.py +++ b/tests/optimize/test_backtesting_adjust_position.py @@ -87,9 +87,9 @@ def test_backtest_position_adjustment(default_conf, fee, mocker, testdatadir) -> for _, t in results.iterrows(): ln = data_pair.loc[data_pair["date"] == t["open_date"]] - # Check open trade rate alignes to open rate + # Check open trade rate aligns to open rate assert ln is not None - # check close trade rate alignes to close rate or is between high and low + # check close trade rate aligns to close rate or is between high and low ln = data_pair.loc[data_pair["date"] == t["close_date"]] assert (round(ln.iloc[0]["open"], 6) == round(t["close_rate"], 6) or round(ln.iloc[0]["low"], 6) < round( diff --git a/tests/optimize/test_hyperopt.py b/tests/optimize/test_hyperopt.py index be27bb3f5..a68a0fc39 100644 --- a/tests/optimize/test_hyperopt.py +++ b/tests/optimize/test_hyperopt.py @@ -901,6 +901,7 @@ def test_in_strategy_auto_hyperopt(mocker, hyperopt_conf, tmp_path, fee) -> None hyperopt.get_optimizer([], 2) +@pytest.mark.filterwarnings("ignore::DeprecationWarning") def test_in_strategy_auto_hyperopt_with_parallel(mocker, hyperopt_conf, tmp_path, fee) -> None: mocker.patch(f'{EXMS}.validate_config', MagicMock()) mocker.patch(f'{EXMS}.get_fee', fee) diff --git a/tests/optimize/test_hyperopt_tools.py b/tests/optimize/test_hyperopt_tools.py index c46897374..47aba6b76 100644 --- a/tests/optimize/test_hyperopt_tools.py +++ b/tests/optimize/test_hyperopt_tools.py @@ -172,8 +172,8 @@ def test__pprint_dict(): }""" -def test_get_strategy_filename(default_conf): - +def test_get_strategy_filename(default_conf, tmp_path): + default_conf['user_data_dir'] = tmp_path x = HyperoptTools.get_strategy_filename(default_conf, 'StrategyTestV3') assert isinstance(x, Path) assert x == Path(__file__).parents[1] / 'strategy/strats/strategy_test_v3.py' @@ -233,6 +233,7 @@ def test_export_params(tmp_path): def test_try_export_params(default_conf, tmp_path, caplog, mocker): default_conf['disableparamexport'] = False + default_conf['user_data_dir'] = tmp_path export_mock = mocker.patch("freqtrade.optimize.hyperopt_tools.HyperoptTools.export_params") filename = tmp_path / f"{CURRENT_TEST_STRATEGY}.json" diff --git a/tests/optimize/test_lookahead_analysis.py b/tests/optimize/test_lookahead_analysis.py index d7c4bc6fa..6c84663b6 100644 --- a/tests/optimize/test_lookahead_analysis.py +++ b/tests/optimize/test_lookahead_analysis.py @@ -14,7 +14,8 @@ from tests.conftest import EXMS, get_args, log_has_re, patch_exchange @pytest.fixture -def lookahead_conf(default_conf_usdt): +def lookahead_conf(default_conf_usdt, tmp_path): + default_conf_usdt['user_data_dir'] = tmp_path default_conf_usdt['minimum_trade_amount'] = 10 default_conf_usdt['targeted_trade_amount'] = 20 default_conf_usdt['timerange'] = '20220101-20220501' @@ -152,7 +153,7 @@ def test_lookahead_helper_text_table_lookahead_analysis_instances(lookahead_conf assert data[0][2].__contains__('too few trades') assert len(data[0]) == 3 - # now check for an error which occured after enough trades + # now check for an error which occurred after enough trades analysis.total_signals = 12 analysis.false_entry_signals = 11 analysis.false_exit_signals = 10 diff --git a/tests/optimize/test_optimize_reports.py b/tests/optimize/test_optimize_reports.py index db360e10d..f38fcb885 100644 --- a/tests/optimize/test_optimize_reports.py +++ b/tests/optimize/test_optimize_reports.py @@ -129,7 +129,7 @@ def test_generate_backtest_stats(default_conf, testdatadir, tmp_path): assert strat_stats['backtest_start'] == min_date.strftime(DATETIME_PRINT_FORMAT) assert strat_stats['backtest_end'] == max_date.strftime(DATETIME_PRINT_FORMAT) assert strat_stats['total_trades'] == len(results['DefStrat']['results']) - # Above sample had no loosing trade + # Above sample had no losing trade assert strat_stats['max_drawdown_account'] == 0.0 # Retry with losing trade @@ -229,6 +229,28 @@ def test_store_backtest_stats(testdatadir, mocker): assert str(dump_mock.call_args_list[0][0][0]).startswith(str(testdatadir / 'testresult')) +def test_store_backtest_stats_real(tmp_path): + data = {'metadata': {}, 'strategy': {}, 'strategy_comparison': []} + store_backtest_stats(tmp_path, data, '2022_01_01_15_05_13') + + assert (tmp_path / 'backtest-result-2022_01_01_15_05_13.json').is_file() + assert (tmp_path / 'backtest-result-2022_01_01_15_05_13.meta.json').is_file() + assert not (tmp_path / 'backtest-result-2022_01_01_15_05_13_market_change.feather').is_file() + assert (tmp_path / LAST_BT_RESULT_FN).is_file() + fn = get_latest_backtest_filename(tmp_path) + assert fn == 'backtest-result-2022_01_01_15_05_13.json' + + store_backtest_stats(tmp_path, data, '2024_01_01_15_05_25', market_change_data=pd.DataFrame()) + assert (tmp_path / 'backtest-result-2024_01_01_15_05_25.json').is_file() + assert (tmp_path / 'backtest-result-2024_01_01_15_05_25.meta.json').is_file() + assert (tmp_path / 'backtest-result-2024_01_01_15_05_25_market_change.feather').is_file() + assert (tmp_path / LAST_BT_RESULT_FN).is_file() + + # Last file reference should be updated + fn = get_latest_backtest_filename(tmp_path) + assert fn == 'backtest-result-2024_01_01_15_05_25.json' + + def test_store_backtest_candles(testdatadir, mocker): dump_mock = mocker.patch( diff --git a/tests/optimize/test_recursive_analysis.py b/tests/optimize/test_recursive_analysis.py index 33fae0d08..95a96c9f5 100644 --- a/tests/optimize/test_recursive_analysis.py +++ b/tests/optimize/test_recursive_analysis.py @@ -14,7 +14,8 @@ from tests.conftest import get_args, log_has_re, patch_exchange @pytest.fixture -def recursive_conf(default_conf_usdt): +def recursive_conf(default_conf_usdt, tmp_path): + default_conf_usdt['user_data_dir'] = tmp_path default_conf_usdt['timerange'] = '20220101-20220501' default_conf_usdt['strategy_path'] = str( diff --git a/tests/persistence/test_migrations.py b/tests/persistence/test_migrations.py index a6a107a5e..d354e8f22 100644 --- a/tests/persistence/test_migrations.py +++ b/tests/persistence/test_migrations.py @@ -436,8 +436,8 @@ def test_migrate_pairlocks(mocker, default_conf, fee, caplog): assert len(PairLock.session.scalars(select(PairLock).filter(PairLock.pair == '*')).all()) == 1 pairlocks = PairLock.session.scalars(select(PairLock).filter(PairLock.pair == 'ETH/BTC')).all() assert len(pairlocks) == 1 - pairlocks[0].pair == 'ETH/BTC' - pairlocks[0].side == '*' + assert pairlocks[0].pair == 'ETH/BTC' + assert pairlocks[0].side == '*' @pytest.mark.parametrize('dialect', [ diff --git a/tests/persistence/test_persistence.py b/tests/persistence/test_persistence.py index 18f28da2b..a9c27a9b5 100644 --- a/tests/persistence/test_persistence.py +++ b/tests/persistence/test_persistence.py @@ -1871,7 +1871,7 @@ def test_get_trades__query(fee, is_short): # without orders there should be no join issued. query1 = Trade.get_trades_query([], include_orders=False) - # Empty "with-options -> default - selectin" + # Empty "with-options -> default - selection" assert query._with_options == () assert query1._with_options != () diff --git a/tests/plugins/test_pairlist.py b/tests/plugins/test_pairlist.py index 39f48f454..1a23846b7 100644 --- a/tests/plugins/test_pairlist.py +++ b/tests/plugins/test_pairlist.py @@ -433,7 +433,7 @@ def test_VolumePairList_refresh_empty(mocker, markets_empty, whitelist_conf): # ShuffleFilter, no seed ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume"}, {"method": "ShuffleFilter"}], - "USDT", 3), # whitelist_result is integer -- check only length of randomized pairlist + "USDT", 4), # whitelist_result is integer -- check only length of randomized pairlist # AgeFilter only ([{"method": "AgeFilter", "min_days_listed": 2}], "BTC", 'filter_at_the_beginning'), # OperationalException expected @@ -565,7 +565,7 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t if isinstance(whitelist_result, list): assert whitelist == whitelist_result else: - len(whitelist) == whitelist_result + assert len(whitelist) == whitelist_result for pairlist in pairlists: if pairlist['method'] == 'AgeFilter' and pairlist['min_days_listed'] and \ @@ -605,7 +605,7 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume", "lookback_days": 1}], "BTC", "binance", "default_refresh_too_short"), # OperationalException expected - # ambigous configuration with lookback days and period + # ambiguous configuration with lookback days and period ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume", "lookback_days": 1, "lookback_period": 1}], "BTC", "binance", "lookback_days_and_period"), # OperationalException expected @@ -617,7 +617,7 @@ def test_VolumePairList_whitelist_gen(mocker, whitelist_conf, shitcoinmarkets, t ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume", "lookback_timeframe": "1m", "lookback_period": 2000, "refresh_period": 3600}], "BTC", "binance", "lookback_exceeds_exchange_request_size"), # OperationalException expected - # expecing pairs as given + # expecting pairs as given ([{"method": "VolumePairList", "number_assets": 5, "sort_key": "quoteVolume", "lookback_timeframe": "1d", "lookback_period": 1, "refresh_period": 86400}], "BTC", "binance", ['LTC/BTC', 'ETH/BTC', 'TKN/BTC', 'XRP/BTC', 'HOT/BTC']), diff --git a/tests/rpc/test_fiat_convert.py b/tests/rpc/test_fiat_convert.py index 0dfa20185..717866cfd 100644 --- a/tests/rpc/test_fiat_convert.py +++ b/tests/rpc/test_fiat_convert.py @@ -90,7 +90,7 @@ def test_loadcryptomap(mocker): fiat_convert = CryptoToFiatConverter() assert len(fiat_convert._coinlistings) == 2 - assert fiat_convert._get_gekko_id("btc") == "bitcoin" + assert fiat_convert._get_gecko_id("btc") == "bitcoin" def test_fiat_init_network_exception(mocker): @@ -109,16 +109,16 @@ def test_fiat_init_network_exception(mocker): def test_fiat_convert_without_network(mocker): - # Because CryptoToFiatConverter is a Singleton we reset the value of _coingekko + # Because CryptoToFiatConverter is a Singleton we reset the value of _coingecko fiat_convert = CryptoToFiatConverter() - cmc_temp = CryptoToFiatConverter._coingekko - CryptoToFiatConverter._coingekko = None + cmc_temp = CryptoToFiatConverter._coingecko + CryptoToFiatConverter._coingecko = None - assert fiat_convert._coingekko is None + assert fiat_convert._coingecko is None assert fiat_convert._find_price(crypto_symbol='btc', fiat_symbol='usd') == 0.0 - CryptoToFiatConverter._coingekko = cmc_temp + CryptoToFiatConverter._coingecko = cmc_temp def test_fiat_too_many_requests_response(mocker, caplog): @@ -152,9 +152,9 @@ def test_fiat_multiple_coins(mocker, caplog): {'id': 'ethereum-wormhole', 'symbol': 'eth', 'name': 'Ethereum Wormhole'}, ] - assert fiat_convert._get_gekko_id('btc') == 'bitcoin' - assert fiat_convert._get_gekko_id('hnt') is None - assert fiat_convert._get_gekko_id('eth') == 'ethereum' + assert fiat_convert._get_gecko_id('btc') == 'bitcoin' + assert fiat_convert._get_gecko_id('hnt') is None + assert fiat_convert._get_gecko_id('eth') == 'ethereum' assert log_has('Found multiple mappings in CoinGecko for hnt.', caplog) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 050c51fed..5c8602c2f 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -221,7 +221,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') assert "Since" in headers assert "Pair" in headers - assert 'instantly' == result[0][2] + assert 'now' == result[0][2] assert 'ETH/BTC' in result[0][1] assert '0.00 (0.00)' == result[0][3] assert '0.00' == f'{fiat_profit_sum:.2f}' @@ -232,7 +232,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') assert "Since" in headers assert "Pair" in headers - assert 'instantly' == result[0][2] + assert 'now' == result[0][2] assert 'ETH/BTC' in result[0][1] assert '-0.41% (-0.00)' == result[0][3] assert '-0.00' == f'{fiat_profit_sum:.2f}' @@ -243,7 +243,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: assert "Since" in headers assert "Pair" in headers assert len(result[0]) == 4 - assert 'instantly' == result[0][2] + assert 'now' == result[0][2] assert 'ETH/BTC' in result[0][1] assert '-0.41% (-0.06)' == result[0][3] assert '-0.06' == f'{fiat_profit_sum:.2f}' @@ -260,7 +260,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None: mocker.patch(f'{EXMS}.get_rate', MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available"))) result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD') - assert 'instantly' == result[0][2] + assert 'now' == result[0][2] assert 'ETH/BTC' in result[0][1] assert 'nan%' == result[0][3] assert isnan(fiat_profit_sum) diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 9fdff1c7c..5b189371a 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -72,8 +72,10 @@ def botclient(default_conf, mocker): ApiServer.shutdown() -def client_post(client: TestClient, url, data={}): +def client_post(client: TestClient, url, data=None): + if data is None: + data = {} return client.post(url, json=data, headers={'Authorization': _basic_auth_str(_TEST_USER, _TEST_PASS), @@ -82,8 +84,10 @@ def client_post(client: TestClient, url, data={}): }) -def client_patch(client: TestClient, url, data={}): +def client_patch(client: TestClient, url, data=None): + if data is None: + data = {} return client.patch(url, json=data, headers={'Authorization': _basic_auth_str(_TEST_USER, _TEST_PASS), @@ -1573,8 +1577,10 @@ def test_api_pair_candles(botclient, ohlcv_history): ]) -def test_api_pair_history(botclient, mocker): +def test_api_pair_history(botclient, tmp_path, mocker): _ftbot, client = botclient + _ftbot.config['user_data_dir'] = tmp_path + timeframe = '5m' lfm = mocker.patch('freqtrade.strategy.interface.IStrategy.load_freqAI_model') # No pair @@ -1619,7 +1625,7 @@ def test_api_pair_history(botclient, mocker): assert 'data' in result data = result['data'] assert len(data) == 289 - # analyed DF has 30 columns + # analyzed DF has 30 columns assert len(result['columns']) == 30 assert len(data[0]) == 30 date_col_idx = [idx for idx, c in enumerate(result['columns']) if c == 'date'][0] @@ -1644,8 +1650,9 @@ def test_api_pair_history(botclient, mocker): assert rc.json()['detail'] == ("No data for UNITTEST/BTC, 5m in 20200111-20200112 found.") -def test_api_plot_config(botclient, mocker): +def test_api_plot_config(botclient, mocker, tmp_path): ftbot, client = botclient + ftbot.config['user_data_dir'] = tmp_path rc = client_get(client, f"{BASE_URI}/plot_config") assert_response(rc) @@ -1713,8 +1720,9 @@ def test_api_strategies(botclient, tmp_path): ]} -def test_api_strategy(botclient): +def test_api_strategy(botclient, tmp_path): _ftbot, client = botclient + _ftbot.config['user_data_dir'] = tmp_path rc = client_get(client, f"{BASE_URI}/strategy/{CURRENT_TEST_STRATEGY}") @@ -2249,6 +2257,42 @@ def test_api_patch_backtest_history_entry(botclient, tmp_path: Path): assert fileres[CURRENT_TEST_STRATEGY]['notes'] == 'FooBar' +def test_api_patch_backtest_market_change(botclient, tmp_path: Path): + ftbot, client = botclient + + # Create a temporary directory and file + bt_results_base = tmp_path / "backtest_results" + bt_results_base.mkdir() + file_path = bt_results_base / "test_22_market_change.feather" + df = pd.DataFrame({ + 'date': ['2018-01-01T00:00:00Z', '2018-01-01T00:05:00Z'], + 'count': [2, 4], + 'mean': [2555, 2556], + 'rel_mean': [0, 0.022], + }) + df['date'] = pd.to_datetime(df['date']) + df.to_feather(file_path, compression_level=9, compression='lz4') + # Nonexisting file + rc = client_get(client, f"{BASE_URI}/backtest/history/randomFile.json/market_change") + assert_response(rc, 503) + + ftbot.config['user_data_dir'] = tmp_path + ftbot.config['runmode'] = RunMode.WEBSERVER + + rc = client_get(client, f"{BASE_URI}/backtest/history/randomFile.json/market_change") + assert_response(rc, 404) + + rc = client_get(client, f"{BASE_URI}/backtest/history/test_22/market_change") + assert_response(rc, 200) + result = rc.json() + assert result['length'] == 2 + assert result['columns'] == ['date', 'count', 'mean', 'rel_mean', '__date_ts'] + assert result['data'] == [ + ['2018-01-01T00:00:00Z', 2, 2555, 0.0, 1514764800000], + ['2018-01-01T00:05:00Z', 4, 2556, 0.022, 1514765100000] + ] + + def test_health(botclient): _ftbot, client = botclient diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 3bd372b19..9a3b713e2 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1821,8 +1821,8 @@ async def test_edge_enabled(edge_conf, update, mocker) -> None: @pytest.mark.parametrize('is_short,regex_pattern', - [(True, r"just now[ ]*XRP\/BTC \(#3\) -1.00% \("), - (False, r"just now[ ]*XRP\/BTC \(#3\) 1.00% \(")]) + [(True, r"now[ ]*XRP\/BTC \(#3\) -1.00% \("), + (False, r"now[ ]*XRP\/BTC \(#3\) 1.00% \(")]) async def test_telegram_trades(mocker, update, default_conf, fee, is_short, regex_pattern): telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) @@ -1846,7 +1846,7 @@ async def test_telegram_trades(mocker, update, default_conf, fee, is_short, rege context = MagicMock() context.args = [5] await telegram._trades(update=update, context=context) - msg_mock.call_count == 1 + assert msg_mock.call_count == 1 assert "2 recent trades:" in msg_mock.call_args_list[0][0][0] assert "Profit (" in msg_mock.call_args_list[0][0][0] assert "Close Date" in msg_mock.call_args_list[0][0][0] @@ -1870,7 +1870,7 @@ async def test_telegram_delete_trade(mocker, update, default_conf, fee, is_short context = MagicMock() context.args = [1] await telegram._delete_trade(update=update, context=context) - msg_mock.call_count == 1 + assert msg_mock.call_count == 1 assert "Deleted trade 1." in msg_mock.call_args_list[0][0][0] assert "Please make sure to take care of this asset" in msg_mock.call_args_list[0][0][0] @@ -2032,20 +2032,20 @@ def test_send_msg_enter_notification(default_conf, mocker, caplog, message_type, '*Total:* `0.01465333 BTC / 180.895 USD`' ) - freqtradebot.config['telegram']['notification_settings'] = {'buy': 'off'} + freqtradebot.config['telegram']['notification_settings'] = {'entry': 'off'} caplog.clear() msg_mock.reset_mock() telegram.send_msg(msg) - msg_mock.call_count == 0 - log_has("Notification 'buy' not sent.", caplog) + assert msg_mock.call_count == 0 + assert log_has("Notification 'entry' not sent.", caplog) - freqtradebot.config['telegram']['notification_settings'] = {'buy': 'silent'} + freqtradebot.config['telegram']['notification_settings'] = {'entry': 'silent'} caplog.clear() msg_mock.reset_mock() telegram.send_msg(msg) - msg_mock.call_count == 1 - msg_mock.call_args_list[0][1]['disable_notification'] is True + assert msg_mock.call_count == 1 + assert msg_mock.call_args_list[0][1]['disable_notification'] is True @pytest.mark.parametrize('message_type,enter_signal', [ @@ -2423,7 +2423,7 @@ def test_send_msg_unknown_type(default_conf, mocker) -> None: telegram.send_msg({ 'type': None, }) - msg_mock.call_count == 0 + assert msg_mock.call_count == 0 @pytest.mark.parametrize('message_type,enter,enter_signal,leverage', [ diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index dbff49b57..a53eead95 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -81,7 +81,7 @@ def test_returns_latest_signal(ohlcv_history): assert _STRATEGY.get_entry_signal('ETH/BTC', '5m', mocked_history) == (None, None) _STRATEGY.config['trading_mode'] = 'futures' - # Short signal get's ignored as can_short is not set. + # Short signal gets ignored as can_short is not set. assert _STRATEGY.get_entry_signal('ETH/BTC', '5m', mocked_history) == (None, None) _STRATEGY.can_short = True diff --git a/tests/strategy/test_strategy_helpers.py b/tests/strategy/test_strategy_helpers.py index 22c7359bf..b7fb7dea1 100644 --- a/tests/strategy/test_strategy_helpers.py +++ b/tests/strategy/test_strategy_helpers.py @@ -253,7 +253,7 @@ def test_stoploss_from_open(side, profitrange): assert stoploss >= 0 # Technically the formula can yield values greater than 1 for shorts - # eventhough it doesn't make sense because the position would be liquidated + # even though it doesn't make sense because the position would be liquidated if side == 'long': assert stoploss <= 1 diff --git a/tests/strategy/test_strategy_loading.py b/tests/strategy/test_strategy_loading.py index a31408b5c..33245cc5f 100644 --- a/tests/strategy/test_strategy_loading.py +++ b/tests/strategy/test_strategy_loading.py @@ -78,7 +78,9 @@ def test_load_strategy_base64(dataframe_1m, caplog, default_conf): r".*(/|\\).*(/|\\)SampleStrategy\.py'\.\.\.", caplog) -def test_load_strategy_invalid_directory(caplog, default_conf): +def test_load_strategy_invalid_directory(caplog, default_conf, tmp_path): + default_conf['user_data_dir'] = tmp_path + extra_dir = Path.cwd() / 'some/path' with pytest.raises(OperationalException, match=r"Impossible to load Strategy.*"): StrategyResolver._load_strategy('StrategyTestV333', config=default_conf, @@ -87,7 +89,8 @@ def test_load_strategy_invalid_directory(caplog, default_conf): assert log_has_re(r'Path .*' + r'some.*path.*' + r'.* does not exist', caplog) -def test_load_not_found_strategy(default_conf): +def test_load_not_found_strategy(default_conf, tmp_path): + default_conf['user_data_dir'] = tmp_path default_conf['strategy'] = 'NotFoundStrategy' with pytest.raises(OperationalException, match=r"Impossible to load Strategy 'NotFoundStrategy'. " diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 7f80a8588..185bfeaf1 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -125,7 +125,7 @@ def test_add_areas(default_conf, testdatadir, caplog): assert fig == fig2 assert log_has_re(r'Indicator "no_indicator" ignored\..*', caplog) - # everythin given in plot config, row 3 + # everything given in plot config, row 3 fig3 = add_areas(fig, 3, data, indicators) figure = fig3.layout.figure fill_macd = find_trace_in_fig_data(figure.data, "MACD Fill") @@ -495,7 +495,7 @@ def test_plot_profit(default_conf, mocker, testdatadir): # no main_plot, adds empty main_plot ([], [], {'subplots': {'RSI': {'rsi': {'color': 'red'}}}}, {'main_plot': {}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}}), - # indicator 1 / 2 should have prevelance + # indicator 1 / 2 should have prevalence (['sma', 'ema3'], ['macd'], {'main_plot': {'sma': {}}, 'subplots': {'RSI': {'rsi': {'color': 'red'}}}}, {'main_plot': {'sma': {}, 'ema3': {}}, 'subplots': {'Other': {'macd': {}}}} diff --git a/tests/test_wallets.py b/tests/test_wallets.py index 1c1a3b548..0d0ada1b7 100644 --- a/tests/test_wallets.py +++ b/tests/test_wallets.py @@ -381,10 +381,10 @@ def test_sync_wallet_futures_dry(mocker, default_conf, fee): assert len(freqtrade.wallets._wallets) == 1 assert len(freqtrade.wallets._positions) == 4 positions = freqtrade.wallets.get_all_positions() - positions['ETH/BTC'].side == 'short' - positions['ETC/BTC'].side == 'long' - positions['XRP/BTC'].side == 'long' - positions['LTC/BTC'].side == 'short' + assert positions['ETH/BTC'].side == 'short' + assert positions['ETC/BTC'].side == 'long' + assert positions['XRP/BTC'].side == 'long' + assert positions['LTC/BTC'].side == 'short' assert freqtrade.wallets.get_starting_balance() == default_conf['dry_run_wallet'] total = freqtrade.wallets.get_total('BTC') diff --git a/tests/utils/test_datetime_helpers.py b/tests/utils/test_datetime_helpers.py index 6fbe75200..20e6fc0f5 100644 --- a/tests/utils/test_datetime_helpers.py +++ b/tests/utils/test_datetime_helpers.py @@ -3,8 +3,9 @@ from datetime import datetime, timedelta, timezone import pytest import time_machine -from freqtrade.util import (dt_floor_day, dt_from_ts, dt_humanize, dt_now, dt_ts, dt_ts_def, - dt_ts_none, dt_utc, format_date, format_ms_time, shorten_date) +from freqtrade.util import (dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_ts_def, dt_ts_none, dt_utc, + format_date, format_ms_time, shorten_date) +from freqtrade.util.datetime_helpers import dt_humanize_delta def test_dt_now(): @@ -68,9 +69,12 @@ def test_shorten_date() -> None: def test_dt_humanize() -> None: - assert dt_humanize(dt_now()) == 'just now' - assert dt_humanize(dt_now(), only_distance=True) == 'instantly' - assert dt_humanize(dt_now() - timedelta(hours=16), only_distance=True) == '16 hours' + assert dt_humanize_delta(dt_now()) == 'now' + assert dt_humanize_delta(dt_now() - timedelta(minutes=50)) == '50 minutes ago' + assert dt_humanize_delta(dt_now() - timedelta(hours=16)) == '16 hours ago' + assert dt_humanize_delta(dt_now() - timedelta(hours=16, minutes=30)) == '16 hours ago' + assert dt_humanize_delta(dt_now() - timedelta(days=16, hours=10, minutes=25)) == '16 days ago' + assert dt_humanize_delta(dt_now() - timedelta(minutes=50)) == '50 minutes ago' def test_format_ms_time() -> None: @@ -79,11 +83,12 @@ def test_format_ms_time() -> None: date = format_ms_time(date_in_epoch_ms) assert isinstance(date, str) res = datetime(2018, 4, 10, 18, 2, 1, tzinfo=timezone.utc) - assert date == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S') + assert date == res.strftime('%Y-%m-%dT%H:%M:%S') + assert date == '2018-04-10T18:02:01' res = datetime(2017, 12, 13, 8, 2, 1, tzinfo=timezone.utc) # Date 2017-12-13 08:02:01 date_in_epoch_ms = 1513152121000 - assert format_ms_time(date_in_epoch_ms) == res.astimezone(None).strftime('%Y-%m-%dT%H:%M:%S') + assert format_ms_time(date_in_epoch_ms) == res.strftime('%Y-%m-%dT%H:%M:%S') def test_format_date() -> None: diff --git a/tests/utils/test_measure_time.py b/tests/utils/test_measure_time.py new file mode 100644 index 000000000..dac509907 --- /dev/null +++ b/tests/utils/test_measure_time.py @@ -0,0 +1,34 @@ +from unittest.mock import MagicMock + +import time_machine + +from freqtrade.util import MeasureTime + + +def test_measure_time(): + + callback = MagicMock() + with time_machine.travel("2021-09-01 05:00:00 +00:00", tick=False) as t: + + measure = MeasureTime(callback, 5, ttl=60) + with measure: + pass + + assert callback.call_count == 0 + + with measure: + t.shift(10) + + assert callback.call_count == 1 + callback.reset_mock() + with measure: + t.shift(10) + assert callback.call_count == 0 + + callback.reset_mock() + # Shift past the ttl + t.shift(45) + + with measure: + t.shift(10) + assert callback.call_count == 1 diff --git a/tests/utils/test_rendering_utils.py b/tests/utils/test_rendering_utils.py index 7d52b4f26..e03307ff1 100644 --- a/tests/utils/test_rendering_utils.py +++ b/tests/utils/test_rendering_utils.py @@ -7,7 +7,9 @@ def test_render_template_fallback(): from jinja2.exceptions import TemplateNotFound with pytest.raises(TemplateNotFound): val = render_template( - templatefile='subtemplates/indicators_does-not-exist.j2',) + templatefile='subtemplates/indicators_does-not-exist.j2', + arguments={}, + ) val = render_template_with_fallback( templatefile='strategy_subtemplates/indicators_does-not-exist.j2',