Esempio n. 1
0
def run(queue):
    MyLog.info('child process %s is running' % os.getpid())
    try:
        dh = None
        data = queue.get(True)
        while data is not None and data['df'] is not None and len(
                data['df']) > 0:
            timestamp = data['timestamp']
            zs = data['zs']
            df = data['df']
            hygn = None
            netMoney = None
            s = int(round(time.time() * 1000))
            if dh is None:
                codeList = df['code'].tolist()
                dh = DataHolder(codeList)
            dh.addData(df)
            res = analyze.calcMain(zs, dh, hygn, netMoney, timestamp)
            if len(res) > 0:
                for code in res:
                    dh.add_buyed(code, True)
            MyLog.debug('process %s, calc data time = %d' %
                        (os.getpid(), (int(round(time.time() * 1000)) - s)))
            data = queue.get(True)
    except Exception as e:
        MyLog.error('error %s' % str(e))
Esempio n. 2
0
def start_test(codes):
    for code in codes:
        try:
            src_datas[code] = pd.read_sql_table('live_' + code, con=engine)
        except Exception as e:
            MyLog.error('read mock data error \n')
            MyLog.error(str(e) + '\n')
    for i in range(5200):
        run(i)
    input('please enter to exit')
Esempio n. 3
0
def start_test_by_df(df_list):
    for df in df_list:
        try:
            code = df.iloc[0]['code']
            src_datas[code] = df
        except Exception as e:
            MyLog.error('read mock data error \n')
            MyLog.error(str(e) + '\n')
    for i in range(5200):
        run(i)
    return result
Esempio n. 4
0
 def saveData(self, data):
     try:
         line = data.iloc[0]
         code = line['code']
         data.to_sql('live_' + code,
                     con=self.__engine,
                     if_exists='replace',
                     index=False)
         MyLog.info('[%s] save data' % code)
     except Exception as e:
         MyLog.error('[%s %s] save [%s] data error \n' %
                     (line['date'], line['time'], code))
         MyLog.error(str(e) + '\n')
Esempio n. 5
0
 def recoverData(self, codes):
     for code in codes:
         try:
             src_data = pd.read_sql_table('live_' + code, con=self.__engine)
             if src_data is not None and len(src_data) > 0:
                 last = src_data.iloc[-1]
                 now_date = time.strftime('%Y-%m-%d',
                                          time.localtime(time.time()))
                 if now_date == last['date']:
                     self.__data[code] = Stock(code, src_data)
         except Exception as e:
             MyLog.error('recover data error \n')
             MyLog.error(str(e) + '\n')
Esempio n. 6
0
def run(queue,balance,lock):
    MyLog.info('child process %s is running' % os.getpid())
    try:
        dh = None
        data = queue.get(True)
        while data is not None and data['df'] is not None and len(data['df']) > 0:
              timestamp = data['timestamp']
              df = data['df']
              zs = data['zs']
              if data['balance'] is not None:
                 balance.value = data['balance']
              if dh is None:
                 dh = NewDataHolder2() 
              dh.addData(df)
              analyze.calcMain(zs,dh,timestamp,balance,lock)
              data = queue.get(True)   
    except Exception as e:
           MyLog.error('error %s' % str(e))
Esempio n. 7
0
def run(queue):
    MyLog.info('child process %s is running' % os.getpid())
    try:
        dh = None
        data = queue.get(True)
        while data is not None and data['df'] is not None and len(
                data['df']) > 0:
            df = data['df']
            zs = data['zs']
            s = int(round(time.time() * 1000))
            if dh is None:
                codeList = df['code'].tolist()
                dh = DataHolder(codeList)
            dh.addSellData(df)
            analyze.calcMain(zs, dh)
            MyLog.debug('process %s, calc data time = %d' %
                        (os.getpid(), (int(round(time.time() * 1000)) - s)))
            data = queue.get(True)
    except Exception as e:
        MyLog.error('error %s' % str(e))
Esempio n. 8
0
def run(queue,queueout):
    MyLog.info('child process %s is running' % os.getpid())
    try:
        dh = None
        data = queue.get(True)
        while data is not None and data['df'] is not None and len(data['df']) > 0:
              timestamp = data['timestamp']
              df = data['df']
              zs = data['zs']
              buyCount = data['buyCount']
              if dh is None:
                 dh = NewDataHolder() 
              dh.addData(df)
              res = analyze.calcMain(zs,dh,timestamp,buyCount)
              if len(res) > 0:
                 for code in res: 
                     dh.add_buyed(code)
                     queueout.put({'buyed' : 1})
              data = queue.get(True)   
    except Exception as e:
            MyLog.error('error %s' % str(e))
Esempio n. 9
0
def run(codes, dh):
    # if len(dh.get_buyed()) > 0:
    #    for code in dh.get_buyed():
    #        if code in codes:
    #           codes.remove(code)
    try:
        # if len(codes) > 0:
        #    df = ts.get_realtime_quotes(codes)
        #    dh.addData(df)
        #    res = analyze.calcMain(dh)
        #    if res != '':
        #       dh.add_buyed(res)
        print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
        print(codes)
    except Exception as e:
        MyLog.error('get data error %s %s' % (codes, str(e)))
    finally:
        global timer
        timer = threading.Timer(setting.get_t1()['get_data_inter'],
                                run,
                                args=[codes, dh])
        timer.start()
Esempio n. 10
0
# thsgn = pd.read_sql_table('concept', con=engine)
# analyze = Analyze(thshy,thsgn)
analyze = Analyze(None,None)
mockTrade = MockTrade()
mockTrade.relogin()
# concept = Concept()
# netMoney = NetMoney()
# hygn = concept.getCurrentTopHYandConcept()
# net = netMoney.getNetMoneyRatio()
zs = ts.get_realtime_quotes(['sh','sz','hs300','sz50','zxb','cyb'])

for code in codes:
    try:
       src_datas[code] = pd.read_sql_table('live_' + code, con=engine)
    except Exception as e:
           MyLog.error('read mock data error \n')
           MyLog.error(str(e) +  '\n')   

def run(i):
    df = pd.DataFrame()
    for code in src_datas:
        if i < len(src_datas[code]):
           df = df.append(src_datas[code].iloc[i])
    if len(df) > 0:
       dh.addData(df)
       codes = analyze.calcMain(zs,dh,None,None,dt.datetime.now())
       if len(codes) > 0:
          for code in codes: 
              dh.add_buyed(code,False)

for i in range(5200):