Example #1
0
def get_stopped_stocks(given_stocks=[],except_stocks=[],hist_dir='C:/hist/day/data/'):
    import easyquotation
    quotation =easyquotation.use('qq')
    stop_stocks = []
    if given_stocks:
        this_quotation = quotation.stocks(given_stocks)
    else:
        this_quotation = quotation.all
    all_stocks = list(this_quotation.keys())
    #print('all_stocks=',('150251'  in all_stocks))
    #print('hist_dir=',hist_dir)
    exist_codes = pds.get_all_code(hist_dir)
    #print('exist_codes=',('150251'  in exist_codes))
    #print('all_stocks=',all_stocks)
    all_codes = list(set(all_stocks) & (set(exist_codes)))
    #print('all_codes=',all_codes)
    for stock_code in all_codes:
        if this_quotation[stock_code]:
            #print(this_quotation[stock_code])
            if this_quotation[stock_code]['ask1']==0 and this_quotation[stock_code]['volume']==0:
                stop_stocks.append(stock_code)
            else:
                pass
    
    if except_stocks:
        all_codes = list(set(all_codes).difference(set(except_stocks)))
    #print('all_codes=',('150251'  in all_codes))
    #print('stop_stocks=', stop_stocks)
    #print(len(stop_stocks))
    #print('all_stocks=',all_stocks)
    #print(len(all_stocks))
    return stop_stocks,all_codes
Example #2
0
def get_stopped_stocks(given_stocks=[],
                       except_stocks=[],
                       hist_dir='C:/hist/day/data/'):
    import easyquotation
    quotation = easyquotation.use('qq')
    stop_stocks = []
    if given_stocks:
        this_quotation = quotation.stocks(given_stocks)
    else:
        this_quotation = quotation.all
    all_stocks = list(this_quotation.keys())
    #print('all_stocks=',('150251'  in all_stocks))
    #print('hist_dir=',hist_dir)
    exist_codes = pds.get_all_code(hist_dir)
    #print('exist_codes=',('150251'  in exist_codes))
    #print('all_stocks=',all_stocks)
    all_codes = list(set(all_stocks) & (set(exist_codes)))
    #print('all_codes=',all_codes)
    for stock_code in all_codes:
        if this_quotation[stock_code]:
            #print(this_quotation[stock_code])
            if this_quotation[stock_code]['ask1'] == 0 and this_quotation[
                    stock_code]['volume'] == 0:
                stop_stocks.append(stock_code)
            else:
                pass

    if except_stocks:
        all_codes = list(set(all_codes).difference(set(except_stocks)))
    #print('all_codes=',('150251'  in all_codes))
    #print('stop_stocks=', stop_stocks)
    #print(len(stop_stocks))
    #print('all_stocks=',all_stocks)
    #print(len(all_stocks))
    return stop_stocks, all_codes
def update_hist_k_datas(update_type='yh'):
    target_last_date_str = pds.tt.get_last_trade_date(date_format='%Y/%m/%d')
    last_date_str, is_need_del_tdx_last_string = get_last_trade_date_yh_hist(
        target_last_date_str)
    is_need_update = pds.tt.is_need_update_histdata(last_date_str)
    update_state = 0
    if is_need_update or is_need_del_tdx_last_string:
        start = time.time()
        all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/')
        #multiprocess_update_k_data(code_list_dict)  #apply,非阻塞,传不同参数,支持回调函数
        multiprocess_update_k_data(all_codes, update_type)  #map,阻塞,一个参数
        end = time.time()
        print('Task update yh hist data runs %0.2f seconds.' % (end - start))
        """Post-check"""
        last_date_str, is_need_del_tdx_last_string = get_last_trade_date_yh_hist(
            target_last_date_str)
        is_need_update = pds.tt.is_need_update_histdata(last_date_str)
        if is_need_update and not is_need_del_tdx_last_string:
            print('尝试更新历史数据,但是更新失败;请全部盘后数据已下载...')
            update_state = -1
        else:
            update_state = 1
    else:
        print('No need to update history data')
    return update_state
Example #4
0
def get_stop_trade_symbol():
    today_df = ts.get_today_all()
    today_df = today_df[today_df.amount > 0]
    today_df_high_open = today_df[today_df.open > today_df.settlement * 1.005]
    all_trade_code = today_df['code'].values.tolist()
    all_a_code = pds.get_all_code(hist_dir="C:/中国银河证券海王星/T0002/export/")
    #all_a_code = pds.get_all_code(hist_dir="C:/hist/day/data/")
    all_stop_codes = list(set(all_a_code).difference(set(all_trade_code)))
    return all_stop_codes
