Пример #1
0
 def collect(self):
     cdata = dict()
     cdata['name'] = list()
     cdata['price'] = list()
     cdata['volume'] = list()
     cdata['amount'] = list()
     cdict = self.get_combination_dict()
     if 0 == len(cdict): return False
     try:
         df = ts.get_realtime_quotes('sh')
         price = float(df.price.tolist()[0])
         p_volume = float(df.volume.tolist()[0])
         p_amount = float(df.amount.tolist()[0])
         cdata['name'].append("上证指数")
         cdata['price'].append(price)
         cdata['volume'].append(p_volume)
         cdata['amount'].append(p_amount)
     except Exception as e:
         logger.info(e)
         return False
     for code in cdict:
         key = cdict[code]
         df_byte = self.redis.get(Combination.get_redis_name(code))
         if df_byte is None: continue
         df = _pickle.loads(df_byte)
         price = float(df.price.tolist()[0])
         p_volume = float(df.volume.tolist()[0])
         p_amount = float(df.amount.tolist()[0])
         cdata['name'].append(key)
         cdata['price'].append(price)
         cdata['volume'].append(p_volume)
         cdata['amount'].append(p_amount)
     df = pd.DataFrame.from_dict(cdata)
     df['ctime'] = datetime.fromtimestamp(time.time()).strftime('%H:%M:%S')
     df['cdate'] = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d')
     self.mysql_client.set(df, self.table)
     return True
Пример #2
0
 def collect(self):
     cdata = dict()
     cdata['name'] = list()
     cdata['price'] = list()
     cdata['volume'] = list()
     cdata['amount'] = list()
     cdict = self.get_combination_dict()
     if 0 == len(cdict): return False
     for code in ct.INDEX_DICT:
         df_byte = self.redis.get(
             CIndex.get_redis_name(CIndex.get_dbname(code)))
         if df_byte is None: continue
         df = _pickle.loads(df_byte)
         price = float(df.last_price.tolist()[0])
         p_volume = float(df.volume.tolist()[0])
         p_amount = float(df.turnover.tolist()[0])
         cdata['name'].append(ct.INDEX_DICT[code])
         cdata['price'].append(price)
         cdata['volume'].append(p_volume)
         cdata['amount'].append(p_amount)
     for code in cdict:
         key = cdict[code]
         df_byte = self.redis.get(Combination.get_redis_name(code))
         if df_byte is None: continue
         df = _pickle.loads(df_byte)
         price = float(df.price.tolist()[0])
         p_volume = float(df.volume.tolist()[0])
         p_amount = float(df.amount.tolist()[0])
         cdata['name'].append(key)
         cdata['price'].append(price)
         cdata['volume'].append(p_volume)
         cdata['amount'].append(p_amount)
     df = pd.DataFrame.from_dict(cdata)
     df['time'] = datetime.fromtimestamp(time.time()).strftime('%H:%M:%S')
     df['date'] = datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d')
     self.mysql_client.set(df, self.table)
     return True