aboutsummaryrefslogtreecommitdiffstats
path: root/python/Dawn/process_queue.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/Dawn/process_queue.py')
-rw-r--r--python/Dawn/process_queue.py72
1 files changed, 0 insertions, 72 deletions
diff --git a/python/Dawn/process_queue.py b/python/Dawn/process_queue.py
deleted file mode 100644
index 60a08bc5..00000000
--- a/python/Dawn/process_queue.py
+++ /dev/null
@@ -1,72 +0,0 @@
-import redis
-import pandas as pd
-import csv
-from io import BytesIO, StringIO
-import datetime
-from pickle import loads
-
-def get_trades():
- q = redis.Redis(host = 'debian')
- p = q.pipeline()
- p.lrange('trades', 0, -1).delete('trades')
- r = p.execute()
- return pd.DataFrame([loads(e) for e in r[0]])
-
-def aux(v):
- if v.action.iat[-1] == 'CANCEL':
- return None
- if v.action.iat[0] == 'NEW':
- v.action.iat[-1] = 'NEW'
- return v.iloc[-1]
-
-def build_line(obj):
- line = ["Mortgage", obj.dealid, obj.action ,"Serenitas", None, None , obj.folder,
- obj.custodian, obj.cashaccount, obj.cp_code, None, 'Valid',
- str(obj.trade_date), str(obj.settle_date), None, None, obj.cusip, obj['isin'],
- None, None, None, obj['description'], "Buy" if obj.buysell else "Sell", None,
- obj.accrued, obj.price, None, None, 'SERCGMAST', 'MORTGAGE',
- None, None, None, None, obj.faceamount, None, None, 'S']
- return line
-
-def delete_trade(tradeid):
- pass
-
-def generate_csv(df):
- output = StringIO()
- csvwriter = csv.writer(output)
- headers = ['Deal Type', 'Deal ID', 'Action', 'Client', 'Reserved', 'Reserved',
- 'Folder', 'Custodian', 'Cash Account', 'Counterparty', 'Comments',
- 'State', 'Trade Date', 'Settlement Date', 'Reserved', 'GlopeOp Security Identifier',
- 'CUSIP', 'ISIN', 'Reserved', 'Reserved',
- 'Reserved', 'Security Description', 'Transaction Indicator',
- 'SubTransaction Indicator', 'Accrued', 'Price', 'BlockId', 'BlockAmount',
- 'Fund', 'Portfolio', 'Reserved', 'Reserved', 'ClientReference', 'ClearingMode',
- 'FaceAmount', 'Pool Factor', 'FactorAsOfDate', 'Delivery']
- csvwriter.writerow(headers)
- for tradeid, v in df.sort('lastupdate').groupby('id'):
- trade = aux(v)
- if trade is None:
- delete_trade(tradeid)
- else:
- csvwriter.writerow(build_line(trade))
- #convert to bytes
- output = BytesIO(output.getvalue().encode('utf-8'))
- return output
-
-def upload_buffer(buf):
- # ftp = FTP('ftp.globeop.com')
- # ftp.login('srntsftp', config.ftp_password)
- # ftp.cwd('incoming')
- filename = ('Serenitas.ALL.{0}.Mortgages.csv'
- .format(pd.datetime.strftime(pd.datetime.now(),
- "%Y%m%d.%H%M%S")))
- # cmd = 'STOR {0}'.format(filename)
- # ftp.storbinary(cmd, buf)
- # buf.seek()
- with open(filename, 'wb') as fh:
- fh.write(buf.getbuffer())
-
-if __name__=="__main__":
- df = get_trades()
- buf = generate_csv(df)
- upload_buffer(buf)