def dload(symlist,barlist,strikelist,expirylist):
    print symlist
    global bar, sym
    trans_id = 0
    strikelist = [1]
    expirylist  = [1]
    for sym in symlist:
        print sym
        for bar in barlist:
            for strike in strikelist:
                for expiry in expirylist:
                    fname = DataDown+ today + '.' + sym + '.'  + bar.replace(' ','')+'.ddload.csv'
                    TicksUtile.backupTickfiles(fname)
                    ##########
                    duration = bardict[bar]
                    barspaced = bardictspaced[bar]
                    contract = ibutiles.create_contract(sym,strike,expiry)
                    ticktype = ticktypedict[sym]
                    print bar, sym, duration,ticktype, barspaced, strike, expiry
                    tws_conn.reqHistoricalData(trans_id, contract, '', duration, barspaced, ticktype, 0, 2)
                    trans_id = trans_id + 1  
                    sleep(10)
                    
                    tmp = DataDown+ today + '.' + 'tempdlfile' + '.ddload.csv'
                    fname = DataDown+ today + '.' + sym + '.'  + bar.replace(' ','')+'.ddload.csv'
                    shutil.copyfile(tmp,fname)
                    TicksUtile.throw_out_lastbar(fname)
Exemplo n.º 2
0
def dload(symlist, barlist, strikelist, expirylist):
    print symlist
    global bar, sym
    trans_id = 0
    strikelist = [1]
    expirylist = [1]
    for sym in symlist:
        print sym
        for bar in barlist:
            for strike in strikelist:
                for expiry in expirylist:
                    fname = DataDown + today + '.' + sym + '.' + bar.replace(
                        ' ', '') + '.ddload.csv'
                    TicksUtile.backupTickfiles(fname)
                    ##########
                    duration = bardict[bar]
                    barspaced = bardictspaced[bar]
                    contract = ibutiles.create_contract(sym, strike, expiry)
                    ticktype = ticktypedict[sym]
                    print bar, sym, duration, ticktype, barspaced, strike, expiry
                    tws_conn.reqHistoricalData(trans_id, contract, '',
                                               duration, barspaced, ticktype,
                                               0, 2)
                    trans_id = trans_id + 1
                    sleep(10)

                    tmp = DataDown + today + '.' + 'tempdlfile' + '.ddload.csv'
                    fname = DataDown + today + '.' + sym + '.' + bar.replace(
                        ' ', '') + '.ddload.csv'
                    shutil.copyfile(tmp, fname)
                    TicksUtile.throw_out_lastbar(fname)
Exemplo n.º 3
0
########################################
symTickerIddict = {}
contractdict = {}
symid = 0
strike = 90
expiry = ''
##flush files here is bad if building on hist....
for sym in symbol_list:
    print sym
    symid += 1
    contract = ibutiles.create_contract(sym, strike, expiry)
    contractdict.update({sym: contract})
    symTickerIddict.update({str(symid): sym})

    fname1 = DataDown + today + '.' + sym + '.RTMktDepth.csv'
    TicksUtile.backupTickfiles(fname1)
    fname3 = DataDown + today + '.' + sym + '.RTtickData.csv'
    TicksUtile.backupTickfiles(fname3)
    ######################
rpu_rp.WriteArrayToCsvfile(TMP + 'replys.RTtickDOMs', [])
#################
onerow = []
current_time = datetime.now().time()
timenow = current_time.isoformat()
'''
2048.75', ' size=385>', '22:12:56.097000']
<updateMktDepth tickerId=1, position=8, operation=1, side=0, price=2049.75, size=415>
['<updateMktDepth tickerId=1', ' position=8', ' operation=1', ' side=0', ' price=2049.75', ' size=415>', '22:12:56.121000']
'''
global depthpricearray, depthsizearray
depthpricearray = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
from ib.opt import Connection, message   ##??
#############################
global  sym, symbol_list, symdict
########################################
symbol_list = symlistTicker
symTickerIddict ={}
contractdict ={}
symid=0
### backup tick files ####
print symbol_list
for sym in symbol_list:
    symid+=1
    symTickerIddict.update({str(symid) : sym})
    for filename in ['.RTticks.csv','.RTMktDepth.csv','.RTtickData.csv']:
        fname1 = DataDown+ today + '.' + sym  +filename
        TicksUtile.backupTickfiles(fname1)
##        flush file
        rpu_rp.WriteArrayToCsvfile(fname1,[])
##flush tick files where necessary   
rpu_rp.WriteArrayToCsvfile(TMP +'replys.RTticks',[])
rpu_rp.WriteArrayToCsvfile(TMP +'replys.RTtickDOMs',[])
#################
onerow =[]
current_time = datetime.now().time()
timenow=current_time.isoformat()
################
def reply_handler(msg):
    msgarray = (str(msg)).split()
    print msgarray, 'rawmessg'
    reqid=(msgarray[1]).split('=')[1].replace(',','')
    fieldnum = (msgarray[2]).split('=')[1].replace(',','')