예제 #1
0
 def __init__(self, dbinfo = ct.DB_INFO, redis_host = None):
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(host = redis_host)
     self.dbname = self.get_dbname()
     self.redis_host = redis_host
     self.logger = getLogger(__name__)
     self.mysql_client = CMySQL(dbinfo, self.dbname, iredis = self.redis)
     if not self.mysql_client.create_db(self.get_dbname()): raise Exception("init rstock database failed")
예제 #2
0
 def __init__(self, dbinfo = ct.DB_INFO, redis_host = None):
     self.dbname = self.get_dbname()
     self.table_name = self.get_tablename()
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(host = redis_host)
     self.mysql_client = CMySQL(dbinfo, self.dbname, iredis = self.redis)
     if not self.mysql_client.create_db(self.dbname): raise Exception("create plate database failed")
     if not self.create_table(self.table_name): raise Exception("create valuation table failed")
예제 #3
0
 def __init__(self, dbinfo=ct.DB_INFO, redis_host=None):
     self.table = ct.COMBINATION_INFO_TABLE
     self.logger = getLogger(__name__)
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(host=redis_host)
     self.mysql_client = cmysql.CMySQL(dbinfo, iredis=self.redis)
     if not self.init(): raise Exception("init combination table failed")
예제 #4
0
 def __init__(self, dbinfo = ct.DB_INFO, without_init = False, redis_host = None):
     self.table = ct.CALENDAR_TABLE
     self.trigger = ct.SYNCCAL2REDIS
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(host = redis_host)
     self.mysql_client = cmysql.CMySQL(dbinfo, iredis = self.redis)
     if without_init == False:
         if not self.init(): raise Exception("calendar table init failed")
예제 #5
0
 def __init__(self,
              market=ct.SH_MARKET_SYMBOL,
              dbinfo=ct.DB_INFO,
              redis_host=None):
     self.market = market
     self.dbinfo = dbinfo
     self.balcklist = ['2006-07-10'
                       ] if market == ct.SH_MARKET_SYMBOL else list()
     self.logger = getLogger(__name__)
     self.dbname = self.get_dbname(market)
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(host=redis_host)
     self.header = {
         "Host":
         "query.sse.com.cn",
         "Referer":
         "http://www.sse.com.cn/market/stockdata/overview/day/",
         "User-Agent":
         "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"
     }
     self.mysql_client = CMySQL(self.dbinfo,
                                dbname=self.dbname,
                                iredis=self.redis)
     if not self.mysql_client.create_db(self.dbname):
         raise Exception("create %s failed" % self.dbname)
예제 #6
0
 def __init__(self, dbinfo = ct.DB_INFO, redis_host = None):
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(dbinfo)
     self.table = ct.ANIMATION_INFO
     self.trigger = ct.SYNC_ANIMATION_2_REDIS
     if not self.create(): raise Exception("create animation table %s table failed" % self.table)
     if not self.register(): raise Exception("create animation trigger %s failed" % self.trigger)
예제 #7
0
 def __init__(self, code, dbname, dbinfo, redis_host):
     self.code = code
     self._dbname = dbname
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(dbinfo=dbinfo,
                                dbname=dbname,
                                iredis=self.redis)
예제 #8
0
 def __init__(self, dbinfo = ct.DB_INFO, redis_host = None):
     self.dbinfo = dbinfo
     self.emotion_table = ct.EMOTION_TABLE
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(self.dbinfo, iredis = self.redis)
     self.rstock_client = RIndexStock(dbinfo, redis_host)
     self.logger = getLogger(__name__)
     if not self.create(): raise Exception("create emotion table failed")
예제 #9
0
 def __init__(self, code, dbinfo, redis_host):
     self.code = code
     self.logger = getLogger(__name__)
     self.dbname = self.get_dbname(code)
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(dbinfo,
                                dbname=self.dbname,
                                iredis=self.redis)
