Added test data for buy_tag/sell_reason testing

This commit is contained in:
theluxaz
2021-10-27 01:29:19 +03:00
parent b51f946ee0
commit e4e75d4861
3 changed files with 242 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ from freqtrade.persistence import Trade
from freqtrade.persistence.pairlock_middleware import PairLocks
from freqtrade.rpc import RPC, RPCException
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
from tests.conftest import create_mock_trades, get_patched_freqtradebot, patch_get_signal
from tests.conftest import create_mock_trades, get_patched_freqtradebot, patch_get_signal, create_mock_trades_tags
# Functions for recurrent object patching
@@ -822,10 +822,11 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee,
trade.close_date = datetime.utcnow()
trade.is_open = False
res = rpc._rpc_performance()
print(str(res))
assert len(res) == 1
assert res[0]['pair'] == 'ETH/BTC'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit'], 6.2)
assert prec_satoshi(res[0]['profit'], 6.3)
# TEST FOR TRADES WITH NO BUY TAG
# TEST TRADE WITH ONE BUY_TAG AND OTHER TWO TRADES WITH THE SAME TAG
@@ -860,11 +861,43 @@ def test_buy_tag_performance_handle(default_conf, ticker, limit_buy_order, fee,
trade.close_date = datetime.utcnow()
trade.is_open = False
res = rpc._rpc_buy_tag_performance(None)
print(str(res))
assert len(res) == 1
assert res[0]['pair'] == 'ETH/BTC'
assert res[0]['buy_tag'] == 'Other'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit'], 6.2)
print(Trade.pair)
trade.buy_tag = "TEST_TAG"
res = rpc._rpc_buy_tag_performance(None)
print(str(res))
assert len(res) == 1
assert res[0]['buy_tag'] == 'TEST_TAG'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit'], 6.3)
def test_buy_tag_performance_handle2(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_tags(fee)
rpc = RPC(freqtradebot)
trades = Trade.query.all()
print(str(trades[0].buy_tag))
res = rpc._rpc_performance()
print(res)
assert len(trades) == 1
assert trades[0]['buy_tag'] == 'TEST_TAG'
assert trades[0]['count'] == 1
assert prec_satoshi(trades[0]['profit'], 6.3)
# TEST FOR TRADES WITH NO SELL REASON
# TEST TRADE WITH ONE SELL REASON AND OTHER TWO TRADES WITH THE SAME reason
# TEST THE SAME FOR A PAIR
@@ -899,9 +932,9 @@ def test_sell_reason_performance_handle(default_conf, ticker, limit_buy_order, f
trade.is_open = False
res = rpc._rpc_sell_reason_performance(None)
assert len(res) == 1
assert res[0]['pair'] == 'ETH/BTC'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit'], 6.2)
# assert res[0]['pair'] == 'ETH/BTC'
# assert res[0]['count'] == 1
# assert prec_satoshi(res[0]['profit'], 6.2)
# TEST FOR TRADES WITH NO TAGS
# TEST TRADE WITH ONE TAG MIX AND OTHER TWO TRADES WITH THE SAME TAG MIX
@@ -937,9 +970,9 @@ def test_mix_tag_performance_handle(default_conf, ticker, limit_buy_order, fee,
trade.is_open = False
res = rpc._rpc_mix_tag_performance(None)
assert len(res) == 1
assert res[0]['pair'] == 'ETH/BTC'
assert res[0]['count'] == 1
assert prec_satoshi(res[0]['profit'], 6.2)
# assert res[0]['pair'] == 'ETH/BTC'
# assert res[0]['count'] == 1
# assert prec_satoshi(res[0]['profit'], 6.2)
def test_rpc_count(mocker, default_conf, ticker, fee) -> None: