Move create_mock_tests to conftest and add test for test_trade-history
This commit is contained in:
parent
200111fef6
commit
bdc85ec89b
@ -166,6 +166,52 @@ def patch_get_signal(freqtrade: FreqtradeBot, value=(True, False)) -> None:
|
|||||||
freqtrade.exchange.refresh_latest_ohlcv = lambda p: None
|
freqtrade.exchange.refresh_latest_ohlcv = lambda p: None
|
||||||
|
|
||||||
|
|
||||||
|
def create_mock_trades(fee):
|
||||||
|
"""
|
||||||
|
Create some fake trades ...
|
||||||
|
"""
|
||||||
|
# Simulate dry_run entries
|
||||||
|
trade = Trade(
|
||||||
|
pair='ETH/BTC',
|
||||||
|
stake_amount=0.001,
|
||||||
|
amount=123.0,
|
||||||
|
fee_open=fee.return_value,
|
||||||
|
fee_close=fee.return_value,
|
||||||
|
open_rate=0.123,
|
||||||
|
exchange='bittrex',
|
||||||
|
open_order_id='dry_run_buy_12345'
|
||||||
|
)
|
||||||
|
Trade.session.add(trade)
|
||||||
|
|
||||||
|
trade = Trade(
|
||||||
|
pair='ETC/BTC',
|
||||||
|
stake_amount=0.001,
|
||||||
|
amount=123.0,
|
||||||
|
fee_open=fee.return_value,
|
||||||
|
fee_close=fee.return_value,
|
||||||
|
open_rate=0.123,
|
||||||
|
close_rate=0.128,
|
||||||
|
close_profit=0.005,
|
||||||
|
exchange='bittrex',
|
||||||
|
is_open=False,
|
||||||
|
open_order_id='dry_run_sell_12345'
|
||||||
|
)
|
||||||
|
Trade.session.add(trade)
|
||||||
|
|
||||||
|
# Simulate prod entry
|
||||||
|
trade = Trade(
|
||||||
|
pair='ETC/BTC',
|
||||||
|
stake_amount=0.001,
|
||||||
|
amount=123.0,
|
||||||
|
fee_open=fee.return_value,
|
||||||
|
fee_close=fee.return_value,
|
||||||
|
open_rate=0.123,
|
||||||
|
exchange='bittrex',
|
||||||
|
open_order_id='prod_buy_12345'
|
||||||
|
)
|
||||||
|
Trade.session.add(trade)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def patch_coingekko(mocker) -> None:
|
def patch_coingekko(mocker) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -15,7 +15,7 @@ from freqtrade.data.btanalysis import (BT_DATA_COLUMNS,
|
|||||||
load_backtest_data, load_trades,
|
load_backtest_data, load_trades,
|
||||||
load_trades_from_db)
|
load_trades_from_db)
|
||||||
from freqtrade.data.history import load_data, load_pair_history
|
from freqtrade.data.history import load_data, load_pair_history
|
||||||
from tests.test_persistence import create_mock_trades
|
from tests.conftest import create_mock_trades
|
||||||
|
|
||||||
|
|
||||||
def test_load_backtest_data(testdatadir):
|
def test_load_backtest_data(testdatadir):
|
||||||
|
@ -13,7 +13,7 @@ from freqtrade.persistence import Trade
|
|||||||
from freqtrade.rpc import RPC, RPCException
|
from freqtrade.rpc import RPC, RPCException
|
||||||
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
|
||||||
from freqtrade.state import State
|
from freqtrade.state import State
|
||||||
from tests.conftest import get_patched_freqtradebot, patch_get_signal
|
from tests.conftest import get_patched_freqtradebot, patch_get_signal, create_mock_trades
|
||||||
|
|
||||||
|
|
||||||
# Functions for recurrent object patching
|
# Functions for recurrent object patching
|
||||||
@ -211,6 +211,32 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee,
|
|||||||
rpc._rpc_daily_profit(0, stake_currency, fiat_display_currency)
|
rpc._rpc_daily_profit(0, stake_currency, fiat_display_currency)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rpc_trade_history(mocker, default_conf, markets, fee):
|
||||||
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
|
mocker.patch.multiple(
|
||||||
|
'freqtrade.exchange.Exchange',
|
||||||
|
markets=PropertyMock(return_value=markets)
|
||||||
|
)
|
||||||
|
|
||||||
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
||||||
|
create_mock_trades(fee)
|
||||||
|
rpc = RPC(freqtradebot)
|
||||||
|
rpc._fiat_converter = CryptoToFiatConverter()
|
||||||
|
trades = rpc._rpc_trade_history(2)
|
||||||
|
assert len(trades['trades']) == 2
|
||||||
|
assert trades['trades_count'] == 2
|
||||||
|
assert isinstance(trades['trades'][0], dict)
|
||||||
|
assert isinstance(trades['trades'][1], dict)
|
||||||
|
|
||||||
|
trades = rpc._rpc_trade_history(0)
|
||||||
|
assert len(trades['trades']) == 3
|
||||||
|
assert trades['trades_count'] == 3
|
||||||
|
# The first trade is for ETH ... sorting is descending
|
||||||
|
assert trades['trades'][-1]['pair'] == 'ETH/BTC'
|
||||||
|
assert trades['trades'][0]['pair'] == 'ETC/BTC'
|
||||||
|
assert trades['trades'][1]['pair'] == 'ETC/BTC'
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
|
def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee,
|
||||||
limit_buy_order, limit_sell_order, mocker) -> None:
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
|
@ -9,53 +9,7 @@ from sqlalchemy import create_engine
|
|||||||
from freqtrade import constants
|
from freqtrade import constants
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.persistence import Trade, clean_dry_run_db, init
|
from freqtrade.persistence import Trade, clean_dry_run_db, init
|
||||||
from tests.conftest import log_has
|
from tests.conftest import log_has, create_mock_trades
|
||||||
|
|
||||||
|
|
||||||
def create_mock_trades(fee):
|
|
||||||
"""
|
|
||||||
Create some fake trades ...
|
|
||||||
"""
|
|
||||||
# Simulate dry_run entries
|
|
||||||
trade = Trade(
|
|
||||||
pair='ETH/BTC',
|
|
||||||
stake_amount=0.001,
|
|
||||||
amount=123.0,
|
|
||||||
fee_open=fee.return_value,
|
|
||||||
fee_close=fee.return_value,
|
|
||||||
open_rate=0.123,
|
|
||||||
exchange='bittrex',
|
|
||||||
open_order_id='dry_run_buy_12345'
|
|
||||||
)
|
|
||||||
Trade.session.add(trade)
|
|
||||||
|
|
||||||
trade = Trade(
|
|
||||||
pair='ETC/BTC',
|
|
||||||
stake_amount=0.001,
|
|
||||||
amount=123.0,
|
|
||||||
fee_open=fee.return_value,
|
|
||||||
fee_close=fee.return_value,
|
|
||||||
open_rate=0.123,
|
|
||||||
close_rate=0.128,
|
|
||||||
close_profit=0.005,
|
|
||||||
exchange='bittrex',
|
|
||||||
is_open=False,
|
|
||||||
open_order_id='dry_run_sell_12345'
|
|
||||||
)
|
|
||||||
Trade.session.add(trade)
|
|
||||||
|
|
||||||
# Simulate prod entry
|
|
||||||
trade = Trade(
|
|
||||||
pair='ETC/BTC',
|
|
||||||
stake_amount=0.001,
|
|
||||||
amount=123.0,
|
|
||||||
fee_open=fee.return_value,
|
|
||||||
fee_close=fee.return_value,
|
|
||||||
open_rate=0.123,
|
|
||||||
exchange='bittrex',
|
|
||||||
open_order_id='prod_buy_12345'
|
|
||||||
)
|
|
||||||
Trade.session.add(trade)
|
|
||||||
|
|
||||||
|
|
||||||
def test_init_create_session(default_conf):
|
def test_init_create_session(default_conf):
|
||||||
|
Loading…
Reference in New Issue
Block a user