twse

package module
v0.0.0-...-44aee5f Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2020 License: MIT Imports: 23 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

twse - TWSE API in Go

GoDoc

Table of Contents

Installation

$ go get github.com/z-Wind/twse

Examples

Client
client := GetClient()
twse, err := New(client)
Quotes
call := twse.Quotes.GetStockInfoTWSE("0050")
stockInfo, err := call.Do()

Reference

Documentation

Index

Examples

Constants

View Source
const (
	TWSEURL  = "https://mis.twse.com.tw"
	TWSEHOST = "https://www.twse.com.tw"
	OTCHOST  = "https://www.tpex.org.tw"
)

const strings

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(res *http.Response) error

CheckResponse returns an error (of type *Error) if the response status code is not 2xx.

func DecodeResponseCSV

func DecodeResponseCSV(target interface{}, res *http.Response) error

DecodeResponseCSV decodes the body of res into target. If there is no body, target is unchanged.

func DecodeResponseJSON

func DecodeResponseJSON(target interface{}, res *http.Response) error

DecodeResponseJSON decodes the body of res into target. If there is no body, target is unchanged.

func GetClient

func GetClient() *http.Client

GetClient get client

func JSONReader

func JSONReader(v interface{}) (io.Reader, error)

JSONReader convert struct to reader for json request

func ResolveRelative

func ResolveRelative(basePath string, elem ...string) string

ResolveRelative join path

func SendRequest

func SendRequest(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)

SendRequest sends a single HTTP request using the given client. If ctx is non-nil, it sends the request with req.WithContext

Types

type DefaultCall

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

DefaultCall DefaultCall function

func (*DefaultCall) Context

func (c *DefaultCall) Context(ctx context.Context) *DefaultCall

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DefaultCall) Header

func (c *DefaultCall) Header() http.Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type Error

type Error struct {
	// Code is the HTTP response status code and will always be populated.
	Code int `json:"code,omitempty"`
	// Message is the server response message and is only populated when
	// explicitly referenced by the JSON server response.
	Message string `json:"rtmessage,omitempty"`
	// Body is the raw response returned by the server.
	// It is often but not always JSON, depending on how the request fails.
	Body string
	// Header contains the response header fields from the server.
	Header http.Header
}

Error contains an error response from the server.

func (*Error) Error

func (e *Error) Error() string

type Float64

type Float64 float64

Float64 unmarshal string to Float64

func (*Float64) UnmarshalCSV

func (f *Float64) UnmarshalCSV(data []byte) error

UnmarshalCSV process Date

func (*Float64) UnmarshalJSON

func (f *Float64) UnmarshalJSON(data []byte) error

UnmarshalJSON process Date

type ListFloat64

type ListFloat64 []float64

ListFloat64 unmarshal string to ListInt

func (*ListFloat64) UnmarshalJSON

func (l *ListFloat64) UnmarshalJSON(data []byte) error

UnmarshalJSON process Date

type QuotesGetStockInfoCall

type QuotesGetStockInfoCall struct {
	DefaultCall
	// contains filtered or unexported fields
}

QuotesGetStockInfoCall call function

func (*QuotesGetStockInfoCall) Do

Do send request

type QuotesService

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

QuotesService get last price http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_1101.tw&json=1&delay=0&_=1539865363091

func (*QuotesService) GetStockInfoTWSE

func (r *QuotesService) GetStockInfoTWSE(symbol string) *QuotesGetStockInfoCall

GetStockInfoTWSE 上市股票查詢 http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_1101.tw&json=1&delay=0&_=1539865363091

Example
client := GetClient()
twse, err := New(client)
if err != nil {
	panic(err)
}

call := twse.Quotes.GetStockInfoTWSE("0050")
stockInfo, err := call.Do()
if err != nil {
	panic(err)
}

fmt.Printf("%+v", stockInfo)

type ServerResponse

type ServerResponse struct {
	// HTTPStatusCode is the server's response status code. When using a
	// resource method's Do call, this will always be in the 2xx range.
	HTTPStatusCode int
	// Header contains the response header fields from the server.
	Header http.Header
}

ServerResponse is embedded in each Do response and provides the HTTP status code and header sent by the server.

type Service

type Service struct {
	Quotes     *QuotesService
	Timeseries *TimeseriesService
	// contains filtered or unexported fields
}

Service TWSE api

func New

func New(client *http.Client) (*Service, error)

New TWSE API server

type StockInfo

