aboutsummaryrefslogtreecommitdiffstats
path: root/python/book_bbg.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/book_bbg.py')
-rw-r--r--python/book_bbg.py24
1 files changed, 15 insertions, 9 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")