aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/ack_checker.py81
1 files changed, 36 insertions, 45 deletions
diff --git a/python/ack_checker.py b/python/ack_checker.py
index 5f984dd5..2250d8b9 100644
--- a/python/ack_checker.py
+++ b/python/ack_checker.py
@@ -1,8 +1,8 @@
-import codecs
import datetime
import re
from csv import reader
-from io import BytesIO
+from itertools import chain
+from io import BytesIO, TextIOWrapper
from serenitas.utils.remote import SftpClient, FtpClient
from serenitas.utils.db import dbconn
from serenitas.utils import SerenitasFileHandler
@@ -17,7 +17,7 @@ def serenitas_files(date):
buf = BytesIO()
ftp.client.retrbinary("RETR " + f, buf.write)
buf.seek(0)
- yield codecs.iterdecode(buf, "utf-8")
+ yield buf
def bowdst_files(date):
@@ -33,9 +33,8 @@ def ack_check(date: datetime.date, conn):
fh = SerenitasFileHandler("truload.log")
logger.addHandler(fh)
logger.setLevel(logging.INFO)
- files = list(serenitas_files(date)) + list(bowdst_files(date))
- for f in files:
- csv = reader(f)
+ for f in chain(serenitas_files(date), bowdst_files(date)):
+ csv = reader(TextIOWrapper(f))
for serenitas_id, action, dealtype, result, globeop_id, _, _ in csv:
if action == "NEW" and result == "Loaded":
# BOWDST globeop uses dealid with colon
@@ -45,46 +44,38 @@ def ack_check(date: datetime.date, conn):
globeop_id = int(globeop_id.split()[1])
if m := re.match("[^0-9]*([0-9]*)", serenitas_id):
serenitas_id = int(m.groups()[0])
- if dealtype == "CreditDefaultSwapDeal":
- with conn.cursor() as c:
- c.execute(
- "SELECT trade_date, orig_attach FROM cds WHERE id=%s",
- (serenitas_id,),
- )
- (trade_date, attach) = c.fetchone()
- if attach is None:
- continue
+ with conn.cursor() as c:
+ match dealtype:
+ case "CreditDefaultSwapDeal":
+ c.execute(
+ "SELECT trade_date, orig_attach FROM cds WHERE id=%s",
+ (serenitas_id,),
+ )
+ (trade_date, attach) = c.fetchone()
+ if attach is None:
+ continue
- with conn.cursor() as c:
- c.execute(
- "INSERT INTO id_mapping VALUES(%s, %s, %s, %s) "
- "ON CONFLICT DO NOTHING",
- (trade_date, "CDS", serenitas_id, globeop_id),
- )
- if dealtype == "SwaptionDeal":
- with conn.cursor() as c:
- c.execute(
- "UPDATE swaptions SET globeop_id=%s WHERE id=%s",
- (globeop_id, serenitas_id),
- )
- if dealtype == "ForwardDeal":
- with conn.cursor() as c:
- c.execute(
- "UPDATE spots SET globeop_id=%s WHERE id=%s",
- (globeop_id, serenitas_id),
- )
- if dealtype == "TotalReturnSwapDeal":
- with conn.cursor() as c:
- c.execute(
- "UPDATE trs SET globeop_id=%s WHERE id=%s",
- (globeop_id, serenitas_id),
- )
- if dealtype == "InterestRateSwapDeal":
- with conn.cursor() as c:
- c.execute(
- "UPDATE irs SET globeop_id=%s WHERE id=%s",
- (globeop_id, serenitas_id),
- )
+ c.execute(
+ "INSERT INTO id_mapping VALUES(%s, %s, %s, %s) "
+ "ON CONFLICT DO NOTHING",
+ (trade_date, "CDS", serenitas_id, globeop_id),
+ )
+ continue
+ case "SwaptionDeal":
+ table = "swaptions"
+ case "ForwardDeal":
+ table = "spots"
+ case "TotalReturnSwapDeal":
+ table = "trs"
+ case "InterestRateSwapDeal":
+ table = "irs"
+ case _:
+ logging.info(f"unkown {dealtype}")
+ continue
+ c.execute(
+ f"UPDATE {table} SET globeop_id=%s WHERE id=%s",
+ (globeop_id, serenitas_id),
+ )
elif action == "Failed":
logger.warning(f"{serenitas_id} ({action}): {globeop_id} ")
conn.commit()