Update more trades to use create_mock_trades
This commit is contained in:
parent
43c871f2f4
commit
e67d29cd2f
@ -11,7 +11,6 @@ from freqtrade.edge import PairInfo
|
|||||||
from freqtrade.enums import SignalDirection, State, TradingMode
|
from freqtrade.enums import SignalDirection, State, TradingMode
|
||||||
from freqtrade.exceptions import ExchangeError, InvalidOrderException, TemporaryError
|
from freqtrade.exceptions import ExchangeError, InvalidOrderException, TemporaryError
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.persistence.models import Order
|
|
||||||
from freqtrade.persistence.pairlock_middleware import PairLocks
|
from freqtrade.persistence.pairlock_middleware import PairLocks
|
||||||
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
|
||||||
@ -407,8 +406,7 @@ def test_rpc_delete_trade(mocker, default_conf, fee, markets, caplog, is_short):
|
|||||||
assert stoploss_mock.call_count == 0
|
assert stoploss_mock.call_count == 0
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_trade_statistics11(default_conf_usdt, ticker, fee,
|
def test_rpc_trade_statistics(default_conf_usdt, ticker, fee, mocker) -> None:
|
||||||
mocker) -> None:
|
|
||||||
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=1.1)
|
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=1.1)
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
@ -463,14 +461,9 @@ def test_rpc_trade_statistics11(default_conf_usdt, ticker, fee,
|
|||||||
|
|
||||||
# Test that rpc_trade_statistics can handle trades that lacks
|
# Test that rpc_trade_statistics can handle trades that lacks
|
||||||
# trade.open_rate (it is set to None)
|
# trade.open_rate (it is set to None)
|
||||||
def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
|
def test_rpc_trade_statistics_closed(mocker, default_conf_usdt, ticker, fee):
|
||||||
ticker_sell_up, limit_buy_order, limit_sell_order):
|
|
||||||
mocker.patch.multiple(
|
|
||||||
'freqtrade.rpc.fiat_convert.CoinGeckoAPI',
|
|
||||||
get_price=MagicMock(return_value={'bitcoin': {'usd': 15000.0}}),
|
|
||||||
)
|
|
||||||
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
|
mocker.patch('freqtrade.rpc.fiat_convert.CryptoToFiatConverter._find_price',
|
||||||
return_value=15000.0)
|
return_value=1.1)
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -478,46 +471,32 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
patch_get_signal(freqtradebot)
|
patch_get_signal(freqtradebot)
|
||||||
stake_currency = default_conf['stake_currency']
|
stake_currency = default_conf_usdt['stake_currency']
|
||||||
fiat_display_currency = default_conf['fiat_display_currency']
|
fiat_display_currency = default_conf_usdt['fiat_display_currency']
|
||||||
|
|
||||||
rpc = RPC(freqtradebot)
|
rpc = RPC(freqtradebot)
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
freqtradebot.enter_positions()
|
create_mock_trades_usdt(fee)
|
||||||
trade = Trade.query.first()
|
|
||||||
# Simulate fulfilled LIMIT_BUY order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
# Update the ticker with a market going up
|
|
||||||
mocker.patch.multiple(
|
|
||||||
'freqtrade.exchange.Exchange',
|
|
||||||
fetch_ticker=ticker_sell_up,
|
|
||||||
get_fee=fee
|
|
||||||
)
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
trade.close_date = datetime.utcnow()
|
|
||||||
trade.is_open = False
|
|
||||||
|
|
||||||
for trade in Trade.query.order_by(Trade.id).all():
|
for trade in Trade.query.order_by(Trade.id).all():
|
||||||
trade.open_rate = None
|
trade.open_rate = None
|
||||||
|
|
||||||
stats = rpc._rpc_trade_statistics(stake_currency, fiat_display_currency)
|
stats = rpc._rpc_trade_statistics(stake_currency, fiat_display_currency)
|
||||||
assert prec_satoshi(stats['profit_closed_coin'], 0)
|
assert stats['profit_closed_coin'] == 0
|
||||||
assert prec_satoshi(stats['profit_closed_percent_mean'], 0)
|
assert stats['profit_closed_percent_mean'] == 0
|
||||||
assert prec_satoshi(stats['profit_closed_fiat'], 0)
|
assert stats['profit_closed_fiat'] == 0
|
||||||
assert prec_satoshi(stats['profit_all_coin'], 0)
|
assert stats['profit_all_coin'] == 0
|
||||||
assert prec_satoshi(stats['profit_all_percent_mean'], 0)
|
assert stats['profit_all_percent_mean'] == 0
|
||||||
assert prec_satoshi(stats['profit_all_fiat'], 0)
|
assert stats['profit_all_fiat'] == 0
|
||||||
assert stats['trade_count'] == 1
|
assert stats['trade_count'] == 7
|
||||||
assert stats['first_trade_date'] == 'just now'
|
assert stats['first_trade_date'] == '2 days ago'
|
||||||
assert stats['latest_trade_date'] == 'just now'
|
assert stats['latest_trade_date'] == '17 minutes ago'
|
||||||
assert stats['avg_duration'] == '0:00:00'
|
assert stats['avg_duration'] == '0:00:00'
|
||||||
assert stats['best_pair'] == 'ETH/BTC'
|
assert stats['best_pair'] == 'XRP/USDT'
|
||||||
assert prec_satoshi(stats['best_rate'], 6.2)
|
assert stats['best_rate'] == 10.0
|
||||||
|
|
||||||
|
|
||||||
def test_rpc_balance_handle_error(default_conf, mocker):
|
def test_rpc_balance_handle_error(default_conf, mocker):
|
||||||
@ -869,8 +848,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None:
|
|||||||
assert cancel_order_mock.call_count == 3
|
assert cancel_order_mock.call_count == 3
|
||||||
|
|
||||||
|
|
||||||
def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
def test_performance_handle(default_conf_usdt, ticker, fee, mocker) -> None:
|
||||||
limit_sell_order, mocker) -> None:
|
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -879,34 +857,21 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
patch_get_signal(freqtradebot)
|
patch_get_signal(freqtradebot)
|
||||||
rpc = RPC(freqtradebot)
|
rpc = RPC(freqtradebot)
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
freqtradebot.enter_positions()
|
create_mock_trades_usdt(fee)
|
||||||
trade = Trade.query.first()
|
|
||||||
assert trade
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_BUY order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_SELL order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
trade.close_date = datetime.utcnow()
|
|
||||||
trade.is_open = False
|
|
||||||
res = rpc._rpc_performance()
|
res = rpc._rpc_performance()
|
||||||
assert len(res) == 1
|
assert len(res) == 3
|
||||||
assert res[0]['pair'] == 'ETH/BTC'
|
assert res[0]['pair'] == 'XRP/USDT'
|
||||||
assert res[0]['count'] == 1
|
assert res[0]['count'] == 1
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
assert res[0]['profit_pct'] == 10.0
|
||||||
|
|
||||||
|
|
||||||
def test_enter_tag_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
def test_enter_tag_performance_handle(default_conf, ticker, fee, mocker) -> None:
|
||||||
limit_sell_order, mocker) -> None:
|
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -920,34 +885,22 @@ def test_enter_tag_performance_handle(default_conf, ticker, limit_buy_order, fee
|
|||||||
rpc = RPC(freqtradebot)
|
rpc = RPC(freqtradebot)
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
|
create_mock_trades_usdt(fee)
|
||||||
freqtradebot.enter_positions()
|
freqtradebot.enter_positions()
|
||||||
trade = Trade.query.first()
|
|
||||||
assert trade
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_BUY order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_SELL order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
trade.close_date = datetime.utcnow()
|
|
||||||
trade.is_open = False
|
|
||||||
res = rpc._rpc_enter_tag_performance(None)
|
res = rpc._rpc_enter_tag_performance(None)
|
||||||
|
|
||||||
assert len(res) == 1
|
assert len(res) == 3
|
||||||
assert res[0]['enter_tag'] == 'Other'
|
assert res[0]['enter_tag'] == 'TEST3'
|
||||||
assert res[0]['count'] == 1
|
assert res[0]['count'] == 1
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
assert res[0]['profit_pct'] == 10.0
|
||||||
|
|
||||||
trade.enter_tag = "TEST_TAG"
|
|
||||||
res = rpc._rpc_enter_tag_performance(None)
|
res = rpc._rpc_enter_tag_performance(None)
|
||||||
|
|
||||||
assert len(res) == 1
|
assert len(res) == 3
|
||||||
assert res[0]['enter_tag'] == 'TEST_TAG'
|
assert res[0]['enter_tag'] == 'TEST3'
|
||||||
assert res[0]['count'] == 1
|
assert res[0]['count'] == 1
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
assert res[0]['profit_pct'] == 10.0
|
||||||
|
|
||||||
|
|
||||||
def test_enter_tag_performance_handle_2(mocker, default_conf, markets, fee):
|
def test_enter_tag_performance_handle_2(mocker, default_conf, markets, fee):
|
||||||
@ -979,8 +932,7 @@ def test_enter_tag_performance_handle_2(mocker, default_conf, markets, fee):
|
|||||||
assert prec_satoshi(res[0]['profit_pct'], 0.5)
|
assert prec_satoshi(res[0]['profit_pct'], 0.5)
|
||||||
|
|
||||||
|
|
||||||
def test_exit_reason_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
def test_exit_reason_performance_handle(default_conf_usdt, ticker, fee, mocker) -> None:
|
||||||
limit_sell_order, mocker) -> None:
|
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -989,39 +941,22 @@ def test_exit_reason_performance_handle(default_conf, ticker, limit_buy_order, f
|
|||||||
get_fee=fee,
|
get_fee=fee,
|
||||||
)
|
)
|
||||||
|
|
||||||
freqtradebot = get_patched_freqtradebot(mocker, default_conf)
|
freqtradebot = get_patched_freqtradebot(mocker, default_conf_usdt)
|
||||||
patch_get_signal(freqtradebot)
|
patch_get_signal(freqtradebot)
|
||||||
rpc = RPC(freqtradebot)
|
rpc = RPC(freqtradebot)
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
freqtradebot.enter_positions()
|
create_mock_trades_usdt(fee)
|
||||||
trade = Trade.query.first()
|
|
||||||
assert trade
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_BUY order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_SELL order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
trade.close_date = datetime.utcnow()
|
|
||||||
trade.is_open = False
|
|
||||||
res = rpc._rpc_exit_reason_performance(None)
|
res = rpc._rpc_exit_reason_performance(None)
|
||||||
|
|
||||||
assert len(res) == 1
|
assert len(res) == 3
|
||||||
assert res[0]['exit_reason'] == 'Other'
|
assert res[0]['exit_reason'] == 'roi'
|
||||||
assert res[0]['count'] == 1
|
assert res[0]['count'] == 1
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
assert res[0]['profit_pct'] == 10.0
|
||||||
|
|
||||||
trade.exit_reason = "TEST1"
|
assert res[1]['exit_reason'] == 'exit_signal'
|
||||||
res = rpc._rpc_exit_reason_performance(None)
|
assert res[2]['exit_reason'] == 'Other'
|
||||||
|
|
||||||
assert len(res) == 1
|
|
||||||
assert res[0]['exit_reason'] == 'TEST1'
|
|
||||||
assert res[0]['count'] == 1
|
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
|
||||||
|
|
||||||
|
|
||||||
def test_exit_reason_performance_handle_2(mocker, default_conf, markets, fee):
|
def test_exit_reason_performance_handle_2(mocker, default_conf, markets, fee):
|
||||||
@ -1053,8 +988,7 @@ def test_exit_reason_performance_handle_2(mocker, default_conf, markets, fee):
|
|||||||
assert prec_satoshi(res[0]['profit_pct'], 0.5)
|
assert prec_satoshi(res[0]['profit_pct'], 0.5)
|
||||||
|
|
||||||
|
|
||||||
def test_mix_tag_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
def test_mix_tag_performance_handle(default_conf, ticker, fee, mocker) -> None:
|
||||||
limit_sell_order, mocker) -> None:
|
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram', MagicMock())
|
||||||
mocker.patch.multiple(
|
mocker.patch.multiple(
|
||||||
'freqtrade.exchange.Exchange',
|
'freqtrade.exchange.Exchange',
|
||||||
@ -1068,35 +1002,14 @@ def test_mix_tag_performance_handle(default_conf, ticker, limit_buy_order, fee,
|
|||||||
rpc = RPC(freqtradebot)
|
rpc = RPC(freqtradebot)
|
||||||
|
|
||||||
# Create some test data
|
# Create some test data
|
||||||
freqtradebot.enter_positions()
|
create_mock_trades_usdt(fee)
|
||||||
trade = Trade.query.first()
|
|
||||||
assert trade
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_BUY order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
# Simulate fulfilled LIMIT_SELL order for trade
|
|
||||||
oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell')
|
|
||||||
trade.update_trade(oobj)
|
|
||||||
|
|
||||||
trade.close_date = datetime.utcnow()
|
|
||||||
trade.is_open = False
|
|
||||||
res = rpc._rpc_mix_tag_performance(None)
|
res = rpc._rpc_mix_tag_performance(None)
|
||||||
|
|
||||||
assert len(res) == 1
|
assert len(res) == 3
|
||||||
assert res[0]['mix_tag'] == 'Other Other'
|
assert res[0]['mix_tag'] == 'TEST3 roi'
|
||||||
assert res[0]['count'] == 1
|
assert res[0]['count'] == 1
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
assert res[0]['profit_pct'] == 10.0
|
||||||
|
|
||||||
trade.enter_tag = "TESTBUY"
|
|
||||||
trade.exit_reason = "TESTSELL"
|
|
||||||
res = rpc._rpc_mix_tag_performance(None)
|
|
||||||
|
|
||||||
assert len(res) == 1
|
|
||||||
assert res[0]['mix_tag'] == 'TESTBUY TESTSELL'
|
|
||||||
assert res[0]['count'] == 1
|
|
||||||
assert prec_satoshi(res[0]['profit_pct'], 6.2)
|
|
||||||
|
|
||||||
|
|
||||||
def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee):
|
def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee):
|
||||||
|
Loading…
Reference in New Issue
Block a user