aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/position_file_bowdst.py71
1 files changed, 35 insertions, 36 deletions
diff --git a/python/position_file_bowdst.py b/python/position_file_bowdst.py
index f47700a2..3930389d 100644
--- a/python/position_file_bowdst.py
+++ b/python/position_file_bowdst.py
@@ -8,22 +8,40 @@ from pandas.tseries.offsets import MonthEnd
from serenitas.utils.exchange import ExchangeMessage, FileAttachment
-def process_upload(trades, asset_type, upload):
- buf = StringIO()
- csvwriter = csv.writer(buf)
- csvwriter.writerow(HEADERS[asset_type])
- csvwriter.writerows(build_line(trade, asset_type) for trade in trades)
- buf = buf.getvalue().encode()
- fname = f"HEDGEMARK.POSITION.BOS_PAT_BOWDOIN.{datetime.datetime.now():%Y%m%d.%H%M%S}.{asset_type.capitalize()}Deal.PositionsAsOf{args.date}.csv"
- if upload:
- sftp = SftpClient.from_creds("hm_globeop")
- sftp.client.chdir("incoming")
- sftp.put(buf, fname)
- base_dir = DAILY_DIR / str(datetime.date.today())
- base_dir.mkdir(exist_ok=True, parents=True)
- dest = base_dir / fname
- dest.write_bytes(buf)
- return fname, buf
+def process_upload(positions, upload):
+ attachments = []
+ for asset_type, trades in positions.items():
+ buf = StringIO()
+ csvwriter = csv.writer(buf)
+ csvwriter.writerow(HEADERS[asset_type])
+ csvwriter.writerows(build_line(trade, asset_type) for trade in trades)
+ buf = buf.getvalue().encode()
+ fname = f"HEDGEMARK.POSITION.BOS_PAT_BOWDOIN.{datetime.datetime.now():%Y%m%d.%H%M%S}.{asset_type.capitalize()}Deal.PositionsAsOf{args.date}.csv"
+ if upload:
+ sftp = SftpClient.from_creds("hm_globeop")
+ sftp.client.chdir("incoming")
+ sftp.put(buf, fname)
+ base_dir = DAILY_DIR / str(datetime.date.today())
+ base_dir.mkdir(exist_ok=True, parents=True)
+ dest = base_dir / fname
+ dest.write_bytes(buf)
+ attachments.append(FileAttachment(name=fname, content=buf))
+
+ if args.upload:
+ em = ExchangeMessage()
+ recipients = (
+ "hm-operations@bnymellon.com",
+ "hedgemark.lmcg.ops@sscinc.com",
+ "Hedgemark.OTC@sscinc.com",
+ "catherine.porter@bnymellon.com",
+ "shkumar@sscinc.com",
+ )
+ cc_recipients = ("bowdoin-ops@lmcg.com",)
+ subject = f"Position_files for Bowdoin Street as of {args.date}"
+ body = f"Please see monthend positions for Bowdoin Street as of {args.date}. They have been uploaded to the SFTP as well."
+ em.send_email(
+ subject, body, recipients, cc_recipients=cc_recipients, attach=attachments
+ )
def build_line(obj, asset_type):
@@ -263,23 +281,4 @@ if __name__ == "__main__":
positions = {
p: list(globals()[f"positions_{p}"](conn, args.date)) for p in args.product
}
- attachments = []
- for asset_type, trades in positions.items():
- fname, buf = process_upload(trades, asset_type, args.upload)
- attachments.append(FileAttachment(name=fname, content=buf))
-
- if args.upload:
- em = ExchangeMessage()
- recipients = (
- "hm-operations@bnymellon.com",
- "hedgemark.lmcg.ops@sscinc.com",
- "Hedgemark.OTC@sscinc.com",
- "catherine.porter@bnymellon.com",
- "shkumar@sscinc.com",
- )
- cc_recipients = ("bowdoin-ops@lmcg.com",)
- subject = f"Position_files for Bowdoin Street as of {args.date}"
- body = f"Please see monthend positions for Bowdoin Street as of {args.date}. They have been uploaded to the SFTP as well."
- em.send_email(
- subject, body, recipients, cc_recipients=cc_recipients, attach=attachments
- )
+ process_upload(positions, args.upload)