blob: fae9dd97ad6c25532d2491a9e26983f2d674b9c4 (
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
25
26
27
|
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:
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
except OSError:
sftp.client.close()
sftp = SftpClient.from_creds("bbg")
time.sleep(60)
if __name__ == "__main__":
run()
|