Example #5
0
def get_stop_trade_symbol():
    today_df = ts.get_today_all()
    today_df = today_df[today_df.amount>0]
    today_df_high_open = today_df[today_df.open>today_df.settlement*1.005]
    all_trade_code = today_df['code'].values.tolist()
    all_a_code = pds.get_all_code(hist_dir="C:/中国银河证券海王星/T0002/export/")
    #all_a_code = pds.get_all_code(hist_dir="C:/hist/day/data/")
    all_stop_codes = list(set(all_a_code).difference(set(all_trade_code)))
    return all_stop_codes
def update_k_data(update_type='yh'):
    stock_sql = StockSQL()
    hold_df, hold_stocks, available_sells = stock_sql.get_hold_stocks(
        accounts=['36005', '38736'])
    print('hold_stocks=', hold_stocks)
    print('available_sells=', available_sells)

    #pds.get_exit_price(hold_codes=['002521'],data_path='C:/中国银河证券海王星/T0002/export/' )

    #print(hold_df)
    """从新浪 qq网页更新股票"""
    #easyhistory.init(path="C:/hist",stock_codes=hold_stocks)
    #easyhistory.update(path="C:/hist",stock_codes=hold_stocks)
    """从银河更新股票"""
    #for stock in hold_stocks:
    #pds.update_one_stock(symbol=stock,realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=False)
    #   pass

    #stock_sql.update_sql_position(users={'account':'36005','broker':'yh','json':'yh.json'})
    #stock_sql.update_sql_position(users={'account':'38736','broker':'yh','json':'yh1.json'})
    #hold_df,hold_stocks,available_sells = stock_sql.get_hold_stocks(accounts = ['36005', '38736'])
    #print('hold_stocks=',hold_stocks)
    #print(hold_df)
    #pds.update_one_stock(symbol='sh',force_update=False)
    #pds.update_codes_from_YH(realtime_update=False)
    """从银河更新指数"""
    #pds.update_codes_from_YH(realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True)

    #pds.update_codes_from_YH(realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True)
    #indexs = ['zxb', 'sh50', 'hs300', 'sz300', 'cyb', 'sz', 'zx300', 'sh']
    """
    potential_df = stock_sql.query_data(table='potential',fields='category_id,code,valid,name',condition='valid>=1')
    print(potential_df)
    lanchou_df = potential_df[potential_df['category_id']==1]
    print(lanchou_df['code'].values.tolist())
    """
    #"""
    last_date_str = pds.tt.get_last_trade_date(date_format='%Y/%m/%d')
    latest_date_str = pds.tt.get_latest_trade_date(date_format='%Y/%m/%d')
    next_date_str = pds.tt.get_next_trade_date(date_format='%Y/%m/%d')
    print('last_date = ', last_date_str)
    print('latest_date_str=', latest_date_str)
    print('next_date_str=', next_date_str)
    indexs, funds, b_stock, all_stocks = pds.get_different_symbols()
    if update_type == 'index':
        #从银河更新指数
        #stock_sql.update_sql_index(index_list=['sh','sz','zxb','cyb','hs300','sh50'],force_update=False)
        #stock_sql.download_hist_as_csv(indexs = ['sh','sz','zxb','cyb','hs300','sh50'],dir='C:/hist/day/data/')
        pds.update_codes_from_YH(indexs,
                                 realtime_update=False,
                                 dest_dir='C:/hist/day/data/',
                                 force_update_from_YH=True)
    elif update_type == 'fund':
        #从银河更新基金
        all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/')
        funds = []
        for code in all_codes:
            if code.startswith('1') or code.startswith('5'):
                funds.append(code)
        pds.update_codes_from_YH(funds,
                                 realtime_update=False,
                                 dest_dir='C:/hist/day/data/',
                                 force_update_from_YH=True)
    elif update_type == 'position':
        #更新仓位
        #stock_sql.update_sql_position(users={'36005':{'broker':'yh','json':'yh.json'},'38736':{'broker':'yh','json':'yh1.json'}})
        stock_sql.update_sql_position(users={
            'account': '36005',
            'broker': 'yh',
            'json': 'yh.json'
        })
        stock_sql.update_sql_position(users={
            'account': '38736',
            'broker': 'yh',
            'json': 'yh1.json'
        })
        hold_df, hold_stocks, available_sells = stock_sql.get_hold_stocks(
            accounts=['36005', '38736'])
        print('hold_stocks=', hold_stocks)
        print(hold_df)
    elif update_type == 'stock':
        #从新浪 qq网页更新股票
        #easyhistory.init(path="C:/hist",stock_codes=hold_stocks)
        #easyhistory.update(path="C:/hist",stock_codes=hold_stocks)
        #easyhistory.init(path="C:/hist")#,stock_codes=all_codes)
        easyhistory.update(path="C:/hist", stock_codes=all_stocks)  #+b_stock)
    elif update_type == 'YH' or update_type == 'yh':
        all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/')
        #all_codes = ['999999', '000016', '399007', '399008', '399006', '000300', '399005', '399001',
        #             '399004','399106','000009','000010','000903','000905']
        #all_codes=['300162']
        """
        code_list_dict = seprate_list(all_codes,4)
        print('code_list_dict=',code_list_dict)
        print('Parent process %s.' % os.getpid())
        #update_yh_hist_data(codes_list=[],process_id=0)
        p = Pool()
        for i in range(4):
            p.apply_async(update_yh_hist_data, args=(code_list_dict[i],i))
        print('Waiting for all subprocesses done...')
        p.close()
        p.join()
        print('All subprocesses done.')
        """
        all_count = len(all_codes)
        latest_count = 0
        count = 0
        pc0 = 0
        for code in all_codes:
            df, has_tdx_last_string = pds.get_yh_raw_hist_df(code,
                                                             latest_count=None)
            count = count + 1
            pc = round(round(count, 2) / all_count, 2) * 100
            if pc > pc0:
                print('count=', count)
                print('完成数据更新百分之%s' % pc)
                pc0 = pc
            if len(df) >= 1:
                last_code_trade_date = df.tail(1).iloc[0].date
                if last_code_trade_date == latest_date_str:
                    latest_count = latest_count + 1
        latest_update_rate = round(round(latest_count, 2) / all_count, 2)
        print('latest_update_rate=', latest_update_rate)
        #"""

    else:
        pass
