aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/baml_fcm_fx.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/python/baml_fcm_fx.py b/python/baml_fcm_fx.py
index 4d06991f..2ac9af9b 100644
--- a/python/baml_fcm_fx.py
+++ b/python/baml_fcm_fx.py
@@ -3,17 +3,38 @@ from report_ops.utils import BamlFcmNotify
from serenitas.utils.db2 import dbconn
from tabulate import tabulate
+_fcm_alias = {"V0NSCLMSPT": "6MZ20049"}
+
def main(trade_date, conn, fund):
with conn.cursor() as c:
- c.execute("SELECT * FROM baml_fcm_fx(%s, %s) ", (trade_date, fund))
- if rec := c.fetchone():
- rec = list(rec)
+ c.execute(
+ "SELECT spots.cash_account, buy_currency, sell_currency, buy_amount, sell_amount, spot_rate, settle_date FROM spots LEFT JOIN accounts2 USING (cash_account) WHERE account_type='Fcm' AND spots.cp_code='BAMSNY' AND spots.trade_date =%s AND spots.fund=%s;",
+ (trade_date, fund),
+ )
+ for rec in c:
+ rec = rec._asdict()
+ if rec["sell_currency"] == "USD":
+ key1, key2 = "buy", "sell"
+ else:
+ key1, key2 = "sell", "buy"
+ fcm_account = _fcm_alias.get(rec["cash_account"], rec["cash_account"])
+ line = [
+ fcm_account,
+ rec[f"{key1}_currency"],
+ rec[f"{key1}_amount"],
+ rec[f"{key2}_currency"],
+ rec["spot_rate"],
+ rec[f"{key2}_amount"],
+ "Buy" if rec["sell_currency"] == "USD" else "Sell",
+ rec["settle_date"],
+ ]
+
num_format = [("{0:,.2f}", 2), ("{0:.5f}", 4), ("{0:,.2f}", 5)]
for f, i in num_format:
- rec[i] = f.format(rec[i])
+ line[i] = f.format(line[i])
t = tabulate(
- [rec],
+ [line],
headers=[
"account",
"curr",
@@ -26,7 +47,7 @@ def main(trade_date, conn, fund):
],
tablefmt="unsafehtml",
)
- BamlFcmNotify.email_fcm(trade_date, rec[0], t)
+ BamlFcmNotify.email_fcm(trade_date, fcm_account, t)
if __name__ == "__main__":