Giter VIP home page Giter VIP logo

Comments (2)

Micro-sheep avatar Micro-sheep commented on July 25, 2024

如何通过接口获取一只股票当日的炸板次数和一段时间内的连板次数

这是一个获取某日涨停股信息的代码,你可以根据它实现你说的两个需求

import pandas as pd
import requests
from datetime import datetime
from jsonpath import jsonpath


def get_zt_stock_rank(date: str = None) -> pd.DataFrame:
    """
    获取指定日期涨停股票行情

    Parameters
    ----------
    date : str
        指定日期,默认为当前日期 格式形如 ``'20220506'``

    Returns
    -------
    DataFrame
        指定日期涨停股票行情

    Fields
    ------
    ``['日期', '股票代码', '股票名称', '涨跌幅', '成交额', '封板资金', '流通市值', '最新价', '换手率','首次封板时间', '最后封板时间', '炸板次数', '连扳数', '所属行业']``
    """
    if date is None:
        date = datetime.today().strftime('%Y%m%d')
    params = (
        ('ut', '7eea3edcaed734bea9cbfc24409ed989'),
        ('dpt', 'wz.ztzt'),
        ('Pageindex', '0'),
        ('pagesize', '10000'),
        ('sort', 'fbt:asc'),
        ('date', date),
    )

    response = requests.get(
        'http://push2ex.eastmoney.com/getTopicZTPool', params=params,  verify=False)
    fields = {
        'c': '股票代码',
        'n': '股票名称',
        'zdp': '涨跌幅',
        'amount': '成交额',
        'fund': '封板资金',
        'ltsz': '流通市值',
        'p': '最新价',
        'hs': '换手率',
        'fbt': '首次封板时间',
        'lbt': '最后封板时间',
        'zbc': '炸板次数',
        'lbc': '连扳数',
        'hybk': '所属行业'
    }
    items = jsonpath(response.json(), '$..pool[:]')
    if not items:
        df = pd.DataFrame(
            columns=['日期']+list(fields.values())+['统计天数', '涨停次数'])
        return df
    df = pd.DataFrame(items)
    extra_df: pd.DataFrame = pd.DataFrame.from_records(df['zttj']).rename(columns={
        'days': '统计天数',
        'ct': '涨停次数'
    })
    df: pd.DataFrame = pd.concat([df, extra_df], axis=1)
    df: pd.DataFrame = df.rename(columns=fields)[fields.values()]
    df['首次封板时间'] = df['首次封板时间'].apply(lambda x: pd.to_datetime(
        str(x), format='%H%M%S').strftime('%H:%M:%S'))
    df['最后封板时间'] = df['最后封板时间'].apply(lambda x: pd.to_datetime(
        str(x), format='%H%M%S').strftime('%H:%M:%S'))
    df['最新价'] /= 1000
    df['涨跌幅'] = df['涨跌幅'].apply(lambda x: round(x, 2))
    df.insert(0, '日期', date)
    return df


df = get_zt_stock_rank('20220520')
df

运行结果
image

from efinance.

ifcheung2012 avatar ifcheung2012 commented on July 25, 2024

wow 感谢大佬! 非常感谢!

from efinance.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.