Example #7
0
def update_histdatas(stock_sql):
    print('start: ', datetime.datetime.now())
    """
    #user = easytrader.use('yh')
    stock_sql = StockSQL()
    is_tdx_uptodate,is_pos_uptodate,systime_dict = stock_sql.is_histdata_uptodate()
    is_tdx_uptodate=False
    update_hour = systime_dict['hist_update_hour']
    if update_now:#立即更新
        pass
    else:
        if is_tdx_uptodate:
            print('通达信历史数据已经是最新了')
            return
        else:
            if update_hour==datetime.datetime.now().hour:
                pass
    """  
    is_tdx_uptodate,is_pos_uptodate = False,False 
    user = use('yh_client')
    #title='通达信网上交易V6'
    title = '中国银河证券海王星V2.55'
    user.set_title(title)
    account_dict={
        "inputaccount": "331600036005",
        "trdpwd": "F71281A2D62C4b3a8268C6453E9C42212CCC5BA9AB89CAFF4E97CC31AE0E4C48"
    }
    
    user.set_type(type='quote_only')
    user.enable_debug_mode()
    user.prepare(user='******', password='******',exe_path='C:/中国银河证券海王星/TdxW.exe')
    user.update_tdx_k_data()
    
    all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/')
            #all_codes = ['999999', '000016', '399007', '399008', '399006', '000300', '399005', '399001',
            #             '399004','399106','000009','000010','000903','000905']
            #all_codes=['300162']
    count = 0
    all_count = len(all_codes)
    pc0=0
    now_time =datetime.datetime.now()
    now_time_str = now_time.strftime('%Y/%m/%d %X')
    print('now_time = ',now_time_str)
    d_format='%Y/%m/%d'
    last_date_str = pds.tt.get_last_trade_date(date_format=d_format)
    latest_date_str = pds.tt.get_latest_trade_date(date_format='%Y/%m/%d')
    next_date_str = pds.tt.get_next_trade_date(date_format='%Y/%m/%d')
    print('last_date = ',last_date_str)
    print('latest_date_str=',latest_date_str)
    print('next_date_str=',next_date_str)
    latest_count = 0
    for code in all_codes:
        df = pds.get_yh_raw_hist_df(code,latest_count=None)
        count = count + 1
        pc = round(round(count,2)/all_count,2)* 100
        if pc>pc0:
            print('count=',count)
            print('完成数据更新百分之%s' % pc)
            pc0 = pc
        if len(df)>=1:
            last_code_trade_date = df.tail(1).iloc[0].date
            if last_code_trade_date==latest_date_str:
                latest_count = latest_count + 1
            
    latest_update_rate =round(round(latest_count,2)/all_count,2)
    print('latest_update_rate=',latest_update_rate)
    
    if latest_update_rate>0.5:
        now_time =datetime.datetime.now()
        now_time_str = now_time.strftime('%Y/%m/%d %X')
        print('now_time = ',now_time_str)
        print('update_latest update datetime to sql')
        #stock_sql.update_data(table='systime',fields='tdx_update_time',values=now_time_str,condition='id=0')
        stock_sql.write_tdx_histdata_update_time(now_time_str)
        #stock_sql.write_position_update_time(now_time_str)
        systime_dict = stock_sql.get_systime()
        print(systime_dict)
        is_tdx_uptodate,is_pos_uptodate,systime = stock_sql.is_histdata_uptodate()
    print('is_tdx_uptodate=',is_tdx_uptodate)
    print('is_pos_uptodate=',is_pos_uptodate)
