From 6ee38adbb5e20f890f88d290a516c77e593be381 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 27 Dec 2024 19:18:10 +0100 Subject: [PATCH 1/8] fix: round open_rate to tradable precisionThis prevents odd display issues with 16 decimals in case of multiple entries. --- freqtrade/persistence/trade_model.py | 6 +++++- tests/persistence/test_persistence.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index 2ad5ade481a..cbe928752e2 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -1249,7 +1249,11 @@ def recalc_trade_from_orders(self, *, is_closing: bool = False): if current_amount_tr > 0.0: # Trade is still open # Leverage not updated, as we don't allow changing leverage through DCA at the moment. - self.open_rate = float(current_stake / current_amount) + self.open_rate = price_to_precision( + float(current_stake / current_amount), + self.price_precision, + self.precision_mode_price, + ) self.amount = current_amount_tr self.stake_amount = float(current_stake) / (self.leverage or 1.0) self.fee_open_cost = self.fee_open * float(self.max_stake_amount) diff --git a/tests/persistence/test_persistence.py b/tests/persistence/test_persistence.py index a5e237a45fa..9109fce4395 100644 --- a/tests/persistence/test_persistence.py +++ b/tests/persistence/test_persistence.py @@ -8,6 +8,7 @@ from freqtrade.constants import CUSTOM_TAG_MAX_LENGTH, DATETIME_PRINT_FORMAT from freqtrade.enums import TradingMode from freqtrade.exceptions import DependencyException +from freqtrade.exchange.exchange_utils import TICK_SIZE from freqtrade.persistence import LocalTrade, Order, Trade, init_db from freqtrade.util import dt_now from tests.conftest import ( @@ -2833,6 +2834,8 @@ def test_recalc_trade_from_orders_dca(data) -> None: is_short=False, leverage=1.0, trading_mode=TradingMode.SPOT, + price_precision=0.001, + precision_mode_price=TICK_SIZE, ) Trade.session.add(trade) From fbb757fa2ff34911394e35a7ef08a4067d5604ec Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:03:37 +0100 Subject: [PATCH 2/8] chore: may myokx to okx - it's just an alias for european users --- freqtrade/exchange/common.py | 1 + 1 file changed, 1 insertion(+) diff --git a/freqtrade/exchange/common.py b/freqtrade/exchange/common.py index 4fd9cea634c..6e3e6767868 100644 --- a/freqtrade/exchange/common.py +++ b/freqtrade/exchange/common.py @@ -47,6 +47,7 @@ def _get_logging_mixin(): "binanceje": "binance", "binanceusdm": "binance", "okex": "okx", + "myokx": "okx", "gateio": "gate", "huboi": "htx", } From a180cb95dcc7393504b870492efdec230030d36b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:05:02 +0100 Subject: [PATCH 3/8] chore: Improve list-exchanges output --- freqtrade/exchange/exchange_utils.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/freqtrade/exchange/exchange_utils.py b/freqtrade/exchange/exchange_utils.py index 1c989424248..d20ff13f957 100644 --- a/freqtrade/exchange/exchange_utils.py +++ b/freqtrade/exchange/exchange_utils.py @@ -23,6 +23,7 @@ BAD_EXCHANGES, EXCHANGE_HAS_OPTIONAL, EXCHANGE_HAS_REQUIRED, + MAP_EXCHANGE_CHILDCLASS, SUPPORTED_EXCHANGES, ) from freqtrade.exchange.exchange_utils_timeframe import timeframe_to_minutes, timeframe_to_prev_date @@ -91,21 +92,24 @@ def validate_exchange(exchange: str) -> tuple[bool, str, ccxt.Exchange | None]: def _build_exchange_list_entry( exchange_name: str, exchangeClasses: dict[str, Any] ) -> ValidExchangesType: + exchange_name = exchange_name.lower() valid, comment, ex_mod = validate_exchange(exchange_name) + mapped_exchange_name = MAP_EXCHANGE_CHILDCLASS.get(exchange_name, exchange_name).lower() + is_alias = getattr(ex_mod, "alias", False) result: ValidExchangesType = { "name": getattr(ex_mod, "name", exchange_name), "classname": exchange_name, "valid": valid, - "supported": exchange_name.lower() in SUPPORTED_EXCHANGES, + "supported": mapped_exchange_name in SUPPORTED_EXCHANGES and not is_alias, "comment": comment, "dex": getattr(ex_mod, "dex", False), - "is_alias": getattr(ex_mod, "alias", False), + "is_alias": is_alias, "alias_for": inspect.getmro(ex_mod.__class__)[1]().id if getattr(ex_mod, "alias", False) else None, "trade_modes": [{"trading_mode": "spot", "margin_mode": ""}], } - if resolved := exchangeClasses.get(exchange_name.lower()): + if resolved := exchangeClasses.get(mapped_exchange_name): supported_modes = [{"trading_mode": "spot", "margin_mode": ""}] + [ {"trading_mode": tm.value, "margin_mode": mm.value} for tm, mm in resolved["class"]._supported_trading_mode_margin_pairs From 9a201566f205c9ae69e9efd2f18e7a08263591fb Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:05:55 +0100 Subject: [PATCH 4/8] chore: fix typo in telegram help message --- freqtrade/rpc/telegram.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index e50771481fe..a2926a278d9 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -1829,7 +1829,7 @@ async def _help(self, update: Update, context: CallbackContext) -> None: "*/fx |all:* `Alias to /forceexit`\n" f"{force_enter_text if self._config.get('force_entry_enable', False) else ''}" "*/delete :* `Instantly delete the given trade in the database`\n" - "*/reload_trade :* `Relade trade from exchange Orders`\n" + "*/reload_trade :* `Reload trade from exchange Orders`\n" "*/cancel_open_order :* `Cancels open orders for trade. " "Only valid when the trade has open orders.`\n" "*/coo |all:* `Alias to /cancel_open_order`\n" From 3f41910eb4628af4bdf400cf45daf01ba5d50a50 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:10:22 +0100 Subject: [PATCH 5/8] docs: add myokx special case documentation --- docs/exchanges.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/exchanges.md b/docs/exchanges.md index 34a2e4d1425..c513c5646d0 100644 --- a/docs/exchanges.md +++ b/docs/exchanges.md @@ -236,6 +236,9 @@ OKX requires a passphrase for each api key, you will therefore need to add this } ``` +If you've registered with OKX on the host my.okx.com (OKX EAA)- you will need to use `"myokx"` as the exchange name. +Using the wrong exchange will result in the error "OKX Error 50119: API key doesn't exist" - as the 2 are separate entities. + !!! Warning OKX only provides 100 candles per api call. Therefore, the strategy will only have a pretty low amount of data available in backtesting mode. From a58fde367c39d36a5eb87ff74f50362afd9ebc2c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:45:35 +0100 Subject: [PATCH 6/8] chore: remove "former OKEX" terminology --- README.md | 3 ++- docs/exchanges.md | 2 +- docs/index.md | 3 ++- freqtrade/exchange/exchange.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5a4330bb9ac..8fbd154b9c3 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,8 @@ Please read the [exchange specific notes](docs/exchanges.md) to learn about even - [X] [HTX](https://www.htx.com/) (Former Huobi) - [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX) - [X] [Kraken](https://kraken.com/) -- [X] [OKX](https://okx.com/) (Former OKEX) +- [X] [OKX](https://okx.com/) +- [X] [MyOKX](https://okx.com/) (OKX EEA) - [ ] [potentially many others](https://github.com/ccxt/ccxt/). _(We cannot guarantee they will work)_ ### Supported Futures Exchanges (experimental) diff --git a/docs/exchanges.md b/docs/exchanges.md index c513c5646d0..82e223847f3 100644 --- a/docs/exchanges.md +++ b/docs/exchanges.md @@ -222,7 +222,7 @@ Kucoin accounts may use `KCS` for fees, and if a trade happens to be on `KCS`, f !!! Tip "Stoploss on Exchange" HTX supports `stoploss_on_exchange` and uses `stop-limit` orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. -## OKX (former OKEX) +## OKX OKX requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows: diff --git a/docs/index.md b/docs/index.md index 45871acb9c7..8a1088d76d0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -47,7 +47,8 @@ Please read the [exchange specific notes](exchanges.md) to learn about eventual, - [X] [HTX](https://www.htx.com/) (Former Huobi) - [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX) - [X] [Kraken](https://kraken.com/) -- [X] [OKX](https://okx.com/) (Former OKEX) +- [X] [OKX](https://okx.com/) +- [X] [MyOKX](https://okx.com/) (OKX EEA) - [ ] [potentially many others through ccxt](https://github.com/ccxt/ccxt/). _(We cannot guarantee they will work)_ ### Supported Futures Exchanges (experimental) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index bba6c5aaf05..57d0baee397 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -3666,7 +3666,7 @@ def dry_run_liquidation_price( Wherein, "+" or "-" depends on whether the contract goes long or short: "-" for long, and "+" for short. - okex: https://www.okx.com/support/hc/en-us/articles/ + okx: https://www.okx.com/support/hc/en-us/articles/ 360053909592-VI-Introduction-to-the-isolated-mode-of-Single-Multi-currency-Portfolio-margin :param pair: Pair to calculate liquidation price for From 5ca31508fb2cc46af0b541f1c83b5cf0cb90e7c9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:46:57 +0100 Subject: [PATCH 7/8] chore: remove "former huobi" terminology --- README.md | 2 +- docs/exchanges.md | 2 +- docs/index.md | 2 +- docs/stoploss.md | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8fbd154b9c3..72994d89ca3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Please read the [exchange specific notes](docs/exchanges.md) to learn about even - [X] [BingX](https://bingx.com/invite/0EM9RX) - [X] [Bybit](https://bybit.com/) - [X] [Gate.io](https://www.gate.io/ref/6266643) -- [X] [HTX](https://www.htx.com/) (Former Huobi) +- [X] [HTX](https://www.htx.com/) - [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX) - [X] [Kraken](https://kraken.com/) - [X] [OKX](https://okx.com/) diff --git a/docs/exchanges.md b/docs/exchanges.md index 82e223847f3..ca041346c72 100644 --- a/docs/exchanges.md +++ b/docs/exchanges.md @@ -217,7 +217,7 @@ Kucoin supports [time_in_force](configuration.md#understand-order_time_in_force) For Kucoin, it is suggested to add `"KCS/"` to your blacklist to avoid issues, unless you are willing to maintain enough extra `KCS` on the account or unless you're willing to disable using `KCS` for fees. Kucoin accounts may use `KCS` for fees, and if a trade happens to be on `KCS`, further trades may consume this position and make the initial `KCS` trade unsellable as the expected amount is not there anymore. -## HTX (formerly Huobi) +## HTX !!! Tip "Stoploss on Exchange" HTX supports `stoploss_on_exchange` and uses `stop-limit` orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. diff --git a/docs/index.md b/docs/index.md index 8a1088d76d0..79c60072da8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -44,7 +44,7 @@ Please read the [exchange specific notes](exchanges.md) to learn about eventual, - [X] [Bitmart](https://bitmart.com/) - [X] [Bybit](https://bybit.com/) - [X] [Gate.io](https://www.gate.io/ref/6266643) -- [X] [HTX](https://www.htx.com/) (Former Huobi) +- [X] [HTX](https://www.htx.com/) - [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX) - [X] [Kraken](https://kraken.com/) - [X] [OKX](https://okx.com/) diff --git a/docs/stoploss.md b/docs/stoploss.md index 7442484dea2..69c69626fe9 100644 --- a/docs/stoploss.md +++ b/docs/stoploss.md @@ -30,8 +30,8 @@ The Order-type will be ignored if only one mode is available. |----------|-------------| | Binance | limit | | Binance Futures | market, limit | -| Bingx | market, limit | -| HTX (former Huobi) | limit | +| Bingx | market, limit | +| HTX | limit | | kraken | market, limit | | Gate | limit | | Okx | limit | From 0032f9a960ea9279eb6fe892036c54ac00cfca8c Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 12:49:55 +0100 Subject: [PATCH 8/8] chore: bump ccxt to 4.4.43 this adds support for myokx, the OKX EAA subsidiary. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7a41985369d..38bc907495a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ bottleneck==1.4.2 numexpr==2.10.2 pandas-ta==0.3.14b -ccxt==4.4.42 +ccxt==4.4.43 cryptography==42.0.8; platform_machine == 'armv7l' cryptography==44.0.0; platform_machine != 'armv7l' aiohttp==3.10.11