forked from robcarver17/pysystemtrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposition_limits.py
98 lines (78 loc) · 3.1 KB
/
position_limits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
We want to limit the size of position we can take, both for a given strategy and across strategies
When we want to trade (create an instrument / strategy order) we check that the new net position
for that instrument (for the strategy, and across all strategies) doesn't exceed any limits
"""
from syscore.exceptions import missingData
from sysdata.base_data import baseData
from syslogging.logger import *
from sysobjects.production.position_limits import (
positionLimitForInstrument,
positionLimitForStrategyInstrument,
)
from sysobjects.production.tradeable_object import (
listOfInstrumentStrategies,
instrumentStrategy,
)
class positionLimitData(baseData):
def __init__(self, log=get_logger("Overrides")):
super().__init__(log=log)
def get_position_limit_object_for_instrument_strategy(
self, instrument_strategy: instrumentStrategy
) -> positionLimitForStrategyInstrument:
try:
position_limit = self._get_abs_position_limit_for_instrument_strategy(
instrument_strategy
)
except missingData:
position_limit_object = positionLimitForStrategyInstrument.no_limit(
instrument_strategy
)
else:
position_limit_object = positionLimitForStrategyInstrument(
instrument_strategy, position_limit
)
return position_limit_object
def get_position_limit_object_for_instrument(
self, instrument_code: str
) -> positionLimitForInstrument:
try:
position_limit = self._get_abs_position_limit_for_instrument(
instrument_code
)
except missingData:
position_limit_object = positionLimitForInstrument.no_limit(instrument_code)
else:
position_limit_object = positionLimitForInstrument(
instrument_code, position_limit
)
return position_limit_object
def _get_abs_position_limit_for_instrument_strategy(
self, instrument_strategy: instrumentStrategy
) -> int:
# return missing_data if no limit found
raise NotImplementedError
def _get_abs_position_limit_for_instrument(
self,
instrument_code: str,
) -> int:
# return missing_data if no limit found
raise NotImplementedError
def get_all_instruments_with_limits(self) -> list:
raise NotImplementedError
def get_all_instrument_strategies_with_limits(self) -> listOfInstrumentStrategies:
raise NotImplementedError
def set_position_limit_for_instrument_strategy(
self, instrument_strategy: instrumentStrategy, new_position_limit: int
):
raise NotImplementedError
def set_position_limit_for_instrument(
self, instrument_code: str, new_position_limit: int
):
raise NotImplementedError
def delete_position_limit_for_instrument_strategy(
self, instrument_strategy: instrumentStrategy
):
raise NotImplementedError
def delete_position_limit_for_instrument(self, instrument_code: str):
raise NotImplementedError