Exemplo n.º 1
0
def get_vola():
    reqID = 33
    ##contract = ibutiles.create_ticksym(99,sym)
    genericTicks = ''
    snapshot = True
    sym = 'SPY'
    contract = contractdict[sym]
    tws_conn.reqMktData(reqID, contract, genericTicks, snapshot)
    #########################################
    symid = 0
    for sym in symbol_list:
        print sym
        underlying = symdict[sym]
        if underlying == 'SPY':
            underPricenew = TicksUtile.recenttick(underlying, 'dload')
            optionpricenew = TicksUtile.recenttick(sym, 'dload')
            optionprice = 5.00
            underPrice = 200.0
            print underPricenew, optionpricenew
            print typedict[sym]
            ATMstrike = round(underPrice, -2)
            print 'atm', ATMstrike
            if typedict[sym] == 'OPT':
                symid += 1
                contract = contractdict[sym]
                tws_conn.calculateImpliedVolatility(reqID, contract,
                                                    optionprice, underPrice)
                reqID += 1
                sleep(1)
                tws_conn.cancelCalculateImpliedVolatility(reqID)
Exemplo n.º 2
0
def run_oneloop(dur,now,sym):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
    print '##### ',now, dur, sym,' ####### '
    Createlines.create_HAs([sym])
    ##########
    perc = .60
    maxlines = 12
    difflimit = 700
    taglist = ['buy','sell','allxx']
    for tag in taglist:    
        b = showlines(sym,dur,tag)
        print '#############'
        print '>>>>>> ',tag.upper(), 'WINDOW',dur,sym, ' <<<'
        lenha = len(b)
        c=0
        climitlines = int(lenha * perc)
        climit = max((lenha-maxlines),climitlines)
        bar_time = '  2016-02-21 13:16:30'
        for lha in b:
            c+=1
            if tag != 'allxx':
                if len(lha.split('|')) > 2:
                    bar_time = (lha.split('|')[3]).replace(' 201','201')  
                bar_time_epoch =  TicksUtile.time_to_epoch(bar_time)          
                tdiff =  now_epoch - bar_time_epoch
            else:
                    bar_time_epoch =  TicksUtile.time_to_epoch(bar_time)          
                    tdiff =  0# now_epoch - bar_time_epoch                
            if c > climit and tdiff < difflimit :
                print lha,'>>> ',tdiff #,difflimit
def run_oneloop(dur, now, sym):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
    print '##### ', now, dur, sym, ' ####### '
    Createlines.create_HAs([sym])
    ##########
    perc = .70
    maxlines = 6
    difflimit = 700
    taglist = ['buy', 'sell', 'allxx']
    for tag in taglist:
        b = showlines(sym, dur, tag)
        print '#############'
        print '>>>>>> ', tag.upper(), 'WINDOW', dur, sym, ' <<<'
        lenha = len(b)
        c = 0
        climitlines = int(lenha * perc)
        climit = max((lenha - maxlines), climitlines)
        bar_time = '  2016-02-21 13:16:30'
        for lha in b:
            c += 1
            if tag != 'allxx':
                if len(lha.split('|')) > 2:
                    bar_time = (lha.split('|')[3]).replace(' 201', '201')
                bar_time_epoch = TicksUtile.time_to_epoch(bar_time)
                tdiff = now_epoch - bar_time_epoch
            else:
                bar_time_epoch = TicksUtile.time_to_epoch(bar_time)
                tdiff = 0  # now_epoch - bar_time_epoch
            if c > climit and tdiff < difflimit:
                print lha, '>>> ', tdiff  #,difflimit
Exemplo n.º 4
0
def chopMonthToDays(bararray,sym,dur,secs):  ### what does this do?
    lines = bararray
    print secs
    preve = 0
    prevfname = 0
    ubars =[]
    uubars =[]
    diffprev = 1
    daylist =[]
    for l in lines:
        if len(l) > 2:
            timestring = l[1]
            date = timestring[0:11]
            daylist.append(date)
    daylistu = rpu_rp.uniq(daylist)
    for day in daylistu:
        daysarray=[]
        for l in bararray:
            if day in l[1] :
                timestring = l[1]
                try:
                    e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
                except:
                    e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
                diffcur = e - preve
                preve = e
##                print diffcur,timestring
                if diffcur == int(secs):
                    daysarray.append(l)
##                    print l
        print day, sym,dur, len(daysarray)
        fileoutname = DataDown + day +'.' + sym +'.' + dur+'.cleaned.csv' 
        rpu_rp.WriteArrayToCsvfile(fileoutname, daysarray)
Exemplo n.º 5
0
def get_vola(symbol_list_opts):
    reqID = 111
    symid = 0
    for sym in symbol_list_opts:
        if sym != 'SPY':
            print sym
            underlying = symdict[sym]
            if underlying == 'SPY':
                underPricenew = float(TicksUtile.recenttick(
                    underlying, '1min'))
                optionpricenew = float(TicksUtile.recenttick(sym, 'both'))
                optionprice = underPricenew  # 5.00
                underPrice = underPricenew  #200.0

                ticktype = ticktypedict[sym]

                ATMstrike = round(underPrice, 0)

                if 'SPYF' in sym:
                    print sym, underPrice, optionprice, typedict[
                        sym], 'atm', ATMstrike
                    symid += 1
                    ##                    contract  = contractdict[sym]
                    ATMspyoption = ibutiles.create_option_contract(
                        sym, ATMstrike)
                    ##                    tws_conn.reqRealTimeBars(reqID,ATMspyoption,'',ticktype,0)
                    ##                    print rpu_rp.CsvToLines(replyfname)
                    ##                    reqID +=1
                    tws_conn.calculateImpliedVolatility(
                        reqID, ATMspyoption, optionprice, underPrice)
                    reqID += 1
                    sleep(1)
Exemplo n.º 6
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.º 7
0
def create_statesdaily():
    for sym in symbol_list:      
        for barsize in barlist :
            timeframe = bardict[barsize]
            durinseconds = secdict[barsize]
            barsizeNtimeframe = timeframe + barsize
            dur = barsize
            TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds)  
            DurBoth = rpu_rp.CsvToLines( DataDown+ today + '.'+sym+'.' + dur.replace(' ','') + '.both.csv')
            indlist = ['pivot', 'R', 'S', 'S2', 'R2']
            for indicator in indlist:
##                print sym
                indarr = rpInd.GetPivots(DurBoth,sym,indicator)
                statename = sym+'.'+dur.replace(' ','')+'.'
                statefile = statearea +statename + indicator  + '.state.csv'
                rpu_rp.WriteArrayToCsvfile(statefile, indarr)
            indlist2 = ['kupper', 'klower', 'kmid']
            for indicator in indlist2:
    ##                print indicator
                indarr = rpInd.GetKupper(DurBoth,sym,indicator)
                statename = sym+'.'+dur.replace(' ','')+'.'
                statefile = statearea +statename + indicator  + '.state.csv'
                rpu_rp.WriteArrayToCsvfile(statefile, indarr)
    ##                keltner_channel_upper(highs,lows,closes,mult)
            indlist3 = ['ema']
            for indicator in indlist3:
    ##                print indicator
                indarr = rpInd.GetEMA(DurBoth,sym,indicator)
                statename = sym+'.'+dur.replace(' ','')+'.'
                statefile = statearea +statename + indicator  + '.state.csv'
                rpu_rp.WriteArrayToCsvfile(statefile, indarr)
