雪球美股

Posted kend

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了雪球美股相关的知识,希望对你有一定的参考价值。

import requests
import csv
from pyecharts import Bar

url = https://xueqiu.com/hq?page=1#exchange=US&firstName=3&secondName=3_0
headers = 
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/73.0.3683.86 Safari/537.36"

session = requests.Session()
session.get(url=url,headers=headers)


ALL_DATA = []
def get_page_list():
    url = https://xueqiu.com/service/v5/stock/screener/quote/list
    for i in range(1,254):
        params = 
            page: i,
            size: 30,
            order: desc,
            orderby: percent,
            order_by: percent,
            market: US,
            type: us,
            _: 1561292727168
        

        response = session.get(url=url, headers=headers, params=params)
        page_text = response.json()  # dict
        # print(page_text)
        content_list = page_text[data][list]
        # print(content_list)

        for stock in content_list:
            info_dict = 
            stock_code = stock[symbol]
            stock_name = stock[name]
            cur_price = stock[current]
            zhangdie = stock[percent]
            ttm = stock[pe_ttm]
            value = stock[market_capital]
            if value:
                value = value/10000


            info_dict[股票代码] = stock_code
            info_dict[股票名称] = stock_name
            info_dict[当前价] = cur_price
            # info_dict[‘涨跌幅‘] = float(str(zhangdie)+‘%‘)
            info_dict[涨跌幅(%)] = zhangdie
            info_dict[市值] = str(value)+
            info_dict[市盈率] = ttm

            # print(info_dict)
            ALL_DATA.append(info_dict)
    # print(ALL_DATA)


def main():
    get_page_list()
    try:
        ALL_DATA.sort(key=lambda data: data["涨跌幅(%)"],reverse=True)
        print(ALL_DATA)
        data = ALL_DATA[0:100]

        # 图形化展示
        stock_name = list(map(lambda x:x[股票名称], data))
        zhangdie = list(map(lambda x:x[涨跌幅(%)], data))
        chart = Bar()
        chart.add("涨幅最大的100个股票",
                  stock_name,
                  zhangdie,
                  is_more_utils=True)
        chart.render(stock.html)


        # 保存到csv
        with open(./雪球美股.csv, w, encoding=utf-8, errors=ignore, newline="") as csvfile:
            fieldnames = [股票代码, 股票名称, 当前价, 涨跌幅(%), 市值, 市盈率]
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writeheader()
            writer.writerows(data)
    except:
        pass

if __name__ == __main__:
    main()

 

以上是关于雪球美股的主要内容,如果未能解决你的问题,请参考以下文章

案例|雪球的Docker实践

使用容器的正确方式,Docker在雪球的技术实践

求最新的美股通道 标签及手续费返费

美股 基础知识2-常见问答

雪球访谈笔记---20170928

同花顺和雪球同步--测试