Skip to content

Commit 2f70f87

Browse files
author
rob
committed
2 parents a4eae20 + af44305 commit 2f70f87

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

sysdata/production/TEMP_old_capital_objects.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import datetime
33
import pandas as pd
44

5+
from syscore.exceptions import missingData
56
from syscore.objects import arg_not_supplied, failure, missing_data
67
from syscore.pandas.pdutils import uniquets
78

@@ -81,8 +82,9 @@ def get_current_pandl_account(self) -> float:
8182
return self.get_current_capital_for_strategy(ACC_PROFIT_VALUES)
8283

8384
def get_current_capital_for_strategy(self, strategy_name: str) -> float:
84-
current_capital_entry = self.get_last_entry_for_strategy(strategy_name)
85-
if current_capital_entry is missing_data:
85+
try:
86+
current_capital_entry = self.get_last_entry_for_strategy(strategy_name)
87+
except missingData:
8688
return missing_data
8789

8890
capital_value = current_capital_entry.capital_value
@@ -92,8 +94,9 @@ def get_current_capital_for_strategy(self, strategy_name: str) -> float:
9294
def get_date_of_last_entry_for_strategy(
9395
self, strategy_name: str
9496
) -> datetime.datetime:
95-
current_capital_entry = self.get_last_entry_for_strategy(strategy_name)
96-
if current_capital_entry is missing_data:
97+
try:
98+
current_capital_entry = self.get_last_entry_for_strategy(strategy_name)
99+
except missingData:
97100
return missing_data
98101

99102
entry_date = current_capital_entry.date

sysdata/production/historic_positions.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pandas as pd
22

33
from syscore.exceptions import missingData
4-
from syscore.objects import arg_not_supplied, missing_data
4+
from syscore.objects import arg_not_supplied
55
from sysobjects.contracts import futuresContract, listOfFuturesContracts
66

77
from sysdata.production.timed_storage import (
@@ -71,10 +71,13 @@ def get_current_position_for_instrument_strategy_object(
7171
self, instrument_strategy: instrumentStrategy
7272
) -> int:
7373

74-
position_entry = self.get_current_position_entry_for_instrument_strategy_object(
75-
instrument_strategy
76-
)
77-
if position_entry is missing_data:
74+
try:
75+
position_entry = (
76+
self.get_current_position_entry_for_instrument_strategy_object(
77+
instrument_strategy
78+
)
79+
)
80+
except missingData:
7881
return 0
7982
else:
8083
# ignore warning it's because we dynamically assign attributes
@@ -275,10 +278,11 @@ def get_position_as_df_for_contract_object(self, contract_object: futuresContrac
275278
return df_object
276279

277280
def get_current_position_for_contract_object(self, contract_object):
278-
position_entry = self.get_current_position_entry_for_contract_object(
279-
contract_object
280-
)
281-
if position_entry is missing_data:
281+
try:
282+
position_entry = self.get_current_position_entry_for_contract_object(
283+
contract_object
284+
)
285+
except missingData:
282286
return 0.0
283287

284288
return position_entry.position

sysobjects/production/timed_storage.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pandas as pd
55

66
from syscore.exceptions import missingData
7-
from syscore.objects import success, arg_not_supplied, missing_data
7+
from syscore.objects import success, arg_not_supplied
88

99
DATE_KEY_NAME = "date"
1010

@@ -221,13 +221,13 @@ def sort(self):
221221

222222
def final_entry(self):
223223
if len(self) == 0:
224-
return missing_data
224+
raise missingData
225225
self.sort()
226226
return self[-1]
227227

228228
def append(self, item):
229-
previous_final_entry = self.final_entry()
230229
if len(self) > 0:
230+
previous_final_entry = self.final_entry()
231231
try:
232232
previous_final_entry.check_args_match(item)
233233
except Exception as e:

0 commit comments

Comments
 (0)