Exemplo n.º 8
0
def get_vola(symbol_list_opts):
    reqID =111
    symid = 0
    for sym in symbol_list_opts:
        if sym != 'SPY':
            print sym
            underlying = symdict[sym]
            if underlying == 'SPY':
                underPricenew =  float(TicksUtile.recenttick(underlying,'1min'))
                optionpricenew = float(TicksUtile.recenttick(sym,'both'))
                optionprice = underPricenew # 5.00
                underPrice = underPricenew #200.0
                
                ticktype = ticktypedict[sym]
                
                ATMstrike = round(underPrice,0)
                
                if 'SPYF' in sym:
                    print sym, underPrice, optionprice, typedict[sym], 'atm', ATMstrike
                    symid+=1
##                    contract  = contractdict[sym]
                    ATMspyoption = ibutiles.create_option_contract(sym,ATMstrike)
##                    tws_conn.reqRealTimeBars(reqID,ATMspyoption,'',ticktype,0)
##                    print rpu_rp.CsvToLines(replyfname)
##                    reqID +=1 
                    tws_conn.calculateImpliedVolatility(reqID,ATMspyoption,optionprice,underPrice)
                    reqID +=1        
                    sleep(1)
def createOneMerge(dur, now, sym, date):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
    ##    print '##### ', dur, sym,' ####### '
    durinseconds = secdict[dur]
    basisdur = '1min'
    if dur == '1min':
        basisdur = '5secs'
    basisfile = DataDown + date + '.' + sym + '.' + basisdur + '.both.csv'  ### this bit not used yet until expand startmode
    basisbars = rpu_rp.CsvToLines(basisfile)
    ##    print'creating bars'
    recentbars = TicksUtile.create_bars_from_bars(basisbars, date, sym, dur,
                                                  durinseconds, 'noHA')
    ##    print 'done creating bars'
    filerecent = DataDown + date + '.' + sym + '.' + dur.replace(
        ' ', '') + '.recent' + '.csv'
    rpu_rp.WriteArrayToCsvfile(filerecent, recentbars)
    ## now merge recent and both
    fileddload = filerecent.replace('recent', 'ddload')
    outfile = filerecent.replace('recent', 'both')
    cutoffmintime = int(int(durinseconds) - 5)
    if os.path.isfile(filerecent):
        TicksUtile.merge_bar_files(filerecent, fileddload, outfile,
                                   cutoffmintime)
    else:
        shutil.copyfile(fileddload, outfile)
##        print 'found no ddload file so did no merge'
##########
    basisfile = DataDown + date + '.' + sym + '.' + dur + '.both.csv'  ### note the basis dur changed to just dur!!
    basisbars = rpu_rp.CsvToLines(basisfile)
    HAbars = TicksUtile.create_bars_from_bars(basisbars, date, sym, dur,
                                              durinseconds, 'hamode')
    ##    print 'done creating HA bars'
    fileHABoth = DataDown + date + '.' + sym + '.' + dur.replace(
        ' ', '') + '.bothHA' + '.csv'
    rpu_rp.WriteArrayToCsvfile(fileHABoth, HAbars)
Exemplo n.º 10
0
def get_vola():
    reqID =33
    ##contract = ibutiles.create_ticksym(99,sym)
    genericTicks =''
    snapshot = True
    sym = 'SPY'
    contract = contractdict[sym]
    tws_conn.reqMktData(reqID,contract,genericTicks,snapshot)
    #########################################
    symid = 0
    for sym in symbol_list:
        print sym
        underlying = symdict[sym]
        if underlying == 'SPY':
            underPricenew = TicksUtile.recenttick(underlying,'dload')
            optionpricenew = TicksUtile.recenttick(sym,'dload')
            optionprice = 5.00
            underPrice = 200.0
            print underPricenew, optionpricenew
            print typedict[sym]
            ATMstrike = round(underPrice,-2)
            print 'atm', ATMstrike
            if typedict[sym] == 'OPT':
                symid+=1
                contract  = contractdict[sym]
                tws_conn.calculateImpliedVolatility(reqID,contract,optionprice,underPrice)
                reqID +=1        
                sleep(1)
                tws_conn.cancelCalculateImpliedVolatility(reqID)
Exemplo n.º 11
0
def createOneMerge(dur,now,sym,date):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
##    print '##### ', dur, sym,' ####### '
    durinseconds= secdict[dur]
    basisdur = '1min'
    if dur == '1min':
        basisdur ='5secs'
    basisfile = DataDown +date+'.'+sym+'.'+basisdur+'.both.csv' ### this bit not used yet until expand startmode
    basisbars = rpu_rp.CsvToLines(basisfile)
##    print'creating bars'   
    recentbars = TicksUtile.create_bars_from_bars(basisbars,date,sym,dur,durinseconds,'noHA')
##    print 'done creating bars'
    filerecent = DataDown +date+'.'+sym+'.'+dur.replace(' ','')+'.recent' +'.csv'
    rpu_rp.WriteArrayToCsvfile(filerecent,recentbars)
    ## now merge recent and both
    fileddload = filerecent.replace('recent','ddload')
    outfile = filerecent.replace('recent','both')
    cutoffmintime = int(int(durinseconds) - 5)
    if os.path.isfile(filerecent):
        TicksUtile.merge_bar_files(filerecent,fileddload,outfile,cutoffmintime)
    else:
        shutil.copyfile(fileddload,outfile)
##        print 'found no ddload file so did no merge'
        ##########
    basisfile = DataDown +date+'.'+sym+'.'+dur+'.both.csv' ### note the basis dur changed to just dur!!
    basisbars = rpu_rp.CsvToLines(basisfile)
    HAbars = TicksUtile.create_bars_from_bars(basisbars,date,sym,dur,durinseconds,'hamode')
##    print 'done creating HA bars'
    fileHABoth = DataDown +date+'.'+sym+'.'+dur.replace(' ','')+'.bothHA' +'.csv'
    rpu_rp.WriteArrayToCsvfile(fileHABoth,HAbars)
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.º 13
0
def ShowABarofIndByTime(sym,dur,ind,bartime,barfnumlimit):
    lastbar =[]
    statefile = statearea + sym + '.' +  dur + '.' + ind  + '.state.csv'
    lastfewbars = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(statefile),barfnumlimit)
    for bar in lastfewbars:
        if TicksUtile.time_to_epoch(bar[0]) <= TicksUtile.time_to_epoch(bartime) :
            lastbar = bar
    return lastbar
Exemplo n.º 14
0
def make_bars_no_5sec(date,startmode,symbol_list,barlist):
    for sym in symbol_list:
        for dur in barlist :
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur  = '1min'
            TicksUtile.assemble_dur_bars(date,sym,dur,startmode,basisdur)
