def scanOne(cls, etf, beforeDayNum=2): gevent.sleep(0.001) startDate, endDate = cls.getBeginEndDate(20) sh = StockHistory(etf.code.lower(), startDate, endDate) pointList, err = sh.getPointList() if err != None: cls.logError("get etf history failed:" + str(err)) return index = 0 - beforeDayNum pointList = pointList[index:] length = len(pointList) #判断价格是否连续下跌 isStillRise = True for i in range(length - 1): if pointList[i].dayEnd <= pointList[i + 1].dayEnd: isStillRise = False if isStillRise == False: return #判断是否连续下跌 for point in pointList: if point.dayBegin <= point.dayEnd: return now = Point.getNow(etf.code) #大于30块的不要 if now.now >= 30: return msg = NotifyTpl.genETFRiseTpl('关注信息', etf.name, etf.code, length, now.now) notify.asyncSendMsg(msg)
def scan(cls, stock, beforeDayNum=10): gevent.sleep(0.001) #如果是ST类型的股票,不分析 if 'ST' in stock.name or 'st' in stock.name: return startDate, endDate = cls.getBeginEndDate(35) print(startDate, endDate) sh = StockHistory(code=stock.code, startDate=startDate, endDate=endDate) pointList, err = sh.getPointList() if err != None: cls.logError("code:%s, name:%s, get history failed:%s" % (stock.code, stock.name, err)) return index = 0 - beforeDayNum pointList = pointList[index:] for point in pointList: if point.dayBegin >= point.dayEnd: return #判断价格是否连续上涨 isStillRose = True length = len(pointList) for i in range(length - 1): if pointList[i].dayEnd >= pointList[i + 1].dayEnd: isStillRose = False if isStillRose == False: return now = Point.getNow(stock.code) msg = NotifyTpl.genStillRoseNotify('关注信号', stock.name, stock.code, length, now.now) notify.asyncSendMsg(msg)
def checkOnce(cls): gevent.sleep(0.001) f = open('./data/his_buy_profit.json', 'r') content = f.read() f.close() data = demjson.decode(content) for code, buyProfitList in data.items(): buyProfitList.sort() print(code, buyProfitList) point = Point.getNow(code) print(point) isLessThanHis = False comparePrice = 0 for price in buyProfitList: if point.now <= price: isLessThanHis = True comparePrice = price break print(isLessThanHis, point.now) if not isLessThanHis: continue print('allow send:', cls.isAllowSend(code)) if not cls.isAllowSend(code): return msg = NotifyTpl.genHisBuyProfitNotify('买入信号', point.name, code, point.now, comparePrice) print('msg:', msg) notify.defaultSendDDMsg(msg) cls.markSend(code)
def watchOnce(self): if not Point.isStcokTime(): print('is not stock time, current time:' + str(dt.current_time())) return try: point = Point.getNow(self.code) except: return self.onNewPoint(point)
async def handle(self): try: code = self.param('code') remote = self.remoteAddr() self.logInfo(f'code:{code}, remote:{remote}') now = Point.getNow(code) return now.toString() except Exception as ex: return str(ex)
def test(cls): startDate, endDate = cls.getBeginEndDate(20) print(startDate, endDate) sh = StockHistory(code='sz002078', startDate=startDate, endDate=endDate) pointList, err = sh.getPointList() if err != None: print(err) return for p in pointList: print(p.dayMin, p.time) now = Point.getNow('sz002078') print('now:', now.now) isLatestMin = True for point in pointList: #按照日期升序2020-07-13 ~ 2020-07-14 #for test #print('code:', point.code, 'time:', point.time, 'dayBegin:', point.dayBegin, 'dayEnd:', point.dayEnd, 'dayMax:', point.dayMax, 'dayMin:', point.dayMin) if float(now.now) >= float(point.dayMin): isLatestMin = False break print('isLatestMin:', isLatestMin)
def analyseOneStock(cls, stock_name, stock_code, beforeDayNum, allowDynicPe=40, allowStaticPe=40, allowPb=20, allowLowPrice=0.5, allowHighPrice=30, dy_pe=0, sta_pe=0, pb=0): #如果是ST类型的股票,不分析 if 'ST' in stock_name or 'st' in stock_name: return print(stock_name) startDate, endDate = cls.getBeginEndDate(beforeDayNum) sh = StockHistory(code=stock_code, startDate=startDate, endDate=endDate) pointList, err = sh.getPointList() if err != None: cls.logError("code:%s, name:%s, get history failed:%s" % (stock_code, stock_name, err)) return if len(pointList) <= 0: cls.logError("get latest n days data return empty list") return #判断是否到达最近几天的最低点 now = Point.getNow(stock_code) #now.now = 1 isLatestMin = True for point in pointList: #print('now:', now.now, 'daymin:', point.dayMin) #按照日期升序2020-07-13 ~ 2020-07-14 if float(now.now) >= float(point.dayMin): isLatestMin = False break if isLatestMin == False: return #判断最近几天是否有振荡 (判断是否有涨有跌) roseNum = 0 fallNum = 0 for point in pointList: if point.dayBegin < point.dayEnd: roseNum += 1 else: fallNum += 1 sumNum = roseNum + fallNum #计算增长率 roseRate = float(roseNum) / float(sumNum) * 100 #判断当前价格是否符合购买区间 if not (now.now >= allowLowPrice and now.now <= allowHighPrice): return print(dy_pe, sta_pe, pb, err) #日志 cls.logInfo( "[buy event] code:%s, name:%s, dyPe:%s, staPe:%s, pb:%s, now:%s" % (stock_code, stock_name, dy_pe, sta_pe, pb, now.now)) #生成消息内容 msg = NotifyTpl.genHighProbStrategyNotify('关注信号', stock_name, stock_code, now.now, len(pointList), dy_pe, sta_pe, pb, str(roseRate)[0:4]) defaultSendDDMsg(msg)
def analyseOneStock(cls, stock, beforeDayNum, allowDynicPe=40, allowStaticPe=40, allowPb=20, allowLowPrice=2, allowHighPrice=40): gevent.sleep(0.001) #如果是ST类型的股票,不分析 if 'ST' in stock.name or 'st' in stock.name: return startDate, endDate = cls.getBeginEndDate(beforeDayNum) print(startDate, endDate) sh = StockHistory(code=stock.code, startDate=startDate, endDate=endDate) pointList, err = sh.getPointList() if err != None: cls.logError("code:%s, name:%s, get history failed:%s" % (stock.code, stock.name, err)) return pointList = pointList[-10:] for p in pointList: print(p.time) if len(pointList) <= 0: return #判断是否到达最近几天的最低点 now = Point.getNow(stock.code) line = stock.name + ' now:' + str(now.now) for p in pointList: line = line + "|%s %s %s|" % (p.dayBegin, p.dayEnd, p.time) print(line, beforeDayNum, startDate, endDate, len(pointList), now.now) isLatestMin = True for point in pointList: #按照日期升序2020-07-13 ~ 2020-07-14 #for test #print('code:', point.code, 'time:', point.time, 'dayBegin:', point.dayBegin, 'dayEnd:', point.dayEnd, 'dayMax:', point.dayMax, 'dayMin:', point.dayMin) if float(now.now) >= float(point.dayMin): isLatestMin = False break #判断最近几天是否有振荡 (判断是否有涨有跌) if isLatestMin == False: return roseNum = 0 fallNum = 0 for point in pointList: if point.dayBegin < point.dayEnd: roseNum = roseNum + 1 else: fallNum = fallNum + 1 sumNum = roseNum + fallNum roseRate = float(roseNum) / float(sumNum) if roseRate <= 0.25: return dyPe, staPe, pb, err = stock.getPePb() print(dyPe, staPe, pb, err) cls.logInfo("pb pe :%s,%s,%s,%s" % (dyPe, staPe, pb, err)) if err != None: cls.logError('get pe pb info failed:' + str(err)) return if dyPe < 0 or staPe < 0: return if dyPe > allowDynicPe: return if staPe > allowStaticPe: return if pb > allowPb: return if not (now.now >= allowLowPrice and now.now <= allowHighPrice): return if not cls.isAllowSend(stock.code): return try: cls.logInfo( "[buy event] code:%s, name:%s, dyPe:%s, staPe:%s, pb:%s, now:%s" % (stock.code, stock.name, dyPe, staPe, pb, now.now)) msg = NotifyTpl.genHighProbStrategyNotify('关注信号', stock.name, stock.code, now.now, len(pointList), dyPe, staPe, pb, str(roseRate)[0:4]) notify.asyncSendMsg(msg) cls.markSend(stock.code) except Exception as ex: cls.logError("send msg exception:" + str(ex)) return cls.logInfo("send once")