|
|
@ -2,7 +2,7 @@ import pytest |
|
|
|
from pandas import DataFrame # type: ignore |
|
|
|
|
|
|
|
from auto_trading.ptf.in_memory import InMemoryPortfolio |
|
|
|
from auto_trading.interfaces import PTFState as State |
|
|
|
from auto_trading.errors import PTFException |
|
|
|
from auto_trading.orders import Long, Short |
|
|
|
|
|
|
|
|
|
|
@ -26,3 +26,20 @@ def test_execute( |
|
|
|
ptf.execute_multiples([order]) |
|
|
|
assert ptf._stocks == stop_stocks |
|
|
|
assert ptf._balance == stop_balance |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
"change_rate, stocks, balance, order, msg", |
|
|
|
[ |
|
|
|
({"AAPL": 10}, {"AAPL": 0}, 0, Short("AAPL", 1, 10), "Not enough stock."), |
|
|
|
({"AAPL": 10}, {"AAPL": 10}, 0, Short("AAPL", 1, 15), "You shell it too high."), |
|
|
|
({"AAPL": 10}, {"AAPL": 0}, 0, Long("AAPL", 1, 10), "Not enough money."), |
|
|
|
({"AAPL": 10}, {"AAPL": 0}, 100, Long("AAPL", 1, 5), "You buy it too low."), |
|
|
|
], |
|
|
|
) |
|
|
|
def test_raises(change_rate, stocks, balance, order, msg): |
|
|
|
ptf = InMemoryPortfolio(skip_errors=False, change_rate_getter=lambda: change_rate) |
|
|
|
ptf._stocks = stocks |
|
|
|
ptf._balance = balance |
|
|
|
with pytest.raises(PTFException, match=f"Got and order exception : {msg}"): |
|
|
|
ptf.execute_multiples([order]) |
|
|
|