예제 #10
0
 def __init__(self, dbinfo = ct.DB_INFO, redis_host = None):
     self.table = self.get_table_name()
     self.logger = getLogger(__name__)
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(dbinfo, iredis = self.redis)
     self.header = {"Host": "home.flashdata2.jrj.com.cn",
                    "Referer": "http://stock.jrj.com.cn/tzzs/zdtwdj/zdforce.shtml",
                    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36"}
     if not self.create(): raise Exception("create stock %s failed" % self.table)
예제 #11
0
 def __init__(self, dbinfo = ct.DB_INFO, redis_host = None):
     self.table = ct.STOCK_INFO_TABLE
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(host = redis_host)
     self.mysql_client = cmysql.CMySQL(dbinfo, iredis = self.redis)
     self.mysql_dbs = self.mysql_client.get_all_databases()
     #self.trigger = ct.SYNCSTOCK2REDIS
     #if not self.create(): raise Exception("create stock info table:%s failed" % self.table)
     if not self.init():
         raise Exception("init stock info table failed")
예제 #12
0
 def __init__(self, dbinfo=ct.DB_INFO, redis_host=None):
     self.table = ct.DELISTED_INFO_TABLE
     self.trigger = ct.SYNC_DELISTED_2_REDIS
     self.mysql_client = CMySQL(dbinfo)
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(host=redis_host)
     if not self.create(): raise Exception("create delisted table failed")
     if not self.init(True): raise Exception("init delisted table failed")
     if not self.register():
         raise Exception("create delisted trigger failed")
예제 #13
0
 def __init__(self, index_code, dbinfo = ct.DB_INFO, redis_host = None):
     self.dbinfo = dbinfo
     self.index_code = index_code
     self.index_obj = CIndex(index_code, dbinfo = self.dbinfo, redis_host = redis_host)
     self.db_name = self.index_obj.get_dbname(index_code)
     self.logger = getLogger(__name__)
     self.ris = RIndexStock(dbinfo, redis_host)
     self.bull_stock_ratio_table = self.get_table_name()
     self.redis = create_redis_obj() if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(self.dbinfo, dbname = self.db_name, iredis = self.redis)
     if not self.create(): raise Exception("create emotion table failed")
예제 #14
0
 def get(code=None, column=None, redis=None, redis_host=None):
     if redis is None:
         redis = create_redis_obj(
         ) if redis_host is None else create_redis_obj(host=redis_host)
     df_byte = redis.get(ct.STOCK_INFO)
     if df_byte is None: return pd.DataFrame()
     df = _pickle.loads(df_byte)
     if code is None: return df
     if column is None:
         return df.loc[df.code == code]
     else:
         return df.loc[df.code == code][column].values[0]
예제 #15
0
 def __init__(self,
              dbinfo=ct.DB_INFO,
              redis_host=None,
              stocks_dir='/data/tdx/history/days',
              stock_path='/data/tdx/base/stocks.csv'):
     self.table = ct.STOCK_INFO_TABLE
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(host=redis_host)
     self.mysql_client = cmysql.CMySQL(dbinfo, iredis=self.redis)
     self.mysql_dbs = self.mysql_client.get_all_databases()
     self.stocks_dir = stocks_dir
     self.stock_path = stock_path
예제 #16
0
 def __init__(self, dbinfo=ct.DB_INFO, redis_host=None):
     self.dbinfo = dbinfo
     self.logger = getLogger(__name__)
     self.tu_client = get_tushare_client()
     self.doc = CDoc()
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(redis_host)
     self.mysql_client = CMySQL(dbinfo, iredis=self.redis)
     self.margin_client = Margin(dbinfo=dbinfo, redis_host=redis_host)
     self.rstock_client = RIndexStock(dbinfo=dbinfo, redis_host=redis_host)
     self.sh_market_client = StockExchange(ct.SH_MARKET_SYMBOL)
     self.sz_market_client = StockExchange(ct.SZ_MARKET_SYMBOL)
     self.emotion_client = Emotion()
예제 #17
0
 def __init__(self,
              market_from=ct.SH_MARKET_SYMBOL,
              market_to=ct.HK_MARKET_SYMBOL,
              dbinfo=ct.DB_INFO,
              redis_host=None):
     self.market_from = market_from
     self.market_to = market_to
     self.balcklist = None
     self.crawler = None
     self.mysql_client = None
     self.dbinfo = dbinfo
     self.logger = getLogger(__name__)
     self.redis = create_redis_obj(
     ) if redis_host is None else create_redis_obj(host=redis_host)
예제 #18
0
 def is_trading_day(_date=None, redis=None):
     _redis = create_redis_obj() if redis is None else redis
     df = CCalendar.get(redis=_redis)
     tmp_date = _date if _date is not None else datetime.now().strftime(
         '%Y-%m-%d')
     return True if df.empty else 1 == df.loc[df.calendarDate ==
                                              tmp_date].isOpen.values[0]
예제 #19
0
 def get(index_type = None, redis = None):
     redis = create_redis_obj() if redis is None else redis
     df_byte = redis.get(ct.COMBINATION_INFO) 
     if df_byte is None: return pd.DataFrame() 
     df = _pickle.loads(df_byte)
     if index_type is None: return df
     return df[[df.cType == index_type]]
예제 #20
0
def choose_plate(edate = '2016-10-11', ndays = 90):
    rindustry_info_client = RIndexIndustryInfo(redis_host='127.0.0.1')
    today_industry_df = rindustry_info_client.get_k_data(edate)
    pchange_df = today_industry_df.sort_values(by = 'pchange', ascending = False).head(3)
    mchange_df = today_industry_df.sort_values(by = 'mchange', ascending = False).head(3)
    plate_code_list = list(set(pchange_df.code.tolist()).intersection(pchange_df.code.tolist()))
    if len(plate_code_list) == 0: 
        logger.info("no interested plate for date:%s" % edate)
        return list()
    sdate = get_day_nday_ago(edate, ndays, '%Y-%m-%d')
    #get sh index data
    sh_index_obj = CIndex('000001', redis_host='127.0.0.1')
    sh_index_info = sh_index_obj.get_k_data_in_range(sdate, edate)
    sh_index_pchange = 100 * (sh_index_info.loc[len(sh_index_info) - 1, 'close'] -  sh_index_info.loc[0, 'preclose']) / sh_index_info.loc[0, 'preclose']
    #get industry data
    all_industry_df = rindustry_info_client.get_k_data_in_range(sdate, edate)
    all_industry_df = all_industry_df.loc[all_industry_df.code.isin(plate_code_list)]
    industry_static_info = DataFrame(columns={'code', 'sai', 'pchange', ct.KL, ct.QL, ct.JL, ct.FL})
    #choose better industry
    redisobj = create_redis_obj("127.0.0.1") 
    today_industry_info = IndustryInfo.get(redisobj)
    for code, industry in all_industry_df.groupby('code'):
        industry = industry.reset_index(drop = True)
        industry['sri'] = 0
        industry['sri'] = industry['pchange'] - sh_index_info['pchange']
        industry['sai'] = 0
        industry.at[(industry.pchange > 0) & (sh_index_info.pchange < 0), 'sai'] = industry.loc[(industry.pchange > 0) & (sh_index_info.pchange < 0), 'sri']
        industry_sai = len(industry.loc[industry.sai > 0])
        industry_pchange = 100 * (industry.loc[len(industry) - 1, 'close'] -  industry.loc[0, 'preclose']) / industry.loc[0, 'preclose']
        code_list = json.loads(today_industry_info.loc[today_industry_info.code == code, 'content'].values[0])
        info_dict, good_code_list = choose_stock(code_list, sdate, edate)
        industry_static_info = industry_static_info.append(DataFrame([[code, industry_sai, industry_pchange, info_dict[ct.KL], info_dict[ct.QL], info_dict[ct.JL], info_dict[ct.FL]]], columns = ['code', 'sai', 'pchange', ct.KL, ct.QL, ct.JL, ct.FL]), sort = 'True')
    industry_static_info = industry_static_info.reset_index(drop = True)
    industry_static_info = industry_static_info.sort_values(by=['pchange'], ascending=False)
    return good_code_list
예제 #21
0
 def __init__(self, dbinfo, table):
     self.table = table
     self.redis = create_redis_obj()
     self.mysql_client = CMySQL(dbinfo)
     self.trigger = ct.SYNC_HALTED_2_REDIS
     if not self.create(): raise Exception("create chalted table failed")
     if not self.init(True): raise Exception("init chalted table failed")
     if not self.register(): raise Exception("create chalted trigger failed")
예제 #22
0
 def __init__(self, dbinfo, code):
     self.code = code
     self.dbname = self.get_dbname(code)
     self.redis = create_redis_obj()
     self.data_type_dict = {9: "day"}
     self.influx_client = CInflux(ct.IN_DB_INFO, self.dbname)
     self.mysql_client = cmysql.CMySQL(dbinfo, self.dbname)
     if not self.create():
         raise Exception("create combination table failed")
예제 #23
0
 def __init__(self, dbinfo, dbname, iredis=create_redis_obj()):
     self.redis = iredis
     self.dbname = dbname
     self.df_client = DataFrameClient(dbinfo['host'],
                                      dbinfo['port'],
                                      dbinfo['user'],
                                      dbinfo['password'],
                                      self.dbname,
                                      timeout=10)
예제 #24
0
 def __init__(self, dbinfo, dbname='stock'):
     self.dbinfo = dbinfo
     self.dbname = dbname
     self.redis = create_redis_obj()
     self.engine = create_engine(
         "mysql://%s:%s@%s/%s?charset=utf8" %
         (self.dbinfo['user'], self.dbinfo['password'], self.dbinfo['host'],
          self.dbname),
         pool_size=0,
         max_overflow=-1,
         pool_recycle=120)
예제 #25
0
 def __init__(self, dbinfo):
     self.dbinfo = dbinfo
     self.sdir = '/data/docs/blog/hellobiek.github.io/source/_posts'
     self.doc = CDoc(self.sdir)
     self.stock_objs = dict()
     self.redis = create_redis_obj()
     self.mysql_client = CMySQL(self.dbinfo, iredis=self.redis)
     self.cal_client = ccalendar.CCalendar(without_init=True)
     self.animating = False
     self.emotion_table = ct.EMOTION_TABLE
     if not self.create_emotion():
         raise Exception("create emotion table failed")
예제 #26
0
 def __init__(self, dbinfo, dbname='stock', iredis=None):
     self.dbinfo = dbinfo
     self.dbname = dbname
     self.redis = create_redis_obj() if iredis is None else iredis
     self.engine = create_engine(
         "mysql://%s:%s@%s/%s?charset=utf8" %
         (self.dbinfo['user'], self.dbinfo['password'], self.dbinfo['host'],
          self.dbname),
         pool_size=0,
         max_overflow=-1,
         pool_recycle=20,
         pool_timeout=5,
         connect_args={'connect_timeout': 3})
예제 #27
0
 def __init__(self, dbinfo=ct.DB_INFO, without_init=False):
     self.table = ct.CALENDAR_TABLE
     self.trigger = ct.SYNCCAL2REDIS
     self.mysql_client = cmysql.CMySQL(dbinfo)
     self.redis = create_redis_obj()
     if without_init == False:
         if not self.create():
             raise Exception("create calendar table failed")
         if not self.init(True):
             raise Exception("calendar table init failed")
         # here must be first init and second register, for init will delete table
         # which will delete trigger
         if not self.register():
             raise Exception("create calendar trigger failed")
예제 #28
0
 def __init__(self, dbinfo):
     self.sdir = '/data/docs/blog/hellobiek.github.io/source/_posts'
     self.doc = CDoc(self.sdir)
     self.redis = create_redis_obj()
     self.mysql_client = CMySQL(dbinfo)
     self.cal_client = ccalendar.CCalendar(without_init=True)
     self.trading_info = None
     self.animating = False
     self.emotion_table = ct.EMOTION_TABLE
     self.industry_table = ct.INDUSTRY_TABLE
     if not self.create_industry():
         raise Exception("create industry table failed")
     if not self.create_emotion():
         raise Exception("create emotion table failed")
예제 #29
0
def worker(client_id, func_name, df, key, subset):
    worker = gear.Worker(client_id)
    worker.addServer(host=ct.GEARMAND_HOST, port=ct.GEARMAND_PORT)
    worker.registerFunction(func_name)
    redis = create_redis_obj()
    while True:
        job = worker.getJob()
        info = json.loads(job.arguments.decode('utf-8'))
        tmp_df = pandas.DataFrame(info, index=[0])
        tmp_redis = redis.get(key)
        if tmp_redis is not None: df = _pickle.loads(tmp_redis)
        df = df.append(tmp_df)
        df = df.drop_duplicates(subset)
        redis.set(key, _pickle.dumps(df, 2))
        job.sendWorkComplete()
예제 #30
0
 def get(redis=None):
     redis = create_redis_obj() if redis is None else redis
     df_byte = redis.get(ct.INDUSTRY_INFO)
     return pd.DataFrame() if df_byte is None else _pickle.loads(df_byte)