Retour au classement

mlouielu/twstock

Pythontwstock.readthedocs.io

台灣股市股票價格擷取 (含即時股票資訊) - Taiwan Stock Opendata with realtime

stocktaiwanstockopendatafinancegrs
Croissance des étoiles
Étoiles
1.5k
Forks
406
Croissance hebdomadaire
Issues
36
5001k
juil. 2017juil. 2020juil. 2023juil. 2026
ArtefactsPyPIpip install twstock
README

GitHub Actions Status Coverage Status PyPI version Documentation Status

有任何問題歡迎透過 Gitter.im 詢問。

twstock 台灣股市股票價格擷取

擷取台灣證券交易所之股價資料 重新製作 toomore/grs 之功能

資料來源:

(請注意,TWSE 有 request limit, 每 5 秒鐘 3 個 request,超過的話會被 ban 掉,請自行注意)

Documentation

Requirements

  • Python 3
  • lxml
  • requests

Install

By PyPi

$ python -m pip install --user twstock

By Source

$ git clone https://github.com/mlouielu/twstock
$ cd twstock
$ python -m pip install -e .

By Source & install

$ git clone https://github.com/mlouielu/twstock
$ cd twstock
$ python -m pip install --user flit
$ flit install

CLI Tools

$ twstock -b 2330 6223
四大買賣點判斷 Best Four Point
------------------------------
2330: Buy   量大收紅
6223: Sell  量縮價跌, 三日均價小於六日均價
$ twstock -s 2330 6223
-------------- 2330 ----------------
high : 215.0 214.0 210.0 210.5 208.5
low  : 212.0 211.0 208.0 208.5 206.5
price: 215.0 211.5 208.5 210.0 208.5
-------------- 2337 ----------------
high :  16.2  16.8  16.4 16.75 16.75
low  :  15.8  16.1 15.15  16.3 16.25
price: 15.95 16.25 16.25  16.6  16.7

Update Codes

當你第一次使用 twstock 時,你可以更新 TPEX 跟 TWSE 的列表,可以使用兩種方式更新:

  • By CLI
$ twstock -U
Start to update codes
Done!
  • By Python
>>> import twstock
>>> twstock.__update_codes()

Quick Start

分析計算

from twstock import Stock

stock = Stock('2330')                             # 擷取台積電股價
ma_p = stock.moving_average(stock.price, 5)       # 計算五日均價
ma_c = stock.moving_average(stock.capacity, 5)    # 計算五日均量
ma_p_cont = stock.continuous(ma_p)                # 計算五日均價持續天數
ma_br = stock.ma_bias_ratio(5, 10)                # 計算五日、十日乖離值

擷取自 2024 年 3 月至今之資料

stock = Stock('2330')
stock.fetch_from(2024, 3)

基本資料之使用

>>> stock = Stock('2330')
>>> stock.price
[203.5, 203.0, 205.0, 205.0, 205.5, 207.0, 207.0, 203.0, 207.0, 209.0, 209.0, 212.0, 210.5, 211.5, 213.0, 212.0, 207.5, 208.0, 207.0, 208.0, 211.5, 213.0, 216.5, 215.5, 218.0, 217.0, 215.0, 211.5, 208.5, 210.0, 208.5]
>>> stock.capacity
[22490217, 17163108, 17419705, 23028298, 18307715, 26088748, 32976727, 67935145, 29623649, 23265323, 1535230, 22545164, 15382025, 34729326, 21654488, 35190159, 63111746, 49983303, 39083899, 19486457, 32856536, 17489571, 28784100, 45384482, 26094649, 39686091, 60140797, 44504785, 52273921, 27049234, 31709978]
>>> stock.data[0]
Data(date=datetime.datetime(2017, 5, 18, 0, 0), capacity=22490217, turnover=4559780051, open=202.5, high=204.0, low=201.5, close=203.5, change=-0.5, transaction=6983)

台股證券編碼

>>> import twstock
>>> print(twstock.codes)                # 列印台股全部證券編碼資料
>>> print(twstock.codes['2330'])        # 列印 2330 證券編碼資料
StockCodeInfo(type='股票', code='2330', name='台積電', ISIN='TW0002330008', start='1994/09/05', market='上市', group='半導體業', CFI='ESVUFR')
>>> print(twstock.codes['2330'].name)   # 列印 2330 證券名稱
'台積電'
>>> print(twstock.codes['2330'].start)  # 列印 2330 證券上市日期
'1994/09/05'

使用 Proxy (基於 requests proxies)

