aboutsummaryrefslogtreecommitdiffstats
path: root/python/book_bbg.py
blob: a0c6d9a8be030c659f4039293c07fc841fc1e928 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from serenitas.utils.remote import SftpClient
from trade_dataclasses import Deal, DealType, BbgDeal
from stat import S_ISREG
import re
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 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()