def check(securitys, frequencys, nowTimeString=tools.getYMDHMS()): strArray = [] print('[' + tools.getYMDHMS() + ']: start checking') for s in securitys: row = "security:" + s + "#" for f in frequencys: print('[' + tools.getYMDHMS() + ']: start handling security - ' + str(s) + ' frequency - ' + str(f)) df = p2m.getPrice( security=s, count=50, end_date=nowTimeString[0:nowTimeString.rindex(':') + 1] + '30', frequency=f, fields=['close', 'open', 'high', 'low', 'volume'] ) close = [float(x) for x in df['close']] df['RSI9'] = talib.RSI(np.array(close), timeperiod=9) df['EMAF'] = talib.EMA(np.array(close), timeperiod=5) df['EMAS'] = talib.EMA(np.array(close), timeperiod=10) count = getPricePosiArrayDur(df) rsi = df[df.EMAS == df.EMAS].RSI9.tolist()[-1] row += "#frequency:" + f + "_count:" + str(count) + "_rsi:" + str(rsi) print('[' + tools.getYMDHMS() + ']: ' + nowTimeString + ' - ' + s + ' - ' + f + ' - ' + str( count) + ' - ' + str(rsi)) strArray.append(row) return strArray
def daemon_listen(): smtp.sendMail(subject=util.getYMDHMS() + ': 日线策略监听程序启动', content='Engine Start!') while True: nowTimeString = util.getYMDHMS() if '20:30' in util.getHMS() or '08:00' in util.getHMS(): if util.isFutureTradingTime(nowTimeString) is True: tick(nowTimeString) else: smtp.sendMail(subject='节假日监听程序运行中', content='Engine running!') time.sleep(60 * 60) time.sleep(49)
def __init__(self, security, frequency, starttime_fortest=None, endtime_fortest=util.getYMDHMS(), layer1_from_timeperiod=5, layer1_to_timeperiod=10, layer1_rsi_top=65, layer1_rsi_bottom=35, layer1_rsi_timeperiod=9): self.security = security self.frequency = frequency self.db = DataBody(security, frequency) self.ab = AnalysisBody() self.ownPosition = 0 self.starttime_fortest = starttime_fortest self.endtime_fortest = endtime_fortest # 策略层次1 self.layer1_from_timeperiod = layer1_from_timeperiod self.layer1_to_timeperiod = layer1_to_timeperiod self.layer1_rsi_top = layer1_rsi_top self.layer1_rsi_bottom = layer1_rsi_bottom self.layer1_rsi_timeperiod = layer1_rsi_timeperiod self.layer1_pre1_ownerPosition = None self.layer1_ownPosition = 0 self.layer1_startcount = 0 self.layer1_startRate = 0 self.layer1_pre_flag_5IsLt10 = False self.layer1_rates = [] self.layer1_starttime_rate_map = {} self.smtpClient = SmtpClient()
def testMain(self): if self.starttime_fortest is None: return ts = util.getTimeSerial(starttime=self.starttime_fortest, periodSec=59, count=300000) now = util.getYMDHMS() for nowTimeString in ts: self.tick(nowTimeString) if nowTimeString > now or nowTimeString > self.endtime_fortest: return
def tick(self): nowTimeString = util.getYMDHMS() action = self.getAction(nowTimeString) if action == 'duo': print('[' + nowTimeString + ']: ' + str(action)) pass if action == 'kon': print('[' + nowTimeString + ']: ' + str(action)) pass if action == 'clear': print('[' + nowTimeString + ']: ' + str(action)) pass if action == 'still': print('[' + nowTimeString + ']: ' + str(action)) pass
def __init__(self, security, frequency, starttime_fortest=None, endtime_fortest=util.getYMDHMS(), layer1_from_timeperiod=5, layer1_to_timeperiod=10, layer1_rsi_top=65, layer1_rsi_bottom=35, layer1_rsi_timeperiod=9, layer2_stoprate=0.01, layer2_fromstartrate=0.995, layer2_getLastestPrice_frequency='5m'): self.security = security self.frequency = frequency self.db = DataBody(security, frequency) self.ab = AnalysisBody() self.ownPosition = 0 self.starttime_fortest = starttime_fortest self.endtime_fortest = endtime_fortest self.rates_markAtHandleAction = [] self.actions_markAtHandleAction = [''] # 策略层次1 self.layer1_from_timeperiod = layer1_from_timeperiod self.layer1_to_timeperiod = layer1_to_timeperiod self.layer1_rsi_top = layer1_rsi_top self.layer1_rsi_bottom = layer1_rsi_bottom self.layer1_rsi_timeperiod = layer1_rsi_timeperiod self.layer1_pre1_ownerPosition = None self.layer1_ownPosition = 0 self.layer1_startcount = 0 self.layer1_startprice = 0 self.layer1_startRate = 0 self.layer1_pre_flag_5IsLt10 = False self.layer1_rates = [] self.layer1_starttime_rate_map = {} self.layer1_action = None # 策略层次2 self.layer2_stoprate = layer2_stoprate self.layer2_fromstartrate = layer2_fromstartrate self.layer2_nowPrice = None self.layer2_maxRate = 0 self.layer2_nowRate = 0 self.layer2_action = None self.layer2_getLastestPrice_frequency = layer2_getLastestPrice_frequency self.smtpClient = SmtpClient()
def startListen(): while True: nowTimeString = tools.getYMDHMS() if tools.isFutureTradingTime(nowTimeString) is False or tools.isOpen(nowTimeString) is False: time.sleep(61) continue hms = tools.getHMS() tick = False if "08:00:00" < hms < "08:01:00" or \ "10:00:00" < hms < "10:01:00" or \ "12:30:00" < hms < "12:31:00" or \ "14:00:00" < hms < "14:01:00" or \ "20:30:00" < hms < "20:31:00" or \ "22:00:00" < hms < "22:01:00": tick = True if tick is False: time.sleep(50) print("[" + nowTimeString + "]: tick is False") continue time.sleep(61) print("[" + nowTimeString + "]: action") action(nowTimeString)
def tick(self, nowTimeString=util.getYMDHMS()): self.layer1(nowTimeString) self.layer2(nowTimeString) self.handleAction(nowTimeString)
from traderbody import TraderBody import time import util.tools as util ft = 5 tt = 10 rt = 65 rb = 35 rtp = 9 trader = TraderBody(security='RB8888.XSGE', frequency='17m', layer1_from_timeperiod=ft, layer1_to_timeperiod=tt, layer1_rsi_top=rt, layer1_rsi_bottom=rb, layer1_rsi_timeperiod=rtp) while True: trader.tick() time.sleep(6) print('[' + util.getYMDHMS() + ']: tick...')
def action(nowTimeString=tools.getYMDHMS()): strArray = check([ 'RB8888.XSGE', 'BU8888.XSGE', 'HC8888.XSGE', 'ZN8888.XSGE', 'AP8888.XZCE', 'CF8888.XZCE', 'MA8888.XZCE', 'SF8888.XZCE', 'SM8888.XZCE', 'ZC8888.XZCE', 'JD8888.XDCE', 'M8888.XDCE', 'EG8888.XDCE' ], frequencyArr, nowTimeString) print("\n".join(strArray)) rowStr = "" rowHtml = "" for row in strArray: skipRow = False cols = row.split('##') realSecurity = cols[0].split(':')[-1] security = cols[0].split(':')[-1][0:2] frequencyRows = cols[-1].split('#') rowmsg = [security] counts = [] rsis = [] for fr in frequencyRows: frequency = fr.split('_')[0].split(':')[1] count = int(fr.split('_')[1].split(':')[1]) rsi = float(fr.split('_')[2].split(':')[1]) # if count > 0 and rsi < 65: # skipRow = True # break # if count < 0 and rsi > 35: # skipRow = True # break rowmsg.append(str(count)) counts.append(count) rsis.append(rsi) if skipRow is True: continue num = 0 if counts.__len__() == frequencyRows.__len__(): count1 = 0 for c in counts: rsi = rsis[count1] if count1 == 0 and (abs(c) > 5 or (c > 0 and rsi < 60) or (c < 0 and rsi > 40)): break if abs(c) >= 5: num = num + 1 count1 = count1 + 1 if num == counts.__len__() or count1 == 0: continue if rowmsg.__len__() > 0: rowHtml = rowHtml + '<a href="'+getListenForwardShakeUrl(realSecurity)+'">' + "_".join(rowmsg) + "</a><br/>" rowStr = rowStr + "_".join(rowmsg) + '\n' else: rowHtml = "正在搜寻机会..." rowHtml = rowHtml + '\n' + str("Frequencies: " + "_".join(frequencyArr)) print(rowStr) print(rowHtml) smtpClient.sendMail(subject="[" + nowTimeString + "]: 机会报告", content=rowHtml)