Пример #1
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
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 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])
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])
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 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
Пример #10
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
Пример #11
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 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
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
Пример #15
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
Пример #16
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
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
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
Пример #19
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
Пример #20
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    
Пример #21
0
def get_dload_barsWbu(start_path, dur, barfileout, sym):
    total_size = 0
    alllines = []
    alltimes = []
    fileoutname = barfileout
    for dirpath, dirnames, filenames in os.walk(start_path):
        ##        print dirpath
        subdirsize = 0
        for f in filenames:
            ##            if 'ES.'+dur+'.ddload' in f :
            if '.' + sym + '.' + dur + '.ddload' in f:
                print f
                fp = os.path.join(dirpath, f)
                total_size += os.path.getsize(fp)
                print fp, 'working'
                lines = rpu_rp.CsvToLines(fp)
                for l in lines:
                    ##                    print l
                    newl = []
                    if len(l) > 2:
                        timestring = l[1]
                        e = TicksUtile.time_to_epoch(timestring)
                        ##                        fsourcedate = f.replace('.ES.'+dur+'.ddload.csv','')
                        fsourcedate = f.split('.')[0]
                        fsourcesym = f.split('.')[1]
                        fsourcedur = f.split('.')[2]
                        l.append(fsourcedate)
                        l.append(fsourcesym)
                        l.append(fsourcedur)
                        newl.append(l[8])
                        newl.append(l[9])

                        newl.append(l[1])
                        newl.append(l[7])

                        newl.append(l[2])
                        newl.append(l[3])
                        newl.append(l[4])
                        newl.append(l[5])
                        newl.append(l[6])
                        alllines.append(newl)
    from operator import itemgetter, attrgetter, methodcaller
    sortedall = sorted(alllines, key=itemgetter(0, 1, 2, 3), reverse=True)
    usort = rpu_rp.uniqnosort(sortedall)
    prevdur = time = ''
    cleans = []
    for y in usort:
        ##        print y
        dur = y[2]
        time = y[3]
        if dur == prevdur and time == prevtime:
            ##            print y
            ##            print prevy,'prev'
            pass
        else:
            cleans.append(y)
        prevdur = dur
        prevtime = time
        prevy = y
    rpu_rp.WriteArrayToCsvfile(fileoutname + 'news', cleans)
    newalls = []
    for n in cleans:
        ##        print n
        newn = []
        sym = n[0]
        dur = n[1]
        time = n[2]
        openp = n[4]
        hip = n[5]
        lowp = n[6]
        closep = n[7]
        volu = n[8]
        newn.append(sym)
        newn.append(time)
        newn.append(openp)
        newn.append(hip)
        newn.append(lowp)
        newn.append(closep)
        newn.append(volu)
        newalls.append(newn)
    rpu_rp.WriteArrayToCsvfile(fileoutname, newalls)
Пример #22
0
def get_dload_barsWbu(start_path,dur,barfileout,sym):
    total_size = 0
    alllines =[]
    alltimes =[]
    fileoutname = barfileout
    for dirpath, dirnames, filenames in os.walk(start_path):
##        print dirpath
        subdirsize = 0
        for f in filenames:
##            if 'ES.'+dur+'.ddload' in f :
            if '.'+sym+'.'+dur+'.ddload' in f  :
                print f
                fp = os.path.join(dirpath, f)
                total_size += os.path.getsize(fp)
                print  fp,'working'
                lines = rpu_rp.CsvToLines(fp)
                for l in lines:
##                    print l
                    newl =[]
                    if len(l) > 2:
                        timestring = l[1]
                        e = TicksUtile.time_to_epoch(timestring)
##                        fsourcedate = f.replace('.ES.'+dur+'.ddload.csv','')
                        fsourcedate = f.split('.')[0]
                        fsourcesym = f.split('.')[1]
                        fsourcedur = f.split('.')[2]
                        l.append(fsourcedate)
                        l.append(fsourcesym)
                        l.append(fsourcedur)
                        newl.append(l[8])
                        newl.append(l[9])

                        newl.append(l[1])
                        newl.append(l[7])

                        newl.append(l[2])
                        newl.append(l[3])
                        newl.append(l[4])
                        newl.append(l[5])
                        newl.append(l[6])
                        alllines.append(newl)
    from operator import itemgetter, attrgetter, methodcaller
    sortedall = sorted(alllines,key=itemgetter(0,1,2,3),reverse=True)
    usort = rpu_rp.uniqnosort(sortedall)
    prevdur = time = ''
    cleans =[]
    for y in usort:
##        print y
        dur = y[2]
        time = y[3]
        if dur == prevdur and time == prevtime:
##            print y
##            print prevy,'prev'
            pass
        else:
            cleans.append(y)
        prevdur = dur
        prevtime = time
        prevy = y
    rpu_rp.WriteArrayToCsvfile(fileoutname+'news', cleans)
    newalls=[]
    for n in cleans:
##        print n
        newn =[]
        sym = n[0]
        dur = n[1]
        time = n[2]
        openp = n[4]
        hip = n[5]
        lowp = n[6]
        closep = n[7]
        volu = n[8]
        newn.append(sym)
        newn.append(time)
        newn.append(openp)
        newn.append(hip)
        newn.append(lowp)
        newn.append(closep)
        newn.append(volu)
        newalls.append(newn)
    rpu_rp.WriteArrayToCsvfile(fileoutname, newalls)