type StockInfo struct {
	// ServerResponse contains the HTTP response code and headers from the
	// server.
	ServerResponse `json:"-"`

	MilliSecond string `json:"tlong,omitempty"` //資料時間(毫秒)
	Date        string `json:"d,omitempty"`     //今日日期
	Time        string `json:"t,omitempty"`     //資料時間

	FullName string `json:"nf,omitempty"` //全名
	Name     string `json:"n,omitempty"`  //名字
	Symbol   string `json:"c,omitempty"`  //股要代碼
	Channel  string `json:"ch,omitempty"` //1101.tw

	BestBuyAmount      ListFloat64 `json:"f,omitempty"`         //最佳五檔賣出數量
	BestBuyPrice       ListFloat64 `json:"b,omitempty"`         //最佳五檔買入價格
	BestSellAmount     ListFloat64 `json:"g,omitempty"`         //最佳五檔買入數量
	BestSellPrice      ListFloat64 `json:"a,omitempty"`         //最佳五檔賣出價格
	TradePrice         Float64     `json:"z,omitempty,string"`  //最近成交價
	PreviousTradePrice Float64     `json:"pz,omitempty,string"` //前一個成交價
	YesterdayPrice     Float64     `json:"y,omitempty,string"`  //昨天收價
	Open               Float64     `json:"o,omitempty,string"`  //開盤價
	DayLow             Float64     `json:"l,omitempty,string"`  //今日最低
	DayHigh            Float64     `json:"h,omitempty,string"`  //今日最高

	Ex string `json:"ex,omitempty"` //上市上櫃
}

StockInfo for Quotes

type Time

type Time time.Time

Time redefine time.time for Unmarshal

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalCSV

func (t *Time) UnmarshalCSV(data []byte) error

UnmarshalCSV process Date

type TimeSeriesOTC

type TimeSeriesOTC struct {
	Time         Time    `csv:"日 期"`
	Volume       Float64 `csv:"成交仟股"`
	Turnover     Float64 `csv:"成交仟元"`
	Open         Float64 `csv:"開盤"`
	High         Float64 `csv:"最高"`
	Low          Float64 `csv:"最低"`
	Close        Float64 `csv:"收盤"`
	Change       Float64 `csv:"漲跌"`
	Transactions Float64 `csv:"筆數"`
}

TimeSeriesOTC time series

type TimeSeriesOTCList

type TimeSeriesOTCList struct {
	// ServerResponse contains the HTTP response code and headers from the
	// server.
	ServerResponse `csv:"-"`

	TimeSeries []*TimeSeriesOTC
}

TimeSeriesOTCList TimeSeries List

type TimeSeriesTWSE

type TimeSeriesTWSE struct {
	Time         Time    `csv:"日期"`
	Volume       Float64 `csv:"成交股數"`
	Turnover     Float64 `csv:"成交金額"`
	Open         Float64 `csv:"開盤價"`
	High         Float64 `csv:"最高價"`
	Low          Float64 `csv:"最低價"`
	Close        Float64 `csv:"收盤價"`
	Change       Float64 `csv:"漲跌價差"`
	Transactions Float64 `csv:"成交筆數"`
}

TimeSeriesTWSE time series

type TimeSeriesTWSEList

type TimeSeriesTWSEList struct {
	// ServerResponse contains the HTTP response code and headers from the
	// server.
	ServerResponse `csv:"-"`

	TimeSeries []*TimeSeriesTWSE
}

TimeSeriesTWSEList TimeSeries List

type TimeseriesMonthlyOTCCall

type TimeseriesMonthlyOTCCall struct {
	DefaultCall
	// contains filtered or unexported fields
}

TimeseriesMonthlyOTCCall call function

func (*TimeseriesMonthlyOTCCall) Do

Do send request

type TimeseriesMonthlyTWSECall

type TimeseriesMonthlyTWSECall struct {
	DefaultCall
	// contains filtered or unexported fields
}

TimeseriesMonthlyTWSECall call function

func (*TimeseriesMonthlyTWSECall) Do

Do send request

type TimeseriesService

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

TimeseriesService get timeseries

func NewTimeseriesService

func NewTimeseriesService(s *Service) *TimeseriesService

NewTimeseriesService get timeseries

func (*TimeseriesService) MonthlyTWSE

func (r *TimeseriesService) MonthlyTWSE(symbol string, date time.Time) *TimeseriesMonthlyTWSECall

MonthlyTWSE 上市股票查詢 http://www.twse.com.tw/exchangeReport/STOCK_DAY?response=csv&date=20181230&stockNo=0050 fix csv type

Jump to

Keyboard shortcuts

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