Add 5th mock trade

This commit is contained in:
Matthias 2020-09-09 07:01:43 +02:00
parent caf0476717
commit 98840eef3c
6 changed files with 66 additions and 11 deletions

View File

@ -1116,7 +1116,7 @@ def test_show_trades(mocker, fee, capsys, caplog):
pargs = get_args(args) pargs = get_args(args)
pargs['config'] = None pargs['config'] = None
start_show_trades(pargs) start_show_trades(pargs)
assert log_has("Printing 4 Trades: ", caplog) assert log_has("Printing 5 Trades: ", caplog)
captured = capsys.readouterr() captured = capsys.readouterr()
assert "Trade(id=1" in captured.out assert "Trade(id=1" in captured.out
assert "Trade(id=2" in captured.out assert "Trade(id=2" in captured.out

View File

@ -23,7 +23,7 @@ from freqtrade.persistence import Trade
from freqtrade.resolvers import ExchangeResolver from freqtrade.resolvers import ExchangeResolver
from freqtrade.worker import Worker from freqtrade.worker import Worker
from tests.conftest_trades import (mock_trade_1, mock_trade_2, mock_trade_3, from tests.conftest_trades import (mock_trade_1, mock_trade_2, mock_trade_3,
mock_trade_4) mock_trade_4, mock_trade_5)
logging.getLogger('').setLevel(logging.INFO) logging.getLogger('').setLevel(logging.INFO)
@ -186,6 +186,9 @@ def create_mock_trades(fee):
trade = mock_trade_4(fee) trade = mock_trade_4(fee)
Trade.session.add(trade) Trade.session.add(trade)
trade = mock_trade_5(fee)
Trade.session.add(trade)
@pytest.fixture(autouse=True) @pytest.fixture(autouse=True)
def patch_coingekko(mocker) -> None: def patch_coingekko(mocker) -> None:

View File

@ -172,3 +172,54 @@ def mock_trade_4(fee):
o = Order.parse_from_ccxt_object(mock_order_4(), 'ETH/BTC', 'buy') o = Order.parse_from_ccxt_object(mock_order_4(), 'ETH/BTC', 'buy')
trade.orders.append(o) trade.orders.append(o)
return trade return trade
def mock_order_5():
return {
'id': 'prod_buy_3455',
'symbol': 'XRP/BTC',
'status': 'closed',
'side': 'buy',
'type': 'limit',
'price': 0.123,
'amount': 123.0,
'filled': 123.0,
'remaining': 0.0,
}
def mock_order_5_stoploss():
return {
'id': 'prod_stoploss_3455',
'symbol': 'XRP/BTC',
'status': 'open',
'side': 'sell',
'type': 'stop_loss_limit',
'price': 0.123,
'amount': 123.0,
'filled': 0.0,
'remaining': 123.0,
}
def mock_trade_5(fee):
"""
Simulate prod entry with stoploss
"""
trade = Trade(
pair='XRP/BTC',
stake_amount=0.001,
amount=123.0,
amount_requested=124.0,
fee_open=fee.return_value,
fee_close=fee.return_value,
open_rate=0.123,
exchange='bittrex',
strategy='SampleStrategy',
stoploss_order_id='prod_stoploss_3455'
)
o = Order.parse_from_ccxt_object(mock_order_5(), 'ETH/BTC', 'buy')
trade.orders.append(o)
o = Order.parse_from_ccxt_object(mock_order_5_stoploss(), 'ETH/BTC', 'sell')
trade.orders.append(o)
return trade

View File

@ -110,7 +110,7 @@ def test_load_trades_from_db(default_conf, fee, mocker):
trades = load_trades_from_db(db_url=default_conf['db_url']) trades = load_trades_from_db(db_url=default_conf['db_url'])
assert init_mock.call_count == 1 assert init_mock.call_count == 1
assert len(trades) == 4 assert len(trades) == 5
assert isinstance(trades, DataFrame) assert isinstance(trades, DataFrame)
assert "pair" in trades.columns assert "pair" in trades.columns
assert "open_date" in trades.columns assert "open_date" in trades.columns

View File

@ -4213,7 +4213,7 @@ def test_cancel_all_open_orders(mocker, default_conf, fee, limit_buy_order, limi
freqtrade = get_patched_freqtradebot(mocker, default_conf) freqtrade = get_patched_freqtradebot(mocker, default_conf)
create_mock_trades(fee) create_mock_trades(fee)
trades = Trade.query.all() trades = Trade.query.all()
assert len(trades) == 4 assert len(trades) == 5
freqtrade.cancel_all_open_orders() freqtrade.cancel_all_open_orders()
assert buy_mock.call_count == 1 assert buy_mock.call_count == 1
assert sell_mock.call_count == 1 assert sell_mock.call_count == 1
@ -4244,14 +4244,15 @@ def test_update_open_orders(mocker, default_conf, fee, caplog):
assert log_has_re(r"Error updating Order .*", caplog) assert log_has_re(r"Error updating Order .*", caplog)
caplog.clear() caplog.clear()
assert len(Order.get_open_orders()) == 1 assert len(Order.get_open_orders()) == 2
matching_buy_order = mock_order_4() matching_buy_order = mock_order_4()
matching_buy_order.update({ matching_buy_order.update({
'status': 'closed', 'status': 'closed',
}) })
mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=matching_buy_order) mocker.patch('freqtrade.exchange.Exchange.fetch_order', return_value=matching_buy_order)
freqtrade.update_open_orders() freqtrade.update_open_orders()
assert len(Order.get_open_orders()) == 0 # Only stoploss order is kept open
assert len(Order.get_open_orders()) == 1
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
@ -4276,7 +4277,7 @@ def test_update_closed_trades_without_assigned_fees(mocker, default_conf, fee):
create_mock_trades(fee) create_mock_trades(fee)
trades = Trade.get_trades().all() trades = Trade.get_trades().all()
assert len(trades) == 4 assert len(trades) == 5
for trade in trades: for trade in trades:
assert trade.fee_open_cost is None assert trade.fee_open_cost is None
assert trade.fee_open_currency is None assert trade.fee_open_currency is None
@ -4285,8 +4286,8 @@ def test_update_closed_trades_without_assigned_fees(mocker, default_conf, fee):
freqtrade.update_closed_trades_without_assigned_fees() freqtrade.update_closed_trades_without_assigned_fees()
# trades = Trade.get_trades().all() trades = Trade.get_trades().all()
assert len(trades) == 4 assert len(trades) == 5
for trade in trades: for trade in trades:
if trade.is_open: if trade.is_open:

View File

@ -734,7 +734,7 @@ def test_adjust_min_max_rates(fee):
def test_get_open(default_conf, fee): def test_get_open(default_conf, fee):
create_mock_trades(fee) create_mock_trades(fee)
assert len(Trade.get_open_trades()) == 2 assert len(Trade.get_open_trades()) == 3
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")
@ -1004,7 +1004,7 @@ def test_total_open_trades_stakes(fee):
assert res == 0 assert res == 0
create_mock_trades(fee) create_mock_trades(fee)
res = Trade.total_open_trades_stakes() res = Trade.total_open_trades_stakes()
assert res == 0.002 assert res == 0.003
@pytest.mark.usefixtures("init_persistence") @pytest.mark.usefixtures("init_persistence")