def find_swing_points(sym, barsize, start, end): arrayin = [[ 'ES', ' 2015-10-20 22:58:05', 2019.5, 2020.25, 2019.5, 2019.75, 'full', '60' ], [ 'ES', ' 2015-10-20 22:58:05', 2019.5, 2020.25, 2019.5, 2019.75, 'full', '60' ]] bs = strip1float(arrayin, 5, sym) ##raw close price symES = 'ES' ## date = rpu_rp.todaysdateunix() ## EsFile = rpu_rp.CsvToLines(DataDown + date + '.' + symES + '.' + dur.replace(' ', '') + '.both.csv') DurBothBoostedES = boost_pricearray(EsFile, symES) bsES = strip1float(DurBothBoostedES, 5, 'ES') ## print sym,dur,Indtitle bsopen = strip1float(arrayin, 2, sym) ##raw open price bshighs = strip1float(arrayin, 3, sym) bslows = strip1float(arrayin, 4, sym) bsbardiff = difftwoarrays(bs, bsopen) barrange = difftwoarrays(bshighs, bslows) timestamparray = strip1string(arrayin, 1) stochval = 14 stochval2 = 3 rvival = 4 rvival2 = 10 comparebs = rpu_rp.tail_array_to_array(bs, 100) compareES = rpu_rp.tail_array_to_array(bsES, 100) comparetimes = rpu_rp.tail_array_to_array(timestamparray, 100) bars = get_bars(today, sym, barsize, start, end)
def get_latest_tick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] for f in tickline: if 'close' in str(f): lasttick = f.split('=')[1] return lasttick
def ShowABarofBars(sym, dur, barnum): lastbar = [] ## statefile = DataDown + sym + '.' + dur + '.' + ind + '.state.csv' statefile = DataDown + today + '.' + sym + '.' + dur + '.both.csv' lastbar = (rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(statefile), barnum))[0] return lastbar
def recenttick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] for f in tickline: if 'close' in str(f): lasttick = f.split('=')[1] return lasttick
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 get_latest_tick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile), 1) for f in tickline: if '2015' in str(f): print f lasttick = f[5] return lasttick
def get_latest_tick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1) for f in tickline: if '2016' in str(f): ## print f lasttick = f[5] return lasttick
def recenttick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickvalue = float(tickvaluedict[sym]) if os.path.isfile(RecentTickFile) : tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] lasttick = rounderrp(float(tickline[5]),tickvalue) else: lasttick = 9999 return lasttick
def presort(sym,style): larray=[] filein = DataDown +date+'.'+sym+ '.RTMktDepth.csv' if style == 'dom': for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein),1000): if 'updateMktDepth' in str(line): ## print line larray.append(line) return larray
def presortDOM(sym,style): larray=[] filein = DataDown +today+'.'+sym+ '.RTMktDepth.csv' if style == 'dom': for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein),1000): if 'updateMktDepth' in str(line): ## print line larray.append(line) return larray
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 recenttick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' if os.path.isfile(RecentTickFile) : tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] for f in tickline: if 'close' in str(f): lasttick = f.split('=')[1] else: lasttick =1 return lasttick
def last_bar_epoch(filename, roundformat): #'rounded or noround #last_bar_epochrounded ## from datetime import date, timedelta, datetime, time from datetime import datetime, timedelta twolines = [] try: if 'both' in filename: stag = 'partial' else: stag = 'xxcxxx' twolines = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filename), 2) ## print twolines for line in twolines: ### the both file has partial tag, ddload does not if stag not in str(line): timeofbar = line[1] ## print timeofbar if len(twolines) == 0: lastlines = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filename), 2) timeofbar = ' 2000-01-01 23:59:51' #### <<< this needs work!!!!! possible bad for hourly merging early in day if roundformat == 'noround': epochtimeofbar = convertTime(timeofbar, 'dashspace', 'timetoepoch') # ###### print epochtimeofbar,'bla' else: roundTo = 60 timeb = datetime.strptime(timeofbar, spaceYtime_format) dt = timeb seconds = (dt - dt.min).seconds # // is a floor division, not a comment on following line: rounding = (seconds + roundTo / 2) // roundTo * roundTo roundtime = dt + timedelta(0, rounding - seconds, -dt.microsecond) epochtimeofbar = convertTime( str(roundtime), 'dashnospace', 'timetoepoch' ) # int(time.mktime(time.strptime(timeofbar, formatstring))) except: timeofbar = ' 2000-03-01 23:59:51' print 'bombed getting last bar epoch time in TicksUtile here' print 'probably missing a download file for one or all durations' ## epochtimeofbar = convertTime(timeofbar,'dashspace','timetoepoch') print timeofbar, filename return epochtimeofbar
def createVolHistogram(sym, fnums): ## fullarray =[] ## today = '20151013' filein = DataDown + today + '.' + sym + '.RTtickData.csv' prevtotdiff = ask = bid = 0 string = '' time = '' size = '' tprice = 0.0 tsize = singletrade = totdaysize = vwap = '' totdowns = totups = 0 tottickups = 0 pricearrayraw = [] pnsize = [] lastsize = lastprice = bidsize = asksize = 9999 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein), 4440000): if 'tickString' in str(line) and 'tickType=48' in str(line): pnsizeline = [] ## print line time = line[3] string = line[2].split(';') if len(string) > 2: ## print string tprice = float(string[0].replace('value=', '')) tsize = float(string[1]) singletrade = string[5] totdaysize = string[3] vwaps = string[4] if len(vwaps) > 0: vwap = round(float(string[4]), 2) else: vwap = 0.0 ## value=1984.50;1;1441796865858;207069;1982.49963539;true> ## print tsize,tprice,time,'trade', bid, ask, bidsize, asksize pricearrayraw.append(tprice) pnsizeline.append(tprice) pnsizeline.append(tsize) pnsize.append(pnsizeline) uarray = rpu_rp.uniqArray(pricearrayraw) ldiv = 100 print "\n" * 50 strings = '' for price in uarray: lvol = 0.0 for l in pnsize: if price == l[0]: lvol += l[1] if lvol > 6: ## print ('avg %6.2f ... %4d .. %s' % (price,lvol,int(lvol/ldiv)*'l')) strings += ('avg %6.2f ... %4d .. %s\n' % (price, lvol, int(lvol / ldiv) * 'l')) print strings Mbox('b', strings, '')
def recenttick(sym): RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickvalue = float(tickvaluedict[sym]) if os.path.isfile(RecentTickFile) : tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] for f in tickline: if 'close' in str(f): lasttick = rounderrp(float(f.split('=')[1]),tickvalue) else: lasttick =1 return lasttick
def presort(sym,style,headnum,tailnum): larray=[] filein = DataDown +date+'.'+sym+ '.RTMktDepth.csv' if style == 'dom': topsection = rpu_rp.head_array_to_array(rpu_rp.CsvToLines(filein),headnum) print len(topsection) for line in rpu_rp.tail_array_to_array(topsection,tailnum): if 'updateMktDepth' in str(line): ## print line larray.append(line) return larray
def createVolHistogram(sym,fnums): ## fullarray =[] ## today = '20151013' filein = DataDown +today+'.'+sym+ '.RTtickData.csv' prevtotdiff = ask = bid =0 string ='' time = '' size = '' tprice = 0.0 tsize = singletrade = totdaysize= vwap ='' totdowns = totups = 0 tottickups=0 pricearrayraw =[] pnsize =[] lastsize = lastprice = bidsize = asksize = 9999 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein),4440000): if 'tickString' in str(line) and 'tickType=48' in str(line): pnsizeline =[] ## print line time = line[3] string = line[2].split(';') if len(string) > 2: ## print string tprice = float(string[0].replace('value=','')) tsize = float(string[1]) singletrade = string[5] totdaysize = string[3] vwaps = string[4] if len(vwaps) > 0: vwap = round(float(string[4]),2) else: vwap =0.0 ## value=1984.50;1;1441796865858;207069;1982.49963539;true> ## print tsize,tprice,time,'trade', bid, ask, bidsize, asksize pricearrayraw.append(tprice) pnsizeline.append(tprice) pnsizeline.append(tsize) pnsize.append(pnsizeline) uarray = rpu_rp.uniqArray(pricearrayraw) ldiv = 100 print "\n" * 50 strings ='' for price in uarray: lvol =0.0 for l in pnsize: if price == l[0]: lvol += l[1] if lvol > 6 : ## print ('avg %6.2f ... %4d .. %s' % (price,lvol,int(lvol/ldiv)*'l')) strings += ('avg %6.2f ... %4d .. %s\n' % (price,lvol,int(lvol/ldiv)*'l')) print strings Mbox('b', strings, '')
def presort(sym, style, headnum): larray = [] filein = DataDown + date + '.' + sym + '.RTMktDepth.csv' if style == 'dom': topsection = rpu_rp.head_array_to_array(rpu_rp.CsvToLines(filein), headnum) print len(topsection) for line in rpu_rp.tail_array_to_array(topsection, 1000): if 'updateMktDepth' in str(line): ## print line larray.append(line) return larray
def gatherline(sym,ind): ## print sym, ind #take a price syand find the 2 lines over and under it.... dur = '1day' if ind == 'pivot': indfile = statearea + sym + '.' + dur + '.' + 'pivot.state.csv' elif ind == 'R' : indfile = statearea + sym + '.' + dur + '.' + 'R.state.csv' else: indfile = statearea + sym + '.' + dur + '.' + 'S.state.csv' lineprice = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(indfile),1)[0] ## print lineprice return lineprice
def gatherline(sym, ind): ## print sym, ind #take a price syand find the 2 lines over and under it.... dur = '1day' if ind == 'pivot': indfile = statearea + sym + '.' + dur + '.' + 'pivot.state.csv' elif ind == 'R': indfile = statearea + sym + '.' + dur + '.' + 'R.state.csv' else: indfile = statearea + sym + '.' + dur + '.' + 'S.state.csv' lineprice = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(indfile), 1)[0] ## print lineprice return lineprice
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 gatherline(sym,ind): dur = '1day' if ind == 'pivot': indfile = statearea + sym + '.' + dur + '.' + 'pivot.state.csv' elif ind == 'R' : indfile = statearea + sym + '.' + dur + '.' + 'R.state.csv' elif ind == 'R' : indfile = statearea + sym + '.' + dur + '.' + 'R2.state.csv' elif ind == 'R' : indfile = statearea + sym + '.' + dur + '.' + 'S2.state.csv' else: indfile = statearea + sym + '.' + dur + '.' + 'S.state.csv' lineprice = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(indfile),1)[0] return lineprice
def find_swing_points(sym,barsize,start,end): arrayin = [['ES', ' 2015-10-20 22:58:05',2019.5,2020.25,2019.5,2019.75,'full','60'],['ES', ' 2015-10-20 22:58:05',2019.5,2020.25,2019.5,2019.75,'full','60']] bs = strip1float(arrayin,5,sym) ##raw close price symES = 'ES' ## date = rpu_rp.todaysdateunix() ## EsFile = rpu_rp.CsvToLines( DataDown+ date + '.'+symES+'.' + dur.replace(' ','') + '.both.csv') DurBothBoostedES = boost_pricearray(EsFile,symES) bsES = strip1float(DurBothBoostedES,5,'ES') ## print sym,dur,Indtitle bsopen = strip1float(arrayin,2,sym) ##raw open price bshighs = strip1float(arrayin,3,sym) bslows = strip1float(arrayin,4,sym) bsbardiff = difftwoarrays(bs,bsopen) barrange = difftwoarrays(bshighs,bslows) timestamparray = strip1string(arrayin,1) stochval = 14 stochval2 = 3 rvival = 4 rvival2 = 10 comparebs = rpu_rp.tail_array_to_array(bs,100) compareES = rpu_rp.tail_array_to_array(bsES,100) comparetimes = rpu_rp.tail_array_to_array(timestamparray,100) bars = get_bars(today,sym,barsize,start,end)
def last_bar_epoch(filename,roundformat): #'rounded or noround #last_bar_epochrounded ## from datetime import date, timedelta, datetime, time from datetime import datetime, timedelta twolines =[] try: if 'both' in filename: stag = 'partial' else: stag = 'xxcxxx' twolines = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filename),2) ## print twolines for line in twolines: ### the both file has partial tag, ddload does not if stag not in str(line): timeofbar = line[1] ## print timeofbar if len(twolines) == 0: lastlines = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filename),2) timeofbar = ' 2000-01-01 23:59:51' #### <<< this needs work!!!!! possible bad for hourly merging early in day if roundformat == 'noround': epochtimeofbar = convertTime(timeofbar,'dashspace','timetoepoch')# ###### print epochtimeofbar,'bla' else: roundTo=60 timeb = datetime.strptime(timeofbar, spaceYtime_format) dt = timeb seconds = (dt - dt.min).seconds # // is a floor division, not a comment on following line: rounding = (seconds+roundTo/2) // roundTo * roundTo roundtime = dt + timedelta(0,rounding-seconds,-dt.microsecond) epochtimeofbar = convertTime(str(roundtime),'dashnospace','timetoepoch')# int(time.mktime(time.strptime(timeofbar, formatstring))) except: timeofbar =' 2000-03-01 23:59:51' print 'bombed getting last bar epoch time in TicksUtile here' print 'probably missing a download file for one or all durations' ## epochtimeofbar = convertTime(timeofbar,'dashspace','timetoepoch') print timeofbar, filename return epochtimeofbar
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
def recenttick(sym,mode): if mode == 'recent': RTFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' elif mode == '1min': RTFile = DataDown + today + '.' + sym + '.1min.ddload.csv' else: RTFile = DataDown + today + '.' + sym + '.1min.both.csv' tickvalue = float(tickvaluedict[sym]) if os.path.isfile(RTFile) : arr = rpu_rp.CsvToLines(RTFile) tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RTFile),1)[0] ## tickp = (tickline[2]).replace(' price=','')# price=8948.5', ## for using live ticker nto 5sec tickp = tickline[5] ## uses 5 sec tick bar style lasttick = rpu_rp.rounderrp(float(tickp),tickvalue) else: lasttick = 9999 return lasttick
def recenttick(sym, mode): if mode == 'recent': RTFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' elif mode == '1min': RTFile = DataDown + today + '.' + sym + '.1min.ddload.csv' else: RTFile = DataDown + today + '.' + sym + '.1min.both.csv' tickvalue = float(tickvaluedict[sym]) if os.path.isfile(RTFile): arr = rpu_rp.CsvToLines(RTFile) tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RTFile), 1)[0] ## tickp = (tickline[2]).replace(' price=','')# price=8948.5', ## for using live ticker nto 5sec tickp = tickline[5] ## uses 5 sec tick bar style lasttick = rpu_rp.rounderrp(float(tickp), tickvalue) else: lasttick = 9999 return lasttick
def check_for_lines(sym): ##eventually add time range / how to see approaching? start = '00:00:00' end = '19:00:00' spotlines=[1970.00,1960.00,1972.50,1956,1978.0,1983.0,1989.0,2030.0,2075.0] ##spotlines = file and later perhaps dict... autocreate roundies at least bars = RP_Snapshot.show_bar_range(sym,'5mins',start,end,date) for spotline in rpu_rp.tail_array_to_array(spotlines,2): ## print spotline for l in bars: close = float(l[5]) difftoline = close - spotline if difftoline < 0.00001: tag = 'below' pass else: tag = 'above' if abs(difftoline) < 2.50: print difftoline, 'SPOTon >>> ',spotline, tag
def check_for_lines( sym): ##eventually add time range / how to see approaching? start = '00:00:00' end = '19:00:00' spotlines = [ 1970.00, 1960.00, 1972.50, 1956, 1978.0, 1983.0, 1989.0, 2030.0, 2075.0 ] ##spotlines = file and later perhaps dict... autocreate roundies at least bars = RP_Snapshot.show_bar_range(sym, '5mins', start, end, date) for spotline in rpu_rp.tail_array_to_array(spotlines, 2): ## print spotline for l in bars: close = float(l[5]) difftoline = close - spotline if difftoline < 0.00001: tag = 'below' pass else: tag = 'above' if abs(difftoline) < 2.50: print difftoline, 'SPOTon >>> ', spotline, tag
def prepare_tickfilesto5secBars(today, sym, startmode): ## print 'preparing 5secs in tickutiles...',startmode durinseconds = 1 singleslist = glob.glob(DataDown + today + '.' + sym + '.rtimebar.*') newsingles = [] filesinglebars = DataDown + today + '.' + sym + '.' + '5secs' + '.singlesb.csv' for f in singleslist: fline = rpu_rp.CsvToLines(f) newsingles.append(fline[0]) ## movefile = f.replace(DataDown,DataDown+'tempsingles/') ## movearea = DataDown+'tempsingles' ## shutil.move(f,movearea) os.remove(f) rpu_rp.WriteArrayToCsvfileAppend(filesinglebars, newsingles) basisdur = 'RTticks' outputdur = '5secs' basisFile = filesinglebars # DataDown +today+'.'+sym+ '.'+ basisdur +'.csv' if startmode == 'initialize': basisBars = rpu_rp.CsvToLines(basisFile) else: basisBars = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(basisFile), 40) create_bars_from_bars(basisBars, today, sym, outputdur, durinseconds, 'initialize') #. .. this creates the recent file 5secs used in merge_bar #### print 'got here in preparer creator finished' outputbothFile = DataDown + today + '.' + sym + '.' + outputdur + '.both.csv' file1 = DataDown + today + '.' + sym + '.' + '5secs' + '.ddload.csv' file2 = DataDown + today + '.' + sym + '.' + '5secs' + '.recent.csv' cutoffmintime = int(2) print 'got here in preparer' merge_bar_files(file1, file2, outputbothFile, cutoffmintime) ## this creates both file
def prepare_tickfilesto5secBars(today,sym,startmode): ## print 'preparing 5secs in tickutiles...',startmode durinseconds= 1 singleslist = glob.glob(DataDown+ today + '.' + sym +'.rtimebar.*') newsingles =[] filesinglebars = DataDown +today+'.'+sym+'.'+'5secs'+'.singlesb.csv' for f in singleslist: fline = rpu_rp.CsvToLines(f) newsingles.append(fline[0]) ## movefile = f.replace(DataDown,DataDown+'tempsingles/') ## movearea = DataDown+'tempsingles' ## shutil.move(f,movearea) os.remove(f) rpu_rp.WriteArrayToCsvfileAppend(filesinglebars,newsingles) basisdur = 'RTticks' outputdur = '5secs' basisFile = filesinglebars # DataDown +today+'.'+sym+ '.'+ basisdur +'.csv' if startmode == 'initialize': basisBars = rpu_rp.CsvToLines(basisFile) else: basisBars = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(basisFile),40) create_bars_from_bars(basisBars,today,sym,outputdur,durinseconds,'initialize') #. .. this creates the recent file 5secs used in merge_bar #### print 'got here in preparer creator finished' outputbothFile = DataDown +today+'.'+sym+'.'+outputdur+'.both.csv' file1 = DataDown +today+'.'+sym+'.'+'5secs'+'.ddload.csv' file2 = DataDown +today+'.'+sym+'.'+'5secs'+'.recent.csv' cutoffmintime = int(2) print 'got here in preparer' merge_bar_files(file1,file2,outputbothFile,cutoffmintime) ## this creates both file
def checkDOMticks(sym,fnums): filein = DataDown +today+'.'+sym+ '.RTMktDepth.csv' buylineprice = prepare_empty_array(fnums) buylinesize = prepare_empty_array(fnums) selllineprice = prepare_empty_array(fnums) selllinesize = prepare_empty_array(fnums) prevtotdiff = 0 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein),1500): ## print line position = int(line[1].replace('position=','').replace('>','').replace(' ','')) size = float(line[5].replace('size=','').replace('>','').replace(' ','')) operation = line[2].replace('operation=','').replace('>','').replace(' ','') price = float(line[4].replace('price=','').replace('>','').replace(' ','')) time = line[6].replace(' ','') zflag = 'clean' if price == 0 or size == 0: ## print 'zeros' zflag = 'haszeros' if 'side=1' in str(line): buylineprice[position] = price buylinesize[position] = size buylinesizewtd = buylineprice[position] * buylinesize[position] else: selllineprice[position] = price selllinesize[position] = size ## return buylineprice, buylinesize,selllineprice,selllinesize,timenow sizeweightedbid = sum_2arrays_weighted(buylineprice,buylinesize,'bla') sizeweightedsell = sum_2arrays_weighted(selllineprice,selllinesize,'bla') totalbuy = float(sum_array(buylinesize,'all')) totalsell = float(sum_array(selllinesize,'all') ) totdiff = totalbuy - totalsell totalratio = totalbuy/totalsell topbuy = float(sum_array(buylinesize,'toponly')) topsell = float(sum_array(selllinesize,'toponly')) topdiff = topbuy - topsell if totdiff == 0: totdiff = 1 if totalbuy > 0: totdiffperc = 100 * (round(float(totdiff/(totalsell +totalbuy)),3)) else: totdiffperc = 0.0 ############ if topdiff == 0: topdiff = 1 if topbuy > 0: topdiffperc = 100 * (round(float(topdiff/(topsell +topbuy)),3)) else: topdiffperc = 0.0 ## print totdiffperc, totdiff, totalbuy difftoprev = totdiff - prevtotdiff prevtotdiff = totdiff buytopprice = buylineprice[0] selltopprice = selllineprice[0] ## print 'SELL', selllinesize, totalsell, totdiff showflag = 'no' if abs(totalratio) > 1.20 or totalratio < .95 : showflag = 'show' if abs(difftoprev) > 2000000: showflag ='show' if abs(topdiffperc)> 20000 : showflag = 'show' if showflag == 'show' : ## print buytopprice,'BUY', buylinesize, totalbuy, totdiff, totalsell, selllinesize, 'SELL',selltopprice,time,difftoprev,str(totdiffperc) ## print 'tot',totalbuy,'x',totalsell, totdiff, str(totdiffperc),'%', difftoprev print 'topBOOK>>',topbuy,'x',topsell, 'Topbuy ratio =',round(topbuy/(topsell+1),2), 'Totalbook Ratio >>>',round(totalratio,2)
def create_TS_array(sym,fnums): recentlimit = 2000000 fullarray =[] filein = DataDown +today+'.'+sym+ '.RTtickData.csv' prevtotdiff = ask = bid =0 prevtime ='' string ='' prevtradeuid='' time = '' size = '' tprice = 0.0 tsize = singletrade = totdaysize= vwap ='' totdowns = totups = 0 tottickups=0 nettickhits = 0 lastsize = lastprice = bidsize = asksize = 0 prevtick = nettickups = totHits = totLifts = 0 tickflag = tickdir = minute = hour = 'na' bidsize=bidp=askp=asksize=empty = tsizenew = tpricenew= 'na' ## aout=[tickflag,tprice,tsize,bid,ask,tickdir,nettickhits,nettickups,minute,hour,time] newline=[] newlist = [bidsize,bidp,askp,asksize,tpricenew,tsizenew,tickflag,tprice,tsize,tickdir,minute,hour,time] for item in newlist: newline.append(item) for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein),recentlimit): if 'tickSize' in line[0] or 'tickPrice' in line[0]: ## print line fflag = line[1].replace(' field=','') value = float((line[2].replace(' size=','')).replace('>','').replace(' price=','')) time = line[len(line)-1] ############# if 'tickSize' in line[0] : ## 0 BID_SIZE tickSize() 1 BID_PRICE tickPrice() 2 ASK_PRICE tickPrice() 3 ASK_SIZE tickSize() 4 LAST_PRICE tickPrice()5 LAST_SIZE tickSize() size = value newline[int(fflag)]=value ################## if 'tickPrice' in str(line) and int(fflag) < 4: newline[int(fflag)]=value ########################## if 'tickString' in str(line) and 'tickType=48' in str(line): ttime = line[3] string = line[2].split(';') if len(string) > 2: tprice = float(string[0].replace('value=','')) tsize = float(string[1]) newline[5]=tsize newline[7]=tprice newline[8]=tsize singletrade = string[5] notsure = string[5] totdaysize = string[3] vwaps = string[4] if len(vwaps) > 0: vwap = round(float(string[4]),2) else: vwap =0.0 ## value=1984.50;1;1441796865858;207069;1982.49963539;true> ## if bid == 0.0: tradeuid = ttime + str(tsize) + str(tprice) if tradeuid != prevtradeuid: ## print 'adding line' #bid > 0 and ask > 0 and aout =[] if prevtick < tprice: tickdir = 'uptick' elif prevtick == tprice: tickdir = 'flat' else: tickdir = 'downtick' prevtick = tprice if tsize > 0 and ttime != 'xxx': minute = ttime[0:5]#'20:47:32.488000' hour = ttime[0:4] ## newline=[bidsize,bidp,askp,asksize,empty,tsizenew,tickflag,tprice,tsize,bid,ask,tickdir,minute,hour,time] newline[12]=ttime newline[11]=hour newline[10]=minute newline[9]=tickdir numlist = [0,1,2,3,4,5,6,7,8,9,10,11,12] for n in numlist: aout.append(newline[n]) fullarray.append(aout) ### how many upticks in a row? prevtime = ttime prevtradeuid = tradeuid return fullarray
def checkDOMticks(sym, fnums): filein = DataDown + today + '.' + sym + '.RTMktDepth.csv' buylineprice = prepare_empty_array(fnums) buylinesize = prepare_empty_array(fnums) selllineprice = prepare_empty_array(fnums) selllinesize = prepare_empty_array(fnums) prevtotdiff = 0 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein), 15000): ## print line position = int(line[1].replace('position=', '').replace('>', '').replace(' ', '')) size = float(line[5].replace('size=', '').replace('>', '').replace(' ', '')) operation = line[2].replace('operation=', '').replace('>', '').replace(' ', '') price = float(line[4].replace('price=', '').replace('>', '').replace(' ', '')) time = line[6].replace(' ', '') zflag = 'clean' if price == 0 or size == 0: ## print 'zeros' zflag = 'haszeros' if 'side=1' in str(line): buylineprice[position] = price buylinesize[position] = size buylinesizewtd = buylineprice[position] * buylinesize[position] else: selllineprice[position] = price selllinesize[position] = size ## return buylineprice, buylinesize,selllineprice,selllinesize,timenow sizeweightedbid = sum_2arrays_weighted(buylineprice, buylinesize, 'bla') sizeweightedsell = sum_2arrays_weighted(selllineprice, selllinesize, 'bla') totalbuy = float(sum_array(buylinesize, 'all')) totalsell = float(sum_array(selllinesize, 'all')) totdiff = totalbuy - totalsell totalratio = totalbuy / totalsell topbuy = float(sum_array(buylinesize, 'toponly')) topsell = float(sum_array(selllinesize, 'toponly')) topdiff = topbuy - topsell if totdiff == 0: totdiff = 1 if totalbuy > 0: totdiffperc = 100 * (round(float(totdiff / (totalsell + totalbuy)), 3)) else: totdiffperc = 0.0 ############ if topdiff == 0: topdiff = 1 if topbuy > 0: topdiffperc = 100 * (round(float(topdiff / (topsell + topbuy)), 3)) else: topdiffperc = 0.0 ## print totdiffperc, totdiff, totalbuy difftoprev = totdiff - prevtotdiff prevtotdiff = totdiff buytopprice = buylineprice[0] selltopprice = selllineprice[0] ## print 'SELL', selllinesize, totalsell, totdiff showflag = 'no' if abs(totalratio) > 1.20 or totalratio < .95: showflag = 'show' if abs(difftoprev) > 2000000: showflag = 'show' if abs(topdiffperc) > 20000: showflag = 'show' if showflag == 'show': ## print buytopprice,'BUY', buylinesize, totalbuy, totdiff, totalsell, selllinesize, 'SELL',selltopprice,time,difftoprev,str(totdiffperc) ## print 'tot',totalbuy,'x',totalsell, totdiff, str(totdiffperc),'%', difftoprev print 'topBOOK>>', topbuy, 'x', topsell, 'Topbuy ratio =', round( topbuy / (topsell + 1), 2), 'Totalbook Ratio >>>', round(totalratio, 2)
def checkRTnonbarticksNEW(sym, fnums): recentlimit = 20000 fullarray = [] filein = DataDown + today + '.' + sym + '.RTtickData.csv' prevtotdiff = ask = bid = 0 prevtime = '' string = '' prevtradeuid = '' time = '' size = '' tprice = 0.0 tsize = singletrade = totdaysize = vwap = '' totdowns = totups = 0 tottickups = 0 nettickhits = 0 lastsize = lastprice = bidsize = asksize = 0 prevtick = nettickups = totHits = totLifts = 0 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein), recentlimit): if 'tickString' in str(line) and 'tickType=48' in str(line): print line time = line[3] string = line[2].split(';') if len(string) > 2: tprice = float(string[0].replace('value=', '')) tsize = float(string[1]) singletrade = string[5] totdaysize = string[3] vwaps = string[4] if len(vwaps) > 0: vwap = round(float(string[4]), 2) else: vwap = 0.0 ## value=1984.50;1;1441796865858;207069;1982.49963539;true> if 'tickSize' in line[0] or 'tickPrice' in line[0]: print line ## 0 BID_SIZE tickSize() 1 BID_PRICE tickPrice() ## 2 ASK_PRICE tickPrice() 3 ASK_SIZE tickSize() ## 4 LAST_PRICE tickPrice() 5 LAST_SIZE tickSize() fs = line[1].replace(' field=', '') sizetime = line[3] value = int((line[2].replace(' size=', '')).replace('>', '')) size = value if fs == '0': bidsize = value elif fs == '3': asksize = value elif fs == '5': lastsize = value else: pass if 'tickPrice' in str(line): pricetime = line[4] value = float(line[2].replace(' price=', '')) fp = line[1].replace(' field=', '') if fp == '1': bid = value pass elif fp == '2': ask = value else: lastprice = value ## if bid == 0.0: tradeuid = time + str(tsize) + str(tprice) if 'tickString' in str(line) and len( string ) > 2 and bid > 0 and ask > 0 and tradeuid != prevtradeuid: if tprice > prevtick: tickdir = 'uptick' nettickups += 1 elif tprice < prevtick: tickdir = 'downtick' nettickups = nettickups - 1 else: tickdir = 'neutral' if bid == tprice: tickflag = 'HitBid' nettickhits = nettickhits - 1 else: tickflag = 'LiftOffer' nettickhits = nettickhits + 1 totLifts += tsize aout = [] prevtick = tprice if tsize > 0 and time != 'xxx': minute = time[0:5] #'20:47:32.488000' hour = time[0:4] #### minute = tprice# time[0:5]#'20:47:32.488000' aout.append(tickflag) aout.append(tprice) aout.append(tsize) aout.append(bid) aout.append(ask) aout.append(tickdir) ## aout.append(totHits) aout.append(nettickhits) aout.append(nettickups) aout.append(minute) aout.append(hour) fullarray.append(aout) ### how many upticks in a row? prevtime = time prevtradeuid = tradeuid return fullarray
################## global timedate_format, nextorderID, date, today,recentlimit, time_format from time import sleep, strftime, localtime import rpu_rp, rpInd, ibutiles, TicksUtile, RP_Snapshot, glob, csv, subprocess, datetime, shutil, time, BarUtiles from time import sleep, strftime, localtime import RulesEngine from datetime import datetime import ctypes ################ date = today #'20160219' #yesterday # today ######## <<<<<<< style = '' symlist = ['ES','FDAX'] ##symlist = ['ES']#,'FDAX'] for sym in symlist: print sym,'========' bla = TicksUtile.recenttick(sym,'recent') print bla,' is latest tick' flist = [sym+'.RTticks.csv',sym+'.5mins.both.csv'] for f in flist: print f,'====' tickfile5 = DataDown + date +'.'+f l = rpu_rp.CsvToLines(tickfile5) lastlines = rpu_rp.tail_array_to_array(l,5) for e in lastlines: print e[0],e[1] ##print lastlines raw_input('close...')
def create_bars_from_bars( bararrayin, today, sym, dur, durinseconds, startmode): #startmodes[initialize,bartobar,addonbartoboth] ## print 'start creator' import time if startmode == 'bartobar': ## no need for recent or rootfile as prev both dur bars have 5ticks in them startbartime = 0 ## print 'set mode here' if startmode == 'initialize': rootname = '.ddload.csv' rootfile = DataDown + today + '.' + sym + '.' + dur.replace( ' ', '') + rootname if startmode == 'addonebartoboth': rootname = '.both.csv' rootfile = DataDown + today + '.' + sym + '.' + dur.replace( ' ', '') + rootname ## print 'getting startbar' startbartime = last_bar_epoch( rootfile, 'rounded') ####ddload_cutoff_epoch(rootfile,'normal') ######## print startbartime bar_percentage_required = 0.10 ###<<<<<<<<<<<<< ######## print 'creating bars startmode,',startmode,startbartime barhi = float(0) barlo = float(99999999) tickcount = tottickcount = 0 bararrayout = [] timearray = [] prevhi = prevlo = 0 totallength = len(bararrayin) prevbar_time = ' 2015-06-01 00:00:00' ## if dur == '5secs': ## prevbar_time = ' 2015-11-09 10:03:55' prevbar_time_epoch = convertTime(prevbar_time, 'dashspace', 'timetoepoch') print prevbar_time_epoch, prevbar_time prevdurbar_epoch = 0 ################## ## if filemode == 'test': ## recentfile = DataDown +today+'.'+sym+ '.' +dur.replace(' ','')+ '.rtest.csv' ## else: recentfile = DataDown + today + '.' + sym + '.' + dur.replace( ' ', '') + '.recent.csv' ## flush the recentfile rpu_rp.WriteArrayToCsvfile(recentfile, []) ## print recentfile ###################### firsttripflag = 'notstarted' hardlimit = 4000 if dur == '5secs': hardlimit = 99000000000 barlimiter = min(4000, len(bararrayin)) if startmode == 'addonebartoboth': taillines = rpu_rp.tail_array_to_array( bararrayin, barlimiter ) ##the one hour needs 720 rt msec ticks..so this might savesomething else: taillines = rpu_rp.tail_array_to_array( bararrayin, barlimiter ) ##the one hour needs 720 rt msec ticks..so this might savesomething totallength = len(taillines) lc = 1 barvolumetot = 0 tickval = float(tickvaluedict[sym]) prevhaopenpr = prevhaclosepr = openpr = 1950.0 for line in taillines: ## print line if lc == 2: prevhaopenpr = float(line[2]) prevhaclosepr = float(line[5]) lc += 1 tottickcount += 1 if len(line) > 3: ## print line, 'this line' bar_time = line[1] if bar_time == '1': bar_time = ' 2015-06-01 00:00:00' bar_time_epoch = convertTime(bar_time, 'dashspace', 'timetoepoch') openpr = float(line[2]) highpr = float(line[3]) lowpr = float(line[4]) closepr = float(line[5]) barvolume = int(line[6]) barvolumetot += barvolume ############ barTobarElapsed = bar_time_epoch - prevbar_time_epoch barToprevdurbarElapsed = bar_time_epoch - prevdurbar_epoch prevbar_time_epoch = bar_time_epoch ################## ## if int(durinseconds) > -1: ## lessthanval = -1 ## else: lessthanval = 0 testval = int(durinseconds) - barToprevdurbarElapsed - lessthanval ## print testval tickcount += 1 if highpr > barhi: barhi = highpr if lowpr < barlo: barlo = lowpr if tickcount == 1: habaropenpr = openpr newbartime = bar_time ############# setflag = 'skip' haclosepr = quarterround( ((habaropenpr + barhi + barlo + closepr) / 4)) # habaropenpr = quarterround(((prevhaopenpr + prevhaclosepr) / 2)) habarhi = max(highpr, habaropenpr, haclosepr) habarlo = min(lowpr, habaropenpr, haclosepr) if int( durinseconds ) == 60 and firsttripflag != 'started': ######<<<<<<<<< this sets up the 5 second delay resetamt = 5 elif int(durinseconds) > 60 and firsttripflag != 'started': resetamt = 60 ## print resetamt else: resetamt = 0 partflag = 'full' if tottickcount == 1: setflag = 'noreset' if bar_time_epoch >= (startbartime - resetamt) and firsttripflag != 'started': ## print 'tripped',dur,sym,bar_time_epoch,startbartime,bar_time setflag = 'reset' firsttripflag = 'started' if testval <= 0: setflag = 'reset' partbar = True barperc = float( float(barToprevdurbarElapsed) / float(durinseconds)) if tottickcount == totallength and setflag != 'reset' and barperc > bar_percentage_required: ## print round(barperc,3), barToprevdurbarElapsed, int(durinseconds) time = ' 2019-03-03 03:03:03' partflag = 'partial' setflag = 'reset' partbar = True if setflag == 'reset' and len(line) > 3: tickcount = 0 barline = [] bardir = 'grn' bartdesc = 'tail' bardesc = 'shortbar' barlen = haclosepr - habaropenpr if barlen < tickval: bardir = 'red' barhead = habarhi - max(habaropenpr, haclosepr) bartail = habarlo - min(habaropenpr, haclosepr) barbigmult = 2 if dur == '3mins': barbigmult = 1 barminbig = (tickval * barbigmult) - (tickval * 0.10) if abs(barlen) > barminbig: bardesc = 'bigbar' if barhead == 0 and bardir == 'red': bartdesc = 'notail' if bartail == 0 and bardir == 'grn': bartdesc = 'notail' bardesc = bardir + 'N' + bartdesc + 'N' + bardesc ilist = [sym, newbartime,openpr,barhi,barlo,closepr,barvolumetot,partflag,barToprevdurbarElapsed,\ habaropenpr,habarhi,habarlo,haclosepr,barlen,barhead,bartail,bardesc] for item in ilist: barline.append(item) prevdurbar_epoch = bar_time_epoch if partbar == True: bararrayout.append(barline) barhi = 0 barlo = 99999999 habarhi = 0 #max(highpr,habaropenpr,haclosepr) habarlo = 9999999 #min(lowpr,habaropenpr,haclosepr) barvolumetot = 0 partflag = 'full' prevhaopenpr = habaropenpr prevhaclosepr = haclosepr rpu_rp.WriteArrayToCsvfileAppend(recentfile, bararrayout) ## print 'just wrote recent file with bars t bars in tickutiles' return bararrayout
prevbart_dt = now_dt prevbart_epoch = now_epoch for l in macdTriggers: bart = l[0] bart_dt = dt.datetime.strptime(bart, spaceYtime_format) bart_epoch = int(time.mktime(time.strptime(bart, spaceYtime_format))) barToNow = now_epoch - bart_epoch barToPrev = bart_epoch - prevbart_epoch prevbart_epoch = bart_epoch ## alerttxt = l[1] + '|' + str(barToNow) + '|' + str(barToPrev)+ '|' +str(l) if barToNow < recentlimit: onesig = l sym =onesig[1] RecentTickFile = DataDown + today + '.' + sym + '.RTtickslastquote.csv' tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] for f in tickline: if 'close' in str(f): lasttick = f.split('=')[1] onesig.append(barToNow) onesig.append(barToPrev) onesig.append(lasttick) recentsigs.append(onesig) ############ print onesig dur = '' if len(recentsigs) > 0: ## macrossstate = statefile = sigarea +statename +'.MACROSS.state.csv' sigcount =0 for sig in sorted(recentsigs): sigcount+=1 if sigcount == len(recentsigs):
typedict = rpu_rp.create_dict(libsyms, 0, 5) currdict = rpu_rp.create_dict(libsyms, 0, 3) expiredict = rpu_rp.create_dict(libsyms, 0, 4) dboostdict = rpu_rp.create_dict(libsyms, 0, 6) tickdict = rpu_rp.create_dict(libsyms, 0, 8) tsizedict = rpu_rp.create_dict(libsyms, 0, 7) roundfactordict = rpu_rp.create_dict(libsyms, 0, 9) symdict = rpu_rp.create_dict(libsyms, 0, 1) symbol_list = rpsymdict.keys() ################################### timelimit = 2 timer = 1 ################# while timer < timelimit: sigs = rpu_rp.CsvToLines('sigs.csv') onesig = rpu_rp.tail_array_to_array(sigs, 2) for sig in onesig: tws_conn.reqIds(100) sleep(1) for l in rpu_rp.CsvToLines('OrderIdsSaved.csv'): order_id = int(l[0]) ################## print sig # ['13:51:58', 'USD.CAD', '30 secs', '12436.5002', '-0.007', 'negcrossmcd', 'necd']] sym = sig[1] action = sig[5] decimalboost = float(dboostdict[sym]) onetick = float(tickdict[sym]) roundfactor = int(roundfactordict[sym]) print decimalboost, onetick, roundfactor price = round(float((sig[3])) / float(decimalboost), roundfactor) onetick = float(1 / decimalboost)
def GetStates(arrayin, sym, Indtitle, dur, threshold, date, alternatearrayin): #add barr age from last cross here ## decimalboost = dboostdict[sym] ## print arrayin if len(arrayin) > 3: pass else: print ' small array detected...probaly needs ddload!!', 'getting states for...', Indtitle, dur, sym, date, 'used yesterday' arrayin = alternatearrayin #[['ES', ' 2015-10-20 22:58:05',20.5,20.25,20.5,20.75,'full','60'],['ES', ' 2015-10-20 22:58:05',2019.5,2020.25,2019.5,2019.75,'full','60']] bsclose = strip1float(arrayin, 5, sym) ##raw close price bs = bsclose symES = 'ES' EsFile = rpu_rp.CsvToLines(DataDown + date + '.' + symES + '.' + dur.replace(' ', '') + '.both.csv') DurBothBoostedES = boost_pricearray(EsFile, symES) bsES = strip1float(DurBothBoostedES, 5, 'ES') bsopen = strip1float(arrayin, 2, sym) ##raw open price bshighs = strip1float(arrayin, 3, sym) #### print dur bsvolume = strip1float(arrayin, 6, sym) ## bsvolume = strip1floatfromstring(arrayin,6,sym) bslows = strip1float(arrayin, 4, sym) bsbardiff = difftwoarrays(bsclose, bsopen) barrange = difftwoarrays(bshighs, bslows) barmids = difftwoarraysMIDS(bshighs, bslows) timestamparray = strip1string(arrayin, 1) stochval = 14 stochval2 = 3 rvival = 4 rvival2 = 10 comparebs = rpu_rp.tail_array_to_array(bsclose, 100) compareES = rpu_rp.tail_array_to_array(bsES, 100) comparetimes = rpu_rp.tail_array_to_array(timestamparray, 100) stdvarbb = 1 #.382 bbandma = 20 if Indtitle == 'pivot': indicator = Mod_Indicators.pivotpoint(bshighs, bslows, bsclose) signindicator = indicator elif Indtitle == 'R1': indicator = Mod_Indicators.RS(bshighs, bslows, bsclose, 'R', '1') signindicator = indicator elif Indtitle == 'S1': indicator = Mod_Indicators.RS(bshighs, bslows, bsclose, 'S', '1') signindicator = indicator elif Indtitle == 'S2': indicator = Mod_Indicators.RS(bshighs, bslows, bsclose, 'S', '2') signindicator = indicator elif Indtitle == 'R2': indicator = Mod_Indicators.RS(bshighs, bslows, bsclose, 'R', '2') signindicator = indicator elif Indtitle == 'mcross': indicator = Mod_Indicators.difftwoarrays(EMAmvavgToArray(bsclose, 9), EMAmvavgToArray(bsclose, 21)) signindicator = indicator elif Indtitle == 'AO': indicator = Mod_Indicators.difftwoarrays(SMAmvavgToArray(barmids, 5), SMAmvavgToArray(barmids, 34)) signindicator = indicator elif Indtitle == 'AOAcc': indicator = Mod_Indicators.difftwoarrays( difftwoarrays(SMAmvavgToArray(barmids, 5), SMAmvavgToArray(barmids, 34)), SMAmvavgToArray( difftwoarrays(SMAmvavgToArray(barmids, 5), SMAmvavgToArray(barmids, 34)), 5)) signindicator = indicator elif Indtitle == 'price': indicator = bsclose signindicator = bsbardiff elif Indtitle == 'highs': indicator = bshighs signindicator = bsbardiff elif Indtitle == 'lows': indicator = bslows signindicator = bsbardiff elif Indtitle == 'mcd': indicator = Mod_Indicators.MACDdiverg(bsclose) signindicator = indicator elif Indtitle == 'kupper': indicator = Mod_Indicators.keltner_channels(bshighs, bslows, bsclose, 2, 'upper') signindicator = indicator elif Indtitle == 'klower': indicator = Mod_Indicators.keltner_channels(bshighs, bslows, bsclose, 2, 'lower') signindicator = indicator elif Indtitle == 'stddev': indicator = stddev(bshighs, bslows, bsclose, bbandma) signindicator = indicator elif Indtitle == 'bbandlower': indicator = Mod_Indicators.bbands(bshighs, bslows, bsclose, bbandma, stdvarbb, 'lower') #simpleAvgVal,stdvariable) signindicator = indicator elif Indtitle == 'bbandupper': indicator = Mod_Indicators.bbands(bshighs, bslows, bsclose, bbandma, stdvarbb, 'upper') #simpleAvgVal,stdvariable) signindicator = indicator elif Indtitle == 'kmid': indicator = Mod_Indicators.keltner_channel_mid(bshighs, bslows, bsclose, 2) signindicator = indicator elif Indtitle == 'ema': indicator = Mod_Indicators.EMAmvavgToArray(bsclose, 21) signindicator = indicator elif Indtitle == 'sma200': indicator = mvavgToArray(bsclose, 200) signindicator = indicator elif Indtitle == 'sma50': indicator = mvavgToArray(bsclose, 50) signindicator = indicator elif Indtitle == 'sma100': indicator = mvavgToArray(bsclose, 100) signindicator = indicator elif Indtitle == 'diffvES': indicator = Mod_Indicators.diffvES(comparebs, compareES) ## timestamparray = comparetimes signindicator = indicator elif Indtitle == 'RSI': indicator = Mod_Indicators.RSI(bsclose, 14) signindicator = indicator elif Indtitle == 'ROC': indicator = Mod_Indicators.ROC(bsclose, 9) signindicator = indicator elif Indtitle == 'StochD': indicator = Mod_Indicators.StochD( (Mod_Indicators.StochK(bshighs, bslows, bsclose, stochval)), stochval2) signindicator = indicator elif Indtitle == 'StochK': indicator = Mod_Indicators.StochK(bshighs, bslows, bsclose, stochval) signindicator = indicator elif Indtitle == 'Stoch_CROSS': indicator = Mod_Indicators.Stoch_CROSS( Mod_Indicators.StochK(bshighs, bslows, bsclose, stochval), Mod_Indicators.StochD( Mod_Indicators.StochK(bshighs, bslows, bsclose, stochval), stochval2)) signindicator = indicator elif Indtitle == 'ATR': indicator = Mod_Indicators.ATR(bshighs, bslows, bsclose, 14) signindicator = indicator elif Indtitle == 'RVIline': ind1 = EMAmvavgToArray( Mod_Indicators.RVIsignal(bsopen, bshighs, bslows, bsclose), rvival2) indicator = Mod_Indicators.RVIline(ind1, rvival) signindicator = indicator elif Indtitle == 'RVIsignal': indicator = EMAmvavgToArray( Mod_Indicators.RVIsignal(bsopen, bshighs, bslows, bsclose), rvival2) signindicator = indicator elif Indtitle == 'RVI_CROSS': ind1 = EMAmvavgToArray( Mod_Indicators.RVIsignal(bsopen, bshighs, bslows, bsclose), rvival2) ind2 = Mod_Indicators.RVIline(ind1, rvival) indicator = Mod_Indicators.RVI_CROSS(ind1, ind2) signindicator = indicator pass elif Indtitle == 'CMF': maVal = 20 ## indicator = bsvolume #20 #'20' #CMF(bsclose,bslows,bshighs,bsvolume,maVal) indicator = Mod_Indicators.CMF(bsclose, bslows, bshighs, bsvolume, maVal) signindicator = indicator elif Indtitle == 'OBV': maVal = 20 indicator = Mod_Indicators.OBV( bsclose, bsvolume, maVal ) # bsvolume #20 #'20' #CMF(bsclose,bslows,bshighs,bsvolume,maVal) signindicator = indicator else: print 'unknown indicator', Indtitle sign = show_sign(signindicator, Indtitle, threshold) if Indtitle == 'RSI': sign = show_sign2thresholds(signindicator, Indtitle, 21, 81) durarray = lableToarray(bsclose, dur) slope = show_slope(indicator, 'value') slopetag = show_slope(indicator, 'tagstyle') showcrxx = show_cross(sign, 'noage') crossages = show_cross(sign, 'crossage') stdval = stddev(1, 1, indicator, 50) if Indtitle == 'diffvES': arrayout = joinArraysStates(comparetimes, indicator, sign, slope, slopetag, Indtitle, sym, showcrxx, durarray, bshighs, bslows, bsclose, crossages, stdval) else: arrayout = joinArraysStates(timestamparray, indicator, sign, slope, slopetag, Indtitle, sym, showcrxx, durarray, bshighs, bslows, bsclose, crossages, stdval) alist = timestamparray, indicator, sign, slope, slopetag, Indtitle, sym, showcrxx, durarray, bshighs, bslows, bsclose, crossages, stdval prevlena = 0 return arrayout
def ShowABarofBars(sym,dur,barnum): lastbar =[] ## statefile = DataDown + sym + '.' + dur + '.' + ind + '.state.csv' statefile = DataDown + today + '.'+ sym + '.' + dur + '.both.csv' lastbar = (rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(statefile),barnum))[0] return lastbar
showflag = look_for_dupe_sig(livesigid) sigcount+=1 ## if sigcount == len(recentsigs): if showflag != 'supress': indlist = ['MACROSS']#, 'R', 'S'] ## indlist = ['MACROSS', 'MCDiv', 'price', 'kupper', 'kmid', 'klower', 'pivot', 'R', 'S'] durstatelist =['1hour', '15mins' ] ## durstatelist =['1hour', '15mins', '3mins'] stateinfo = '' for durstate in durstatelist: stateinfo += durstate #+ '\n' for indicator in indlist: sfile = rpu_rp.CsvToLines(statearea +sym+'.' + durstate +'.'+ indicator +'.state.csv') hline = (rpu_rp.tail_array_to_array(sfile,1))[0] stateinfo += str(hline[1:4])+'\n' ############################## tside = 'BUY' if 'negcrs' in action: tside = 'SELL' if tside == 'SELL': beep(soundarea+'sellStocks') else: beep(soundarea+'buyStocks') beep(soundarea+sym) priceinsignal = float(sig[3]/1) pricedrift = round(priceinsignal - float(bid),4) timedrift = barToNow print '==============='
decimalboost = dboostdict[sym] dur = barsize TicksUtile.assemble_dur_bars(today,sym,dur,durinseconds) DurBoth = rpu_rp.CsvToLines( DataDown+ today + '.'+sym+'.' + dur.replace(' ','') + '.both.csv') indicator = 'MACROSS' TicksUtile.create_state_files(today,sym,dur,indicator) indicator = 'MCDiv' TicksUtile.create_state_files(today,sym,dur,indicator) indicator = 'price' TicksUtile.create_state_files(today,sym,dur,indicator) #################### macross = rpInd.process_ticks(DurBoth,sym,barsize) macdTriggers = rpInd.Trigger_MACD(DurBoth,sym,barsize) macd = macdTriggers lline = rpu_rp.tail_array_to_array(macross,1) ## print lline ## statearray =[] state = ((lline[0])[5]) sigbart = ((lline[0])[0]) sigbart_epoch = int(time.mktime(time.strptime(sigbart, spaceYtime_format))) barage = str(round((now_epoch - sigbart_epoch)/int(durinseconds),2)) ## statearray.append(state) ## print statearray ## set the state for each sym statename = sym+dur.replace(' ','') statefile = sigarea +statename +'.MACROSS.state.csv' rpu_rp.WriteStringsToFile(statefile, state+dur.replace(' ','')+'since_bars'+barage+',') rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigsma.csv', macross) rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', macd)
print ResLine,SupLine,PivLine,bid,action dur = sig[2] livesigid = sym+action+dur.replace(' ','') showflag = look_for_dupe_sig(livesigid) sigcount+=1 ## if sigcount == len(recentsigs): if showflag != 'supress': indlist = ['MACROSS', 'MCDiv', 'price', 'kupper', 'kmid', 'klower', 'pivot', 'R'] durstatelist =['1hour', '15mins', '3mins'] stateinfo = '' for durstate in durstatelist: stateinfo += durstate + '\n' for indicator in indlist: sfile = rpu_rp.CsvToLines(statearea +sym+'.' + durstate +'.'+ indicator +'.state.csv') hline = (rpu_rp.tail_array_to_array(sfile,1))[0] stateinfo += str(hline[1:4])+'\n' ############################## tside = 'BUY' if 'negcrs' in action: tside = 'SELL' if tside == 'SELL': beep(soundarea+'sellStocks') else: beep(soundarea+'buyStocks') beep(soundarea+sym) priceinsignal = float(sig[3]/1) pricedrift = round(priceinsignal - float(bid),4) timedrift = barToNow print '===============' print sig
def checkRTnonbarticksNEW(sym, fnums): fullarray = [] filein = DataDown + today + '.' + sym + '.RTtickData.csv' prevtotdiff = ask = bid = 0 prevtime = '' string = '' prevtradeuid = '' time = '' size = '' tprice = 0.0 tsize = singletrade = totdaysize = vwap = '' totdowns = totups = 0 tottickups = 0 nettickhits = 0 lastsize = lastprice = bidsize = asksize = 0 prevtick = nettickups = totHits = totLifts = 0 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein), 4000000): if 'tickString' in str(line) and 'tickType=48' in str(line): time = line[3] string = line[2].split(';') if len(string) > 2: tprice = float(string[0].replace('value=', '')) tsize = float(string[1]) singletrade = string[5] totdaysize = string[3] vwaps = string[4] if len(vwaps) > 0: vwap = round(float(string[4]), 2) else: vwap = 0.0 ## value=1984.50;1;1441796865858;207069;1982.49963539;true> ## print tsize,tprice,time,'trade', bid, ask, bidsize, asksize if 'tickSize' in str(line): ## 0 BID_SIZE tickSize() ## 1 BID_PRICE tickPrice() ## 2 ASK_PRICE tickPrice() ## 3 ASK_SIZE tickSize() ## 4 LAST_PRICE tickPrice() ## 5 LAST_SIZE tickSize() fs = line[1].replace(' field=', '') sizetime = line[3] value = int((line[2].replace(' size=', '')).replace('>', '')) size = value ######## print sizetime,size,fs,'size' if fs == '0': bidsize = value elif fs == '3': asksize = value elif fs == '5': lastsize = value else: pass if 'tickPrice' in str(line): pricetime = line[4] value = float(line[2].replace(' price=', '')) fp = line[1].replace(' field=', '') if fp == '1': bid = value pass elif fp == '2': ask = value else: lastprice = value ## if bid == 0.0: tradeuid = time + str(tsize) + str(tprice) if 'tickString' in str(line) and len( string ) > 2 and bid > 0 and ask > 0 and tradeuid != prevtradeuid: if tprice > prevtick: tickdir = 'uptick' elif tprice < prevtick: tickdir = 'downtick' else: tickdir = 'neutral' if bid == tprice: tickflag = 'HitBid' else: tickflag = 'LiftOffer' aout = [] prevtick = tprice if tsize > 0 and time != 'xxx': aout.append(tickflag) aout.append(tickdir) aout.append(tprice) aout.append(tsize) aout.append(bid) aout.append(ask) aout.append(time) fullarray.append(aout) ### how many upticks in a row? prevtime = time prevtradeuid = tradeuid ## print fullarray c = 0 x = len(fullarray) ## print x limiter = 50 f = x - limiter ## print f netlifts = netticks = 0 for l in fullarray: c += 1 if c > f: ## print l lifttag = l[0] tsize = l[2] ticktag = l[1] if lifttag == 'HitBid': netlifts = netlifts - 1 pass else: netlifts += 1 if ticktag == 'downtick': netticks = netticks - 1 pass elif ticktag == 'uptick': netticks += 1 else: pass if c > (x - 8): print l print netlifts, netticks, x, limiter
def create_slicendice(): #analyze prevcycledelay = 2 ######################## print 'got to loop' while loop < loopmax: if loop == 0: create_statesdaily() if (round((loop/10),-1) - loop) == 0: print 'cycle ', loop fileage = check_for_CP_change(cpfname) if fileage < 50: command = read_vars('Setting',cpfname) cycledelay = int(read_vars('CycleTime',cpfname)) recentlimit = int(read_vars('TimeLimitRecentSigs',cpfname)) print 'cycle delay changed to...',cycledelay # change to cycledelay later now = datetime.strftime(datetime.now(),spaceYtime_format) now_epoch = int(time.mktime(time.strptime(now, spaceYtime_format))) now_dt = dt.datetime.strptime(now, spaceYtime_format) ## print 'ccreate sigs searching for sigs in last ',recentlimit ############### recentsigs =[] ## symbol_list = ['ES'] for sym in symbol_list: ## print sym rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) # flush the file to keep all sigs TicksUtile.prepare_tickfilesto5secBars(today,sym) ## merge the 5secddload with 5sec recents > 5sec boths #################################### rpu_rp.WriteArrayToCsvfile(sigarea +sym+'.sigs.csv', []) 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 = ['MACROSS', 'MCDiv', 'price'] for indicator in indlist: indarr = rpInd.GetStates(DurBoth,sym,indicator) statename = sym+'.'+dur.replace(' ','')+'.' statefile = statearea +statename + indicator + '.state.csv' rpu_rp.WriteArrayToCsvfile(statefile, indarr) indlist = ['klower', 'kmid', 'kupper'] for indicator in indlist: indarr = rpInd.GetKupper(DurBoth,sym,indicator) statename = sym+'.'+dur.replace(' ','')+'.' statefile = statearea +statename + indicator + '.state.csv' rpu_rp.WriteArrayToCsvfile(statefile, indarr) #################### macdTriggers = rpInd.Trigger_MACD(DurBoth,sym,barsize) maCrossTriggers = rpInd.Trigger_MACross(DurBoth,sym,barsize) for a in maCrossTriggers: macdTriggers.append(a) state = 'seefile' ## sigbart = ((lline[0])[0]) ## sigbart_epoch = int(time.mktime(time.strptime(sigbart, spaceYtime_format))) ## barage = str(round((now_epoch - sigbart_epoch)/int(durinseconds),2)) barage = 'need barage' rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', macdTriggers) ############################ prevt = 0 numsigs = len(macdTriggers) signum =0 prevbart_dt = now_dt prevbart_epoch = now_epoch for l in macdTriggers: bart = l[0] bart_dt = dt.datetime.strptime(bart, spaceYtime_format) bart_epoch = int(time.mktime(time.strptime(bart, spaceYtime_format))) barToNow = now_epoch - bart_epoch barToPrev = bart_epoch - prevbart_epoch prevbart_epoch = bart_epoch if barToNow < recentlimit: onesig = l sym =onesig[1] lasttick = recenttick(sym) onesig.append(barToNow) onesig.append(barToPrev) onesig.append(lasttick) recentsigs.append(onesig) dur = '' if len(recentsigs) > 0: ## macrossstate = statefile = sigarea +statename +'.MACROSS.state.csv' sigcount =0 for sig in sorted(recentsigs): sigtime = sig[0] sym = sig[1] sigtype = sig[5] barToPrev=sig[len(sig)-2] barToNow = sig[len(sig)-3] bid = sig[len(sig)-1] action =sig[5] dur = sig[2] livesigid = sym+action+dur.replace(' ','') showflag = look_for_dupe_sig(livesigid) sigcount+=1 ## if sigcount == len(recentsigs): if showflag != 'supress': indlist = ['MACROSS']#, 'R', 'S'] ## indlist = ['MACROSS', 'MCDiv', 'price', 'kupper', 'kmid', 'klower', 'pivot', 'R', 'S'] durstatelist =['1hour', '15mins' ] ## durstatelist =['1hour', '15mins', '3mins'] stateinfo = '' for durstate in durstatelist: stateinfo += durstate #+ '\n' for indicator in indlist: sfile = rpu_rp.CsvToLines(statearea +sym+'.' + durstate +'.'+ indicator +'.state.csv') hline = (rpu_rp.tail_array_to_array(sfile,1))[0] stateinfo += str(hline[1:4])+'\n' ############################## tside = 'BUY' if 'negcrs' in action: tside = 'SELL' if tside == 'SELL': beep(soundarea+'sellStocks') else: beep(soundarea+'buyStocks') beep(soundarea+sym) priceinsignal = float(sig[3]/1) pricedrift = round(priceinsignal - float(bid),4) timedrift = barToNow print '===============' print sym, tside, sigtype, dur, pricedrift, sigtime, now create_lines(sym,bid) ## print symNEWSdict[sym] ## print timedrift,sym, tside,dur, priceinsignal,barToPrev,sigtime,pricedrift,now print stateinfo ###################### ttype = 'LIM' limitprice = bid tfactor = float(0.5) tsize = int(max(1,(int(tsizedict[sym]) * tfactor))) tickvalue = float(tickvaluedict[sym]) showdecimal = int(showdecimaldict[sym]) addamt = tickvalue * int(entrywiderdict[sym]) frsigline=[] frsigline.append(sym) frsigline.append(showdecimal) frsigline.append(tside) frsigline.append(tsize) frsigline.append(ttype) frsigline.append(limitprice) frsigline.append(addamt) frsigline.append(livesigid) frsigline.append(sigtime) frsigline.append(tickvalue) frsigline.append(now) rpu_rp.WriteArrayToCsvfileAppend(sigarea + today +'.recentsigs.csv', [frsigline]) rpu_rp.WriteArrayToCsvfileAppend(sigarea + today +'.recentsigsexec.csv', [frsigline]) loop +=1 #################### sleep(cycledelay) print 'finished ',loopmax,' loops by Signal Creator...dead since..',now ############# def create_report(Sigfile,sym,barsize): barfile = DataDown + today + '.'+sym+ '.'+ barsize +'both.csv' lines = rpu_rp.CsvToLines(barfile) numberBars = len(lines) siglines = rpu_rp.CsvToLines(Sigfile) numsigs = len(siglines) print barsize,sym,'number bars studied=',numberBars,numsigs,'=numsigs'
indlist = [ 'pivot', 'R', 'S', 'S2', 'R2', 'kupper', 'klower', 'kmid', 'ema', 'mcross', 'mcd' ] indlist = ['pivot', 'R', 'S', 'S2', 'R2', 'mcross'] indlist = ['pivot', 'mcross', 'mcd'] indlist = ['mcross', 'mcd'] rpInd.create_states_files(sym, dur, today, threshold, indlist) #################### threshold = 0.0 ALLTriggers = [] lasttwo = [] if dur != '1min': Triggers = rpInd.Trigger_from_states(sym, dur, 'mcross') lasttwo = rpu_rp.tail_array_to_array(Triggers, 1) for a in lasttwo: ALLTriggers.append(a) Triggers = rpInd.Trigger_from_states(sym, '15mins', 'mcd') lasttwo = rpu_rp.tail_array_to_array(Triggers, 1) for a in lasttwo: ALLTriggers.append(a) ## threshold = float(-0.20) ## maCrossNEARTriggers = rpInd.Trigger_MACross(DurBoth,sym,dur,threshold,'manearcross') ## rpu_rp.WriteArrayToCsvfileAppend(sigarea +sym+'.sigs.csv', ALLTriggers) ############################ prevt = 0 numsigs = len(ALLTriggers) signum = 0 prevbart_dt = now_dt prevbart_epoch = now_epoch
typedict = rpu_rp.create_dict(libsyms,0,5) currdict = rpu_rp.create_dict(libsyms,0,3) expiredict = rpu_rp.create_dict(libsyms,0,4) dboostdict = rpu_rp.create_dict(libsyms,0,6) tickdict = rpu_rp.create_dict(libsyms,0,8) tsizedict = rpu_rp.create_dict(libsyms,0,7) roundfactordict = rpu_rp.create_dict(libsyms,0,9) symdict = rpu_rp.create_dict(libsyms,0,1) symbol_list = rpsymdict.keys() ################################### timelimit = 2 timer = 1 ################# while timer < timelimit: sigs = rpu_rp.CsvToLines('sigs.csv') onesig = rpu_rp.tail_array_to_array(sigs,2) for sig in onesig: tws_conn.reqIds(100) sleep(1) for l in rpu_rp.CsvToLines('OrderIdsSaved.csv'): order_id = int(l[0]) ################## print sig # ['13:51:58', 'USD.CAD', '30 secs', '12436.5002', '-0.007', 'negcrossmcd', 'necd']] sym = sig[1] action = sig[5] decimalboost = float(dboostdict[sym]) onetick = float(tickdict[sym]) roundfactor = int(roundfactordict[sym]) print decimalboost, onetick, roundfactor price = round(float((sig[3]))/float(decimalboost),roundfactor) onetick = float(1/decimalboost)
def checkRTnonbarticksNEW(sym,fnums): ## fullarray =[] filein = DataDown +today+'.'+sym+ '.RTtickData.csv' prevtotdiff = ask = bid =0 string ='' time = '' size = '' tprice = 0.0 tsize = singletrade = totdaysize= vwap ='' totdowns = totups = 0 tottickups=0 for line in rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(filein),400): ## print line if 'tickString' in str(line) and 'tickType=48': time = line[3] string = line[2].split(';') if len(string) > 2: ## print string tprice = float(string[0].replace('value=','')) tsize = float(string[1]) singletrade = string[5] totdaysize = string[3] vwaps = string[4] if len(vwaps) > 0: vwap = round(float(string[4]),2) else: vwap =0.0 ## value=1984.50;1;1441796865858;207069;1982.49963539;true> ## print string if 'tickPrice' in str(line): ## print line time = line[4] if line[1] == ' field=1': bid= float(line[2].replace(' price=','')) pass if line[1] == ' field=2': ask = float(line[2].replace(' price=','')) pass ## if bid == 0.0: ## print line if 'tickSize' in str(line): time = line[3] size = line[2] if 'tickString' in str(line) and len(string) > 2 and bid > 0 and ask > 0: if bid == tprice: bflag = 'down' ## print '>>>>>>>>','hitbid',tsize,'@', tprice,bid,ask tag = '>>>>>>>>'+' '+'hitbid'+' '+str(tsize)+' '+'@'+' '+ str(tprice)+ ' '+str(bid)+' '+str(ask) totdowns += tsize tottickups = tottickups -1 pass else: bflag = 'uptick' ## print 'XXXXXXXX','uptick',tsize,'@', tprice,bid,ask tag = 'XXXXXXXX'+' uptick '+str(tsize)+' @ '+ str(tprice)+' '+ str(bid)+' '+str(ask) totups += tsize tottickups +=1 aout =[] if tsize > 50: aout.append(tag) fullarray.append(aout) ## print fullarray c=0 x = len(fullarray) for l in fullarray: c+=1 if c > (x - 4): print l
def gatherlineNEW(sym,ind,dur): print sym,ind,dur ## dur = '1day' indfile = statearea + sym + '.' + dur + '.' + ind + '.state.csv' lineprice = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(indfile),1)[0] return lineprice
def gatherlineNEW(sym, ind, dur): print sym, ind, dur ## dur = '1day' indfile = statearea + sym + '.' + dur + '.' + ind + '.state.csv' lineprice = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(indfile), 1)[0] return lineprice
def GetStates(arrayin,sym,Indtitle,dur,threshold,date): #add barr age from last cross here ## decimalboost = dboostdict[sym] ## print 'getting states for...',Indtitle if len(arrayin) > 3 : pass else: arrayin = [['ES', ' 2015-10-20 22:58:05',2019.5,2020.25,2019.5,2019.75,'full','60'],['ES', ' 2015-10-20 22:58:05',2019.5,2020.25,2019.5,2019.75,'full','60']] bsclose = strip1float(arrayin,5,sym) ##raw close price bs = bsclose ## print Indtitle symES = 'ES' ## date = rpu_rp.todaysdateunix() ## EsFile = rpu_rp.CsvToLines( DataDown+ date + '.'+symES+'.' + dur.replace(' ','') + '.both.csv') DurBothBoostedES = boost_pricearray(EsFile,symES) bsES = strip1float(DurBothBoostedES,5,'ES') ## print sym,dur,Indtitle bsopen = strip1float(arrayin,2,sym) ##raw open price bshighs = strip1float(arrayin,3,sym) ## bsvolume = strip1float(arrayin,6,sym) bslows = strip1float(arrayin,4,sym) bsbardiff = difftwoarrays(bsclose,bsopen) barrange = difftwoarrays(bshighs,bslows) barmids = difftwoarraysMIDS(bshighs,bslows) timestamparray = strip1string(arrayin,1) stochval = 14 stochval2 = 3 rvival = 4 rvival2 = 10 comparebs = rpu_rp.tail_array_to_array(bsclose,100) compareES = rpu_rp.tail_array_to_array(bsES,100) comparetimes = rpu_rp.tail_array_to_array(timestamparray,100) ## print comparetimes stdvarbb = 1#.382 bbandma = 20 if Indtitle == 'pivot': indicator = pivotpoint(bshighs,bslows,bsclose) signindicator = indicator elif Indtitle == 'R1': indicator = RS1(bshighs,bslows,bsclose,'R') signindicator = indicator elif Indtitle == 'S1': indicator = RS1(bshighs,bslows,bsclose,'S') signindicator = indicator elif Indtitle == 'S2': indicator = RS2(bshighs,bslows,bsclose,'S') signindicator = indicator elif Indtitle == 'R2': indicator = RS2(bshighs,bslows,bsclose,'R') signindicator = indicator elif Indtitle == 'mcross': indicator = difftwoarrays(EMAmvavgToArray(bsclose,9),EMAmvavgToArray(bsclose,21)) signindicator = indicator elif Indtitle == 'AO': indicator = difftwoarrays(SMAmvavgToArray(barmids,5),SMAmvavgToArray(barmids,34)) signindicator = indicator elif Indtitle == 'AOAcc': indicator = difftwoarrays(difftwoarrays(SMAmvavgToArray(barmids,5),SMAmvavgToArray(barmids,34)),SMAmvavgToArray(difftwoarrays(SMAmvavgToArray(barmids,5),SMAmvavgToArray(barmids,34)),5)) signindicator = indicator elif Indtitle == 'price': indicator = bsclose signindicator = bsbardiff elif Indtitle == 'highs': indicator = bshighs signindicator = bsbardiff elif Indtitle == 'lows': indicator = bslows signindicator = bsbardiff elif Indtitle == 'mcd': indicator = MACDdiverg(bsclose) signindicator = indicator elif Indtitle == 'kupper': indicator = keltner_channels(bshighs,bslows,bsclose,2,'upper') signindicator = indicator elif Indtitle == 'klower': indicator = keltner_channels(bshighs,bslows,bsclose,2,'lower') signindicator = indicator elif Indtitle == 'stddev': indicator = stddev(bshighs,bslows,bsclose,bbandma) signindicator = indicator elif Indtitle == 'bbandlower': indicator = bbands(bshighs,bslows,bsclose,bbandma,stdvarbb,'lower')#simpleAvgVal,stdvariable) signindicator = indicator elif Indtitle == 'bbandupper': indicator = bbands(bshighs,bslows,bsclose,bbandma,stdvarbb,'upper')#simpleAvgVal,stdvariable) signindicator = indicator elif Indtitle == 'kmid': indicator = keltner_channel_mid(bshighs,bslows,bsclose,2) signindicator = indicator elif Indtitle == 'ema': indicator = EMAmvavgToArray(bsclose,21) signindicator = indicator elif Indtitle == 'sma200': indicator = mvavgToArray(bsclose,200) signindicator = indicator elif Indtitle == 'sma50': indicator = mvavgToArray(bsclose,50) signindicator = indicator elif Indtitle == 'sma100': indicator = mvavgToArray(bsclose,100) signindicator = indicator elif Indtitle == 'diffvES': indicator = diffvES(comparebs,compareES) ## timestamparray = comparetimes signindicator = indicator elif Indtitle == 'RSI': indicator = RSI(bsclose,14) signindicator = indicator elif Indtitle == 'ROC': indicator = ROC(bsclose,9) signindicator = indicator elif Indtitle == 'StochD': indicator = StochD((StochK(bshighs,bslows,bsclose,stochval)),stochval2) signindicator = indicator elif Indtitle == 'StochK': indicator = StochK(bshighs,bslows,bsclose,stochval) signindicator = indicator elif Indtitle == 'Stoch_CROSS': indicator = Stoch_CROSS(StochK(bshighs,bslows,bsclose,stochval),StochD(StochK(bshighs,bslows,bsclose,stochval),stochval2)) signindicator = indicator elif Indtitle == 'ATR': indicator = ATR(bshighs,bslows,bsclose,14) signindicator = indicator elif Indtitle == 'RVIline': ind1 = EMAmvavgToArray(RVIsignal(bsopen,bshighs,bslows,bsclose),rvival2) indicator = RVIline(ind1,rvival) signindicator = indicator elif Indtitle == 'RVIsignal': indicator = EMAmvavgToArray(RVIsignal(bsopen,bshighs,bslows,bsclose),rvival2) signindicator = indicator elif Indtitle == 'RVI_CROSS': ind1 = EMAmvavgToArray(RVIsignal(bsopen,bshighs,bslows,bsclose),rvival2) ind2 = RVIline(ind1,rvival) indicator = RVI_CROSS(ind1,ind2) signindicator = indicator pass elif Indtitle == 'CMF': maVal=20 indicator = bsclose #20 #'20' #CMF(bsclose,bslows,bshighs,bsvolume,maVal) signindicator = indicator else: print 'unknown indicator', Indtitle sign = show_sign(signindicator,Indtitle,threshold) if Indtitle == 'RSI': sign = show_sign2thresholds(signindicator,Indtitle,21,81) durarray =lableToarray(bsclose,dur) slope = show_slope(indicator,'value') slopetag = show_slope(indicator,'tagstyle') showcrxx = show_cross(sign,'noage') crossages = show_cross(sign,'crossage') stdval = stddev(1,1,indicator,50) ## print ' got here' if Indtitle == 'diffvES': arrayout = joinArraysStates(comparetimes,indicator,sign,slope,slopetag,Indtitle,sym,showcrxx,durarray,bshighs,bslows,bsclose,crossages,stdval) else: arrayout = joinArraysStates(timestamparray,indicator,sign,slope,slopetag,Indtitle,sym,showcrxx,durarray,bshighs,bslows,bsclose,crossages,stdval) alist = timestamparray,indicator,sign,slope,slopetag,Indtitle,sym,showcrxx,durarray,bshighs,bslows,bsclose,crossages,stdval prevlena = 0 ## print 'joining states' return arrayout
currentbar = l[0].split()[1] else: currentbar = (l[0].split()[0]) currentbar_dt = dt.datetime.strptime(currentbar, time_format) now_dt = dt.datetime.strptime(now, time_format) barToNow = (now_dt - currentbar_dt).seconds barToPrev = (currentbar_dt - prevbart_dt).seconds alerttxt = l[1] + '|' + str(barToNow) + '|' + str(barToPrev)+ '|' +str(l) prevbart_dt = currentbar_dt recentlimit = read_vars() if barToNow < recentlimit: onesig = l ## Snaptfile = DataDown + today + '.' + sym + '.ticksnaps.csv' RecentTickFile = DataDown + today + '.' + sym + '.RTticks.csv' tickline = rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(RecentTickFile),1)[0] for f in tickline: onesig.append(f) onesig.append(barToNow) ## print onesig ## print len(onesig) recentsigs.append(onesig) dur = '' if len(recentsigs) > 0: sigcount =0 origsigf = 7 for sig in recentsigs: sigcount+=1 barToNow = sig[len(sig)-1] bid = (sig[origsigf +10]).replace('close=','') ask = bid#sig[origsigf +6]
def ShowABarofInd(sym,dur,ind,barnum): lastbar =[] statefile = statearea + sym + '.' + dur + '.' + ind + '.state.csv' lastbar = (rpu_rp.tail_array_to_array(rpu_rp.CsvToLines(statefile),barnum))[0] return lastbar