twse

package
Version: v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2017 License: MIT Imports: 9 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 BaseSellBuy

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

BaseSellBuy 買進賣出合計

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
	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:長榮航}

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 TWTXXU

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

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

func NewTWT38U

func NewTWT38U(date time.Time) *TWTXXU

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

func NewTWT43U

func NewTWT43U(date time.Time) *TWTXXU

NewTWT43U 自營商買賣超彙總表

func NewTWT44U

func NewTWT44U(date time.Time) *TWTXXU

NewTWT44U 投信買賣超彙總表

func (TWTXXU) Get

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

Get 擷取資料

func (TWTXXU) URL

func (t TWTXXU) URL() string

URL 擷取網址

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