Exemplo n.º 15
0
def create_weeklies():
    sym = 'SPX'
    basisdur = '1day'
    TicksUtile.assemble_dur_bars(date,sym,'1day','initialize','5secs')
    TicksUtile.assemble_bars_1min_basis(date,sym,'1Week','bartobar',basisdur)
    indlist = ['mcross','pivot','R','R2','S','S2']
    threshold = 0.0
    rpInd.create_states_files(sym,'1Week',date,threshold,indlist)
    rpInd.create_states_files(sym,'1day',date,threshold,indlist)
def loop_one_prepare():
    basisdur = '5secs'
    barlist = ['1min','3mins', '15mins', '1hour', '1day']
    ## pre prepare ES for compares
    startmode = 'initialize'
##    sym='ES'
    TicksUtile.prepare_tickfilesto5secBars(today,'ES',startmode) ## merge the 5secddload with 5sec recents > 5sec boths         
    for dur in barlist :
##        sym = 'ES'
        TicksUtile.assemble_dur_bars(today,'ES',dur,startmode,basisdur)
Exemplo n.º 17
0
def ShowABarofIndByTime(sym, dur, ind, bartime, barfnumlimit):
    lastbar = []
    statefile = statearea + sym + '.' + dur + '.' + ind + '.state.csv'
    lastfewbars = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(statefile),
                                             barfnumlimit)
    for bar in lastfewbars:
        if TicksUtile.time_to_epoch(
                bar[0]) <= TicksUtile.time_to_epoch(bartime):
            lastbar = bar
    return lastbar
def parse_signalsNEW(rulesetoutput):
    ##    [['result', 'SELL', 'stochkeasy1minSELL.rules.csv', ' 2015-09-23 08:16:05', 'CL', 46.36]]
    dur = ''
    if len(rulesetoutput) > 0:
        sigcount = 0
        for sig in rulesetoutput:
            if len(sig) > 0 and sig[1] != 'nomatch':
                sig.append(now)
                sigtime = sig[3]
                nowepoch = TicksUtile.time_to_epoch(now)
                ##                print sig
                sigepoch = TicksUtile.time_to_epoch(sigtime)
                elapsed = nowepoch - sigepoch
                ##                print elapsed
                ##                print sig,'sigline',elapsed
                sigtime = sig[3]
                indvalue = 0.0  #float(sig[len(sig)-2])   <<<<<<<<<<<<<<<<<<
                sym = sig[4]
                sigtype = sig[2]
                priceinsignal = float(sig[5])  ### need to unboost the price...
                dboost = dboostdict[sym]
                newprice = priceinsignal / float(dboost)
                sig[5] = newprice
                tside = sig[1]
                dur = '0mins'  # sig[8]   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                livesigid = sym + tside + dur + sigtype
                sig.append(livesigid)
                showflag = look_for_dupe_sig(livesigid, sigtime,
                                             delaydupetime)  #'notsupress'
                sigcount += 1
                ######                print sym,tside,sigtype,sigtime,elapsed,str(newprice)
                ##                if btmode == 'BACKTEST':
                ##                    soundarea = 'gg'
                if showflag != 'supress':
                    if tside == 'SELL':
                        ####                        beep(soundarea+'sell')
                        print sig
                        ####                        beep(soundarea+sym)
                        print '==============='
##                        Mbox('BuySignal', sig, style)
                    elif tside == 'BUY':
                        ####                        beep(soundarea+'buy')
                        print sig
                        ####                        beep(soundarea+sym)
                        print '==============='
##                        Mbox('BuySignal', sig, style)
                    else:
                        print 'supressing'
    ######                RP_Snapshot.snapshot_sym(sym,date)
                    frsigline = []
                    rpu_rp.WriteArrayToCsvfileAppend(
                        sigarea + date + '.recentsigs.csv', [sig])
                    rpu_rp.WriteArrayToCsvfileAppend(
                        sigarea + date + '.recentsigsexec.csv', [sig])
Exemplo n.º 19
0
def loop_one_prepare():
    basisdur = '5secs'
    barlist = ['1min', '3mins', '15mins', '1hour', '1day']
    ## pre prepare ES for compares
    startmode = 'initialize'
    ##    sym='ES'
    TicksUtile.prepare_tickfilesto5secBars(
        today, 'ES',
        startmode)  ## merge the 5secddload with 5sec recents > 5sec boths
    for dur in barlist:
        ##        sym = 'ES'
        TicksUtile.assemble_dur_bars(today, 'ES', dur, startmode, basisdur)
Exemplo n.º 20
0
def snapshot_sym(sym, today, durslist):
    ##    print 'got her'
    text = []
    barlist = ['1min', '3mins', '5mins', '15mins', '1hour']
    basisfile = DataDown + today + '.' + sym + '.' + '5secs' + '.both.csv'
    TicksUtile.assemble_dur_bars(today, sym, '1hour', 'initial', basisfile)
    posstate = rpInd.ShowRecentPositionState(sym)
    text.append(posstate + sym)
    threshold = 0.0
    indlist = ['mcross', 'kupper']
    ##    print posstate,sym,'recentstate age val | lastcrosstime| name USING THRESH ', threshold
    textline = 'recentstate age val name USING THRESH ' + str(threshold)
    text.append(textline)
    for dur in barlist:
        ##        print dur
        threshold = 0.0
        if dur == '1min':
            threshold = 0.1
##        print sym,dur
##        make_dur_state(sym,dur,threshold,indlist)
        basisdur = '5secs'
        startmode = 'initialize'
        basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv'
        TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile)
        ### this relys on the sig creator to assemble each time
        rpInd.create_states_files(sym, dur, today, threshold, indlist)
        indlist = ['mcross']
        for ind in indlist:
            mode = 'noboost'
            state = rpInd.ShowRecentState(sym, dur, ind, mode)
            stateAge = rpInd.ShowRecentAge(sym, dur, ind, mode)
            val = rpInd.ShowRecentStateValue(sym, dur, ind, mode)
            crxtime = rpInd.ShowRecentCRXTime(sym, dur, ind, mode)
            price = rpInd.ShowRecentClPrice(sym, dur, ind, mode)
            if ind == 'mcross':
                textline = []
                tlist = [
                    state, dur, stateAge, val, price, crxtime, threshold, sym,
                    ind
                ]
                for t in tlist:
                    textline.append(str(t))
                text.append(str(textline))

                print state, dur, stateAge, val, price, crxtime, threshold, sym, ind
##        Triggers = rpInd.Trigger_from_states(sym,dur,'kupper')
##        lasttwo = rpu_rp.tail_array_to_array(Triggers,2)
##        for l in lasttwo:
##            print l[0],l[1],l[7],l[5],l[8],l[11],'kupperflips'
    print recenttick(sym)
    print '======================='
    return text
