aboutsummaryrefslogtreecommitdiffstats
path: root/python/collateral
diff options
context:
space:
mode:
Diffstat (limited to 'python/collateral')
-rw-r--r--python/collateral/wells.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/python/collateral/wells.py b/python/collateral/wells.py
index 08760d60..8f6e6f5d 100644
--- a/python/collateral/wells.py
+++ b/python/collateral/wells.py
@@ -97,20 +97,25 @@ def collateral(d, positions, *, engine, **kwargs):
"CURRENT_IM",
"CURRENT_EXCESS_DEFICIT",
]
+ update_cols = [c.lower() for c in table_cols[2:]]
if "VALUE_DATE" in df_margin:
df_margin.VALUE_DATE = pd.to_datetime(df_margin.VALUE_DATE)
+ df_margin["CURRENT_EXCESS_DEFICIT"] += df_margin["PENDING_AMOUNT"]
else:
df_margin["Value Date"] = pd.to_datetime(df_margin["Value Date"])
table_cols = [c.replace("_", " ").title() for c in table_cols]
table_cols[-2] = "Current IM"
- try:
- place_holders = ",".join(["%s"] * (len(table_cols) - 1))
- with engine.connect() as conn:
- conn.execute(
- f"INSERT INTO fcm_moneyline VALUES(%s, 'WFNSCLMFCM', {place_holders})",
- list(df_margin[table_cols].itertuples(index=False)),
- )
- except IntegrityError:
- pass
+ df_margin["Current Excess Deficit"] += df_margin["Pending Amount"]
+ place_holders = ",".join(["%s"] * (len(table_cols) - 1))
+ # pomme = (f"INSERT INTO fcm_moneyline VALUES(%s, 'WFNSCLMFCM', {place_holders})"
+ # f"ON CONFLICT (date, account, currency) DO UPDATE "
+ # f"({','.join(update_cols)}) = ({','.join(['EXCLUDED.'+c for c in update_cols])}))
+ with engine.connect() as conn:
+ conn.execute(
+ f"INSERT INTO fcm_moneyline VALUES(%s, 'WFNSCLMFCM', {place_holders})"
+ f"ON CONFLICT (date, account, currency) DO UPDATE SET "
+ f"({','.join(update_cols)}) = ({','.join(['EXCLUDED.'+c for c in update_cols])})",
+ list(df_margin[table_cols].itertuples(index=False)),
+ )
df["date"] = d
return df.set_index("Strategy")