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 ¶
- Variables
- type BFI82U
- type BaseLists
- type BaseMTSS
- type BaseSellBuy
- type BaseT38U
- type BaseT43U
- type BaseT44U
- type CategoryList
- type Data
- func (d Data) FormatData() []FmtData
- func (d *Data) Get() ([][]string, error)
- func (d Data) GetByTimeMap() map[time.Time]interface{}
- func (d *Data) GetDailyRangeList() []float64
- func (d *Data) GetDateList() []time.Time
- func (d *Data) GetHighList() []float64
- func (d *Data) GetLowList() []float64
- func (d *Data) GetOpenList() []float64
- func (d *Data) GetPriceList() []float64
- func (d *Data) GetRangeList() []float64
- func (d *Data) GetVolumeList() []uint64
- func (d Data) IsRed() bool
- func (d Data) IsThanYesterday() bool
- func (d Data) Len() int
- func (d Data) MA(days int) []float64
- func (d Data) MABR(days1, days2 int) []float64
- func (d Data) MAV(days int) []uint64
- func (d Data) MAVBR(days1, days2 int) []int64
- func (d *Data) PlusData()
- func (d *Data) Round()
- func (d Data) URL() string
- type FmtData
- type FmtListData
- type Lists
- type OTCLists
- type QFIISTOP20
- type StockInfo
- type T86
- type T86Data
- type TWMTSS
- type TWT38U
- type TWT43U
- type TWT44U
- type TWTXXU
- type TradingVolume
- type WeightData
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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.
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 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 (*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 (*Data) Get ¶
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 ¶
GetByTimeMap return a map by key of time.Time
func (*Data) GetDailyRangeList ¶
GetDailyRangeList 計算收盤與開盤價差
func (*Data) GetRangeList ¶
GetRangeList 取得 漲跌價差 序列(為當日收盤價與前一日收盤價比較)
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
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 //本益比
}
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 (*Lists) Get ¶
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 ¶
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 (OTCLists) GetCategoryList ¶
GetCategoryList 取得分類的股票代碼與名稱列表
type QFIISTOP20 ¶
QFIISTOP20 取得「外資及陸資持股比率前二十名彙總表」
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
func (*TWMTSS) IsOverBought ¶ added in v1.5.0
IsOverBought 獲取該日某股的融資融券是否為增
type TWT38U ¶ added in v1.5.0
func (*TWT38U) IsOverBoughtDates ¶ added in v1.5.0
type TWT43U ¶ added in v1.5.0
func (*TWT43U) IsOverBoughtDates ¶ added in v1.5.0
type TWT44U ¶ added in v1.5.0
func (*TWT44U) IsOverBoughtDates ¶ added in v1.5.0
type TradingVolume ¶ added in v1.5.0
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}