def parse_signalsNEW(rulesetoutput):
##    [['result', 'SELL', 'stochkeasy1minSELL.rules.csv', ' 2015-09-23 08:16:05', 'CL', 46.36]]
    dur = ''
    if len(rulesetoutput) > 0:
        sigcount =0
        for sig in rulesetoutput:
            if len(sig) > 0  and sig[1] != 'nomatch':
                sig.append(now)
                sigtime = sig[3]
                nowepoch  =  TicksUtile.time_to_epoch(now)
##                print sig
                sigepoch  =  TicksUtile.time_to_epoch(sigtime)
                elapsed = nowepoch - sigepoch
##                print elapsed
##                print sig,'sigline',elapsed
                sigtime = sig[3]
                indvalue = 0.0 #float(sig[len(sig)-2])   <<<<<<<<<<<<<<<<<<
                sym = sig[4]
                sigtype = sig[2]
                priceinsignal = float(sig[5]) ### need to unboost the price...
                dboost = dboostdict[sym]
                newprice = priceinsignal / float(dboost)
                sig[5] = newprice
                tside =sig[1]
                dur = '0mins' # sig[8]   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                livesigid = sym+tside+dur+sigtype
                sig.append(livesigid)
                showflag = look_for_dupe_sig(livesigid,sigtime,delaydupetime)   #'notsupress'
                sigcount+=1
######                print sym,tside,sigtype,sigtime,elapsed,str(newprice)
##                if btmode == 'BACKTEST':
##                    soundarea = 'gg'
                if showflag != 'supress':
                    if tside == 'SELL':
####                        beep(soundarea+'sell')
                        print sig
####                        beep(soundarea+sym)
                        print '==============='
##                        Mbox('BuySignal', sig, style)
                    elif tside == 'BUY':
####                        beep(soundarea+'buy')
                        print sig
####                        beep(soundarea+sym)
                        print '==============='
##                        Mbox('BuySignal', sig, style)
                    else:
                        print 'supressing'
    ######                RP_Snapshot.snapshot_sym(sym,date)
                    frsigline=[]
                    rpu_rp.WriteArrayToCsvfileAppend(sigarea + date +'.recentsigs.csv', [sig])
                    rpu_rp.WriteArrayToCsvfileAppend(sigarea + date +'.recentsigsexec.csv', [sig])
Exemplo n.º 22
0
def loop_one_prepare():
    barlist = ['1min', '3mins', '15mins', '1hour', '1day']
    ## pre prepare ES for compares
    startmode = 'initialize'
    TicksUtile.prepare_tickfilesto5secBars(
        today, 'ES',
        startmode)  ## merge the 5secddload with 5sec recents > 5sec boths
    for dur in barlist:
        durinseconds = secdict[dur]
        basisdur = '5secs'
        basisfile = DataDown + today + '.' + 'ES' + '.' + basisdur + '.both.csv'
        TicksUtile.assemble_dur_bars(today, 'ES', dur, startmode, basisfile)
############## end ES prepare
    for sym in symbol_list:
        startmode = 'initialize'
        TicksUtile.prepare_tickfilesto5secBars(
            today, sym,
            startmode)  ## merge the 5secddload with 5sec recents > 5sec boths
        for dur in barlist:
            ##                print dur, sym
            durinseconds = secdict[dur]
            basisdur = '5secs'
            basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv'
            TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile)
            ##                indlist = ['StochK','Stoch_CROSS','StochD','pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower',\
            ##                           'kmid','ema','mcross', 'mcd','diffESTXvES','RSI']
            indlist = [
                'mcross', 'mcd', 'RSI', 'StochK', 'Stoch_CROSS', 'StochD',
                'kupper', 'klower', 'kmid', 'diffvES'
            ]
            rpInd.create_states_files(sym, dur.replace(' ', ''), today,
                                      threshold, indlist)
Exemplo n.º 23
0
def pnl(tside,tprice,starttime,sym,exitpnl,stoppnl,tickvalue):   
    dur = '1min'
    estarttime = TicksUtile.time_to_epoch(starttime)
    barcount =0
    sidesign = 1
    if tside == 'BUY':
        sidesign = (-1)
    DurBoth = rpu_rp.CsvToLines( DataDown+ today + '.'+sym+'.' + dur.replace(' ','') + '.both.csv')
    triggertime = 'open'
    maxpnl = -99999
    minpnl = 999999
    profittrigger =  stoptrigger = endflag ='o'
    for line in DurBoth:
        if len(line) > 2:
            rtpricelow = float(line[4])
            rtpricehigh = float(line[3])
            rangegap = rtpricehigh - rtpricelow
            time = line[1]
            baretime = TicksUtile.time_to_epoch(time)
##        else:
##            rtpricelow = rtpricehigh = 0.0
##            baretime = TicksUtile.time_to_epoch(' 2015-08-18 01:54:05')
##            time = ' 2015-08-18 01:54:05'
##            print estarttime, baretime
            if estarttime  > baretime:
                triggertime = 'tripped'
                barcount =0
            
            if triggertime == 'tripped':
                barcount +=1
                if tside == 'BUY':
                    priceused = rtpricelow
                else:
                    priceused = rtpricehigh
                pnl = ((tprice -priceused)/ tickvalue)*sidesign
                maxpnl = max(pnl,maxpnl)
                minpnl = min(pnl,minpnl)
                if maxpnl > exitpnl:
                    profittrigger = 't'
                    pass
                if minpnl < stoppnl:
                    stoptrigger ='t'
                if profittrigger == 't' and stoptrigger == 'o' and endflag != 't':
                    print 'exited for profit'
                    print sym, time, tprice, tside, pnl,maxpnl,minpnl,priceused,rangegap,barcount,starttime
                    endflag ='t'
                if stoptrigger == 't' and profittrigger == 'o' and endflag != 't':
                    print 'exited for loss'
                    endflag ='t'
                    print sym, time, tprice, tside, pnl,maxpnl,minpnl,priceused,rangegap,barcount,starttime
def make_bars_no_5sec(startmode,durmode):
    for sym in symbol_list:
        if durmode == 'alldurs':
            barlist =  barlistAll
        elif durmode == '78':
            barlist = barlist78
        else:
            barlist = barlistRecent
        for dur in barlist :
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur  = '1min'
            TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisdur)
Exemplo n.º 25
0
def make_bars_no_5sec(startmode, durmode):
    for sym in symbol_list:
        if durmode == 'alldurs':
            barlist = barlistAll
        elif durmode == '78':
            barlist = barlist78
        else:
            barlist = barlistRecent
        for dur in barlist:
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur = '1min'
            TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisdur)
def make_bars_no_5sec(startmode,durmode):
    for sym in symbol_list:
        if durmode == 'alldurs':
            barlist =  ['1min','3mins', '15mins', '1hour', '1day']
            pass
        else:
            barlist = ['1min', '3mins', '5mins', '15mins']##,'78mins']
        for dur in barlist :
##            print dur
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur  = '1min'
            TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisdur)
