Add test for show_trades
This commit is contained in:
parent
56bb5f7a11
commit
1066a4504b
@ -212,8 +212,8 @@ def start_show_trades(args: Dict[str, Any]) -> None:
|
||||
if config.get('trade_ids'):
|
||||
tfilter.append(Trade.id.in_(config['trade_ids']))
|
||||
|
||||
trades = Trade.get_trades(tfilter)
|
||||
logger.info("Printing Trades: ")
|
||||
trades = Trade.get_trades(tfilter).all()
|
||||
logger.info(f"Printing {len(trades)} Trades: ")
|
||||
if config.get('print_json', False):
|
||||
print(json.dumps([trade.to_json() for trade in trades], indent=4))
|
||||
else:
|
||||
|
@ -10,11 +10,13 @@ from freqtrade.commands import (start_convert_data, start_create_userdir,
|
||||
start_list_hyperopts, start_list_markets,
|
||||
start_list_strategies, start_list_timeframes,
|
||||
start_new_hyperopt, start_new_strategy,
|
||||
start_test_pairlist, start_trading)
|
||||
start_show_trades, start_test_pairlist,
|
||||
start_trading)
|
||||
from freqtrade.configuration import setup_utils_configuration
|
||||
from freqtrade.exceptions import OperationalException
|
||||
from freqtrade.state import RunMode
|
||||
from tests.conftest import (get_args, log_has, log_has_re, patch_exchange,
|
||||
from tests.conftest import (create_mock_trades, get_args, log_has, log_has_re,
|
||||
patch_exchange,
|
||||
patched_configuration_load_config_file)
|
||||
|
||||
|
||||
@ -1040,3 +1042,38 @@ def test_convert_data_trades(mocker, testdatadir):
|
||||
assert trades_mock.call_args[1]['convert_from'] == 'jsongz'
|
||||
assert trades_mock.call_args[1]['convert_to'] == 'json'
|
||||
assert trades_mock.call_args[1]['erase'] is False
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_show_trades(mocker, fee, capsys, caplog):
|
||||
mocker.patch("freqtrade.persistence.init")
|
||||
create_mock_trades(fee)
|
||||
args = [
|
||||
"show-trades",
|
||||
"--db-url",
|
||||
"sqlite:///"
|
||||
]
|
||||
pargs = get_args(args)
|
||||
pargs['config'] = None
|
||||
start_show_trades(pargs)
|
||||
assert log_has("Printing 3 Trades: ", caplog)
|
||||
captured = capsys.readouterr()
|
||||
assert "Trade(id=1" in captured.out
|
||||
assert "Trade(id=2" in captured.out
|
||||
assert "Trade(id=3" in captured.out
|
||||
args = [
|
||||
"show-trades",
|
||||
"--db-url",
|
||||
"sqlite:///",
|
||||
"--print-json",
|
||||
"--tradeids", "1", "2"
|
||||
]
|
||||
pargs = get_args(args)
|
||||
pargs['config'] = None
|
||||
start_show_trades(pargs)
|
||||
|
||||
captured = capsys.readouterr()
|
||||
assert log_has("Printing 2 Trades: ", caplog)
|
||||
assert '"trade_id": 1' in captured.out
|
||||
assert '"trade_id": 2' in captured.out
|
||||
assert '"trade_id": 3' not in captured.out
|
||||
|
Loading…
Reference in New Issue
Block a user