diff options
| -rw-r--r-- | python/book_bbg.py | 24 | ||||
| -rw-r--r-- | python/headers.py | 2 | ||||
| -rw-r--r-- | python/trade_dataclasses.py | 6 |
3 files changed, 19 insertions, 13 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py index 831592a9..33851193 100644 --- a/python/book_bbg.py +++ b/python/book_bbg.py @@ -1,25 +1,31 @@ from serenitas.utils.remote import SftpClient -from trade_dataclasses import Deal, DealType, BbgDeal, FxswapDeal +from trade_dataclasses import Deal, DealType, BbgDeal from stat import S_ISREG import re import time +def get_bbg_id(s): + if m := re.match("(CDX|BOND)-[^_]*_([^$]*)", s): + return m.groups() + if "DEAL" in s: + return "FXSWAP", s.split("_")[3] + + def run(): sftp = SftpClient.from_creds("bbg") while True: try: for f in sftp.client.listdir_iter("/"): if S_ISREG(f.st_mode): - if m := re.match("(CDX|BOND)-[^_]*_([^$]*)", f.filename): - deal_type, bbg_id = m.groups() - if bbg_id not in BbgDeal._cache: - with sftp.client.open(f.filename) as fh: - Deal[DealType(deal_type)].process(fh, bbg_id) - BbgDeal._cache[bbg_id] = None - elif 'DEAL' in f.filename: + try: + deal_type, bbg_id = get_bbg_id(f.filename) + except TypeError: + continue + if bbg_id not in BbgDeal._cache: with sftp.client.open(f.filename) as fh: - FxswapDeal.process(fh, f.filename.split('_')[3]) + Deal[DealType(deal_type)].process(fh, bbg_id) + BbgDeal._cache[bbg_id] = None except OSError: sftp.client.close() sftp = SftpClient.from_creds("bbg") diff --git a/python/headers.py b/python/headers.py index e087e726..0c96f759 100644 --- a/python/headers.py +++ b/python/headers.py @@ -8,7 +8,7 @@ class DealType(Enum): Swaption = "SWAPTION" Termination = "TERM" Spot = "SPOT" - Fxswap = "FXSWAP" + FxSwap = "FXSWAP" HEADERS_PRE = [ diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py index 7986a623..d61dea5e 100644 --- a/python/trade_dataclasses.py +++ b/python/trade_dataclasses.py @@ -294,7 +294,7 @@ class BbgDeal: cls._bbg_sql_insert = ( f"INSERT INTO cds_tickets VALUES({','.join(['%s'] * 22)})" ) - elif deal_type == DealType.Fxswap: + elif deal_type == DealType.FxSwap: cls._bbg_sql_insert = ( f"INSERT INTO fx_tickets VALUES({','.join(['%s'] * 211)})" ) @@ -732,10 +732,10 @@ _fx_accounts = {"serenitas": "V0NSCLMAMB", "bowdst": "319478"} @dataclass -class FxswapDeal( +class FxSwapDeal( BbgDeal, Deal, - deal_type=DealType.Fxswap, + deal_type=DealType.FxSwap, table_name="fx_swaps", insert_ignore=("id", "dealid"), ): |
