示例#1
0
def finance_report(start: Timestamp,
                   end: Timestamp,
                   market: str,
                   symbol: str,
                   report_type: str,
                   quarter="all") -> DataFrame:
    """

    :param start: start time
    :param end: end time
    :param market: {'HK', 'CN'}
    :param symbol: stock symbol
    :param report_type: {'indicator', 'balance', 'income', 'business'}
    :param quarter: {'all', 'Q1', 'Q2', ‘Q3', 'Q4'}
    :return: data frame contains items of financial report
    """
    count = (end.to_period(freq='Q') - start.to_period(freq='Q')).n
    end_timestamp = int(end.timestamp() * 1000)
    urlpath = f"{market}/{report_type}.json?symbol={symbol}&&type={quarter}" \
              f"&is_detail=true&count={count}&timestamp={end_timestamp}"
    url = urljoin(api_ref.finance_base, urlpath)
    data = utls.fetch(url)
    data_list = data.pop('list')
    for d in data_list:
        for k in d:
            if isinstance(d[k], list):
                d[k] = d[k][0]
    df = DataFrame(data_list).drop(columns=['ctime']).rename(
        columns={
            'report_date': 'date'
        }).set_index('date')
    df.date = df.date.astype('M8[ms]')
    df.report_name = df.report_name.str.replace('年报', 'Q4').str.replace('三季报', 'Q3')\
        .str.replace('中报', 'Q2').str.replace('一季报', 'Q1')
    return df
示例#2
0
def bonus(symbol, page=1, size=10):
    url = api_ref.f10_bonus + symbol
    url += '&page='
    url += str(page)
    url += '&size='
    url += str(size)
    return utls.fetch(url)
示例#3
0
def his_data(symbols, period='day', def_cnt=1):
    url = api_ref.his_data + symbols
    url = url + "&begin=" + str(round(time.time() * 1000))
    tail = "&period=" + str(period) + "&type=before&count=-" + str(
        def_cnt
    ) + "&indicator=kline,pe,pb,ps,pcf,market_capital,agt,ggt,balance"
    url = url + tail
    #print('his_data url=%s' % url)
    return utls.fetch(url)
示例#4
0
def indicator(symbol, is_annals=0, count=10):
    
    url = api_ref.finance_indicator_url+symbol
    
    if is_annals == 1:
        url = url + '&type=Q4'
    
    url = url + '&count='+str(count)

    return utls.fetch(url)
示例#5
0
def business(symbol, is_annals=0, count=10):

    url = api_ref.finance_business_url+symbol

    if is_annals == 1:
        url = url + '&type=Q4'

    url = url + '&count='+str(count)

    return utls.fetch(url)
示例#6
0
def cash_flow(symbol, is_annals=0, count=10):

    url = api_ref.finance_cash_flow_url+symbol
    
    if is_annals == 1:
        url = url + '&type=Q4'
    
    url = url + '&count='+str(count)

    return utls.fetch(url)
示例#7
0
def business(symbol, is_annuals=0, count=10):

    url = api_ref.finance_business_url + symbol

    if is_annuals == 1:
        url += '&type=Q4'
    else:
        url += '&type=all&is_detail=true&count='
    url += str(count)

    return utls.fetch(url)
示例#8
0
def cash_flow(symbol, is_annuals=0, count=10):

    url = api_ref.finance_cash_flow_url + symbol

    if is_annuals == 1:
        url += '&type=Q4&count='
    else:
        url += '&type=all&is_detail=true&count='
    url += str(count)

    return utls.fetch(url)
