mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-03 10:33:08 +00:00
add feature custom entry price for live
This commit is contained in:
@@ -431,6 +431,34 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
|
||||
strategy.custom_stoploss = original_stopvalue
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'current_rate, exp_custom_entry', 'expected_result', 'use_custom_entry_price', 'custom_entry' [
|
||||
# Profit, adjusted stoploss(absolute), profit for 2nd call, enable trailing,
|
||||
# enable custom stoploss, expected after 1st call, expected after 2nd call
|
||||
(99, 98, False, True, lambda current_rate, **kwargs: current_rate - (current_rate * 0.01)), # custom_entry_price pice - (price * 0.01)
|
||||
(97.8, 98, True, True, lambda current_rate, **kwargs: current_rate - (current_rate * 0.01)), # price stayed under entry price
|
||||
(97.8, 98, True, True, lambda current_rate, **kwargs: current_rate + (current_rate * 0.01)), # entry price over current price
|
||||
(99.9, 98, True, False, None), # feature not activated
|
||||
])
|
||||
def test_entry_price_reached(default_conf, current_rate, exp_custom_entry, candle_ohlc,
|
||||
expected_result, use_custom_entry_price, custom_entry) -> None:
|
||||
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
|
||||
|
||||
strategy = StrategyResolver.load_strategy(default_conf)
|
||||
|
||||
strategy.use_custom_entry_price = use_custom_entry_price
|
||||
custom_entry_price = custom_entry
|
||||
if use_custom_entry_price:
|
||||
strategy.custom_entry_price = custom_entry(current_rate)
|
||||
|
||||
now = arrow.utcnow().datetime
|
||||
entry_flag = strategy.entry_price_reached(current_rate=current_rate, low= None, high=None)
|
||||
|
||||
|
||||
pass
|
||||
|
||||
def test_custom_sell(default_conf, fee, caplog) -> None:
|
||||
|
||||
default_conf.update({'strategy': 'DefaultStrategy'})
|
||||
|
||||
@@ -904,6 +904,36 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
||||
with pytest.raises(PricingError, match="Could not determine buy price."):
|
||||
freqtrade.execute_buy(pair, stake_amount)
|
||||
|
||||
def test_execute_buy_custom_entry_price(mocker, default_conf, fee, limit_buy_order, limit_buy_order_open) -> None:
|
||||
patch_RPCManager(mocker)
|
||||
patch_exchange(mocker)
|
||||
default_conf.update({'use_custom_entry_price': True})
|
||||
freqtrade = FreqtradeBot(default_conf)
|
||||
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
|
||||
stake_amount = 3
|
||||
bid = 2304
|
||||
buy_rate_mock = MagicMock(return_value=bid)
|
||||
buy_mm = MagicMock(return_value=limit_buy_order_open)
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
get_rate=buy_rate_mock,
|
||||
fetch_ticker=MagicMock(return_value={
|
||||
'bid': 2304,
|
||||
'ask': 0.00001173,
|
||||
'last': 2304
|
||||
}),
|
||||
buy=buy_mm,
|
||||
get_min_pair_stake_amount=MagicMock(return_value=1),
|
||||
get_fee=fee,
|
||||
)
|
||||
pair = 'ETH/USDT'
|
||||
|
||||
# Test calling with custom entry price option activated
|
||||
limit_buy_order_open['id'] = '55'
|
||||
assert freqtrade.execute_buy(pair, stake_amount)
|
||||
# Make sure get_rate called to provide current_rate param to custom_entry_price
|
||||
assert buy_rate_mock.call_count == 1
|
||||
|
||||
|
||||
def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||
|
||||
Reference in New Issue
Block a user