diff options
| -rw-r--r-- | python/book_bbg.py | 20 | ||||
| -rw-r--r-- | scripts/book_bbg.service | 4 |
2 files changed, 13 insertions, 11 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py index 0f5c6990..4856ae5d 100644 --- a/python/book_bbg.py +++ b/python/book_bbg.py @@ -1,10 +1,9 @@ from serenitas.utils.remote import SftpClient import datetime import csv -from trade_dataclasses import CDSDeal, BondDeal +from trade_dataclasses import CDSDeal, BondDeal, BbgDeal, _funds, _cdx_cp, _fcms from decimal import Decimal from stat import S_ISREG -from psycopg2.errors import UniqueViolation def get_indic_data(conn, redcode, tenor): @@ -21,8 +20,6 @@ def get_indic_data(conn, redcode, tenor): def cdx_booking_process(path, conn): reader = csv.DictReader(path) for line in reader: - tenor = line["Security"].rsplit(" ", 1)[-1].lower() + "r" - maturity, coupon = get_indic_data(conn, tenor, line["Red Code"]) trade = CDSDeal( fund=_funds[line["Account"]], folder="*", @@ -31,9 +28,9 @@ def cdx_booking_process(path, conn): security_desc=line["Security"].removesuffix(" PRC"), traded_level=Decimal(line["Price (Dec)"]), notional=line["Quantity"], - fixed_rate=coupon * 0.01, + fixed_rate=float(line["Coupon"]) * 0.01, trade_date=datetime.datetime.strptime(line["Trade Dt"], "%m/%d/%Y").date(), - maturity=maturity, + maturity=datetime.datetime.strptime(line["Mat Dt"], "%m/%d/%Y").date(), currency=line["Curncy"], protection="Buyer" if line["Side"] == "B" else "Seller", upfront=line["Principal"], @@ -59,13 +56,14 @@ def get_bbg_id(name): if __name__ == "__main__": import time + booker = {"BOND": bond_booking_process, "CDX": cdx_booking_process} sftp = SftpClient.from_creds("bbg") while True: for f in sftp.client.listdir_iter("/"): if S_ISREG(f.st_mode): - if "BOND" in f.filename: - 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) - BondDeal._cache[f.filename] = None + if (bbg_id := get_bbg_id(f.filename)) not in BbgDeal._cache: + with sftp.client.open(f.filename) as fh: + booker[f.filename.split("-", 1)[0]](fh, bbg_id) + BbgDeal._cache[bbg_id] = None + time.sleep(60) diff --git a/scripts/book_bbg.service b/scripts/book_bbg.service index 88a1bbad..7439a800 100644 --- a/scripts/book_bbg.service +++ b/scripts/book_bbg.service @@ -1,5 +1,6 @@ [Unit] Description=Autobook bond and cds trades from bloomberg sftp +After=network.target postgresql.service [Service] Type=simple @@ -8,3 +9,6 @@ Group=guillaume ExecStart=/usr/bin/python book_bbg.py WorkingDirectory=/home/guillaume/projects/code/python EnvironmentFile=/etc/serenitas.conf + +[Install] +WantedBy=default.target |
