aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/upload_bbh_trades.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/python/upload_bbh_trades.py b/python/upload_bbh_trades.py
index 4999bd4b..e145e789 100644
--- a/python/upload_bbh_trades.py
+++ b/python/upload_bbh_trades.py
@@ -1,4 +1,3 @@
-from headers import BBH_BOND_HEADERS
import csv
from serenitas.utils.db import dbconn, dawn_engine
import datetime
@@ -12,8 +11,12 @@ from serenitas.utils.remote import SftpClient
if __name__ == "__main__":
conn = dbconn("dawndb")
with conn.cursor() as c:
+ c.execute("SELECT headers from csv_templates where template_name='bbh_bonds'")
+ (headers,) = c.fetchone()
sql_query = "SELECT bond_trades.*, counterparties.dtc_number FROM bond_trades LEFT JOIN counterparties ON cp_code=code WHERE cash_counterparty AND trade_date >= '2022-04-05' AND fund='BRINKER';"
- c.execute(sql_query, (datetime.date(2022, 4, 5),))
+ c.execute(
+ sql_query, (datetime.date(2022, 4, 5),)
+ ) # We don't want to upload trades before this date
for row in c:
obj = row._asdict()
rename_keys(
@@ -24,14 +27,14 @@ if __name__ == "__main__":
"accrued_payment": "Interest Amount",
"dtc_number": "Trading Broker Type/ID",
"principal_payment": "Principal Amount",
- "trade_date": "Trade Date",
- "settle_date": "Settlement Date",
"faceamount": "Unit / Original Face Amount",
"current_face": "Current Face/Amortize Value",
"price": "Unit Price Amount",
"net_amount": "Net Amount",
},
)
+ obj["Trade Date"] = obj["trade_date"].strftime("%m/%d/%Y")
+ obj["Settlement Date"] = obj["settle_date"].strftime("%m/%d/%Y")
obj["Place of Settlement/Country"] = "DTCYUS33"
obj["Transaction Type"] = "RVP" if obj["buysell"] else "DVP"
obj["Function of Instruction"] = "NEWM"
@@ -42,7 +45,7 @@ if __name__ == "__main__":
obj["Commission Amount"] = 0
obj["SEC Fees Amount"] = 0
new_obj = {"tradeid": obj["tradeid"]}
- for header in BBH_BOND_HEADERS:
+ for header in headers:
new_obj[header] = obj.get(header, None)
df = pd.DataFrame(
new_obj,
@@ -59,10 +62,8 @@ if __name__ == "__main__":
else:
buf = StringIO()
csvwriter = csv.writer(buf)
- csvwriter.writerow(BBH_BOND_HEADERS)
- csvwriter.writerow(
- [obj.get(header, None) for header in BBH_BOND_HEADERS]
- )
+ csvwriter.writerow(headers)
+ csvwriter.writerow([obj.get(header, None) for header in headers])
buf = buf.getvalue().encode()
fname = f'LMCG_BBH_TRADES_P.{obj["Client Reference Number"].replace("_", "")}.csv'
dest = DAILY_DIR / str(datetime.date.today()) / fname