Exemplo n.º 27
0
def make_bars_no_5sec(startmode, durmode):
    for sym in symbol_list:
        if durmode == 'alldurs':
            barlist = ['1min', '3mins', '15mins', '1hour', '1day']
            pass
        else:
            barlist = ['1min', '3mins', '5mins', '15mins']  ##,'78mins']
        for dur in barlist:
            ##            print dur
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur = '1min'
            TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisdur)
Exemplo n.º 28
0
def snapshot_sym(sym,today,durslist):
##    print 'got her'
    text = []
    barlist = ['1min', '3mins', '5mins', '15mins', '1hour']
    basisfile = DataDown +today+'.'+sym+'.'+'5secs'+'.both.csv'
    TicksUtile.assemble_dur_bars(today,sym,'1hour','initial',basisfile)
    posstate = rpInd.ShowRecentPositionState(sym)
    text.append(posstate + sym )
    threshold =0.0
    indlist = ['mcross','kupper']
##    print posstate,sym,'recentstate age val | lastcrosstime| name USING THRESH ', threshold
    textline = 'recentstate age val name USING THRESH ' + str(threshold)
    text.append(textline)
    for dur in barlist :
##        print dur
        threshold = 0.0
        if dur == '1min':
            threshold = 0.1
##        print sym,dur
##        make_dur_state(sym,dur,threshold,indlist)
        basisdur = '5secs'
        startmode ='initialize'
        basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv'
        TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisfile)
### this relys on the sig creator to assemble each time
        rpInd.create_states_files(sym,dur,today,threshold,indlist)
        indlist = ['mcross']
        for ind in indlist:
            mode = 'noboost'     
            state = rpInd.ShowRecentState(sym,dur,ind,mode)
            stateAge = rpInd.ShowRecentAge(sym,dur,ind,mode)
            val = rpInd.ShowRecentStateValue(sym,dur,ind,mode)
            crxtime = rpInd.ShowRecentCRXTime(sym,dur,ind,mode)
            price = rpInd.ShowRecentClPrice(sym,dur,ind,mode)
            if ind == 'mcross':
                textline = []
                tlist = [state, dur, stateAge,val, price, crxtime, threshold, sym, ind]
                for t in tlist:       
                    textline.append(str(t))
                text.append(str(textline))

                print  state, dur, stateAge,val, price, crxtime, threshold, sym, ind
##        Triggers = rpInd.Trigger_from_states(sym,dur,'kupper')
##        lasttwo = rpu_rp.tail_array_to_array(Triggers,2)
##        for l in lasttwo:
##            print l[0],l[1],l[7],l[5],l[8],l[11],'kupperflips'
    print recenttick(sym)
    print '======================='
    return text
def look_for_dupe_sig(livesigid, livesigtime):
    showflag = 'show'
    livesigepoch = TicksUtile.time_to_epoch(livesigtime)
    if os.path.isfile(sigarea + today + '.recentsigs.csv'):
        tradedsigs = rpu_rp.CsvToLines(sigarea + today + '.recentsigs.csv')
        showflag = 'show'
        for lin in tradedsigs:
            if len(lin) > 3:
                sigid = lin[3]
                sigtime = lin[4]
                sigtimeepoch = TicksUtile.time_to_epoch(sigtime)
                timediff = livesigepoch - sigtimeepoch
                if sigid == livesigid and timediff < 100:
                    showflag = 'supress'
    return showflag
def look_for_dupe_sig(livesigid,livesigtime):
    showflag = 'show'
    livesigepoch = TicksUtile.time_to_epoch(livesigtime)
    if os.path.isfile(sigarea + today +'.recentsigs.csv'): 
        tradedsigs= rpu_rp.CsvToLines(sigarea + today +'.recentsigs.csv')
        showflag = 'show'     
        for lin in tradedsigs:
            if len(lin) > 3:
                sigid = lin[3]
                sigtime = lin[4]
                sigtimeepoch = TicksUtile.time_to_epoch(sigtime)
                timediff = livesigepoch - sigtimeepoch
                if sigid == livesigid and timediff < 100:
                    showflag = 'supress'
    return showflag
def show_spots(sym,date,limit,spotfile):
    curprice = float(TicksUtile.recenttick(sym,'recent'))
    spotlines= rpu_rp.CsvToLines(spotfile)
    print 'RangeLineFader is  ',limit,' Handles on ',sym, ' Future'
    for l in spotlines:
        spotp = float(l[0])
        if len(l) > 1 :
##            print l
            spotid = l[1]
            pass
        else:
            spotid=''
        distance = abs(spotp-curprice)
        if (spotp-curprice) > 0:
            underover = 'under'
        else:
            underover = 'over'
        if distance < limit:
##            print curprice-spotp,spotp,curprice,sym,'spot prices',limit
            if underover == 'under':
                print ('SELL at %8.2f %s| %s | %4.2f | %8.2f  ...is this pass #1 or #2?' % (spotp,spotid,sym,distance,curprice))
##                print 'ready to SELL at ',spotp, 'how manypasses?',curprice,sym,distance
            else:
##                print 'ready TO BUY at ',spotp, 'how manypasses?',curprice,sym,distance
                print ('BUY  at %8.2f %s| %s | %4.2f | %8.2f  ...is this pass #1 or #2?' % (spotp,spotid,sym,distance,curprice))
Exemplo n.º 32
0
def reply_handler(msg):
    if msg.typeName == 'realtimeBar':
        msgarray = (str(msg)).split()
        ##    print msgarray, 'rawmessg'
        reqid = (msgarray[1]).split('=')[1].replace(',', '')
        ##    fieldnum = (msgarray[2]).split('=')[1].replace(',','')
        sym = symTickerIddict[reqid]
        onerow = (str(msg)).split(',')
        ##    print onerow,'onerow split by comma'
        timenow = datetime.now().time().isoformat()
##        print msg.typeName, sym, timenow
    if msg.typeName == 'realtimeBar':
        cleanonerow = TicksUtile.clean_RTTick5secBars(onerow, sym)
        rpu_rp.WriteArrayToCsvfileAppend(
            DataDown + today + '.' + sym + '.RTticks.csv', [cleanonerow])
        rpu_rp.WriteArrayToCsvfile(
            DataDown + today + '.' + sym + '.RTtickslastquote.csv',
            [cleanonerow])
########    elif msg.typeName == 'tickString' or msg.typeName == 'tickSize' or msg.typeName == 'tickPrice'  :
########        onerow.append(timenow)
########        rpu_rp.WriteArrayToCsvfileAppend(DataDown +today+'.'+sym+ '.RTtickData.csv',[onerow])
########    elif msg.typeName == 'updateMktDepth':
########        onerow.append(timenow)
########        rpu_rp.WriteArrayToCsvfileAppend(DataDown +today+'.'+sym+ '.RTMktDepth.csv',[onerow])
    else:
        print str(msg)
        rpu_rp.WriteStringsToFileAppend(TMP + 'replys.RTticks', str(msg))
