twse

package
v1.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 12 Imported by: 0

README

gogrs - twse

GoDoc Build Status

Documentation

Overview

Package twse - Fetch stock data from TWSE, OTC 擷取台灣股市上市/上櫃股票資訊、上市/上櫃類股清單、外資及陸資持股比率前二十名彙總表、 三大法人買賣金額統計表、三大法人買賣超日報、自營商、投信、外資及陸資買賣超彙總表

Example (NewOTC)

新增一個 OTC 上櫃股票

var stock = NewOTC("8446", time.Date(2015, 3, 27, 0, 0, 0, 0, utils.TaipeiTimeZone))
stock.Get()
fmt.Println(stock.RawData[0])
Output:

[104/03/02 354 33,018 92.00 94.90 90.80 92.60 3.50 299]
Example (NewTWSE)

新增一個 TWSE 上市股票

var stock = NewTWSE("2618", time.Date(2015, 3, 27, 0, 0, 0, 0, utils.TaipeiTimeZone))
stock.Get()
fmt.Println(stock.RawData[0])
Output:

[104/03/02 13,384,378 305,046,992 23.00 23.05 22.50 22.90 -0.10 3,793 ]

Index

Examples

Constants

This section is empty.

Variables

View Source
var OTCCLASS = map[string]string{
	"02": "食品工業",
	"03": "塑膠工業",
	"04": "紡織纖維",
	"05": "電機機械",
	"06": "電器電纜",
	"08": "玻璃陶瓷",
	"10": "鋼鐵工業",
	"11": "橡膠工業",
	"14": "建材營造",
	"15": "航運業",
	"16": "觀光事業",
	"17": "金融保險",
	"18": "貿易百貨",
	"20": "其他",
	"21": "化學工業",
	"22": "生技醫療業",
	"23": "油電燃氣業",
	"24": "半導體業",
	"25": "電腦及週邊設備業",
	"26": "光電業",
	"27": "通信網路業",
	"28": "電子零組件業",
	"29": "電子通路業",
	"30": "資訊服務業",
	"31": "其他電子業",
	"32": "文化創意業",
	"80": "管理股票",
	"AA": "受益證券",
	"AL": "所有證券",
	"BC": "牛證熊證",
	"EE": "上櫃指數股票型基金(ETF)",
	"EW": "所有證券(不含權證、牛熊證)",
	"GG": "認股權憑證",
	"TD": "台灣存託憑證(TDR)",
	"WW": "認購售權證",
}

OTCCLASS is a class list of TWSE.

View Source
var TWSECLASS = map[string]string{
	"MS":         "大盤統計資訊",
	"0049":       "封閉式基金",
	"0099P":      "ETF",
	"01":         "水泥工業",
	"019919T":    "受益證券",
	"02":         "食品工業",
	"03":         "塑膠工業",
	"04":         "紡織纖維",
	"05":         "電機機械",
	"06":         "電器電纜",
	"07":         "化學生技醫療",
	"08":         "玻璃陶瓷",
	"09":         "造紙工業",
	"0999":       "認購權證",
	"0999B":      "熊證",
	"0999C":      "牛證",
	"0999G9":     "認股權憑證",
	"0999GA":     "附認股權特別股",
	"0999GD":     "附認股權公司債",
	"0999P":      "認售權證",
	"0999X":      "可展延牛證",
	"0999Y":      "可展延熊證",
	"10":         "鋼鐵工業",
	"11":         "橡膠工業",
	"12":         "汽車工業",
	"13":         "電子工業",
	"14":         "建材營造",
	"15":         "航運業",
	"16":         "觀光事業",
	"17":         "金融保險",
	"18":         "貿易百貨",
	"19":         "綜合",
	"20":         "其他",
	"21":         "化學工業",
	"22":         "生技醫療業",
	"23":         "油電燃氣業",
	"24":         "半導體業",
	"25":         "電腦及週邊設備業",
	"26":         "光電業",
	"27":         "通信網路業",
	"28":         "電子零組件業",
	"29":         "電子通路業",
	"30":         "資訊服務業",
	"31":         "其他電子業",
	"9299":       "存託憑證",
	"ALL":        "全部",
	"ALLBUT0999": "全部(不含權證、牛熊證、可展延牛熊證)",
	"CB":         "可轉換公司債",
}

TWSECLASS is a class list of TWSE.

Functions

This section is empty.

Types

