Skip to content

Commit 2effa7a

Browse files
authored
Merge branch 'develop' into fix/remove_deprecation_warning
2 parents f4656a0 + c50b773 commit 2effa7a

File tree

15 files changed

+268
-77
lines changed

15 files changed

+268
-77
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ hesitate to read the source code and understand the mechanism of this bot.
2727
Please read the [exchange specific notes](docs/exchanges.md) to learn about eventual, special configurations needed for each exchange.
2828

2929
- [X] [Binance](https://www.binance.com/)
30-
- [X] [Bitmart](https://bitmart.com/)
3130
- [X] [BingX](https://bingx.com/invite/0EM9RX)
31+
- [X] [Bitget](https://www.bitget.com/)
32+
- [X] [Bitmart](https://bitmart.com/)
3233
- [X] [Bybit](https://bybit.com/)
3334
- [X] [Gate.io](https://www.gate.io/ref/6266643)
3435
- [X] [HTX](https://www.htx.com/)
@@ -41,6 +42,7 @@ Please read the [exchange specific notes](docs/exchanges.md) to learn about even
4142
### Supported Futures Exchanges (experimental)
4243

4344
- [X] [Binance](https://www.binance.com/)
45+
- [X] [Bitget](https://www.bitget.com/)
4446
- [X] [Gate.io](https://www.gate.io/ref/6266643)
4547
- [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX)
4648
- [X] [OKX](https://okx.com/)

docs/exchanges.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,14 @@ Without these permissions, the bot will not start correctly and show errors like
298298

299299
Bybit supports [time_in_force](configuration.md#understand-order_time_in_force) with settings "GTC" (good till cancelled), "FOK" (full-or-cancel), "IOC" (immediate-or-cancel) and "PO" (Post only) settings.
300300

301-
Futures trading on bybit is currently supported for isolated futures mode.
301+
!!! Warning "Unified accounts"
302+
Freqtrade assumes accounts to be dedicated to the bot.
303+
We therefore recommend the usage of one subaccount per bot. This is especially important when using unified accounts.
304+
Other configurations (multiple bots on one account, manual non-bot trades on the bot account) are not supported and may lead to unexpected behavior.
305+
306+
### Bybit Futures
307+
308+
Futures trading on bybit is supported for isolated futures mode.
302309

303310
On startup, freqtrade will set the position mode to "One-way Mode" for the whole (sub)account. This avoids making this call over and over again (slowing down bot operations), but means that manual changes to this setting may result in exceptions and errors.
304311

@@ -312,10 +319,6 @@ API Keys for live futures trading must have the following permissions:
312319

313320
We do strongly recommend to limit all API keys to the IP you're going to use it from.
314321

315-
!!! Warning "Unified accounts"
316-
Freqtrade assumes accounts to be dedicated to the bot.
317-
We therefore recommend the usage of one subaccount per bot. This is especially important when using unified accounts.
318-
Other configurations (multiple bots on one account, manual non-bot trades on the bot account) are not supported and may lead to unexpected behavior.
319322

320323
## Bitmart
321324

@@ -355,6 +358,12 @@ Bitget supports [time_in_force](configuration.md#understand-order_time_in_force)
355358
Bitget supports `stoploss_on_exchange` and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it.
356359
You can use either `"limit"` or `"market"` in the `order_types.stoploss` configuration setting to decide which type of stoploss shall be used.
357360

361+
### Bitget Futures
362+
363+
Futures trading on bitget is supported for isolated futures mode.
364+
365+
On startup, freqtrade will set the position mode to "One-way Mode" for the whole (sub)account. This avoids making this call over and over again (slowing down bot operations), but means that manual changes to this setting may result in exceptions and errors.
366+
358367
## Hyperliquid
359368

360369
!!! Tip "Stoploss on Exchange"
@@ -478,3 +487,5 @@ For example, to test the order type `FOK` with Kraken, and modify candle limit t
478487

479488
!!! Warning
480489
Please make sure to fully understand the impacts of these settings before modifying them.
490+
Using `_ft_has_params` overrides may lead to unexpected behavior, and may even break your bot.
491+
We will not be able to provide support for issues caused by custom settings in `_ft_has_params`.

docs/includes/exchange-features.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
| [Binance](exchanges.md#binance) | futures | isolated, cross | market, limit |
66
| [Bingx](exchanges.md#bingx) | spot | | market, limit |
77
| [Bitmart](exchanges.md#bitmart) | spot | | ❌ (not supported) |
8+
| [Bitget](exchanges.md#bitget) | spot | | market, limit |
9+
| [Bitget](exchanges.md#bitget) | futures | isolated | market, limit |
810
| [Bybit](exchanges.md#bybit) | spot | | ❌ (not supported) |
911
| [Bybit](exchanges.md#bybit) | futures | isolated | market, limit |
1012
| [Gate.io](exchanges.md#gateio) | spot | | limit |

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Please read the [exchange specific notes](exchanges.md) to learn about eventual,
3939

4040
- [X] [Binance](https://www.binance.com/)
4141
- [X] [BingX](https://bingx.com/invite/0EM9RX)
42+
- [X] [Bitget](https://www.bitget.com/)
4243
- [X] [Bitmart](https://bitmart.com/)
4344
- [X] [Bybit](https://bybit.com/)
4445
- [X] [Gate.io](https://www.gate.io/ref/6266643)
@@ -52,6 +53,7 @@ Please read the [exchange specific notes](exchanges.md) to learn about eventual,
5253
### Supported Futures Exchanges (experimental)
5354

5455
- [X] [Binance](https://www.binance.com/)
56+
- [X] [Bitget](https://www.bitget.com/)
5557
- [X] [Bybit](https://bybit.com/)
5658
- [X] [Gate.io](https://www.gate.io/ref/6266643)
5759
- [X] [Hyperliquid](https://hyperliquid.xyz/) (A decentralized exchange, or DEX)

docs/requirements-docs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
markdown==3.9
22
mkdocs==1.6.1
3-
mkdocs-material==9.6.21
3+
mkdocs-material==9.6.22
44
mdx_truly_sane_lists==1.3
55
pymdown-extensions==10.16.1
66
jinja2==3.1.6

freqtrade/exchange/bitget.py

Lines changed: 118 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import ccxt
55

6-
from freqtrade.enums import CandleType
6+
from freqtrade.constants import BuySell
7+
from freqtrade.enums import CandleType, MarginMode, TradingMode
78
from freqtrade.exceptions import (
89
DDosProtection,
910
OperationalException,
@@ -20,27 +21,30 @@
2021

2122

2223
class Bitget(Exchange):
23-
"""
24-
Bitget exchange class. Contains adjustments needed for Freqtrade to work
25-
with this exchange.
26-
27-
Please note that this exchange is not included in the list of exchanges
28-
officially supported by the Freqtrade development team. So some features
29-
may still not work as expected.
24+
"""Bitget exchange class.
25+
Contains adjustments needed for Freqtrade to work with this exchange.
3026
"""
3127

3228
_ft_has: FtHas = {
3329
"stoploss_on_exchange": True,
3430
"stop_price_param": "stopPrice",
3531
"stop_price_prop": "stopPrice",
32+
"stoploss_blocks_assets": False, # Stoploss orders do not block assets
3633
"stoploss_order_types": {"limit": "limit", "market": "market"},
3734
"ohlcv_candle_limit": 200, # 200 for historical candles, 1000 for recent ones.
3835
"order_time_in_force": ["GTC", "FOK", "IOC", "PO"],
3936
}
4037
_ft_has_futures: FtHas = {
4138
"mark_ohlcv_timeframe": "4h",
39+
"funding_fee_candle_limit": 100,
4240
}
4341

42+
_supported_trading_mode_margin_pairs: list[tuple[TradingMode, MarginMode]] = [
43+
(TradingMode.SPOT, MarginMode.NONE),
44+
(TradingMode.FUTURES, MarginMode.ISOLATED),
45+
# (TradingMode.FUTURES, MarginMode.CROSS),
46+
]
47+
4448
def ohlcv_candle_limit(
4549
self, timeframe: str, candle_type: CandleType, since_ms: int | None = None
4650
) -> int:
@@ -126,3 +130,109 @@ def fetch_stoploss_order(
126130

127131
def cancel_stoploss_order(self, order_id: str, pair: str, params: dict | None = None) -> dict:
128132
return self.cancel_order(order_id=order_id, pair=pair, params={"stop": True})
133+
134+
@retrier
135+
def additional_exchange_init(self) -> None:
136+
"""
137+
Additional exchange initialization logic.
138+
.api will be available at this point.
139+
Must be overridden in child methods if required.
140+
"""
141+
try:
142+
if not self._config["dry_run"]:
143+
if self.trading_mode == TradingMode.FUTURES:
144+
position_mode = self._api.set_position_mode(False)
145+
self._log_exchange_response("set_position_mode", position_mode)
146+
except ccxt.DDoSProtection as e:
147+
raise DDosProtection(e) from e
148+
except (ccxt.OperationFailed, ccxt.ExchangeError) as e:
149+
raise TemporaryError(
150+
f"Error in additional_exchange_init due to {e.__class__.__name__}. Message: {e}"
151+
) from e
152+
except ccxt.BaseError as e:
153+
raise OperationalException(e) from e
154+
155+
def _lev_prep(self, pair: str, leverage: float, side: BuySell, accept_fail: bool = False):
156+
if self.trading_mode != TradingMode.SPOT:
157+
# Explicitly setting margin_mode is not necessary as marginMode can be set per order.
158+
# self.set_margin_mode(pair, self.margin_mode, accept_fail)
159+
self._set_leverage(leverage, pair, accept_fail)
160+
161+
def _get_params(
162+
self,
163+
side: BuySell,
164+
ordertype: str,
165+
leverage: float,
166+
reduceOnly: bool,
167+
time_in_force: str = "GTC",
168+
) -> dict:
169+
params = super()._get_params(
170+
side=side,
171+
ordertype=ordertype,
172+
leverage=leverage,
173+
reduceOnly=reduceOnly,
174+
time_in_force=time_in_force,
175+
)
176+
if self.trading_mode == TradingMode.FUTURES and self.margin_mode:
177+
params["marginMode"] = self.margin_mode.value.lower()
178+
return params
179+
180+
def dry_run_liquidation_price(
181+
self,
182+
pair: str,
183+
open_rate: float,
184+
is_short: bool,
185+
amount: float,
186+
stake_amount: float,
187+
leverage: float,
188+
wallet_balance: float,
189+
open_trades: list,
190+
) -> float | None:
191+
"""
192+
Important: Must be fetching data from cached values as this is used by backtesting!
193+
194+
195+
https://www.bitget.com/support/articles/12560603808759
196+
MMR: Maintenance margin rate of the trading pair.
197+
198+
CoinMainIndexPrice: The index price for Coin-M futures. For USDT-M futures,
199+
the index price is: 1.
200+
201+
TakerFeeRatio: The fee rate applied when placing taker orders.
202+
203+
Position direction: The current position direction of the trading pair.
204+
1 indicates a long position, and -1 indicates a short position.
205+
206+
Formula:
207+
208+
Estimated liquidation price = [
209+
position margin - position size x average entry price x position direction
210+
] ÷ [position size x (MMR + TakerFeeRatio - position direction)]
211+
212+
:param pair: Pair to calculate liquidation price for
213+
:param open_rate: Entry price of position
214+
:param is_short: True if the trade is a short, false otherwise
215+
:param amount: Absolute value of position size incl. leverage (in base currency)
216+
:param stake_amount: Stake amount - Collateral in settle currency.
217+
:param leverage: Leverage used for this position.
218+
:param wallet_balance: Amount of margin_mode in the wallet being used to trade
219+
Cross-Margin Mode: crossWalletBalance
220+
Isolated-Margin Mode: isolatedWalletBalance
221+
:param open_trades: List of other open trades in the same wallet
222+
"""
223+
market = self.markets[pair]
224+
taker_fee_rate = market["taker"] or self._api.describe().get("fees", {}).get(
225+
"trading", {}
226+
).get("taker", 0.001)
227+
mm_ratio, _ = self.get_maintenance_ratio_and_amt(pair, stake_amount)
228+
229+
if self.trading_mode == TradingMode.FUTURES and self.margin_mode == MarginMode.ISOLATED:
230+
position_direction = -1 if is_short else 1
231+
232+
return (wallet_balance - (amount * open_rate * position_direction)) / (
233+
amount * (mm_ratio + taker_fee_rate - position_direction)
234+
)
235+
else:
236+
raise OperationalException(
237+
"Freqtrade currently only supports isolated futures for bitget"
238+
)

freqtrade/exchange/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _get_logging_mixin():
5656
"binance",
5757
"bingx",
5858
"bitmart",
59+
"bitget",
5960
"bybit",
6061
"gate",
6162
"htx",

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ hyperopt = [
8585
freqai = [
8686
"scikit-learn",
8787
"joblib",
88-
'catboost; platform_machine != "arm"',
88+
"catboost; platform_machine != 'arm'",
8989
"lightgbm",
9090
"xgboost",
9191
"tensorboard",
9292
"datasieve>=0.1.5",
9393
]
9494
freqai_rl = [
95-
"torch",
95+
"torch; sys_platform != 'darwin' or platform_machine != 'x86_64'",
9696
"gymnasium",
97-
"stable-baselines3",
98-
"sb3-contrib",
97+
"stable-baselines3; sys_platform != 'darwin' or platform_machine != 'x86_64'",
98+
"sb3-contrib; sys_platform != 'darwin' or platform_machine != 'x86_64'",
9999
"tqdm",
100100
]
101101
develop = [

requirements-freqai-rl.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
-r requirements-freqai.txt
33

44
# Required for freqai-rl
5-
torch==2.8.0; sys_platform != 'darwin' or platform_machine != 'x86_64'
6-
gymnasium==0.29.1
5+
torch==2.9.0; sys_platform != 'darwin' or platform_machine != 'x86_64'
6+
gymnasium==1.2.1
77
# SB3 >=2.5.0 depends on torch 2.3.0 - which implies it dropped support x86 macos
88
stable_baselines3==2.7.0; sys_platform != 'darwin' or platform_machine != 'x86_64'
9-
sb3_contrib>=2.2.1
9+
sb3_contrib>=2.2.1; sys_platform != 'darwin' or platform_machine != 'x86_64'
1010
# Progress bar for stable-baselines3 and sb3-contrib
1111
tqdm==4.67.1

requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
numpy==2.3.3
1+
numpy==2.3.4
22
pandas==2.3.3
33
bottleneck==1.6.0
4-
numexpr==2.13.1
4+
numexpr==2.14.1
55
# Indicator libraries
66
ft-pandas-ta==0.3.16
77
ta-lib==0.6.7
88
technical==1.5.3
99

1010
ccxt==4.5.11
11-
cryptography==46.0.2
11+
cryptography==46.0.3
1212
aiohttp==3.13.0
1313
SQLAlchemy==2.0.44
1414
python-telegram-bot==22.5
1515
# can't be hard-pinned due to telegram-bot pinning httpx with ~
1616
httpx>=0.24.1
17-
humanize==4.13.0
17+
humanize==4.14.0
1818
cachetools==6.2.1
1919
requests==2.32.5
2020
urllib3==2.5.0
@@ -39,7 +39,7 @@ sdnotify==0.3.2
3939

4040
# API Server
4141
fastapi==0.119.0
42-
pydantic==2.12.0
42+
pydantic==2.12.2
4343
uvicorn==0.37.0
4444
pyjwt==2.10.1
4545
aiofiles==25.1.0

0 commit comments

Comments
 (0)