diff options
Diffstat (limited to 'python/book_bbg.py')
| -rw-r--r-- | python/book_bbg.py | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py index e12646cb..a0c6d9a8 100644 --- a/python/book_bbg.py +++ b/python/book_bbg.py @@ -1,32 +1,24 @@ from serenitas.utils.remote import SftpClient from trade_dataclasses import Deal, DealType, BbgDeal -import csv from stat import S_ISREG +import re +import time -def trade_booking_process(file_handle, index, asset_class): - deal = Deal[DealType(asset_class)] - for row in csv.DictReader(file_handle): - line = {"bbg_ticket_id": index, **row} - trade = deal.from_bbg_line(line) - trade.stage() - deal.commit() - - -def get_bbg_id(name): - return name.split("_", 1)[1] - - -if __name__ == "__main__": - import time - +def run(): sftp = SftpClient.from_creds("bbg") while True: for f in sftp.client.listdir_iter("/"): if S_ISREG(f.st_mode): - if (bbg_id := get_bbg_id(f.filename)) not in BbgDeal._cache: - with sftp.client.open(f.filename) as fh: - trade_booking_process(fh, bbg_id, f.filename.split("-", 1)[0]) - BbgDeal._cache[bbg_id] = None + 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 time.sleep(60) + + +if __name__ == "__main__": + run() |