Exemplo n.º 33
0
def verify_bars(barfile):
    fileoutname = 'barsout.csv'
    lines = rpu_rp.CsvToLines(barfile)
    print barfile, 'needs verify'
    dur = barfile.split('.')[2]
    sym = barfile.split('.')[1]
    print dur
    durinseconds = int(secdict[dur])
    print dur, durinseconds
    preve = 0
    prevfname = 0
    ubars =[]
    uubars =[]
    diffprev = 1
    for l in lines:
        if len(l) > 2:
            timestring = l[1]
            e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
            diffcur = e - preve
##            print diffcur
            if diffcur != durinseconds:
                print sym,dur,diffcur, durinseconds,l
                ubars.append(l)
            else:
                pass
            preve = e
            prevline = l
            diffprev = diffcur
    rpu_rp.WriteArrayToCsvfile(fileoutname, ubars)
##    for b in ubars:
##        print b
    return ubars
Exemplo n.º 34
0
def show_hi_lo_bar_range(sym,dur,startbartime,endbartime,date):
    hilow = []
    prevloprice =99999
    prevhiprice = 0.0
    lowtime = hitime = closetime ='na'
    clsprice =0.0

    newbars = show_bar_range(sym,dur,startbartime,endbartime,date)
    for bar in newbars:
        if len(bar) > 2:
            curbartime = TicksUtile.time_to_epoch(bar[1])
            lowprice = float(bar[4])
            hiprice = float(bar[3])
            clsprice = float(bar[5])
            closetime = bar[1]
            lowtime = hitime ='na'
            if lowprice < prevloprice:
                prevloprice = lowprice
                lowtime = bar[1]
            if hiprice > prevhiprice:
                prevhiprice = hiprice
                hitime = bar[1]
    hilow.append(prevloprice)
    hilow.append(prevhiprice)
    hilow.append(lowtime)
    hilow.append(hitime)
    hilow.append(clsprice)
    hilow.append(closetime)
    if len(newbars) == 0:
        hilow = ['na','na','na','na','na','na']
    return hilow
def show_spots(sym, date, limit, spotfile):
    curprice = float(TicksUtile.recenttick(sym, 'recent'))
    ##    print curprice

    spotlines = rpu_rp.CsvToLines(spotfile)
    print 'RangeLineFader is  ', limit, ' Handles on ', sym, ' Future'
    for l in spotlines:
        spotp = float(l[0])
        if len(l) > 1:
            ##            print l
            spotid = l[1]
            pass
        else:
            spotid = ''
        distance = abs(spotp - curprice)
        if (spotp - curprice) > 0:
            underover = 'under'
        else:
            underover = 'over'
        if distance < limit:
            ##            print curprice-spotp,spotp,curprice,sym,'spot prices',limit
            if underover == 'under':
                print(
                    'SELL at %8.2f %s| %s | %4.2f | %8.2f  ...is this pass #1 or #2?'
                    % (spotp, spotid, sym, distance, curprice))
##                print 'ready to SELL at ',spotp, 'how manypasses?',curprice,sym,distance
            else:
                ##                print 'ready TO BUY at ',spotp, 'how manypasses?',curprice,sym,distance
                print(
                    'BUY  at %8.2f %s| %s | %4.2f | %8.2f  ...is this pass #1 or #2?'
                    % (spotp, spotid, sym, distance, curprice))
Exemplo n.º 36
0
def show_spots(sym, date, limit, spotfile):
    curprice = float(TicksUtile.recenttick(sym, 'recent'))
    spotlines = rpu_rp.CsvToLines(spotfile)
    print 'LINEFADES...################'
    for l in spotlines:
        spotp = float(l[0])
        if len(l) > 1:
            ##            print l
            spotid = l[1]
            pass
        else:
            spotid = ''
        distance = abs(spotp - curprice)
        if (spotp - curprice) > 0:
            underover = 'under'
        else:
            underover = 'over'
        if distance < limit:
            if underover == 'under':
                sflag = 'SELL'
            else:
                sflag = 'BUY'
            print(
                '>>%4s at %8.2f %s|%s |%4.2f |%8.2f > pass #1 or #2? range=%d'
                % (sflag, spotp, spotid, sym, distance, curprice, limit))
Exemplo n.º 37
0
def show_hi_lo_bar_range(sym, dur, startbartime, endbartime, date):
    hilow = []
    prevloprice = 99999
    prevhiprice = 0.0
    lowtime = hitime = closetime = 'na'
    clsprice = 0.0

    newbars = show_bar_range(sym, dur, startbartime, endbartime, date)
    for bar in newbars:
        if len(bar) > 2:
            curbartime = TicksUtile.time_to_epoch(bar[1])
            lowprice = float(bar[4])
            hiprice = float(bar[3])
            clsprice = float(bar[5])
            closetime = bar[1]
            lowtime = hitime = 'na'
            if lowprice < prevloprice:
                prevloprice = lowprice
                lowtime = bar[1]
            if hiprice > prevhiprice:
                prevhiprice = hiprice
                hitime = bar[1]
    hilow.append(prevloprice)
    hilow.append(prevhiprice)
    hilow.append(lowtime)
    hilow.append(hitime)
    hilow.append(clsprice)
    hilow.append(closetime)
    if len(newbars) == 0:
        hilow = ['na', 'na', 'na', 'na', 'na', 'na']
    return hilow
def look_for_dupe_sig(livesigid, livesigtime, delay):
    showflag = 'show'
    livesigepoch = TicksUtile.time_to_epoch(livesigtime)
    if os.path.isfile(sigarea + date + '.recentsigs.csv'):
        tradedsigs = rpu_rp.CsvToLines(sigarea + date + '.recentsigs.csv')
        showflag = 'show'
        for lin in tradedsigs:
            ##            print lin
            if len(lin) > 3:
                ##                print lin
                sigid = lin[9]
                sigtime = lin[3]
                ##                print sigid,sigtime,livesigid,livesigtime
                sigtimeepoch = TicksUtile.time_to_epoch(sigtime)
                timediff = livesigepoch - sigtimeepoch
                if sigid == livesigid and timediff < delay:
                    showflag = 'supress'
    return showflag
def make_states():
    startmode = 'bothfile'
    startmode = 'initialize'
    for sym in symbol_list:
        TicksUtile.prepare_tickfilesto5secBars(today,sym,startmode) ## merge the 5secddload with 5sec recents > 5sec boths
###### TicksUtile.prepare_fake_ddlfile(today,sym,'78mins',startmode)
        barlist = ['1min', '3mins', '5mins', '15mins']##,'78mins']
        for dur in barlist :
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur  = '1min'           
            durinseconds = secdict[dur]
            basisfile = DataDown +today+'.'+sym+'.'+basisdur+'.both.csv'
            TicksUtile.assemble_dur_bars(today,sym,dur,startmode,basisfile)
##            indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] indlist = ['mcross','mcd','diffESTXvES','RSI','STOCH','stochastic_CROSS']
            indlist = ['mcross','mcd','RSI','StochK','Stoch_CROSS','StochD']
            rpInd.create_states_files(sym,dur,today,threshold,indlist)
