Rename execute_buy to execute_entry
This commit is contained in:
parent
7fb570cc58
commit
63844d39f6
@ -433,11 +433,11 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
if ((bid_check_dom.get('enabled', False)) and
|
if ((bid_check_dom.get('enabled', False)) and
|
||||||
(bid_check_dom.get('bids_to_ask_delta', 0) > 0)):
|
(bid_check_dom.get('bids_to_ask_delta', 0) > 0)):
|
||||||
if self._check_depth_of_market_buy(pair, bid_check_dom):
|
if self._check_depth_of_market_buy(pair, bid_check_dom):
|
||||||
return self.execute_buy(pair, stake_amount, buy_tag=buy_tag)
|
return self.execute_entry(pair, stake_amount, buy_tag=buy_tag)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return self.execute_buy(pair, stake_amount, buy_tag=buy_tag)
|
return self.execute_entry(pair, stake_amount, buy_tag=buy_tag)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -465,8 +465,8 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
logger.info(f"Bids to asks delta for {pair} does not satisfy condition.")
|
logger.info(f"Bids to asks delta for {pair} does not satisfy condition.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def execute_buy(self, pair: str, stake_amount: float, price: Optional[float] = None,
|
def execute_entry(self, pair: str, stake_amount: float, price: Optional[float] = None,
|
||||||
forcebuy: bool = False, buy_tag: Optional[str] = None) -> bool:
|
forcebuy: bool = False, buy_tag: Optional[str] = None) -> bool:
|
||||||
"""
|
"""
|
||||||
Executes a limit buy for the given pair
|
Executes a limit buy for the given pair
|
||||||
:param pair: pair for which we want to create a LIMIT_BUY
|
:param pair: pair for which we want to create a LIMIT_BUY
|
||||||
|
@ -613,7 +613,7 @@ class RPC:
|
|||||||
stakeamount = self._freqtrade.wallets.get_trade_stake_amount(pair)
|
stakeamount = self._freqtrade.wallets.get_trade_stake_amount(pair)
|
||||||
|
|
||||||
# execute buy
|
# execute buy
|
||||||
if self._freqtrade.execute_buy(pair, stakeamount, price, forcebuy=True):
|
if self._freqtrade.execute_entry(pair, stakeamount, price, forcebuy=True):
|
||||||
Trade.commit()
|
Trade.commit()
|
||||||
trade = Trade.get_trades([Trade.is_open.is_(True), Trade.pair == pair]).first()
|
trade = Trade.get_trades([Trade.is_open.is_(True), Trade.pair == pair]).first()
|
||||||
return trade
|
return trade
|
||||||
|
@ -185,7 +185,7 @@ def test_check_available_stake_amount(default_conf, ticker, mocker, fee, limit_b
|
|||||||
limit_buy_order_open['id'] = str(i)
|
limit_buy_order_open['id'] = str(i)
|
||||||
result = freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
result = freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
||||||
assert pytest.approx(result) == expected[i]
|
assert pytest.approx(result) == expected[i]
|
||||||
freqtrade.execute_buy('ETH/BTC', result)
|
freqtrade.execute_entry('ETH/BTC', result)
|
||||||
else:
|
else:
|
||||||
with pytest.raises(DependencyException):
|
with pytest.raises(DependencyException):
|
||||||
freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
freqtrade.wallets.get_trade_stake_amount('ETH/BTC')
|
||||||
@ -584,8 +584,8 @@ def test_create_trades_preopen(default_conf, ticker, fee, mocker, limit_buy_orde
|
|||||||
patch_get_signal(freqtrade)
|
patch_get_signal(freqtrade)
|
||||||
|
|
||||||
# Create 2 existing trades
|
# Create 2 existing trades
|
||||||
freqtrade.execute_buy('ETH/BTC', default_conf['stake_amount'])
|
freqtrade.execute_entry('ETH/BTC', default_conf['stake_amount'])
|
||||||
freqtrade.execute_buy('NEO/BTC', default_conf['stake_amount'])
|
freqtrade.execute_entry('NEO/BTC', default_conf['stake_amount'])
|
||||||
|
|
||||||
assert len(Trade.get_open_trades()) == 2
|
assert len(Trade.get_open_trades()) == 2
|
||||||
# Change order_id for new orders
|
# Change order_id for new orders
|
||||||
@ -776,7 +776,7 @@ def test_process_informative_pairs_added(default_conf, ticker, mocker) -> None:
|
|||||||
assert ("ETH/BTC", default_conf["timeframe"]) in refresh_mock.call_args[0][0]
|
assert ("ETH/BTC", default_conf["timeframe"]) in refresh_mock.call_args[0][0]
|
||||||
|
|
||||||
|
|
||||||
def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order_open) -> None:
|
def test_execute_entry(mocker, default_conf, fee, limit_buy_order, limit_buy_order_open) -> None:
|
||||||
patch_RPCManager(mocker)
|
patch_RPCManager(mocker)
|
||||||
patch_exchange(mocker)
|
patch_exchange(mocker)
|
||||||
freqtrade = FreqtradeBot(default_conf)
|
freqtrade = FreqtradeBot(default_conf)
|
||||||
@ -799,7 +799,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
)
|
)
|
||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
|
|
||||||
assert not freqtrade.execute_buy(pair, stake_amount)
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
||||||
assert buy_rate_mock.call_count == 1
|
assert buy_rate_mock.call_count == 1
|
||||||
assert buy_mm.call_count == 0
|
assert buy_mm.call_count == 0
|
||||||
assert freqtrade.strategy.confirm_trade_entry.call_count == 1
|
assert freqtrade.strategy.confirm_trade_entry.call_count == 1
|
||||||
@ -807,7 +807,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
|
|
||||||
limit_buy_order_open['id'] = '22'
|
limit_buy_order_open['id'] = '22'
|
||||||
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
assert buy_rate_mock.call_count == 1
|
assert buy_rate_mock.call_count == 1
|
||||||
assert buy_mm.call_count == 1
|
assert buy_mm.call_count == 1
|
||||||
call_args = buy_mm.call_args_list[0][1]
|
call_args = buy_mm.call_args_list[0][1]
|
||||||
@ -826,7 +826,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
# Test calling with price
|
# Test calling with price
|
||||||
limit_buy_order_open['id'] = '33'
|
limit_buy_order_open['id'] = '33'
|
||||||
fix_price = 0.06
|
fix_price = 0.06
|
||||||
assert freqtrade.execute_buy(pair, stake_amount, fix_price)
|
assert freqtrade.execute_entry(pair, stake_amount, fix_price)
|
||||||
# Make sure get_rate wasn't called again
|
# Make sure get_rate wasn't called again
|
||||||
assert buy_rate_mock.call_count == 0
|
assert buy_rate_mock.call_count == 0
|
||||||
|
|
||||||
@ -844,7 +844,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
|
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
||||||
MagicMock(return_value=limit_buy_order))
|
MagicMock(return_value=limit_buy_order))
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[2]
|
trade = Trade.query.all()[2]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.open_order_id is None
|
assert trade.open_order_id is None
|
||||||
@ -861,7 +861,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
limit_buy_order['id'] = '555'
|
limit_buy_order['id'] = '555'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
||||||
MagicMock(return_value=limit_buy_order))
|
MagicMock(return_value=limit_buy_order))
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[3]
|
trade = Trade.query.all()[3]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.open_order_id == '555'
|
assert trade.open_order_id == '555'
|
||||||
@ -873,7 +873,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
limit_buy_order['id'] = '556'
|
limit_buy_order['id'] = '556'
|
||||||
|
|
||||||
freqtrade.strategy.custom_stake_amount = lambda **kwargs: 150.0
|
freqtrade.strategy.custom_stake_amount = lambda **kwargs: 150.0
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[4]
|
trade = Trade.query.all()[4]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.stake_amount == 150
|
assert trade.stake_amount == 150
|
||||||
@ -881,7 +881,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
# Exception case
|
# Exception case
|
||||||
limit_buy_order['id'] = '557'
|
limit_buy_order['id'] = '557'
|
||||||
freqtrade.strategy.custom_stake_amount = lambda **kwargs: 20 / 0
|
freqtrade.strategy.custom_stake_amount = lambda **kwargs: 20 / 0
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[5]
|
trade = Trade.query.all()[5]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.stake_amount == 2.0
|
assert trade.stake_amount == 2.0
|
||||||
@ -896,20 +896,20 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
limit_buy_order['id'] = '66'
|
limit_buy_order['id'] = '66'
|
||||||
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
mocker.patch('freqtrade.exchange.Exchange.create_order',
|
||||||
MagicMock(return_value=limit_buy_order))
|
MagicMock(return_value=limit_buy_order))
|
||||||
assert not freqtrade.execute_buy(pair, stake_amount)
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
||||||
|
|
||||||
# Fail to get price...
|
# Fail to get price...
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate', MagicMock(return_value=0.0))
|
mocker.patch('freqtrade.exchange.Exchange.get_rate', MagicMock(return_value=0.0))
|
||||||
|
|
||||||
with pytest.raises(PricingError, match="Could not determine buy price."):
|
with pytest.raises(PricingError, match="Could not determine buy price."):
|
||||||
freqtrade.execute_buy(pair, stake_amount)
|
freqtrade.execute_entry(pair, stake_amount)
|
||||||
|
|
||||||
# In case of custom entry price
|
# In case of custom entry price
|
||||||
mocker.patch('freqtrade.exchange.Exchange.get_rate', return_value=0.50)
|
mocker.patch('freqtrade.exchange.Exchange.get_rate', return_value=0.50)
|
||||||
limit_buy_order['status'] = 'open'
|
limit_buy_order['status'] = 'open'
|
||||||
limit_buy_order['id'] = '5566'
|
limit_buy_order['id'] = '5566'
|
||||||
freqtrade.strategy.custom_entry_price = lambda **kwargs: 0.508
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: 0.508
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[6]
|
trade = Trade.query.all()[6]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.open_rate_requested == 0.508
|
assert trade.open_rate_requested == 0.508
|
||||||
@ -924,7 +924,7 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
get_rate=MagicMock(return_value=10),
|
get_rate=MagicMock(return_value=10),
|
||||||
)
|
)
|
||||||
|
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[7]
|
trade = Trade.query.all()[7]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.open_rate_requested == 10
|
assert trade.open_rate_requested == 10
|
||||||
@ -933,13 +933,13 @@ def test_execute_buy(mocker, default_conf, fee, limit_buy_order, limit_buy_order
|
|||||||
limit_buy_order['status'] = 'open'
|
limit_buy_order['status'] = 'open'
|
||||||
limit_buy_order['id'] = '5568'
|
limit_buy_order['id'] = '5568'
|
||||||
freqtrade.strategy.custom_entry_price = lambda **kwargs: "string price"
|
freqtrade.strategy.custom_entry_price = lambda **kwargs: "string price"
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
trade = Trade.query.all()[8]
|
trade = Trade.query.all()[8]
|
||||||
assert trade
|
assert trade
|
||||||
assert trade.open_rate_requested == 10
|
assert trade.open_rate_requested == 10
|
||||||
|
|
||||||
|
|
||||||
def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
def test_execute_entry_confirm_error(mocker, default_conf, fee, limit_buy_order) -> None:
|
||||||
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
freqtrade = get_patched_freqtradebot(mocker, default_conf)
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -957,18 +957,18 @@ def test_execute_buy_confirm_error(mocker, default_conf, fee, limit_buy_order) -
|
|||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
|
|
||||||
freqtrade.strategy.confirm_trade_entry = MagicMock(side_effect=ValueError)
|
freqtrade.strategy.confirm_trade_entry = MagicMock(side_effect=ValueError)
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
|
|
||||||
limit_buy_order['id'] = '222'
|
limit_buy_order['id'] = '222'
|
||||||
freqtrade.strategy.confirm_trade_entry = MagicMock(side_effect=Exception)
|
freqtrade.strategy.confirm_trade_entry = MagicMock(side_effect=Exception)
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
|
|
||||||
limit_buy_order['id'] = '2223'
|
limit_buy_order['id'] = '2223'
|
||||||
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=True)
|
||||||
assert freqtrade.execute_buy(pair, stake_amount)
|
assert freqtrade.execute_entry(pair, stake_amount)
|
||||||
|
|
||||||
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
|
freqtrade.strategy.confirm_trade_entry = MagicMock(return_value=False)
|
||||||
assert not freqtrade.execute_buy(pair, stake_amount)
|
assert not freqtrade.execute_entry(pair, stake_amount)
|
||||||
|
|
||||||
|
|
||||||
def test_add_stoploss_on_exchange(mocker, default_conf, limit_buy_order) -> None:
|
def test_add_stoploss_on_exchange(mocker, default_conf, limit_buy_order) -> None:
|
||||||
|
@ -157,13 +157,13 @@ def test_get_trade_stake_amount_unlimited_amount(default_conf, ticker, balance_r
|
|||||||
assert result == result1
|
assert result == result1
|
||||||
|
|
||||||
# create one trade, order amount should be 'balance / (max_open_trades - num_open_trades)'
|
# create one trade, order amount should be 'balance / (max_open_trades - num_open_trades)'
|
||||||
freqtrade.execute_buy('ETH/USDT', result)
|
freqtrade.execute_entry('ETH/USDT', result)
|
||||||
|
|
||||||
result = freqtrade.wallets.get_trade_stake_amount('LTC/USDT')
|
result = freqtrade.wallets.get_trade_stake_amount('LTC/USDT')
|
||||||
assert result == result1
|
assert result == result1
|
||||||
|
|
||||||
# create 2 trades, order amount should be None
|
# create 2 trades, order amount should be None
|
||||||
freqtrade.execute_buy('LTC/BTC', result)
|
freqtrade.execute_entry('LTC/BTC', result)
|
||||||
|
|
||||||
result = freqtrade.wallets.get_trade_stake_amount('XRP/USDT')
|
result = freqtrade.wallets.get_trade_stake_amount('XRP/USDT')
|
||||||
assert result == 0
|
assert result == 0
|
||||||
|
Loading…
Reference in New Issue
Block a user