diff options
Diffstat (limited to 'python/futures.py')
| -rw-r--r-- | python/futures.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/python/futures.py b/python/futures.py index 112a9037..cde0d931 100644 --- a/python/futures.py +++ b/python/futures.py @@ -4,6 +4,8 @@ import requests import common
import sys
import os
+import pdb
+import pytz
ticker = "GE"
monthcodes = ["F", "G", "H", "J", "K", "M", "N", "Q", "U", "V", "X", "Z"]
@@ -24,18 +26,30 @@ def nextIMMDates(startdate, length = 8): if len(r) == 8:
return r
-
+if len(sys.argv)>1:
+ workdate = datetime.datetime.strptime(sys.argv[1], "%Y-%m-%d").date()
+else:
+ workdate = datetime.date.today()
# get next 8 futures maturities
-contracts = ["GE" + monthcodes[d.month-1] + str(d.year)[-1:] for d in nextIMMDates(datetime.date.today())]
+contracts = ["GE" + monthcodes[d.month-1] + str(d.year)[-1:] for d in nextIMMDates(workdate)]
+
+#putting a historic date doesn't work
if sys.version_info >= (3,3):
- ts = int(datetime.date.today().timestamp()*1000)
+ ts = int(workdate*1000)
else:
- ts = datetime.datetime.strftime(datetime.date.today(), '%s') + '000'
+ ts = datetime.datetime.strftime(workdate, '%s') + '000'
+pdb.set_trace()
uri = "http://www.cmegroup.com/CmeWS/md/MDServer/V1/Venue/G/Exchange/XCME/FOI/FUT/Product/GE?currentTime={0}&contractCDs={1}".format(ts, ",".join(contracts))
r = requests.get(uri)
quotes = json.loads(r.text)
-with open(os.path.join(common.root, "data", "Yield Curves", "futures-{0}.csv".format(datetime.date.today())), "w") as fh:
+trailing_spaces=";".join([" "] * 10)
+central = pytz.timezone('US/Central')
+with open(os.path.join(common.root, "data", "Yield Curves",
+ "futures-{0}.csv".format(workdate)), "w") as fh:
for q in quotes[u'marketDataInfoAsStringList'][u'message']:
- fh.write("{0}, {1}\n".format(q['ticker'], q['tradePrice']))
+ tradedate = datetime.datetime.strptime(q['tradeDate'],
+ "%I:%M:%S %p CT<br/>%m/%d/%Y {0};".format(trailing_spaces))
+ tradedate = central.localize(tradedate)
+ fh.write("{0},{1},{2}\n".format(q['ticker'], q['tradePrice'], tradedate))
|
