twstock

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = "1.1.6"
)

Variables

View Source
var (

	// 當查詢不到個股日成交資訊丟出此錯誤
	ErrNoData = errors.New("no data found")

	// 當查詢日期超出限制的時候丟出此錯誤
	ErrDateOutOffRange = errors.New("date out of range")
)
View Source
var Securities = map[string]Security{}/* 49637 elements not displayed */

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors

Types

type BidAsk

type BidAsk struct {
	Price  decimal.Decimal // 價格
	Volume int             // 數量
}

type Client

type Client struct {

	// Services used for talking to different parts of the API.
	MarketData *MarketDataService
	Security   *SecurityService
	Quote      *QuoteService
	// contains filtered or unexported fields
}

A Client manages communication with the API.

func NewClient

func NewClient() *Client

NewClient returns a new twstock API client.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response.

func (*Client) DoTransformToDocument

func (c *Client) DoTransformToDocument(req *http.Request, t transform.Transformer) (*goquery.Document, error)

DoTransformToDocument sends an API request and returns the goquery.Document.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request.

type DelistedSecurity

type DelistedSecurity struct {
	Code   string // 有價證券代號
	Name   string // 有價證券名稱
	Market Market // 市場別
}

下市的有價證卷

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Market

type Market string
const (
	TWSE Market = "tse" // 臺灣證券交易所
	TPEx Market = "otc" // 證券櫃檯買賣中心
)

type MarketData added in v1.1.0

type MarketData struct {
	Date        civil.Date      // 日期
	TradeVolume int             // 總成交股數
	TradeValue  decimal.Decimal // 總成交金額
	Transaction int             // 總成交筆數
	Index       decimal.Decimal // 發行量加權股價指數或櫃買指數
	Change      decimal.Decimal // 漲跌點數
}

type MarketDataService added in v1.1.0

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

func (*MarketDataService) DownloadTpex added in v1.1.0

func (s *MarketDataService) DownloadTpex(year int, month time.Month) ([]MarketData, error)

從證券櫃檯買賣中心下載盤後每日市場成交資訊

func (*MarketDataService) DownloadTwse added in v1.1.0

func (s *MarketDataService) DownloadTwse(year int, month time.Month) ([]MarketData, error)

從台灣證卷交易所下載盤後每日市場成交資訊

func (*MarketDataService) MinimumDate added in v1.1.0

func (s *MarketDataService) MinimumDate(m Market) civil.Date

台灣證卷交易所或是證券櫃檯買賣中心有最小查詢日期的限制

type Quote

type Quote struct {
	Date   civil.Date      // 本筆資料所屬日期
	Open   decimal.Decimal // 開盤價
	High   decimal.Decimal // 最高價
	Low    decimal.Decimal // 最低價
	Close  decimal.Decimal // 收盤價
	Volume int             // 成交量
}

type QuoteService

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

func (*QuoteService) Download

func (s *QuoteService) Download(code string, year int, month time.Month) ([]Quote, error)

從台灣證卷交易所或證券櫃檯買賣中心下載盤後個股日成交資訊

func (*QuoteService) DownloadTpex

func (s *QuoteService) DownloadTpex(code string, year int, month time.Month) ([]Quote, error)

從證券櫃檯買賣中心下載盤後個股日成交資訊

func (*QuoteService) DownloadTwse

func (s *QuoteService) DownloadTwse(code string, year int, month time.Month) ([]Quote, error)

從台灣證卷交易所下載盤後個股日成交資訊

func (*QuoteService) MinimumDate added in v1.1.0

func (s *QuoteService) MinimumDate(m Market) civil.Date

台灣證卷交易所或是證券櫃檯買賣中心有最小查詢日期的限制

func (*QuoteService) Realtime

func (s *QuoteService) Realtime(codes ...string) (map[string]RealtimeQuote, error)

從台灣證卷交易所下載即時個股成交資訊

type RealtimeQuote

type RealtimeQuote struct {
	At       time.Time       // 最新一筆成交時間
	Code     string          // 股票代號
	Name     string          // 簡稱
	FullName string          // 全名
	Price    decimal.Decimal // 最新一筆成交價
	Open     decimal.Decimal // 開盤價
	High     decimal.Decimal // 最高價
	Low      decimal.Decimal // 最低價
	Volume   int             // 總成交量
	Bids     []BidAsk        // 最佳五檔委買資料
	Asks     []BidAsk        // 最佳五檔委賣資料
}

type Security

type Security struct {
	Type     string     // 有價證卷類別
	Code     string     // 有價證券代號
	Name     string     // 有價證券名稱
	ISIN     string     // 國際證卷辨識號碼
	IPO      civil.Date // 上市日
	Market   Market     // 市場別
	Industry string     // 產業
	CFI      string     // CFICode
	Remark   string     // 備註
}

有價證券

type SecurityService

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

func (*SecurityService) Download

func (s *SecurityService) Download() ([]Security, error)

從台灣證卷交易所下載上市及上櫃國際證券資料

func (*SecurityService) DownloadTpexDelisted

func (s *SecurityService) DownloadTpexDelisted(page int) ([]DelistedSecurity, error)

從證券櫃檯買賣中心下載下櫃的國際證券資料

func (*SecurityService) DownloadTwseDelisted

func (s *SecurityService) DownloadTwseDelisted() ([]DelistedSecurity, error)

從台灣證卷交易所下載下市的國際證券資料

Jump to

Keyboard shortcuts

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