示例#1
0
 def OnRtnDepthMarketData(self, *args):
     
     logger.info("OnRtnDepthMarketData")
     logger.info("id: "+args[0].InstrumentID)
     logger.info("TradingDay: " + args[0].TradingDay + " " + args[0].UpdateTime)
     logger.info("LastPrice: " + str(args[0].LastPrice))
     if self.__insertIntoMysql:
         if self.__mysqlCon == None:
             self.__mysqlCon = client.mysqlConnection(CONSTANTS.HOST,
                                                      CONSTANTS.USERNAME,
                                                      CONSTANTS.PASSWORD,
                                                      CONSTANTS.DATABASE)
         date = datetime.strptime(args[0].TradingDay, "%Y%m%d")
         dateStr = date.strftime("%Y-%m-%d")
         dateStr = dateStr + " " + args[0].UpdateTime
         self.__mysqlCon.addBar(args[0].InstrumentID,
                         RealTimeBar(dateStr,
                                     args[0].LastPrice,
                                     args[0].Volume))
     if self.__dumpToFile:
         try:
             self.dumpToFile(args[0])
         except Exception as e:
             print "except", e
     logger.info("OnRtnDepthMarketData End")
示例#2
0
文件: etl.py 项目: TimonPeng/pi314
def backFill(options):
    try:
        con = mysqlConnection()
        con.backFill(86400, options.logFilename, options.startdate, options.enddate)
        con.backFill(1800, options.logFilename, options.startdate, options.enddate)
        con.backFill(300, options.logFilename, options.startdate, options.enddate)
        if options.logFilename is not None:
            f = open(options.logFilename, 'a')
            f.write("Back fill finished at %s\n" % (datetime.now()))
    except Exception:
        traceback.print_exc()
        if options.logFilename is not None:
            f = open(options.logFilename, 'a')
            f.write("Back fill failed at %s\n" % (datetime.now()))
示例#3
0
文件: etl.py 项目: TimonPeng/pi314
def dailyViewEtl(options):
    try:
        con = mysqlConnection()
        generateTime = datetime.strptime(options.datetime, "%Y-%m-%d") + timedelta(days=1)
        generateTime = generateTime.strftime("%Y-%m-%d")
        con.dailyupdate(86400, options.logFilename, generateTime)
        con.dailyupdate(1800, options.logFilename, generateTime)
        con.dailyupdate(300, options.logFilename, generateTime)
        if dailyViewETLSanityCheck(options):
            if options.logFilename is not None:
                f = open(options.logFilename, 'a')
                f.write("dailyViewETL finished " + options.datetime + "\n")
    except Exception:
        traceback.print_exc()
        if options.logFilename is not None:
            f = open(options.logFilename, 'a')
            f.write("dailyViewETL failed " + options.datetime + "\n")
示例#4
0
文件: etl.py 项目: TimonPeng/pi314
def dailyEtl(options):
    try:
        con = mysqlConnection()
        #delete the given day's data first
        deleteTime = datetime.strptime(options.datetime, "%Y-%m-%d") + timedelta(days=1)
        deleteTime = deleteTime.strftime("%Y-%m-%d")
        con.deleteDataFromDate(deleteTime)
        con.addFromCSVFile(options.filepath + options.datetime + ".csv")
        #log status
        if dailyETLSanityCheck(options):
            if options.logFilename is not None:
                f = open(options.logFilename, 'a')
                f.write("\n********************************************\n")
                f.write("dailyETL finished " + options.datetime + "\n at %s" % (datetime.now()))
    except Exception:
        traceback.print_exc()
        if options.logFilename is not None:
            f = open(options.logFilename, 'a')
            f.write("\n********************************************\n")
            f.write("dailyETL failed " + options.datetime + "\n at %s" % (datetime.now()))
示例#5
0
 def __init__(self, frequency, maxLen=dataseries.DEFAULT_MAX_LEN):
     membf.BarFeed.__init__(self, frequency, maxLen)
     self.__db = mysqlConnection()