示例#1
0
def downBalancesheet(ts_code, startDate='', endDate=''):
    """下载tushare资产负债表

    :param ts_code: str, 股票代码
    :param startDate: str, 开始日期, yyyymmdd
    :param endDate: str, 结束日期, yyyymmdd
    :return:
    """
    if len(ts_code) == 6:
        ts_code = tsCode(ts_code)
    pro = ts.pro_api()
    df = pro.balancesheet(ts_code=tsCode(ts_code),
                          start_date=startDate,
                          end_date=endDate)
    print(df)
    return df
示例#2
0
def downIncome(ts_code, startDate='', endDate=''):
    """下载tushare利润表

    :param ts_code: str, 股票代码
    :param startDate: str, 开始日期, yyyymmdd
    :param endDate: str, 结束日期, yyyymmdd
    :return:
    """
    if len(ts_code) == 6:
        ts_code = tsCode(ts_code)
    pro = ts.pro_api()
    df = pro.income(ts_code=tsCode(ts_code),
                    start_date=startDate,
                    end_date=endDate)
    print(df)
    writeSQL(df, 'income')
示例#3
0
def downPledgeStat(ts_code):
    """获取股权质押统计数据

    :param ts_code:
    :return:
    """
    pro = ts.pro_api()
    df = pro.pledge_stat(ts_code=tsCode(ts_code))
    writeSQL(df, 'pledgestat')
示例#4
0
def setStockList():
    chigu = getChiguList()
    chiguStr = "|".join([i for i in chigu])
    form = StockListForm()
    #     form.stockList = stockListStr
    if form.validate_on_submit():
        chiguStr = form.stockList.data
        # print(stockListStr)
        chigu = chiguStr.split("|")
        chigu = [tsCode(ts_code) for ts_code in chigu]
        allstocks = readStockList().ts_code.to_list()
        checkFlag = True
        for ts_code in chigu:
            if ts_code not in allstocks:
                checkFlag = False
                print('%s is not a valid ts_code' % ts_code)
                break
        if checkFlag:
            print('all ok')
            writeChigu(chigu)
            return redirect(url_for('index'))
    return render_template('stocklist.html', form=form, stockListStr=chiguStr)
示例#5
0
def downDailyBasic(ts_code=None, tradeDate=None, startDate=None, endDate=None):
    """
    从tushare下载股票每日指标
    :param ts_code: 股票代码
    :param tradeDate: 交易日期
    :param startDate: 开始日期
    :param endDate: 结束日期
    :return:
    """
    pro = ts.pro_api()
    df = None
    if ts_code is not None and startDate is not None:
        df = pro.daily_basic(ts_code=tsCode(ts_code),
                             start_date=startDate,
                             end_date=endDate)
    elif tradeDate is not None:
        df = pro.daily_basic(trade_date=tradeDate)
    if isinstance(df, pd.DataFrame):
        # df.rename(columns={'ts_code': 'ts_code', 'trade_date': 'date'},
        #           inplace=True)
        # df['ts_code'] = df['ts_code'].str[:6]
        df.set_index(keys=['ts_code'], inplace=True)
        writeSQL(df, 'daily_basic')
    return df