aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/citco_ops/utils.py41
1 files changed, 38 insertions, 3 deletions
diff --git a/python/citco_ops/utils.py b/python/citco_ops/utils.py
index c60cc20f..bea90d95 100644
--- a/python/citco_ops/utils.py
+++ b/python/citco_ops/utils.py
@@ -14,6 +14,32 @@ def get_file_status(s):
return is_processed, fname_short
+def get_success_data(line):
+ if line["Internal_Order_Id"]: # This is a trade
+ identifier_type = "trade"
+ serenitas_id = line["External_Order_Id"]
+ identifier = line["Internal_Order_Id"]
+ else:
+ identifier_type = "instrument"
+ serenitas_id = line["External_Security_Id"]
+ identifier = line["Internal_Security_Id"]
+ return identifier_type, serenitas_id, identifier
+
+
+def get_failed_data(line):
+
+ if len(line) == 1:
+ return ("failed", line[-1])
+ elif line[1]: # Trade upload
+ return ("trade", line[2])
+ elif (
+ not line[1] and line[2]
+ ): # Instrument upload, just mark as failed if it's a single error message
+ return ("instrument", line[2])
+ else:
+ return ("failed", line[-1])
+
+
@dataclass
class CitcoSubmission(
Deal, deal_type=None, table_name="citco_submission", insert_ignore=("submit_date",)
@@ -26,11 +52,20 @@ class CitcoSubmission(
@classmethod
def from_citco_line(line, fname):
-
- return cls()
+ is_processed, fname_short = get_file_status(fname)
+ if is_processed:
+ identifier_type, serenitas_id, identifier = get_data(line)
+ else:
+ None
+ return cls(
+ fname=fname_short,
+ identifier_type=identifier_type,
+ identifier=identifier,
+ serenitas_id=serenitas_id,
+ )
@classmethod
def process(fh, fname):
- for row in csv.DictReader(file_handle):
+ for row in csv.reader(file_handle):
trade = cls.from_citco_line(line, fname)
trade.stage()