From 7f990e7df665feaa9868cb28fd91b6ba0973310e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 25 May 2024 16:51:28 +0200 Subject: [PATCH 1/8] Enable bingx stoploss --- freqtrade/exchange/bingx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/exchange/bingx.py b/freqtrade/exchange/bingx.py index 4efd621e8..fee74085b 100644 --- a/freqtrade/exchange/bingx.py +++ b/freqtrade/exchange/bingx.py @@ -17,6 +17,6 @@ class Bingx(Exchange): _ft_has: Dict = { "ohlcv_candle_limit": 1000, - "stoploss_on_exchange": False, + "stoploss_on_exchange": True, "stoploss_order_types": {"limit": "limit", "market": "market"}, } From 71cb2ded7958e45c579fa832bfbaef37ff901153 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 25 May 2024 18:18:22 +0200 Subject: [PATCH 2/8] Add Bingx stoploss documentation --- docs/exchanges.md | 7 +++++++ docs/stoploss.md | 1 + freqtrade/exchange/bingx.py | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/docs/exchanges.md b/docs/exchanges.md index d4437cfff..f3550e97e 100644 --- a/docs/exchanges.md +++ b/docs/exchanges.md @@ -127,6 +127,13 @@ These settings will be checked on startup, and freqtrade will show an error if t Freqtrade will not attempt to change these settings. +## Bingx + +BingX supports [time_in_force](configuration.md#understand-order_time_in_force) with settings "GTC" (good till cancelled), "IOC" (immediate-or-cancel) and "PO" (Post only) settings. + +!!! Tip "Stoploss on Exchange" + Bingx supports `stoploss_on_exchange` and can use both stop-limit and stop-market orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. + ## Kraken Kraken supports [time_in_force](configuration.md#understand-order_time_in_force) with settings "GTC" (good till cancelled), "IOC" (immediate-or-cancel) and "PO" (Post only) settings. diff --git a/docs/stoploss.md b/docs/stoploss.md index a1095b465..e0353d4da 100644 --- a/docs/stoploss.md +++ b/docs/stoploss.md @@ -30,6 +30,7 @@ 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 | | kraken | market, limit | | Gate | limit | diff --git a/freqtrade/exchange/bingx.py b/freqtrade/exchange/bingx.py index fee74085b..ea0c32a85 100644 --- a/freqtrade/exchange/bingx.py +++ b/freqtrade/exchange/bingx.py @@ -19,4 +19,9 @@ class Bingx(Exchange): "ohlcv_candle_limit": 1000, "stoploss_on_exchange": True, "stoploss_order_types": {"limit": "limit", "market": "market"}, + "order_time_in_force": [ + "GTC", + "IOC", + "PO", + ], } From 64c7f6b06a3b47644c18d472df71d387af2ddf1d Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 May 2024 09:24:19 +0200 Subject: [PATCH 3/8] Improve bingx file formatting --- freqtrade/exchange/bingx.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/freqtrade/exchange/bingx.py b/freqtrade/exchange/bingx.py index ea0c32a85..2d81643a1 100644 --- a/freqtrade/exchange/bingx.py +++ b/freqtrade/exchange/bingx.py @@ -19,9 +19,5 @@ class Bingx(Exchange): "ohlcv_candle_limit": 1000, "stoploss_on_exchange": True, "stoploss_order_types": {"limit": "limit", "market": "market"}, - "order_time_in_force": [ - "GTC", - "IOC", - "PO", - ], + "order_time_in_force": ["GTC", "IOC", "PO"], } From 89e3fc1c64b55224f7cdf1d91343c09f28348bc5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 May 2024 10:36:51 +0200 Subject: [PATCH 4/8] Test bingx order parsing --- tests/exchange_online/conftest.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/exchange_online/conftest.py b/tests/exchange_online/conftest.py index ee1e8a741..dd106be43 100644 --- a/tests/exchange_online/conftest.py +++ b/tests/exchange_online/conftest.py @@ -288,6 +288,36 @@ EXCHANGES = { "hasQuoteVolume": True, "timeframe": "1h", "futures": False, + "sample_order": [ + { + "symbol": "SOL-USDT", + "orderId": "1762393630149869568", + "transactTime": "1674493798550", + "price": "15.5", + "stopPrice": "0", + "origQty": "1.1", + "executedQty": "1.1", + "cummulativeQuoteQty": "17.05", + "status": "FILLED", + "type": "LIMIT", + "side": "BUY", + "clientOrderID": "", + }, + { + "symbol": "SOL-USDT", + "orderId": "1762393630149869568", + "transactTime": "1674493798550", + "price": "15.5", + "stopPrice": "0", + "origQty": "1.1", + "executedQty": "1.1", + "cummulativeQuoteQty": "17.05", + "status": "FILLED", + "type": "MARKET", + "side": "BUY", + "clientOrderID": "", + }, + ], }, } From c6d132376a2b22e90b17b288b177791acf230178 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 May 2024 10:40:04 +0200 Subject: [PATCH 5/8] Add Binance filled order --- tests/exchange_online/conftest.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/exchange_online/conftest.py b/tests/exchange_online/conftest.py index dd106be43..8820ce3e7 100644 --- a/tests/exchange_online/conftest.py +++ b/tests/exchange_online/conftest.py @@ -45,7 +45,25 @@ EXCHANGES = { "workingTime": 1674493798550, "fills": [], "selfTradePreventionMode": "NONE", - } + }, + { + "symbol": "SOLUSDT", + "orderId": 3551312894, + "orderListId": -1, + "clientOrderId": "x-R4DD3S8297c73a11ccb9dc8f2811ba", + "transactTime": 1674493798550, + "price": "15.50000000", + "origQty": "1.10000000", + "executedQty": "1.10000000", + "cummulativeQuoteQty": "17.05", + "status": "FILLED", + "timeInForce": "GTC", + "type": "LIMIT", + "side": "BUY", + "workingTime": 1674493798550, + "fills": [], + "selfTradePreventionMode": "NONE", + }, ], }, "binanceus": { From 34d7d530a13f73c6cd2d1d82a753b5362352c903 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 May 2024 10:40:27 +0200 Subject: [PATCH 6/8] chore(tests): Filled orders should have an average. --- tests/exchange_online/test_ccxt_compat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/exchange_online/test_ccxt_compat.py b/tests/exchange_online/test_ccxt_compat.py index 6eb9f0023..49fbfc60d 100644 --- a/tests/exchange_online/test_ccxt_compat.py +++ b/tests/exchange_online/test_ccxt_compat.py @@ -76,7 +76,8 @@ class TestCCXTExchange: assert isinstance(po["timestamp"], int) assert isinstance(po["price"], float) assert po["price"] == 15.5 - if po["average"] is not None: + if po["status"] == "closed": + # Filled orders should have average assigned. assert isinstance(po["average"], float) assert po["average"] == 15.5 assert po["symbol"] == pair From 30ad4ca9a94ab7b647d18f8d3d8f2454e638c9c9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 May 2024 14:59:39 +0200 Subject: [PATCH 7/8] Add bingx to list of supported exchanges --- README.md | 1 + docs/index.md | 1 + freqtrade/commands/build_config_commands.py | 3 ++- freqtrade/exchange/common.py | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c6e54b112..d7ab7c05c 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Please read the [exchange specific notes](docs/exchanges.md) to learn about even - [X] [Binance](https://www.binance.com/) - [X] [Bitmart](https://bitmart.com/) +- [X] [BingX](https://bingx.com/invite/0EM9RX) - [X] [Gate.io](https://www.gate.io/ref/6266643) - [X] [HTX](https://www.htx.com/) (Former Huobi) - [X] [Kraken](https://kraken.com/) diff --git a/docs/index.md b/docs/index.md index 26debe993..55835f555 100644 --- a/docs/index.md +++ b/docs/index.md @@ -41,6 +41,7 @@ Please read the [exchange specific notes](exchanges.md) to learn about eventual, - [X] [Binance](https://www.binance.com/) - [X] [Bitmart](https://bitmart.com/) +- [X] [BingX](https://bingx.com/invite/0EM9RX) - [X] [Gate.io](https://www.gate.io/ref/6266643) - [X] [HTX](https://www.htx.com/) (Former Huobi) - [X] [Kraken](https://kraken.com/) diff --git a/freqtrade/commands/build_config_commands.py b/freqtrade/commands/build_config_commands.py index 76f3bb2af..1e771a372 100644 --- a/freqtrade/commands/build_config_commands.py +++ b/freqtrade/commands/build_config_commands.py @@ -113,6 +113,7 @@ def ask_user_config() -> Dict[str, Any]: "choices": [ "binance", "binanceus", + "bingx", "gate", "htx", "kraken", @@ -128,7 +129,7 @@ def ask_user_config() -> Dict[str, Any]: "message": "Do you want to trade Perpetual Swaps (perpetual futures)?", "default": False, "filter": lambda val: "futures" if val else "spot", - "when": lambda x: x["exchange_name"] in ["binance", "gate", "okx"], + "when": lambda x: x["exchange_name"] in ["binance", "gate", "okx", "bybit"], }, { "type": "autocomplete", diff --git a/freqtrade/exchange/common.py b/freqtrade/exchange/common.py index 5035d0dd8..99f891836 100644 --- a/freqtrade/exchange/common.py +++ b/freqtrade/exchange/common.py @@ -53,6 +53,7 @@ MAP_EXCHANGE_CHILDCLASS = { SUPPORTED_EXCHANGES = [ "binance", + "bingx", "bitmart", "gate", "htx", From 83bb65132b7de2fec9d952a6b745895f7eaed514 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 May 2024 18:17:54 +0200 Subject: [PATCH 8/8] Bump ccxt to the required version for bingx --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 12c02b0b4..399b51337 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ numpy==1.26.4 pandas==2.2.2 pandas-ta==0.3.14b -ccxt==4.3.27 +ccxt==4.3.30 cryptography==42.0.7 aiohttp==3.9.5 SQLAlchemy==2.0.30