type BFI82U

type BFI82U struct {
	Begin time.Time
	End   time.Time
}

BFI82U 取得「三大法人買賣金額統計表」

func NewBFI82U

func NewBFI82U(begin, end time.Time) *BFI82U

NewBFI82U 三大法人買賣金額統計表

func (BFI82U) Get

func (b BFI82U) Get() ([]BaseSellBuy, error)

Get 擷取資料

func (BFI82U) URL

func (b BFI82U) URL() string

URL 擷取網址

type BaseLists

type BaseLists interface {
	Get(category string) ([][]string, error)
	GetCategoryList(category string) []StockInfo
}

BaseLists is base list interface.

type BaseMTSS added in v1.5.0

type BaseMTSS struct {
	No   string
	Name string
	MT   TradingVolume
	SS   TradingVolume
}

type BaseSellBuy

type BaseSellBuy struct {
	No    string
	Name  string
	Buy   int64 // 買進
	Sell  int64 // 賣出
	Total int64 // 合計
}

BaseSellBuy 買進賣出合計

type BaseT38U added in v1.5.0

type BaseT38U struct {
	No     string
	Name   string
	Volume TradingVolume
}

type BaseT43U added in v1.5.0

type BaseT43U struct {
	No     string
	Name   string
	Volume TradingVolume
}

type BaseT44U added in v1.5.0

type BaseT44U struct {
	No     string
	Name   string
	Volume TradingVolume
}

type CategoryList

type CategoryList struct {
	// contains filtered or unexported fields
}

CategoryList to show TWSECLASS, OTCCLASS.

func NewCategoryList

func NewCategoryList() *CategoryList

NewCategoryList to new one.

func (*CategoryList) OnlyOTC

func (c *CategoryList) OnlyOTC() map[string]string

OnlyOTC return OTCCLASS but TWSECLASS

func (*CategoryList) OnlyTWSE

func (c *CategoryList) OnlyTWSE() map[string]string

OnlyTWSE return TWSECLASS but OTCCLASS

func (*CategoryList) Same

func (c *CategoryList) Same() map[string]string

Same return TWSECLASS and OTCCLASS.

type Data

type Data struct {
	No          string
	Name        string
	Date        time.Time
	BackupDate  time.Time
	RawData     [][]string
	UnixMapData unixMapData
	// contains filtered or unexported fields
}

Data start with stock no, date.

Example
var d = NewTWSE("2618", time.Date(2014, 12, 26, 0, 0, 0, 0, utils.TaipeiTimeZone))
fmt.Println(d.Date)

stockData, _ := d.Get()
fmt.Println(stockData[0])
Output:

2014-12-26 00:00:00 +0800 Asia/Taipei
[103/12/01 64,418,143 1,350,179,448 20.20 21.40 20.20 21.35 +1.35 13,249 ]

func NewOTC

func NewOTC(No string, Date time.Time) *Data

NewOTC 建立一個 OTC 上櫃股票

func NewTWSE

func NewTWSE(No string, Date time.Time) *Data

NewTWSE 建立一個 TWSE 上市股票

func (Data) FormatData

func (d Data) FormatData() []FmtData

FormatData is format daily data.

func (*Data) Get

func (d *Data) Get() ([][]string, error)

Get return csv data in array.

Example (NotEnoughData)
year, month, _ := time.Now().Date()
var d = NewTWSE("2618", time.Date(year, month+1, 1, 0, 0, 0, 0, utils.TaipeiTimeZone))

stockData, err := d.Get()
if err != nil {
	fmt.Println(err)
} else {
	fmt.Println(stockData)
}
Output:

Not enough data

func (Data) GetByTimeMap

func (d Data) GetByTimeMap() map[time.Time]interface{}

GetByTimeMap return a map by key of time.Time

func (*Data) GetDailyRangeList

func (d *Data) GetDailyRangeList() []float64

GetDailyRangeList 計算收盤與開盤價差

func (*Data) GetDateList

func (d *Data) GetDateList() []time.Time

GetDateList 取出資料時間序列

func (*Data) GetHighList

func (d *Data) GetHighList() []float64

GetHighList 取得 最高價 序列

func (*Data) GetLowList

func (d *Data) GetLowList() []float64

GetLowList 取得 最低價 序列

func (*Data) GetOpenList

func (d *Data) GetOpenList() []float64

GetOpenList 取得 開盤價 序列