def look_for_dupe_sig(livesigid,livesigtime,delay):
    showflag = 'show'
    livesigepoch = TicksUtile.time_to_epoch(livesigtime)
    if os.path.isfile(sigarea + date +'.recentsigs.csv'):
        tradedsigs= rpu_rp.CsvToLines(sigarea + date +'.recentsigs.csv')
        showflag = 'show'
        for lin in tradedsigs:
##            print lin
            if len(lin) > 3:
##                print lin
                sigid = lin[9]
                sigtime = lin[3]
##                print sigid,sigtime,livesigid,livesigtime
                sigtimeepoch = TicksUtile.time_to_epoch(sigtime)
                timediff = livesigepoch - sigtimeepoch
                if sigid == livesigid and timediff < delay:
                    showflag = 'supress'
    return showflag
def look_for_REECNTdupe_sig(livesigid,livesigtime):
    livesigepoch = TicksUtile.time_to_epoch(livesigtime)
    if os.path.isfile(sigarea + today +'.recentsigs.csv'): 
        tradedsigs= rpu_rp.CsvToLines(sigarea + today +'.recentsigs.csv')
        showflag = 'show'
        
        for lin in tradedsigs:
            if len(lin) > 3:
                sigid = lin[3]
                sigtime = lin[1]
                sigtimeepoch = TicksUtile.time_to_epoch(sigtime)
                timediff = livesigepoch - sigtimeepoch
                if sigid == livesigid and timediff < 200:
                    showflag = 'supress'
                    print 'dupe ignored...',sigid, now
    else:
        showflag = 'show'
    return showflag
Exemplo n.º 42
0
def RTBar_reply_handler(msg):
    if msg.typeName == 'realtimeBar':
        reqid=(((str(msg)).split()[1]).split('=')[1]).replace(',','')
        sym=symTickerIddict[reqid]
        onerow = (str(msg)).split(',')
        cleanonerow = TicksUtile.clean_RTTick5secBars(onerow,sym)
        rpu_rp.WriteArrayToCsvfileAppend(DataDown +today+'.'+sym+ '.RTticks.csv',[cleanonerow])
        rpu_rp.WriteArrayToCsvfile(DataDown +today+'.'+sym+ '.RTtickslastquote.csv',[cleanonerow])
    else:
        print str(msg)
        rpu_rp.WriteStringsToFileAppend(TMP +'replys.RTticks',str(msg))
Exemplo n.º 43
0
def make_states():
    startmode = 'bothfile'
    startmode = 'initialize'
    for sym in symbol_list:
        TicksUtile.prepare_tickfilesto5secBars(
            today, sym,
            startmode)  ## merge the 5secddload with 5sec recents > 5sec boths
        ###### TicksUtile.prepare_fake_ddlfile(today,sym,'78mins',startmode)
        barlist = ['1min', '3mins', '5mins', '15mins']  ##,'78mins']
        for dur in barlist:
            if dur == '1min':
                basisdur = '5secs'
            else:
                basisdur = '1min'
            durinseconds = secdict[dur]
            basisfile = DataDown + today + '.' + sym + '.' + basisdur + '.both.csv'
            TicksUtile.assemble_dur_bars(today, sym, dur, startmode, basisfile)
            ##            indlist = ['pivot', 'R', 'S', 'S2', 'R2','kupper', 'klower', 'kmid','ema','mcross', 'mcd'] indlist = ['mcross','mcd','diffESTXvES','RSI','STOCH','stochastic_CROSS']
            indlist = [
                'mcross', 'mcd', 'RSI', 'StochK', 'Stoch_CROSS', 'StochD'
            ]
            rpInd.create_states_files(sym, dur, today, threshold, indlist)
Exemplo n.º 44
0
def show_bar_range(sym,dur,startbartime,endbartime,date):
##    print date
    datehyphen = rpu_rp.todaysdatehypens(date)
##    print datehyphen
    startbartime = TicksUtile.time_to_epoch(datehyphen + startbartime)
    endbartime = TicksUtile.time_to_epoch(datehyphen + endbartime)

    stem = '.'+dur +'.both.csv'
    if dur == 'RTicks':
        stem = '.RTticks.csv'
    barfile =  DataDown + date + '.' + sym + stem
    bars = rpu_rp.CsvToLines(barfile)
    newbars =[]
    for bar in bars:
        if len(bar) > 2:
##            print bar,'is bar'
            curbartime = TicksUtile.time_to_epoch(bar[1])
            if curbartime > startbartime and curbartime < endbartime:
                newbars.append(bar)
##    for b in newbars:
##        print b
    return newbars
Exemplo n.º 45
0
def show_bar_range(sym, dur, startbartime, endbartime, date):
    ##    print date
    datehyphen = rpu_rp.todaysdatehypens(date)
    ##    print datehyphen
    startbartime = TicksUtile.time_to_epoch(datehyphen + startbartime)
    endbartime = TicksUtile.time_to_epoch(datehyphen + endbartime)

    stem = '.' + dur + '.both.csv'
    if dur == 'RTicks':
        stem = '.RTticks.csv'
    barfile = DataDown + date + '.' + sym + stem
    bars = rpu_rp.CsvToLines(barfile)
    newbars = []
    for bar in bars:
        if len(bar) > 2:
            ##            print bar,'is bar'
            curbartime = TicksUtile.time_to_epoch(bar[1])
            if curbartime > startbartime and curbartime < endbartime:
                newbars.append(bar)
##    for b in newbars:
##        print b
    return newbars
Exemplo n.º 46
0
def reply_handler(msg):
    if msg.typeName == 'realtimeBar':
        reqid=(((str(msg)).split()[1]).split('=')[1]).replace(',','')
        sym=symTickerIddict[reqid]
        onerow = (str(msg)).split(',')
        cleanonerow = TicksUtile.format_RTTickoneline_to_5secBars(onerow,sym)
        rpu_rp.WriteArrayToCsvfileAppend(DataDown +today+'.'+sym+ '.RTticks.csv',[cleanonerow])
        rpu_rp.WriteArrayToCsvfile(DataDown +today+'.'+sym+ '.RTtickslastquote.csv',[cleanonerow])
    else:
        if 'connection is OK' in str(msg):
            pass
        else:
            print str(msg)
            rpu_rp.WriteStringsToFileAppend(replyfname,str(msg))
Exemplo n.º 47
0
def ShowIndBar(sym,dur,ind,mode,barnum,bartime):
    barfnumlimit = 500
    lastbar =[]
    statefile = statearea + sym + '.' +  dur + '.' + ind  + '.state.csv'
    arrayin = rpu_rp.CsvToLines(statefile)
    barcount = len(arrayin)
    lastbar = (rpu_rp.tail_array_to_array(arrayin,1))[0]
    nbar = (rpu_rp.tail_array_to_array(arrayin,barnum))[0]
    lastfewbars = (rpu_rp.tail_array_to_array(arrayin,barfnumlimit))
    for bar in lastfewbars:
        if TicksUtile.time_to_epoch(bar[0]) <= TicksUtile.time_to_epoch(bartime) :
            timedbar = bar
    if mode == 'barcount':
        output = barcount
    elif mode == 'LastBar':
        output = lastbar
    elif mode == 'nbar':
        output = nbar
    elif mode == 'bytime':
        output = timedbar
    elif mode == 'barcount':
        output = barcount
    return output
