Improve tests for trades_proxy
This commit is contained in:
parent
d1acc8092c
commit
0320c8dc92
@ -611,8 +611,7 @@ class LocalTrade():
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# Not used during backtesting, but might be used by a strategy
|
# Not used during backtesting, but might be used by a strategy
|
||||||
sel_trades = [trade for trade in LocalTrade.trades + LocalTrade.trades_open
|
sel_trades = [trade for trade in LocalTrade.trades + LocalTrade.trades_open]
|
||||||
if trade.is_open == is_open]
|
|
||||||
|
|
||||||
if pair:
|
if pair:
|
||||||
sel_trades = [trade for trade in sel_trades if trade.pair == pair]
|
sel_trades = [trade for trade in sel_trades if trade.pair == pair]
|
||||||
|
@ -29,6 +29,7 @@ def mock_trade_1(fee):
|
|||||||
fee_open=fee.return_value,
|
fee_open=fee.return_value,
|
||||||
fee_close=fee.return_value,
|
fee_close=fee.return_value,
|
||||||
is_open=True,
|
is_open=True,
|
||||||
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=17),
|
||||||
open_rate=0.123,
|
open_rate=0.123,
|
||||||
exchange='bittrex',
|
exchange='bittrex',
|
||||||
open_order_id='dry_run_buy_12345',
|
open_order_id='dry_run_buy_12345',
|
||||||
@ -183,6 +184,7 @@ def mock_trade_4(fee):
|
|||||||
amount_requested=124.0,
|
amount_requested=124.0,
|
||||||
fee_open=fee.return_value,
|
fee_open=fee.return_value,
|
||||||
fee_close=fee.return_value,
|
fee_close=fee.return_value,
|
||||||
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=14),
|
||||||
is_open=True,
|
is_open=True,
|
||||||
open_rate=0.123,
|
open_rate=0.123,
|
||||||
exchange='bittrex',
|
exchange='bittrex',
|
||||||
@ -234,6 +236,7 @@ def mock_trade_5(fee):
|
|||||||
amount_requested=124.0,
|
amount_requested=124.0,
|
||||||
fee_open=fee.return_value,
|
fee_open=fee.return_value,
|
||||||
fee_close=fee.return_value,
|
fee_close=fee.return_value,
|
||||||
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=12),
|
||||||
is_open=True,
|
is_open=True,
|
||||||
open_rate=0.123,
|
open_rate=0.123,
|
||||||
exchange='bittrex',
|
exchange='bittrex',
|
||||||
@ -284,6 +287,7 @@ def mock_trade_6(fee):
|
|||||||
stake_amount=0.001,
|
stake_amount=0.001,
|
||||||
amount=2.0,
|
amount=2.0,
|
||||||
amount_requested=2.0,
|
amount_requested=2.0,
|
||||||
|
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=5),
|
||||||
fee_open=fee.return_value,
|
fee_open=fee.return_value,
|
||||||
fee_close=fee.return_value,
|
fee_close=fee.return_value,
|
||||||
is_open=True,
|
is_open=True,
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# pragma pylint: disable=missing-docstring, C0103
|
# pragma pylint: disable=missing-docstring, C0103
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
@ -1044,6 +1045,7 @@ def test_fee_updated(fee):
|
|||||||
def test_total_open_trades_stakes(fee, use_db):
|
def test_total_open_trades_stakes(fee, use_db):
|
||||||
|
|
||||||
Trade.use_db = use_db
|
Trade.use_db = use_db
|
||||||
|
Trade.reset_trades()
|
||||||
res = Trade.total_open_trades_stakes()
|
res = Trade.total_open_trades_stakes()
|
||||||
assert res == 0
|
assert res == 0
|
||||||
create_mock_trades(fee, use_db)
|
create_mock_trades(fee, use_db)
|
||||||
@ -1053,6 +1055,26 @@ def test_total_open_trades_stakes(fee, use_db):
|
|||||||
Trade.use_db = True
|
Trade.use_db = True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
|
@pytest.mark.parametrize('use_db', [True, False])
|
||||||
|
def test_get_trades_proxy(fee, use_db):
|
||||||
|
Trade.use_db = use_db
|
||||||
|
Trade.reset_trades()
|
||||||
|
create_mock_trades(fee, use_db)
|
||||||
|
trades = Trade.get_trades_proxy()
|
||||||
|
assert len(trades) == 6
|
||||||
|
|
||||||
|
assert isinstance(trades[0], Trade)
|
||||||
|
|
||||||
|
assert len(Trade.get_trades_proxy(is_open=True)) == 4
|
||||||
|
assert len(Trade.get_trades_proxy(is_open=False)) == 2
|
||||||
|
opendate = datetime.now(tz=timezone.utc) - timedelta(minutes=15)
|
||||||
|
|
||||||
|
assert len(Trade.get_trades_proxy(open_date=opendate)) == 3
|
||||||
|
|
||||||
|
Trade.use_db = True
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("init_persistence")
|
@pytest.mark.usefixtures("init_persistence")
|
||||||
def test_get_overall_performance(fee):
|
def test_get_overall_performance(fee):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user