freqtradebot.leverage_prep minor fixes

This commit is contained in:
Sam Germain 2022-01-15 10:23:20 -06:00
parent 1f1ac8ce9d
commit e4b37c6462
2 changed files with 18 additions and 18 deletions

View File

@ -633,8 +633,8 @@ class FreqtradeBot(LoggingMixin):
collateral=Collateral.ISOLATED, collateral=Collateral.ISOLATED,
mm_ex_1=0.0, mm_ex_1=0.0,
upnl_ex_1=0.0, upnl_ex_1=0.0,
position=amount * open_rate, position=amount,
wallet_balance=amount/leverage, # TODO: Update for cross wallet_balance=(amount * open_rate)/leverage, # TODO: Update for cross
maintenance_amt=maintenance_amt, maintenance_amt=maintenance_amt,
mm_ratio=mm_ratio, mm_ratio=mm_ratio,
taker_fee_rate=taker_fee_rate taker_fee_rate=taker_fee_rate

View File

@ -712,10 +712,10 @@ def test_process_informative_pairs_added(default_conf_usdt, ticker_usdt, mocker)
(True, 'spot', 'binance', None, None), (True, 'spot', 'binance', None, None),
(False, 'spot', 'gateio', None, None), (False, 'spot', 'gateio', None, None),
(True, 'spot', 'gateio', None, None), (True, 'spot', 'gateio', None, None),
(True, 'futures', 'binance', 'isolated', 13.217821782178218), (True, 'futures', 'binance', 'isolated', 11.89108910891089),
(False, 'futures', 'binance', 'isolated', 6.717171717171718), (False, 'futures', 'binance', 'isolated', 8.070707070707071),
(True, 'futures', 'gateio', 'isolated', 13.198706526760379), (True, 'futures', 'gateio', 'isolated', 11.87413417771621),
(False, 'futures', 'gateio', 'isolated', 6.735367414292449), (False, 'futures', 'gateio', 'isolated', 8.085708510208207),
# TODO-lev: Okex # TODO-lev: Okex
# (False, 'spot', 'okex', 'isolated', ...), # (False, 'spot', 'okex', 'isolated', ...),
# (True, 'futures', 'okex', 'isolated', ...), # (True, 'futures', 'okex', 'isolated', ...),
@ -725,21 +725,23 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
exchange_name, margin_mode, liq_price) -> None: exchange_name, margin_mode, liq_price) -> None:
""" """
exchange_name = binance, is_short = true exchange_name = binance, is_short = true
(wb + cum_b - side_1 * position * ep1) / (position * mmr_b - side_1 * position) leverage = 5
((2 + 0.01) - ((-1) * 0.6 * 10)) / ((0.6 * 0.01) - ((-1) * 0.6)) = 13.217821782178218 position = 0.2 * 5
((wb + cum_b) - (side_1 * position * ep1)) / ((position * mmr_b) - (side_1 * position))
((2 + 0.01) - ((-1) * 1 * 10)) / ((1 * 0.01) - ((-1) * 1)) = 11.89108910891089
exchange_name = binance, is_short = false exchange_name = binance, is_short = false
(wb + cum_b - side_1 * position * ep1) / (position * mmr_b - side_1 * position) ((wb + cum_b) - (side_1 * position * ep1)) / ((position * mmr_b) - (side_1 * position))
(2 + 0.01 - 1 * 0.6 * 10) / (0.6 * 0.01 - 1 * 0.6) = 6.717171717171718 ((2 + 0.01) - (1 * 1 * 10)) / ((1 * 0.01) - (1 * 1)) = 8.070707070707071
exchange_name = gateio, is_short = true exchange_name = gateio, is_short = true
(open_rate + (wallet_balance / position)) / (1 + (mm_ratio + taker_fee_rate)) (open_rate + (wallet_balance / position)) / (1 + (mm_ratio + taker_fee_rate))
(10 + (6 / 0.6)) / (1 + (0.01 + 0.0002)) (10 + (2 / 1)) / (1 + (0.01 + 0.0006)) = 11.87413417771621
13.198706526760379
exchange_name = gateio, is_short = false exchange_name = gateio, is_short = false
(open_rate - (wallet_balance / position)) / (1 - (mm_ratio + taker_fee_rate)) (open_rate - (wallet_balance / position)) / (1 - (mm_ratio + taker_fee_rate))
(10 - (2 / 0.6)) / (1 - (0.01 + 0.0002)) = 6.735367414292449 (10 - (2 / 1)) / (1 - (0.01 + 0.0006)) = 8.085708510208207
""" """
open_order = limit_order_open[enter_side(is_short)] open_order = limit_order_open[enter_side(is_short)]
order = limit_order[enter_side(is_short)] order = limit_order[enter_side(is_short)]
@ -768,6 +770,7 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
get_min_pair_stake_amount=MagicMock(return_value=1), get_min_pair_stake_amount=MagicMock(return_value=1),
get_fee=fee, get_fee=fee,
get_funding_fees=MagicMock(return_value=0), get_funding_fees=MagicMock(return_value=0),
name=exchange_name
) )
pair = 'ETH/USDT' pair = 'ETH/USDT'
@ -911,11 +914,8 @@ def test_execute_entry(mocker, default_conf_usdt, fee, limit_order,
assert trade.open_rate_requested == 10 assert trade.open_rate_requested == 10
# In case of custom entry price not float type # In case of custom entry price not float type
mocker.patch.multiple( freqtrade.exchange.get_maintenance_ratio_and_amt = MagicMock(return_value=(0.01, 0.01))
'freqtrade.exchange.Exchange', freqtrade.exchange.name = exchange_name
name=exchange_name,
get_maintenance_ratio_and_amt=MagicMock(return_value=(0.01, 0.01))
)
order['status'] = 'open' order['status'] = 'open'
order['id'] = '5568' order['id'] = '5568'
freqtrade.strategy.custom_entry_price = lambda **kwargs: "string price" freqtrade.strategy.custom_entry_price = lambda **kwargs: "string price"