diff options
| -rw-r--r-- | python/parse_gs_exchange.py | 15 | ||||
| -rw-r--r-- | sql/serenitasdb.sql | 9 |
2 files changed, 18 insertions, 6 deletions
diff --git a/python/parse_gs_exchange.py b/python/parse_gs_exchange.py index 9150f273..f0e49702 100644 --- a/python/parse_gs_exchange.py +++ b/python/parse_gs_exchange.py @@ -1,3 +1,4 @@ +from pathlib import Path from exchange import get_msgs from pytz import timezone from parse_emails import write_todb @@ -71,7 +72,8 @@ def parse_email(email, fwd_index): 'expiry': date, 'index': indextype, 'series': series, - 'ref': refspread if indextype == "IG" else ref} + 'ref': refspread if indextype == "IG" else ref, + 'msg_id': get_msg_id(email)} if indextype == "IG": d['fwdspread'] = float(fwspread) else: @@ -103,11 +105,22 @@ def clean_df(all_df): del all_df['Sprd'] return all_df +def get_msg_id(msg): + return msg.message_id[1:17].lower() + +def save_email(msg, path): + fname = path / ("{:%Y-%m-%d %H-%M-%S}_{}". + format(msg.datetime_sent, + get_msg_id(msg))) + with fname.open("w") as fh: + fh.write(msg.text_body) if __name__ == "__main__": fwd_index = [] swaption_quotes = {} + save_path = Path(os.environ["DATA_DIR"]) "swaptions" / "exchange" for email in get_msgs(count=20): + save_email(email, save_path) try: quotedate, indextype, series, df = parse_email(email, fwd_index) except ParseError as e: diff --git a/sql/serenitasdb.sql b/sql/serenitasdb.sql index 0e591d1d..358acf85 100644 --- a/sql/serenitasdb.sql +++ b/sql/serenitasdb.sql @@ -858,8 +858,7 @@ CREATE TABLE swaption_quotes( gamma float,
tail float);
-ALTER TABLE swaption_quotes ADD CONSTRAINT swaption_quotes_unique_ref_id_strike
-UNIQUE (ref_id, strike);
+ALTER TABLE swaption_quotes ADD UNIQUE (ref_id, strike);
CREATE TABLE swaption_ref_quotes(
ref_id serial PRIMARY KEY,
@@ -871,11 +870,11 @@ CREATE TABLE swaption_ref_quotes( fwdprice float,
fwdspread float,
fwdbpv float,
- quote_source varchar(4));
+ quote_source varchar(4),
+ msg_id bigint);
CREATE INDEX ON swaption_ref_quotes (quotedate, index, series);
-ALTER TABLE swaption_ref_quotes ADD CONSTRAINT swaption_ref_quotes_unique_quotedate_index_series_expiry
-UNIQUE (quotedate, index, series, expiry);
+ALTER TABLE swaption_ref_quotes ADD UNIQUE(quotedate, index, series, expiry);
CREATE TABLE swaption_calib(
quote_id integer PRIMARY KEY REFERENCES swaption_quotes,
|
