Exemplo n.º 1
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)
def run_oneloop(dur, now, sym, date):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
    ##    print '##### ',now, dur, sym,' ####### '
    ##    Createlines.create_HAs([sym],date)
    print 'got to clines'
    Createlines.make_both_states([sym], date)
    ##########
    perc = .70
    maxlines = 5
    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.convertTime(
                    bar_time, 'dashspace', 'timetoepoch')
                tdiff = now_epoch - bar_time_epoch
            else:
                bar_time_epoch = TicksUtile.convertTime(
                    bar_time, 'dashspace', 'timetoepoch')
                tdiff = 0  # now_epoch - bar_time_epoch
            if c > climit and tdiff < difflimit:
                print lha, '>>> ', tdiff  #,difflimit
def run_oneloop(dur,now,sym,date):
    now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format)))
##    print '##### ',now, dur, sym,' ####### '
##    Createlines.create_HAs([sym],date)
    print 'got to clines'
    Createlines.make_both_states([sym],date)
    ##########
    perc = .70
    maxlines = 5
    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.convertTime(bar_time,'dashspace','timetoepoch')       
                tdiff =  now_epoch - bar_time_epoch
            else:
                    bar_time_epoch =  TicksUtile.convertTime(bar_time,'dashspace','timetoepoch')          
                    tdiff =  0# now_epoch - bar_time_epoch                
            if c > climit and tdiff < difflimit :
                print lha,'>>> ',tdiff #,difflimit
Exemplo n.º 4
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.º 5
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:
Exemplo n.º 6
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.convertTime(
                bartime, 'dashspace', 'timetoepoch'):
            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.º 7
0
def get_dload_barsWbu(start_path,dur,barfileout,sym):
    import TicksUtile   
    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  :
                fp = os.path.join(dirpath, f)
                total_size += os.path.getsize(fp)
##############                print  fp,'working'
                lines = rpu_rp.CsvToLines(fp)
                for l in lines:
                    newl =[]
                    if len(l) > 2:
                        timestring = l[1]
                        e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
##                        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)
    sortednewalls = sorted(newalls,key=itemgetter(0),reverse=False)
    sortednewallsu = rpu_rp.uniq(sortednewalls)

    sortednewallsuClean = []
    preve = 0
    for l in sortednewallsu:
        timestring = l[1]
        try:
            e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
        except:
            print timestring,' did not work, needs old format'
            e = TicksUtile.convertTime(timestring,'dashspace','timetoepoch')
        diffcur = e - preve
        preve = e
        if diffcur >= int(secs) or '22:30:00'  in timestring:
            sortednewallsuClean.append(l)
        else:
##            print diffcur,timestring,dur,'did not pass test'
            pass
    lenfull = len(sortednewallsuClean)
    third1 = int(round(lenfull/3))
    third2 = 2*third1
    third3 = lenfull - third2 + 1
    print lenfull,third1,third2,third3,dur,sym
    part33 =  rpu_rp.head_array_to_array(sortednewallsuClean,third1)
    third2array = rpu_rp.head_array_to_array(sortednewallsuClean,third2)
    part34 =  rpu_rp.tail_array_to_array(third2array,third1)
    part35 =  rpu_rp.tail_array_to_array(sortednewallsuClean,third3)
                     
    rpu_rp.WriteArrayToCsvfile(fileoutname, part33)
    third2name = fileoutname.replace('33','34')
    rpu_rp.WriteArrayToCsvfile(third2name, part34)
    third3name = fileoutname.replace('33','35')
    rpu_rp.WriteArrayToCsvfile(third3name, part35)