# 單一 Proxy
>>> from twstock.proxy import SingleProxyProvider
>>> spr = SingleProxyProvider({'http': 'http://localhost:8080'})
>>> twstock.proxy.configure_proxy_provider(spr)

# 多個 Proxy
>>> from twstock.proxy import RoundRobinProxiesProvider
>>> proxies = [{'http': 'http://localhost:5000'}, {'http': 'http://localhost:5001'}]
>>> rrpr = RoundRobinProxiesProvider(proxies)
>>> twstock.proxy.configure_proxy_provider(rrpr)

# 變更 Proxy 表
>>> another_proxies = [{'http': 'http://localhost:8000'}, {'https': 'https://localhost:8001'}]
>>> rrpr.proxies = another_proxies

四大買賣點分析

from twstock import Stock
from twstock import BestFourPoint

stock = Stock('2330')
bfp = BestFourPoint(stock)

bfp.best_four_point_to_buy()    # 判斷是否為四大買點
bfp.best_four_point_to_sell()   # 判斷是否為四大賣點
bfp.best_four_point()           # 綜合判斷

即時股票資訊查詢

import twstock

twstock.realtime.get('2330')    # 擷取當前台積電股票資訊
twstock.realtime.get(['2330', '2337', '2409'])  # 擷取當前三檔資訊

使用範例

Contributing

twstock was created by Louie Lu <git@louie.lu>.

Contributing were welcome, please use GitHub issue and Pull Request to contribute!

歡迎協作,請使用 GitHub issue 以及 Pull Request 功能來協作。

Dépôts similaires
akfamily/akshare

AKShare is an elegant and simple financial data interface library for Python, built for human beings! 开源财经数据接口库

PythonPyPIMIT Licensefuturesfinancial-data
akshare.akfamily.xyz
21.5k3.4k
bbfamily/abu

阿布量化交易系统(股票,期权,期货,比特币,机器学习) 基于python的开源量化交易,量化投资架构

PythonPyPIGNU General Public License v3.0quanttrade
abuquant.com
17.9k4.6k
shengqiangzhang/examples-of-web-crawlers

一些非常有趣的python爬虫例子,对新手比较友好,主要爬取淘宝、天猫、微信、微信读书、豆瓣、QQ等网站。(Some interesting examples of python crawlers that are friendly to beginners. )

HTMLMIT Licensecrawlerspider
14.7k3.8k
myhhub/stock

stock股票.获取股票数据,计算股票指标,筹码分布,识别股票形态,综合选股,选股策略,股票验证回测,股票自动交易,支持PC及移动设备。

PythonPyPIApache License 2.0stockstocks
13.5k2.8k
ghostfolio/ghostfolio

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

TypeScriptnpmGNU Affero General Public License v3.0wealth-managementweb
ghostfol.io
9k1.2k
timercrack/trader

期货自动交易

CApache License 2.0tradectp
8.3k1.9k
Rockyzsu/stock

30天掌握量化交易 (持续更新)

PythonPyPIBSD 3-Clause "New" or "Revised" Licensepythonstock
30daydo.com
7.9k1.5k
Dolibarr/dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.

PHPPackagistGNU General Public License v3.0erpcrm
dolibarr.org
7.4k3.5k
ArvinLovegood/go-stock

🦄🦄🦄AI赋能股票分析:AI加持的股票分析/选股工具。股票行情获取,AI热点资讯分析,AI资金/财务分析,涨跌报警推送。支持A股,港股,美股。支持市场整体/个股情绪分析,AI辅助选股等。数据全部保留在本地。支持DeepSeek,OpenAI, Ollama,LMStudio,AnythingLLM,硅基流动,火山方舟,阿里云百炼等平台或模型。

GoGo ModulesGNU General Public License v3.0stockgolang
go-stock.sparkmemory.top
7k1.2k
ricequant/rqalpha

A extendable, replaceable Python algorithmic backtest && trading framework supporting multiple securities

PythonPyPIOtherquantpython
rqalpha.io
6.6k1.8k
BigBrotherTrade/trader

交易模块

PythonPyPIApache License 2.0tradectp
5.9k1.3k
1nchaos/adata

免费开源A股量化交易数据库; 专注A股,专注量化,向阳而生; 开放、纯净、持续、为Ai(爱)发电。为个人量化交易而生,保卫3000点,珍惜底部机会......【股票数据,股票行情数据,股票量化数据,股票交易数据,k线行情数据,股票概念数据,股票数据接口,行情数据接口,量化交易数据】【多数据源融合,动态设置代理,保障数据高可用性】

PythonPyPIApache License 2.0stocka
adata.30006124.xyz
5k672