Skip to main content

Taiwan Stock Opendata with realtime - twstock

Project description

[![Build
Status](https://travis-ci.org/mlouielu/twstock.svg?branch=master)](https://travis-ci.org/mlouielu/twstock)
[![Coverage Status](https://coveralls.io/repos/github/mlouielu/twstock/badge.svg?branch=master)](https://coveralls.io/github/mlouielu/twstock?branch=master)
[![Documentation Status](https://readthedocs.org/projects/twstock/badge/?version=latest)](http://twstock.readthedocs.io/zh_TW/latest/?badge=latest)


**Currently under heavily design, please *don't* consider API will be stable at this moment.**

有任何問題歡迎透過 [Gitter.im](https://gitter.im/twstock/Lobby) 詢問。

twstock 台灣股市股票價格擷取
----------------------------

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

資料來源:

* [證券交易所 (TWSE)](http://www.twse.com.tw)
* [證券櫃台買賣中心 (TPEX)](http://www.tpex.org.tw)

## Documentation

* [twstock documentation (正體中文)](http://twstock.readthedocs.io/zh_TW/latest)

## Requirements

* requests
* Python 3

## Install

from pip (recommand):

```
$ pip install --user twstock

or

$ sudo pip install twstock
```

from GitHub:

```
$ git clone https://github.com/mlouielu/twstock
$ cd twstock
$ python setup.py 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
```

## Quick Start

分析計算

```
from twstock import Stock

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

擷取自 2015 年 1 月至今之資料

```
stock = Stock('2330')
stock.fetch_from(2015, 1)
```

基本資料之使用

```
>>> 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'
```

## 四大買賣點分析

```
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']) # 擷取當前三檔資訊
```


## 使用範例

* [tw-stocker](https://github.com/mlouielu/stocker)

## 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 功能來協作。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twstock-0.1.3-dev.tar.gz (221.4 kB view details)

Uploaded Source

Built Distribution

twstock-0.1.3_dev-py3-none-any.whl (1.6 MB view details)

Uploaded Python 3

File details

Details for the file twstock-0.1.3-dev.tar.gz.

File metadata

  • Download URL: twstock-0.1.3-dev.tar.gz
  • Upload date:
  • Size: 221.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for twstock-0.1.3-dev.tar.gz
Algorithm Hash digest
SHA256 7769b9086fdfaca847af305e22557a8f17d7b9d944819e7a4c9e599e4295a44d
MD5 2ed1e72f962004a293c14fbcd5ab134f
BLAKE2b-256 48b81f82af30285ad009dfc8a3436c5908e2f7fa27f44cbfe4d54a90587447e7

See more details on using hashes here.

File details

Details for the file twstock-0.1.3_dev-py3-none-any.whl.

File metadata

File hashes

Hashes for twstock-0.1.3_dev-py3-none-any.whl
Algorithm Hash digest
SHA256 45dfcc1b2946e48bac1658ad8febd004db43d7ef66766064c98bf82d2e3f902c
MD5 24056fc4399ec97b46096b4411652709
BLAKE2b-256 0114fbf9c8407578ef8719ba948a2622087a359a45c295f7ee6888dc3059b73f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page