You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
70 lines
1.5 KiB
import pytest
|
|
from datetime import datetime
|
|
|
|
from auto_trading.errors import UnknowOrder
|
|
from auto_trading.interfaces import PTF
|
|
from auto_trading.orders import Short, Long
|
|
|
|
long_order = Long(datetime.now(), "BTC", 1, 1)
|
|
short_order = Short(datetime.now(), "GOLD", 1, 1)
|
|
|
|
|
|
class _TestPTFLong(PTF):
|
|
@property
|
|
def balance(self):
|
|
return 0
|
|
|
|
def execute_long(self, order: Long) -> None:
|
|
assert order == long_order
|
|
|
|
executors = {Long: execute_long}
|
|
|
|
|
|
class _TestPTFLongShort(PTF):
|
|
@property
|
|
def balance(self):
|
|
return 0
|
|
|
|
def execute_long(self, order: Long) -> None:
|
|
assert order == long_order
|
|
|
|
def execute_short(self, order: Long) -> None:
|
|
assert order == short_order
|
|
|
|
executors = {Long: execute_long, Short: execute_short}
|
|
|
|
|
|
class _TestPTFShort(PTF):
|
|
@property
|
|
def balance(self):
|
|
return 0
|
|
|
|
def execute_short(self, order: Long) -> None:
|
|
assert order == short_order
|
|
|
|
executors = {Short: execute_short}
|
|
|
|
|
|
class _TestPTFNone(PTF):
|
|
@property
|
|
def balance(self):
|
|
return 0
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"test_class, must_match",
|
|
[
|
|
(_TestPTFLong, [long_order]),
|
|
(_TestPTFShort, [short_order]),
|
|
(_TestPTFLongShort, [long_order, short_order]),
|
|
(_TestPTFNone, []),
|
|
],
|
|
)
|
|
def test_ptf_execution(test_class, must_match):
|
|
inst = test_class()
|
|
for o in [short_order, long_order]:
|
|
if o in must_match:
|
|
inst._execute(o)
|
|
else:
|
|
with pytest.raises(UnknowOrder):
|
|
inst._execute(o)
|
|
|