Example #8
0
lanchou_df = potential_df[potential_df['category_id']==1]
print(lanchou_df['code'].values.tolist())
"""
#"""
indexs, funds, b_stock, all_stocks = pds.get_different_symbols()
if update_type == 'index':
    #从银河更新指数
    #stock_sql.update_sql_index(index_list=['sh','sz','zxb','cyb','hs300','sh50'],force_update=False)
    #stock_sql.download_hist_as_csv(indexs = ['sh','sz','zxb','cyb','hs300','sh50'],dir='C:/hist/day/data/')
    pds.update_codes_from_YH(indexs,
                             realtime_update=False,
                             dest_dir='C:/hist/day/data/',
                             force_update_from_YH=True)
elif update_type == 'fund':
    #从银河更新基金
    all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/')
    funds = []
    for code in all_codes:
        if code.startswith('1') or code.startswith('5'):
            funds.append(code)
    pds.update_codes_from_YH(funds,
                             realtime_update=False,
                             dest_dir='C:/hist/day/data/',
                             force_update_from_YH=True)
elif update_type == 'position':
    #更新仓位
    #stock_sql.update_sql_position(users={'36005':{'broker':'yh','json':'yh.json'},'38736':{'broker':'yh','json':'yh1.json'}})
    stock_sql.update_sql_position(users={
        'account': '36005',
        'broker': 'yh',
        'json': 'yh.json'
Example #9
0
potential_df = stock_sql.query_data(table='potential',fields='category_id,code,valid,name',condition='valid>=1')
print(potential_df)
lanchou_df = potential_df[potential_df['category_id']==1]
print(lanchou_df['code'].values.tolist())
"""

#"""
indexs,funds,b_stock,all_stocks = pds.get_different_symbols()
if update_type == 'index':
    #从银河更新指数
    #stock_sql.update_sql_index(index_list=['sh','sz','zxb','cyb','hs300','sh50'],force_update=False)
    #stock_sql.download_hist_as_csv(indexs = ['sh','sz','zxb','cyb','hs300','sh50'],dir='C:/hist/day/data/')
    pds.update_codes_from_YH(indexs,realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True)
elif update_type == 'fund':
    #从银河更新基金
    all_codes = pds.get_all_code(hist_dir='C:/中国银河证券海王星/T0002/export/')
    funds =[]
    for code in all_codes:
        if code.startswith('1') or code.startswith('5'):
            funds.append(code)
    pds.update_codes_from_YH(funds,realtime_update=False,dest_dir='C:/hist/day/data/', force_update_from_YH=True)
elif update_type == 'position':
    #更新仓位
    #stock_sql.update_sql_position(users={'36005':{'broker':'yh','json':'yh.json'},'38736':{'broker':'yh','json':'yh1.json'}})
    stock_sql.update_sql_position(users={'account':'36005','broker':'yh','json':'yh.json'})
    stock_sql.update_sql_position(users={'account':'38736','broker':'yh','json':'yh1.json'})
    hold_df,hold_stocks,available_sells = stock_sql.get_hold_stocks(accounts = ['36005', '38736'])
    print('hold_stocks=',hold_stocks)
    print(hold_df)
elif update_type == 'stock':
    #从新浪 qq网页更新股票