diff options
Diffstat (limited to 'python/markit/cds.py')
| -rw-r--r-- | python/markit/cds.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/python/markit/cds.py b/python/markit/cds.py index 459d6340..80c7f8d2 100644 --- a/python/markit/cds.py +++ b/python/markit/cds.py @@ -16,15 +16,18 @@ def convertToNone(v): return v if v else None
-def download_cds_data(payload):
+def download_cds_data(payload, workdate):
r = requests.post("https://www.markit.com/export.jsp", params=payload)
content = io.BytesIO(r.content)
+ save_dir = BASE_DIR / "Tranche_data" / "CDS" / f"{workdate:%Y}"
+ if not save_dir.exists():
+ save_dir.mkdir()
+ csv_file = save_dir / f"{workdate}_fixed.csv"
try:
with zipfile.ZipFile(content) as z:
- fname = BASE_DIR / "Tranche_data" / "CDS" / f"cds eod {payload['date']}.csv"
- with fname.open("wb") as f2:
+ with csv_file.open("wb") as f2:
for f in z.namelist():
- if "csv" in f:
+ if f.endswith("csv"):
f1 = z.open(f)
next(f1)
next(f1)
@@ -34,10 +37,11 @@ def download_cds_data(payload): logger.error(content.getvalue().decode())
-def download_composite_data(payload, historical=False):
+def download_composite_data(payload, workdate, historical=False):
# if historical, we want to maintain the invariant mtime(f)== payload['date'] + BDay(1)
if historical:
- ts = (pd.Timestamp(payload["date"]) + BDay(1)).timestamp()
+ ts = (workdate + BDay(1)).timestamp()
+
for report in ["COMPOSITES", "TRANCHE_COMPOSITES"]:
for family in ["CDX", "ITRAXX-EUROPE"]:
payload.update({"family": family, "report": report})
@@ -46,7 +50,7 @@ def download_composite_data(payload, historical=False): try:
with zipfile.ZipFile(io.BytesIO(r.content)) as z:
for f in z.namelist():
- if "csv" in f:
+ if f.endswith("csv"):
path = z.extract(
f,
path=os.path.join(
|
