def notifyTrade(security): currentTimeString = util.getYMDHMS() duo = str(int(dao.readDuoPosition(security=security))) kon = str(int(dao.readKongPosition(security=security))) max = str(int(dao.readMaxPosition(security=security))) a = '<p>duo: <strong>' + duo + '</strong></p><p>kon: <strong>' + kon + '</strong></p><p>max: <strong>' + max + '</strong></p>' sendEmail(subject='[' + str(currentTimeString) + '] 触发交易动作_' + security, content='' + a)
def log(content): string = "[Time: " + util.getYMDHMS() + "]: " + str(content) print(string) return string
def notifyCloseDuo(security, currentTimeString=None): if currentTimeString is None: currentTimeString = util.getYMDHMS() a = '<a href="http://107.182.31.161:5288/">查看行情</a>' sendEmail(subject='[' + str(currentTimeString) + '] Duo平_' + security, content='' + a)
def notifyVolumeUnusual(security): currentTimeString = util.getYMDHMS() a = '<a href="http://107.182.31.161:5288/">查看行情</a>' sendEmail(subject='[' + str(currentTimeString) + '] 瞬间成交量大增_' + security, content='' + a)
def notifyLockDuo(security): currentTimeString = util.getYMDHMS() a = '<a href="http://107.182.31.161:5288/">查看行情</a>' sendEmail(subject='[' + str(currentTimeString) + '] 锁多(平多仓)_' + security, content='' + a)
def notifyError(content): currentTimeString = util.getYMDHMS() sendEmail(subject='[' + str(currentTimeString) + '] 错误:' + content, content=str(content))
def controlOnTick(self, tick): if self.realOpenDuoPrice is not None and self.realOpenKonPrice is not None: smtp.notifyError('realOpenDuoPrice和realOpenKonPrice都不为空,将中止进程') exit() # 监听区域!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!########################################## # 持有多仓风控计算实时盈亏 rate = None if self.realOpenKonPrice is not None: openPrice = self.realOpenKonPrice rate = round((openPrice - tick.lastPrice) / openPrice, 8) * 100 print '[' + str( util.getYMDHMS()) + '] RiskControl realOpenKonPrice: ' + str( self.realOpenDuoPrice) + ' rate: ' + str(rate) if rate < RiskControlRate: self.lockActionToken = True # 发出放狗指令 if self.locking is True and rate > -RiskControlRate: self.unlockActionToken = True # 发出放狗指令 # 持有空仓风控计算实时盈亏 elif self.realOpenDuoPrice is not None: openPrice = self.realOpenDuoPrice rate = round((tick.lastPrice - openPrice) / openPrice, 8) * 100 print '[' + str( util.getYMDHMS()) + '] RiskControl realOpenDuoPrice: ' + str( self.realOpenDuoPrice) + ' rate: ' + str(rate) if rate < RiskControlRate: self.lockActionToken = True # 发出放狗指令 if self.locking is True and rate > -RiskControlRate: self.unlockActionToken = True # 发出放狗指令 #Return的话,说明还没有开仓,或者开仓时候没有设置这两个值 if self.realOpenDuoPrice is None and self.realOpenKonPrice is None: return # 动作执行区域!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!########################################## # 锁动作执行 if self.lockActionToken is True and self.locking is False: if self.realOpenKonPrice is not None: if self.ctaEngine is not None: self.ctaEngine.cover( tick.upperLimit * 0.995, int32(self.maxPosition) ) # 平空!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! smtp.notifyLockKon(security=self.security) if self.realOpenDuoPrice is not None: if self.ctaEngine is not None: self.ctaEngine.sell( tick.lowerLimit * 1.005, int32(self.maxPosition) ) # 平多!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! smtp.notifyLockDuo(security=self.security) self.locking = True # 持久化,下次策略重载时风控对象重新初始化从数据库读取 dao.activeLocking(security=self.security) self.lockActionToken = False # 解锁动作执行 if self.unlockActionToken is True and self.locking is True: if self.realOpenKonPrice is not None: if self.ctaEngine is not None: smtp.notifyUnLockKon(security=self.security) if self.realOpenDuoPrice is not None: if self.ctaEngine is not None: smtp.notifyUnLockDuo(security=self.security) self.locking = False # 持久化,下次策略重载时风控对象重新初始化从数据库读取 dao.releaseLocking(security=self.security) self.unlockActionToken = False