func (*Data) GetPriceList

func (d *Data) GetPriceList() []float64

GetPriceList 取得 收盤價 序列

func (*Data) GetRangeList

func (d *Data) GetRangeList() []float64

GetRangeList 取得 漲跌價差 序列(為當日收盤價與前一日收盤價比較)

func (*Data) GetVolumeList

func (d *Data) GetVolumeList() []uint64

GetVolumeList 取得 成交股數 序列

func (Data) IsRed

func (d Data) IsRed() bool

IsRed 計算是否收紅 K

func (Data) IsThanYesterday

func (d Data) IsThanYesterday() bool

IsThanYesterday 計算漲跌與昨日收盤相比

func (Data) Len

func (d Data) Len() int

Len 返回資料序列長度

func (Data) MA

func (d Data) MA(days int) []float64

MA 計算 收盤價 的移動平均

func (Data) MABR

func (d Data) MABR(days1, days2 int) []float64

MABR 計算 收盤價移動平均 的乖離

func (Data) MAV

func (d Data) MAV(days int) []uint64

MAV 計算 成交股數 的移動平均

func (Data) MAVBR

func (d Data) MAVBR(days1, days2 int) []int64

MAVBR 計算 成交股數移動平均 的乖離

func (*Data) PlusData

func (d *Data) PlusData()

PlusData will do Round() and Get().

Example
var stock = NewTWSE("2618", time.Date(2015, 3, 27, 0, 0, 0, 0, utils.TaipeiTimeZone))
stock.Get() // 2015/3
fmt.Println(stock.Date)
stock.PlusData() // 2015/2
fmt.Println(stock.Date)
Output:

2015-03-27 00:00:00 +0800 Asia/Taipei
2015-02-01 00:00:00 +0800 Asia/Taipei

func (*Data) Round

func (d *Data) Round()

Round will do sub one month.

Example
var d = NewTWSE("2618", time.Date(2014, 12, 26, 0, 0, 0, 0, utils.TaipeiTimeZone))

fmt.Println(d.Date) // 2014/12

d.Round()
fmt.Println(d.Date) // 2014/11

d.Round()
fmt.Println(d.Date) // 2014/10
Output:

2014-12-26 00:00:00 +0800 Asia/Taipei
2014-11-01 00:00:00 +0800 Asia/Taipei
2014-10-01 00:00:00 +0800 Asia/Taipei

func (Data) URL

func (d Data) URL() string

URL return stock csv url path.

type FmtData

type FmtData struct {
	Date       time.Time
	Volume     uint64  //成交股數
	TotalPrice uint64  //成交金額
	Open       float64 //開盤價
	High       float64 //最高價
	Low        float64 //最低價
	Price      float64 //收盤價
	Range      float64 //漲跌價差
	Totalsale  uint64  //成交筆數
}

FmtData is struct for daily data format.

type FmtListData

type FmtListData struct {
	No             string
	Name           string
	Volume         uint64  //成交股數
	TotalPrice     uint64  //成交金額
	Open           float64 //開盤價
	High           float64 //最高價
	Low            float64 //最低價
	Price          float64 //收盤價
	Range          float64 //漲跌價差
	Totalsale      uint64  //成交筆數
	LastBuyPrice   float64 //最後揭示買價
	LastBuyVolume  uint64  //最後揭示買量
	LastSellPrice  float64 //最後揭示賣價
	LastSellVolume uint64  //最後揭示賣量
	PERatio        float64 //本益比
	IssuedShares   uint64  //發行股數
}

FmtListData 格式化個股的資料資訊

type Lists

type Lists struct {
	Date    time.Time
	FmtData map[string]FmtListData
	// contains filtered or unexported fields
}

Lists is to get TWSE list.

func NewLists

func NewLists(t time.Time) *Lists

NewLists new a Lists.

func (*Lists) Get

func (l *Lists) Get(category string) ([][]string, error)

Get is to get TWSE csv data.

Example
l := NewLists(time.Date(2014, 12, 26, 0, 0, 0, 0, utils.TaipeiTimeZone))
listdata, _ := l.Get("15") //航運業
fmt.Println(listdata[0])
Output:

[2208 台船 729,340 324 12,048,156 16.45 16.60 16.45 16.45   0.00 16.45 67 16.50 58 41.13 ]
Example (FmtData)
l := NewLists(time.Date(2015, 4, 9, 0, 0, 0, 0, utils.TaipeiTimeZone))
l.Get("15") //航運業
fmt.Printf("%+v", l.FmtData["2618"])
Output:

{No:2618 Name:長榮航 Volume:46670950 TotalPrice:1136982254 Open:24 High:24.65 Low:24 Price:24 Range:0.55 Totalsale:11117 LastBuyPrice:24 LastBuyVolume:2027 LastSellPrice:24.1 LastSellVolume:10 PERatio:0 IssuedShares:0}
Example (NotEnoughData)
year, month, day := time.Now().Date()
l := NewLists(time.Date(year, month+1, day, 0, 0, 0, 0, utils.TaipeiTimeZone))
_, err := l.Get("15") //航運業
fmt.Println(err)
Output:

Not enough data

func (Lists) GetCategoryList

func (l Lists) GetCategoryList(category string) []StockInfo

GetCategoryList 取得分類的股票代碼與名稱列表

Example
l := NewLists(time.Date(2015, 4, 27, 0, 0, 0, 0, utils.TaipeiTimeZone))
categoryList := l.GetCategoryList("15")
for _, v := range categoryList {
	if v.No == "2618" {
		fmt.Printf("%+v", v)
		break
	}
}
Output:

{No:2618 Name:長榮航}

func (Lists) Url added in v1.5.0

func (l Lists) Url() string

type OTCLists

type OTCLists struct {
	Date    time.Time
	FmtData map[string]FmtListData
	// contains filtered or unexported fields
}

OTCLists is to get OTC list.

func NewOTCLists

func NewOTCLists(date time.Time) *OTCLists

NewOTCLists new a Lists.

func (*OTCLists) Get

func (o *OTCLists) Get(category string) ([][]string, error)

Get is to get OTC csv data.

func (OTCLists) GetCategoryList

func (o OTCLists) GetCategoryList(category string) []StockInfo

GetCategoryList 取得分類的股票代碼與名稱列表

type QFIISTOP20

type QFIISTOP20 struct {
	Date time.Time
}

QFIISTOP20 取得「外資及陸資持股比率前二十名彙總表」

func (QFIISTOP20) Get

func (q QFIISTOP20) Get() ([][]string, error)

Get 擷取資料

func (QFIISTOP20) URL

func (q QFIISTOP20) URL() string

URL 擷取網址

type StockInfo

type StockInfo struct {
	No   string
	Name string
}

StockInfo is simple stock info for no, name.

type T86

type T86 struct {
	Date time.Time
}

T86 取得「三大法人買賣超日報(股)」

func (T86) Get

func (t T86) Get(cate string) ([]T86Data, error)

Get 擷取資料

func (T86) URL

func (t T86) URL() string

URL 擷取網址

type T86Data

type T86Data struct {
	No     string
	Name   string
	FII    BaseSellBuy // 外資
	SIT    BaseSellBuy // 投信
	DProp  BaseSellBuy // 自營商(自行買賣)
	DHedge BaseSellBuy // 自營商(避險)
	Diff   int64       // 三大法人買賣超股數
}

T86Data 各欄位資料

type TWMTSS added in v1.5.0

type TWMTSS struct {
	Date            time.Time
	Category        string
	UnixMapMTSSData unixMapMTSSData
}

func NewTWMTSS added in v1.5.0

func NewTWMTSS(date time.Time, category string) *TWMTSS

NewTWMTSS 融資融券匯總 Margin Trading and Short Selling

func (*TWMTSS) Get added in v1.5.0

func (t *TWMTSS) Get() (map[string]BaseMTSS, error)

func (*TWMTSS) GetData added in v1.5.0

func (t *TWMTSS) GetData() (map[string]BaseMTSS, error)

func (*TWMTSS) IsOverBought added in v1.5.0

func (t *TWMTSS) IsOverBought(date time.Time, stockNo string) (bool, []int64, error)

IsOverBought 獲取該日某股的融資融券是否為增

func (*TWMTSS) Round added in v1.5.0

func (t *TWMTSS) Round()

func (*TWMTSS) SetDate added in v1.5.0

func (t *TWMTSS) SetDate(date time.Time) *TWMTSS

func (TWMTSS) URL added in v1.5.0

func (t TWMTSS) URL() string

type TWT38U added in v1.5.0

type TWT38U struct {
	Date            time.Time
	UnixMapT38UData unixMapT38UData
}

func NewTWT38U

