Ejemplo n.º 1
0
def insert_cnstock_all():
    stockdao = cdao.cnstock_item_dao()
    dailydao = cdao.cnstock_daily_dao()
    stocklist = stockdao.get_all_tscode()
    existinglist = dailydao.get_existing_symbollist()
    for i in range(0, len(stocklist)):
        ts_code = stocklist[i]
        if ts_code not in existinglist:
            ts_code = ts_code.strip()
            print("reading %s from tushare..."%ts_code)
            try:
                list = ctu.read_cnstock_dailyandbasic(ts_code=ts_code, start_date='20140101', end_date='20190712')
                print("insert %s into database..."%ts_code)
                dailydao.insert_newlist(list)
            except (urllib3.exceptions.ReadTimeoutError, requests.exceptions.ReadTimeout) as err:
                print(str(err))
                print("sleeping... 300s")
                time.sleep(300)
                print("retry....")
                i -= 1
            except Exception as inst:
                print(type(inst))
                print(inst.args)
                print(inst)
        i+=1
Ejemplo n.º 2
0
def insert_cnstock_fina():
    daystr = util.get_today_datestr()
    cndaystr = util.date_us2cn(daystr)
    stkdao = cdao.cnstock_item_dao()
    stocklist = stkdao.get_all_tscode()
    list = ctu.read_cnstock_fina(stocklist, cndaystr)
    fina_dao = cdao.dao_cnstock_fina()
    fina_dao.add_oneItemEachTime(list)
Ejemplo n.º 3
0
def insert_cnstock_fina2():
    daystr = util.get_today_datestr()
    cndaystr = util.date_us2cn(daystr)
    stkdao = cdao.cnstock_item_dao()
    sfadao = cdao.dao_cnstock_fina()
    stocklist = stkdao.get_all_tscode()
    existinglist = sfadao.get_existing_tscodelist()
    print('start fina2 insert...')
    for ts_code in stocklist:
        ts_code = ts_code.strip()
        if ts_code not in existinglist:
            list = ctu.read_cnstock_finaone(ts_code, cndaystr)
            sfadao.add_cnstock_fina(list)
Ejemplo n.º 4
0
def insert_cnstock_all_byodt():
    stockdao = cdao.cnstock_item_dao()
    dailydao = cdao.cnstock_daily_dao()
    stocklist = stockdao.get_all_tscode()
    existinglist = dailydao.get_existing_symbollist()
    for i in range(0, len(stocklist)):
        ts_code = stocklist[i]
        if ts_code not in existinglist:
            ts_code = ts_code.strip()
            print("reading %s from opendatatool..."%ts_code)
            list = codt.read_cnstock_daily(ts_code=ts_code, start_date='2014-01-01', end_date='2019-07-12')
            print("insert %s into database..."%ts_code)
            dailydao.insert_newlist(list)
        i+=1
Ejemplo n.º 5
0
def insert_alldaily_oneday_cn(daystr):
    st_dao = cdao.cnstock_item_dao()
    sd_dao = cdao.cnstock_daily_dao()
    done_list = sd_dao.get_existing_symbollist2(daystr)
    print("the length of donelist: %d" %len(done_list))
    daystr = util.date_us2cn(daystr)
    print("reading %s data from tushare..."%daystr)
    dl = ctu.read_cnstock_daily2(daystr)
    print("the length of read data: %d" %len(dl))
    i = 0
    to_add = []
    for item in dl:
        if item.ts_code not in done_list:
            to_add.append(item)
        else:
            print("%s already exists in database...skipped." %item.ts_code)
            i+=1
    print("totally %d skipped." %i)
    print("totally to be add: %d"%len(to_add))
    print("insert into data base...")
    sd_dao.insert_newlist(to_add)
Ejemplo n.º 6
0
def insert_cnstocklist():
    stocklist = ctu.read_cnstocklist()
    stockdao = cdao.cnstock_item_dao()
    stockdao.insert_newlist(stocklist)
Ejemplo n.º 7
0
def get_symbolists_cn():
    stockitem = cdbo.cnstock_item_dao()
    symbol = stockitem.get_all_tscode()
    return symbol