-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample2.py
More file actions
43 lines (39 loc) · 1.41 KB
/
example2.py
File metadata and controls
43 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -*- coding: utf-8 -*-
"""
Load futures data to MongoDB
"""
import datetime
import time
import logging
from iq2mongo import Iqfeedhistoricdata
LOG = logging.getLogger()
symbols = ['@EU#', '@BP#', '@CD#', '@AD#', '@SF#']
interval = 60
dateStart = datetime.datetime(2007, 1, 1)
dateEnd = datetime.datetime(2016, 12, 31)
dbname = 'Future'
iq = Iqfeedhistoricdata(dateStart, dateEnd, interval, 'Future')
pstart = time.time()
for symbol in symbols:
try:
print 'Downloading '+ symbol + ' from IQFeed...'
start = time.time()
ibars = iq.download_symbol(symbol, timeout=11.5, chunk=32768)
done = time.time()
elapsed = str(done - start)
print 'Download finished in ' + elapsed + ' seconds.'
if len(ibars):
print 'Incerting '+ symbol + ' into MongoDB...'
start = time.time()
#incert_arctic = iq.arctic_store(ibars, symbol, 'ETF')
incert = iq.write_bars_to_mongo(ibars, symbol, dbname)
done = time.time()
elapsed = str(done - start)
print 'Incert finished in ' + elapsed + ' seconds.'
else:
print 'No bars for ' + symbol + ' downloaded'
except Exception as err:
LOG.error('Exception during download, continuing', exc_info=err)
pdone = time.time()
_elapsed = str(pdone - pstart)
print 'Program finished in ' + _elapsed + ' seconds.'