示例#9
0
def population_by_market(market: str, batch_size: int = 1000) -> DataFrame:
    """

    :param market: {'HK', 'CN'}
    :param batch_size: size of one batch
    :return: dataframe contains all population
    """
    url = api_ref.population_base + "?page=1&size={}&order=asc&order_by=symbol&market={}&type={}".format(
        batch_size, market, market.lower())

    res = utls.fetch(url)

    total_count = res['count']
    data: list = res['list']

    # noinspection PyTypeChecker
    time.sleep(np.clip(nr.normal(1, 0.02), 0.9, 1.1))

    for page in range(2, (total_count - 1) // batch_size + 2):
        url = api_ref.population_base + "?page={}&size={}&order=asc&order_by=symbol&market={}&type={}".format(
            page, batch_size, market, market.lower())

        res = utls.fetch(url)
        this_count = res.get('count', 0)
        if this_count != total_count:
            raise RuntimeWarning(
                f"Get record number ({this_count}) from page {page}, which is different from first page ({total_count})"
            )

        this_list = res.get('list', [])
        if not this_list:
            raise RuntimeWarning("empty page, seemingly missing data")

        data.extend(this_list)
        # noinspection PyTypeChecker
        time.sleep(np.clip(nr.normal(1, 0.02), 0.9, 1.1))

    return DataFrame(data).set_index('symbol')
示例#10
0
def industry(symbol):
    url = api_ref.f10_industry + symbol
    return utls.fetch(url)
示例#11
0
def watch_stock(id):
    url = api_ref.watch_stock + str(id)
    return utls.fetch(url)
示例#12
0
def watch_list():
    url = api_ref.watch_list
    return utls.fetch(url)
示例#13
0
def pankou(symbol):
    url = api_ref.realtime_pankou + symbol
    return utls.fetch(url)
示例#14
0
def report(symbol):
    url = api_ref.report_latest_url+symbol
    return utls.fetch(url)
示例#15
0
def shareschg(symbol, count=5):
    url = api_ref.f10_shareschg + symbol
    url = url + '&count=' + str(count)
    return utls.fetch(url)
示例#16
0
def industry_compare(symbol):
    url = api_ref.f10_industry_compare + symbol
    return utls.fetch(url)
示例#17
0
def main_indicator(symbol):
    url = api_ref.f10_indicator + symbol
    return utls.fetch(url)
示例#18
0
def share_quotec(symbols):
    url = api_ref.share_quote + symbols + '&extend=detail'
    return utls.fetch(url)
示例#19
0
def margin(symbol, page=1, size=180):
    url = api_ref.capital_margin_url+symbol
    url = url + '&page='+str(page)
    url = url + '&size='+str(size)
    return utls.fetch(url)
示例#20
0
def quote_detail(symbol):
    return utls.fetch(api_ref.realtime_quote_detail + symbol)
示例#21
0
def earningforecast(symbol):
    url = api_ref.report_earningforecast_url+symbol
    return utls.fetch(url)
示例#22
0
def holders(symbol):
    url = api_ref.f10_holders + symbol
    return utls.fetch(url)
示例#23
0
def org_holding_change(symbol):
    url = api_ref.f10_org_holding_change + symbol
    return utls.fetch(url)
示例#24
0
def capital_flow(symbol):
    url = api_ref.capital_flow_url+symbol
    return utls.fetch(url)
示例#25
0
def business_analysis(symbol):
    url = api_ref.f10_business_analysis + symbol
    return utls.fetch(url)
示例#26
0
def capital_history(symbol, count=20):
    url = api_ref.capital_history_url+symbol
    url = url + '&count='+str(count)
    return utls.fetch(url)
示例#27
0
def top_holders(symbol, circula=1):
    url = api_ref.f10_top_holders + symbol
    url = url + '&circula=' + str(circula)
    return utls.fetch(url)
示例#28
0
def holders(symbol, size=10):
    url = api_ref.f10_holders + symbol
    url += '&extend=true&page=1&size='
    url += str(size)
    return utls.fetch(url)
示例#29
0
def skholderchg(symbol):
    url = api_ref.f10_skholderchg + symbol
    return utls.fetch(url)
示例#30
0
def capital_assort(symbol):
    url = api_ref.capital_assort_url+symbol
    return utls.fetch(url)