mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-15 20:31:43 +00:00
Add log message for Bybit accout type
This commit is contained in:
@@ -25,6 +25,7 @@ class Bybit(Exchange):
|
|||||||
officially supported by the Freqtrade development team. So some features
|
officially supported by the Freqtrade development team. So some features
|
||||||
may still not work as expected.
|
may still not work as expected.
|
||||||
"""
|
"""
|
||||||
|
unified_account = False
|
||||||
|
|
||||||
_ft_has: Dict = {
|
_ft_has: Dict = {
|
||||||
"ohlcv_candle_limit": 1000,
|
"ohlcv_candle_limit": 1000,
|
||||||
@@ -82,9 +83,18 @@ class Bybit(Exchange):
|
|||||||
Must be overridden in child methods if required.
|
Must be overridden in child methods if required.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if self.trading_mode == TradingMode.FUTURES and not self._config['dry_run']:
|
if not self._config['dry_run']:
|
||||||
position_mode = self._api.set_position_mode(False)
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
self._log_exchange_response('set_position_mode', position_mode)
|
position_mode = self._api.set_position_mode(False)
|
||||||
|
self._log_exchange_response('set_position_mode', position_mode)
|
||||||
|
is_unified = self._api.is_unified_enabled()
|
||||||
|
# Returns a tuple of bools, first for margin, second for Account
|
||||||
|
if is_unified and len(is_unified) > 1 and is_unified[1]:
|
||||||
|
self.unified_account = True
|
||||||
|
logger.info("Bybit: Unified account.")
|
||||||
|
else:
|
||||||
|
self.unified_account = False
|
||||||
|
logger.info("Bybit: Standard account.")
|
||||||
except ccxt.DDoSProtection as e:
|
except ccxt.DDoSProtection as e:
|
||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
|
|||||||
@@ -3,18 +3,33 @@ from unittest.mock import MagicMock
|
|||||||
|
|
||||||
from freqtrade.enums.marginmode import MarginMode
|
from freqtrade.enums.marginmode import MarginMode
|
||||||
from freqtrade.enums.tradingmode import TradingMode
|
from freqtrade.enums.tradingmode import TradingMode
|
||||||
from tests.conftest import EXMS, get_mock_coro, get_patched_exchange
|
from tests.conftest import EXMS, get_mock_coro, get_patched_exchange, log_has
|
||||||
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
from tests.exchange.test_exchange import ccxt_exceptionhandlers
|
||||||
|
|
||||||
|
|
||||||
def test_additional_exchange_init_bybit(default_conf, mocker):
|
def test_additional_exchange_init_bybit(default_conf, mocker, caplog):
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
default_conf['trading_mode'] = TradingMode.FUTURES
|
default_conf['trading_mode'] = TradingMode.FUTURES
|
||||||
default_conf['margin_mode'] = MarginMode.ISOLATED
|
default_conf['margin_mode'] = MarginMode.ISOLATED
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.set_position_mode = MagicMock(return_value={"dualSidePosition": False})
|
api_mock.set_position_mode = MagicMock(return_value={"dualSidePosition": False})
|
||||||
get_patched_exchange(mocker, default_conf, id="bybit", api_mock=api_mock)
|
api_mock.is_unified_enabled = MagicMock(return_value=[False, False])
|
||||||
|
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, id="bybit", api_mock=api_mock)
|
||||||
assert api_mock.set_position_mode.call_count == 1
|
assert api_mock.set_position_mode.call_count == 1
|
||||||
|
assert api_mock.is_unified_enabled.call_count == 1
|
||||||
|
assert exchange.unified_account is False
|
||||||
|
|
||||||
|
assert log_has("Bybit: Standard account.", caplog)
|
||||||
|
|
||||||
|
api_mock.set_position_mode.reset_mock()
|
||||||
|
api_mock.is_unified_enabled = MagicMock(return_value=[False, True])
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, id="bybit", api_mock=api_mock)
|
||||||
|
assert api_mock.set_position_mode.call_count == 1
|
||||||
|
assert api_mock.is_unified_enabled.call_count == 1
|
||||||
|
assert exchange.unified_account is True
|
||||||
|
|
||||||
|
assert log_has("Bybit: Unified account.", caplog)
|
||||||
ccxt_exceptionhandlers(mocker, default_conf, api_mock, 'bybit',
|
ccxt_exceptionhandlers(mocker, default_conf, api_mock, 'bybit',
|
||||||
"additional_exchange_init", "set_position_mode")
|
"additional_exchange_init", "set_position_mode")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user