func NewTWT38U(date time.Time) *TWT38U

NewTWT38U 外資及陸資買賣超彙總表

func (*TWT38U) Get added in v1.5.0

func (t *TWT38U) Get() (map[string]BaseT38U, error)

func (*TWT38U) GetData added in v1.5.0

func (t *TWT38U) GetData() (map[string]BaseT38U, error)

func (*TWT38U) IsOverBoughtDates added in v1.5.0

func (t *TWT38U) IsOverBoughtDates(stockNo string, days int) (bool, []int64)

func (*TWT38U) Round added in v1.5.0

func (t *TWT38U) Round()

func (*TWT38U) SetDate added in v1.5.0

func (t *TWT38U) SetDate(date time.Time) *TWT38U

func (TWT38U) URL added in v1.5.0

func (t TWT38U) URL() string

URL 擷取網址

type TWT43U added in v1.5.0

type TWT43U struct {
	Date            time.Time
	UnixMapT43UData unixMapT43UData
}

func NewTWT43U

func NewTWT43U(date time.Time) *TWT43U

NewTWT43U 自營商買賣超彙總表

func (*TWT43U) Get added in v1.5.0

func (t *TWT43U) Get() (map[string]BaseT43U, error)

func (*TWT43U) GetData added in v1.5.0

func (t *TWT43U) GetData() (map[string]BaseT43U, error)

func (*TWT43U) IsOverBoughtDates added in v1.5.0

func (t *TWT43U) IsOverBoughtDates(stockNo string, days int) (bool, []int64)

func (*TWT43U) Round added in v1.5.0

func (t *TWT43U) Round()

func (*TWT43U) SetDate added in v1.5.0

func (t *TWT43U) SetDate(date time.Time) *TWT43U

func (TWT43U) URL added in v1.5.0

func (t TWT43U) URL() string

type TWT44U added in v1.5.0

type TWT44U struct {
	Date            time.Time
	UnixMapT44UData unixMapT44UData
}

func NewTWT44U

func NewTWT44U(date time.Time) *TWT44U

NewTWT44U 投信買賣超彙總表

func (*TWT44U) Get added in v1.5.0

func (t *TWT44U) Get() (map[string]BaseT44U, error)

func (*TWT44U) GetData added in v1.5.0

func (t *TWT44U) GetData() (map[string]BaseT44U, error)

func (*TWT44U) IsOverBoughtDates added in v1.5.0

func (t *TWT44U) IsOverBoughtDates(stockNo string, days int) (bool, []int64)

func (*TWT44U) Round added in v1.5.0

func (t *TWT44U) Round()

func (*TWT44U) SetDate added in v1.5.0

func (t *TWT44U) SetDate(date time.Time) *TWT44U

func (TWT44U) URL added in v1.5.0

func (t TWT44U) URL() string

type TWTXXU

type TWTXXU struct {
	Date time.Time
	// contains filtered or unexported fields
}

TWTXXU 產生 自營商、投信、外資及陸資買賣超彙總表

func (TWTXXU) Get

func (t TWTXXU) Get() ([][]BaseSellBuy, error)

Get 擷取資料

func (*TWTXXU) Round added in v1.5.0

func (t *TWTXXU) Round()

func (TWTXXU) URL

func (t TWTXXU) URL() string

type TradingVolume added in v1.5.0

type TradingVolume struct {
	Buy   int64 // 買進
	Sell  int64 // 賣出
	Total int64 // 合計
}

type WeightData added in v1.1.0

type WeightData struct {
	Date       time.Time
	Volume     uint64  // 成交股數
	TotalPrice uint64  //成交金額
	Totalsale  uint64  //成交筆數
	Point      float64 //收盤價
	Range      float64 //漲跌價差
}

WeightData struct

func Weight added in v1.1.0

func Weight(date time.Time) []*WeightData

Weight is TWSE Weight

Example
result := Weight(time.Date(2017, 3, 5, 0, 0, 0, 0, utils.TaipeiTimeZone))
for _, v := range result {
	if v.Date == time.Date(2017, 3, 1, 0, 0, 0, 0, utils.TaipeiTimeZone) {
		fmt.Printf("%+v", v)
		break
	}
}
Output:

&{Date:2017-03-01 00:00:00 +0800 Asia/Taipei Volume:4352913007 TotalPrice:99915928382 Totalsale:981872 Point:9674.78 Range:-75.69}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL