aboutsummaryrefslogtreecommitdiffstats
path: root/python/collateral/baml_fcm.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/collateral/baml_fcm.py')
-rw-r--r--python/collateral/baml_fcm.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/python/collateral/baml_fcm.py b/python/collateral/baml_fcm.py
index 245c1a30..7508aad1 100644
--- a/python/collateral/baml_fcm.py
+++ b/python/collateral/baml_fcm.py
@@ -8,10 +8,16 @@ logger = logging.getLogger(__name__)
def download_files(*args, fund="Serenitas", **kwargs):
- if fund != "Serenitas":
+ if fund not in ("Serenitas", "Selene"):
return
sftp = SftpClient.from_creds("baml_fcm")
- sftp.download_files("outgoing", DAILY_DIR / fund / "BAML_reports")
+ if fund == "Serenitas":
+ filters = (lambda s: "Selene" not in s.filename,)
+ elif fund == "Selene":
+ filters = (lambda s: "Selene" in s.filename,)
+ sftp.download_files(
+ "outgoing", DAILY_DIR / fund / "BAML_reports", additional_filters=filters
+ )
def load_csv(file_type, fund, d, **kwargs):
@@ -120,8 +126,9 @@ def collateral(d, positions, *, engine, fund="Serenitas", positions_irs, **kwarg
"Initial Margin Requirement",
"Margin Excess/Deficit",
]
+ tag = "Selene_" if fund == "Selene" else ""
df_margin = pd.read_csv(
- DAILY_DIR / fund / "BAML_reports" / f"OTC_Moneyline_{d:%Y%m%d}.CSV",
+ DAILY_DIR / fund / "BAML_reports" / f"OTC_Moneyline_{tag}{d:%Y%m%d}.CSV",
usecols=col_names,
parse_dates=["Statement Date"],
index_col=["Statement Date"],
@@ -143,15 +150,21 @@ def collateral(d, positions, *, engine, fund="Serenitas", positions_irs, **kwarg
df_margin_fut.AT = "USD"
df_margin_fut = df_margin_fut.reset_index()
col_names.pop(2)
+ accounts = {
+ "Serenitas": ("V0NSCLMFCM", "MLNSCLMAFU"),
+ "Selene": ("6MZ20K79", ""),
+ }
+ df_margin["account"], df_margin_fut["account"] = accounts[fund]
+ col_names.insert(1, "account")
try:
- place_holders = ",".join(["%s"] * (len(col_names) - 1))
+ place_holders = ",".join(["%s"] * len(col_names))
with engine.connect() as conn:
conn.execute(
- f"INSERT INTO fcm_moneyline VALUES(%s, 'V0NSCLMFCM', {place_holders})",
+ f"INSERT INTO fcm_moneyline VALUES({place_holders})",
list(df_margin[col_names].itertuples(index=False)),
)
conn.execute(
- f"INSERT INTO fcm_moneyline VALUES(%s, 'MLNSCLMAFU', {place_holders})",
+ f"INSERT INTO fcm_moneyline VALUES({place_holders})",
list(df_margin_fut[col_names].itertuples(index=False)),
)
except IntegrityError as e: