def read_data(self, needStore = False):
     if os.path.exists('i_data.json'):
         with open('k_data.json', 'r') as f:
             k_data = pd.read_json(f.read(), orient = 'records', lines = True)
             k_data.date = k_data.date.dt.strftime('%Y-%m-%d')
         with open('d_data.json', 'r') as f:
             d_data = pd.read_json(f.read(), orient = 'records', lines = True)
         with open('i_data.json', 'r') as f:
             i_data = pd.read_json(f.read(), orient = 'records', lines = True)
             i_data.date = i_data.date.dt.strftime('%Y-%m-%d')
     else:
         obj = CStock(self.code, dbinfo = ct.OUT_DB_INFO, redis_host = '127.0.0.1')
         k_data = obj.get_k_data()
         k_data.date = pd.to_datetime(k_data.date).dt.strftime('%Y-%m-%d')
         d_data = obj.get_chip_distribution()
         iobj = CIndex(self.index_code, dbinfo = ct.OUT_DB_INFO, redis_host = '127.0.0.1')
         i_data = iobj.get_k_data()
         cdates = k_data.date.tolist()
         i_data = i_data.loc[i_data.date.isin(cdates)]
         i_data = i_data.reset_index(drop = True)
         k_data = k_data[['date', 'open', 'high', 'low', 'close', 'volume', 'amount', 'outstanding', 'totals', 'adj', 'aprice', 'uprice', 'sprice', 'mprice', 'lprice', 'profit']]
         k_data = k_data.rename(columns = {"date": "time"})
         i_data = i_data[['date', 'open', 'high', 'low', 'close', 'volume', 'amount']]
         i_data = i_data.rename(columns = {"date": "time"})
         if needStore:
             with open('k_data.json', 'w') as f:
                 f.write(k_data.to_json(orient='records', lines=True))
             with open('d_data.json', 'w') as f:
                 f.write(d_data.to_json(orient='records', lines=True))
             with open('i_data.json', 'w') as f:
                 f.write(i_data.to_json(orient='records', lines=True))
     return k_data, d_data, i_data
Beispiel #2
0
def scallback(event):
    global dist_source, dist_fig, roe_fig, profit_fig
    code = code_text.value
    sobj = CStock(code)
    mdate = stock_source.data['date'][int(event.x)]
    print(code, mdate)
    ddf = sobj.get_chip_distribution(mdate)
    dist_source = ColumnDataSource(ddf)
    dist_fig = create_dist_figure(dist_source)
    layout.children[4] = gridplot([[stock_fig, dist_fig],
                                   [profit_fig, roe_fig]])
Beispiel #3
0
def update_stock(attr, old, new):
    code = code_text.value
    if code is None: return
    sobj = CStock(code)
    sdf = sobj.get_k_data()
    if sdf is None: return
    vdf = get_val_data(code)
    global stock_fig, profit_fig, dist_fig, roe_fig, stock_source, dist_source, val_source
    mdate = mmap_pckr.value
    mdate = mdate.strftime('%Y-%m-%d')
    ddf = sobj.get_chip_distribution(mdate)
    stock_source = ColumnDataSource(sdf)
    dist_source = ColumnDataSource(ddf)
    val_source = ColumnDataSource(vdf)
    stock_fig = create_stock_figure(stock_source)
    profit_fig = create_profit_figure(stock_source)
    dist_fig = create_dist_figure(dist_source)
    roe_fig = create_roe_figure(val_source)
    stock_fig.on_event(DoubleTap, scallback)
    layout.children[4] = gridplot([[stock_fig, dist_fig],
                                   [profit_fig, roe_fig]])