diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/book_bbg.py | 9 | ||||
| -rw-r--r-- | python/trade_dataclasses.py | 9 |
2 files changed, 9 insertions, 9 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py index ddab7f7b..0f5c6990 100644 --- a/python/book_bbg.py +++ b/python/book_bbg.py @@ -49,13 +49,7 @@ def bond_booking_process(file_handle, index): line = {"bbg_ticket_id": index, **row} trade = BondDeal.from_bbg_line(line) trade.stage() - try: - BondDeal.commit() - except UniqueViolation as e: - print(e) - BondDeal._conn.rollback() - BondDeal._bbg_insert_queue.clear() - BondDeal._insert_queue.clear() + BondDeal.commit() def get_bbg_id(name): @@ -70,7 +64,6 @@ if __name__ == "__main__": for f in sftp.client.listdir_iter("/"): if S_ISREG(f.st_mode): if "BOND" in f.filename: - print(BondDeal._cache) if (bbg_id := get_bbg_id(f.filename)) not in BondDeal._cache: with sftp.client.open(f.filename) as fh: bond_booking_process(fh, bbg_id) diff --git a/python/trade_dataclasses.py b/python/trade_dataclasses.py index 9f89a223..af0790c4 100644 --- a/python/trade_dataclasses.py +++ b/python/trade_dataclasses.py @@ -10,6 +10,8 @@ from serenitas.analytics.index import CreditIndex from serenitas.utils.db import dbconn from process_queue import rename_keys from lru import LRU +from psycopg2.errors import UniqueViolation +import logging Fund = Literal["SERCGMAST", "BRINKER", "BOWDST"] Portfolio = Literal[ @@ -211,7 +213,12 @@ class BbgDeal(Deal): with cls._conn.cursor() as c: c.executemany(cls._bbg_sql_insert, cls._bbg_insert_queue) c.executemany(cls._sql_insert, cls._insert_queue) - cls._conn.commit() + try: + cls._conn.commit() + except UniqueViolation as e: + logger = logging.getLogger(__name__) + logger.warning(e) + cls._conn.rollback() cls._bbg_insert_queue.clear() cls._insert_queue.clear() |
