diff options
Diffstat (limited to 'python/book_bbg.py')
| -rw-r--r-- | python/book_bbg.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/python/book_bbg.py b/python/book_bbg.py new file mode 100644 index 00000000..bd817377 --- /dev/null +++ b/python/book_bbg.py @@ -0,0 +1,45 @@ +from serenitas.utils.env import DAILY_DIR +from serenitas.utils.remote import SftpClient +import datetime +import pytz +from stat import S_ISREG +import csv + + +def download_files(date): + downloaded_files = [] + sftp = SftpClient.from_creds("bbg") + dst = DAILY_DIR / f"{date:%Y-%m-%d}" / "bbg_tickets" + if not dst.exists(): + dst.mkdir() + est = pytz.timezone("US/Eastern") + src = "" + for f in sftp.client.listdir_iter(): + if S_ISREG(f.st_mode): + local_file = dst / f.filename + modification_time = datetime.datetime.fromtimestamp( + f.st_mtime, tz=datetime.timezone.utc + ).astimezone(est) + if not local_file.exists() and (modification_time.date() == date): + sftp.client.get(f"{src}/{f.filename}", localpath=local_file) + downloaded_files.append(local_file) + return downloaded_files + + +def cdx_booking_process(path): + reader = csv.DictReader(open(path)) + for csvdict in reader: + breakpoint() + pass + + +def book_trades(date): + downloaded_files = download_files(date) + if downloaded_files: + for f in downloaded_files: + if "CDX" in f.name: + cdx_booking_process(f) + + +if __name__ == "__main__": + book_trades(datetime.date(2022, 2, 4)) |
