aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/collateral_calc.py34
1 files changed, 25 insertions, 9 deletions
diff --git a/python/collateral_calc.py b/python/collateral_calc.py
index 4000fc88..cc73a3f6 100644
--- a/python/collateral_calc.py
+++ b/python/collateral_calc.py
@@ -2,21 +2,37 @@ from exchange import get_msgs, get_account
from exchangelib import Mailbox, Message, HTMLBody
from ftplib import FTP
from pathlib import Path
+from time import sleep
import os
import pandas as pd
from pandas.tseries.offsets import BDay
DAILY_DIR = Path(os.environ["DAILY_DIR"])
-def download_files():
+def download_files(d=None):
DATA_DIR = DAILY_DIR / "SG_reports"
- ftp = FTP('ftp.newedgegroup.com')
- ftp.login('SerenitasGamma@USA', "SSqrrLL99")
- ftp.cwd('OTC')
- for f in ftp.nlst():
- if f.endswith("csv") and (("OTC_CASH_ACTIVITY" in f) or ("OTC_POSITIONS" in f)):
- with open(DATA_DIR / f, "wb") as fh:
- ftp.retrbinary('RETR ' + f, fh.write)
+ with FTP('ftp.newedgegroup.com') as ftp:
+ ftp.login('SerenitasGamma@USA', "SSqrrLL99")
+ ftp.cwd('OTC')
+ if d is None:
+ for f in ftp.nlst():
+ if f.endswith("csv") and (("OTC_CASH_ACTIVITY" in f) or ("OTC_POSITIONS" in f)):
+ with open(DATA_DIR / f, "wb") as fh:
+ ftp.retrbinary('RETR ' + f, fh.write)
+ else:
+ i = 0
+ while i <= 20:
+ i +=1
+ file_list = ftp.nlst()
+ for report_type in ["OTC_CASH_ACTIVITY", "OTC_POSITIONS"]:
+ f = f"{d:%Y%m%d}_{report_type}.csv"
+ if f not in file_list:
+ sleep(500)
+ break
+ with open(DATA_DIR / f, "wb") as fh:
+ ftp.retrbinary('RETR ' + f, fh.write)
+ else:
+ break
def download_emails():
emails = get_msgs(path=["NYops"], subject_filter="SERCX **Daily")
@@ -79,8 +95,8 @@ def send_email(account, df_ms, df_sg):
if __name__ == "__main__":
download_emails()
- download_files()
d = (pd.Timestamp.today() - BDay()).normalize()
+ download_files(d)
df_ms = ms_collateral(d - BDay())
df_sg = sg_collateral(d)
account = get_account('ghorel@lmcg.com')