Exemplo n.º 48
0
def ShowIndBar(sym, dur, ind, mode, barnum, bartime):
    barfnumlimit = 500
    lastbar = []
    statefile = statearea + sym + '.' + dur + '.' + ind + '.state.csv'
    arrayin = rpu_rp.CsvToLines(statefile)
    barcount = len(arrayin)
    lastbar = (rpu_rp.tail_array_to_array(arrayin, 1))[0]
    nbar = (rpu_rp.tail_array_to_array(arrayin, barnum))[0]
    lastfewbars = (rpu_rp.tail_array_to_array(arrayin, barfnumlimit))
    for bar in lastfewbars:
        if TicksUtile.time_to_epoch(
                bar[0]) <= TicksUtile.time_to_epoch(bartime):
            timedbar = bar
    if mode == 'barcount':
        output = barcount
    elif mode == 'LastBar':
        output = lastbar
    elif mode == 'nbar':
        output = nbar
    elif mode == 'bytime':
        output = timedbar
    elif mode == 'barcount':
        output = barcount
    return output
Exemplo n.º 49
0
def run_oneloop(dur,now,sym):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
    print '##### ',now, dur, sym,' ####### '

    Createlines.create_HAs([sym])
    filen = DataDown +date +'.'+sym+'.'+dur + '.both.HA.csv'
    perc = .80
    maxlines = 4
    difflimit = 400
    taglist = ['buy','sell']
    for tag in taglist:    
        b = showlines(filen,tag)
        print '#############'
        print '>>>>>> ',tag.upper(), ' <<<'
        lenha = len(b)
        c=0
        climitlines = int(lenha * perc)
        climit = max((lenha-maxlines),climitlines)
        bar_time = '  2016-02-21 13:16:30'
        for lha in b:
            if len(lha.split('|')) > 2:
                bar_time = (lha.split('|')[3]).replace(' 201','201')
            c+=1
            bar_time_epoch =  TicksUtile.time_to_epoch(bar_time)
            
            tdiff =  now_epoch - bar_time_epoch
            if c > climit and tdiff < difflimit :
                print lha,'>>> ',tdiff #,difflimit
            #######
    taglist = ['allxx']
    for tag in taglist:    
        b = showlines(filen,tag)
        print '    '
        print '>>>>>> ',tag,sym,dur,now
        lenha = len(b)
        c=0
        climitlines = int(lenha * perc)
        climit = max((lenha-maxlines+2),climitlines)
        bar_time = '  2016-02-21 13:16:30'
        for lha in b:
##            if len(lha.split('|')) > 2:
##                bar_time = (lha.split('|')[3]).replace(' 201','201')
            c+=1
##            bar_time_epoch =  TicksUtile.time_to_epoch(bar_time)
            difflimit = 1800000000
            tdiff = bar_time_epoch - now_epoch + difflimit
            if c > climit and tdiff > 0 :
                print lha    
Exemplo n.º 50
0
def run_oneloop(dur, now, sym):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
    print '##### ', now, dur, sym, ' ####### '

    Createlines.create_HAs([sym])
    filen = DataDown + date + '.' + sym + '.' + dur + '.both.HA.csv'
    perc = .80
    maxlines = 4
    difflimit = 400
    taglist = ['buy', 'sell']
    for tag in taglist:
        b = showlines(filen, tag)
        print '#############'
        print '>>>>>> ', tag.upper(), ' <<<'
        lenha = len(b)
        c = 0
        climitlines = int(lenha * perc)
        climit = max((lenha - maxlines), climitlines)
        bar_time = '  2016-02-21 13:16:30'
        for lha in b:
            if len(lha.split('|')) > 2:
                bar_time = (lha.split('|')[3]).replace(' 201', '201')
            c += 1
            bar_time_epoch = TicksUtile.time_to_epoch(bar_time)

            tdiff = now_epoch - bar_time_epoch
            if c > climit and tdiff < difflimit:
                print lha, '>>> ', tdiff  #,difflimit
            #######
    taglist = ['allxx']
    for tag in taglist:
        b = showlines(filen, tag)
        print '    '
        print '>>>>>> ', tag, sym, dur, now
        lenha = len(b)
        c = 0
        climitlines = int(lenha * perc)
        climit = max((lenha - maxlines + 2), climitlines)
        bar_time = '  2016-02-21 13:16:30'
        for lha in b:
            ##            if len(lha.split('|')) > 2:
            ##                bar_time = (lha.split('|')[3]).replace(' 201','201')
            c += 1
            ##            bar_time_epoch =  TicksUtile.time_to_epoch(bar_time)
            difflimit = 1800000000
            tdiff = bar_time_epoch - now_epoch + difflimit
            if c > climit and tdiff > 0:
                print lha
Exemplo n.º 51
0
def reply_handler(msg):
    if msg.typeName == 'realtimeBar':
        reqid = (((str(msg)).split()[1]).split('=')[1]).replace(',', '')
        sym = symTickerIddict[reqid]
        onerow = (str(msg)).split(',')
        cleanonerow = TicksUtile.format_RTTickoneline_to_5secBars(onerow, sym)
        rpu_rp.WriteArrayToCsvfileAppend(
            DataDown + today + '.' + sym + '.RTticks.csv', [cleanonerow])
        rpu_rp.WriteArrayToCsvfile(
            DataDown + today + '.' + sym + '.RTtickslastquote.csv',
            [cleanonerow])
    else:
        if 'connection is OK' in str(msg):
            pass
        else:
            print str(msg)
            rpu_rp.WriteStringsToFileAppend(replyfname, str(msg))
Exemplo n.º 52
0
def show_spots(sym,date,limit):
    curprice = float(TicksUtile.recenttick(sym,'recent'))
    spotfile = libarea + 'spotlines.' + sym+ '.csv'
    spotlines= rpu_rp.CsvToLines(spotfile)
    print limit, ' is limit'
    for l in spotlines:
        spotp = float(l[0])
        distance = abs(spotp-curprice)
        if (spotp-curprice) > 0:
            underover = 'under'
        else:
            underover = 'over'
        if distance < limit:
##            print curprice-spotp,spotp,curprice,sym,'spot prices',limit
            if underover == 'under':
                print 'ready to SELL at ',spotp, 'how manypasses?',curprice,sym,distance
            else:
                print 'ready TO BUY at ',spotp, 'how manypasses?',curprice,sym,distance
Exemplo n.º 53
0
def check_bars(bararray):  ### what does this do?
    lines = bararray
    preve = 0
    prevfname = 0
    ubars =[]
    uubars =[]
    diffprev = 1
    for l in lines:
        if len(l) > 2:
            timestring = l[1]
            e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
            diffcur = e - preve
##            fname = int(l[7])
            fname = str(l[7])
##            fnamediff = fname - prevfname
            # analyze this bars diff and the previous...
            if diffcur == 0 :
                print l
                '''and diffprev == 0: