Documentation
¶
Index ¶
- Constants
- func CheckResponse(res *http.Response) error
- func DecodeResponseCSV(target interface{}, res *http.Response) error
- func DecodeResponseJSON(target interface{}, res *http.Response) error
- func GetClient() *http.Client
- func JSONReader(v interface{}) (io.Reader, error)
- func ResolveRelative(basePath string, elem ...string) string
- func SendRequest(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)
- type DefaultCall
- type Error
- type Float64
- type ListFloat64
- type QuotesGetStockInfoCall
- type QuotesService
- type ServerResponse
- type Service
- type StockInfo
- type Time
- type TimeSeriesOTC
- type TimeSeriesOTCList
- type TimeSeriesTWSE
- type TimeSeriesTWSEList
- type TimeseriesMonthlyOTCCall
- type TimeseriesMonthlyTWSECall
- type TimeseriesService
Examples ¶
Constants ¶
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 ¶
CheckResponse returns an error (of type *Error) if the response status code is not 2xx.
func DecodeResponseCSV ¶
DecodeResponseCSV decodes the body of res into target. If there is no body, target is unchanged.
func DecodeResponseJSON ¶
DecodeResponseJSON decodes the body of res into target. If there is no body, target is unchanged.
func JSONReader ¶
JSONReader convert struct to reader for json request
func ResolveRelative ¶
ResolveRelative join path
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.
type Float64 ¶
type Float64 float64
Float64 unmarshal string to Float64
func (*Float64) UnmarshalCSV ¶
UnmarshalCSV process Date
func (*Float64) UnmarshalJSON ¶
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 ¶
func (c *QuotesGetStockInfoCall) Do() (*StockInfo, error)
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 NewQuotesService ¶
func NewQuotesService(s *Service) *QuotesService
NewQuotesService get last price http://mis.twse.com.tw/stock/api/getStockInfo.jsp?ex_ch=tse_1101.tw&json=1&delay=0&_=1539865363091
func (*QuotesService) GetStockInfoOTC ¶
func (r *QuotesService) GetStockInfoOTC(symbol string) *QuotesGetStockInfoCall
GetStockInfoOTC 上櫃股票查詢 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
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 ¶
Time redefine time.time for Unmarshal
func (*Time) UnmarshalCSV ¶
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 ¶
func (c *TimeseriesMonthlyOTCCall) Do() (*TimeSeriesOTCList, error)
Do send request
type TimeseriesMonthlyTWSECall ¶
type TimeseriesMonthlyTWSECall struct {
DefaultCall
// contains filtered or unexported fields
}
TimeseriesMonthlyTWSECall call function
func (*TimeseriesMonthlyTWSECall) Do ¶
func (c *TimeseriesMonthlyTWSECall) Do() (*TimeSeriesTWSEList, error)
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) MonthlyOTC ¶
func (r *TimeseriesService) MonthlyOTC(symbol string, date time.Time) *TimeseriesMonthlyOTCCall
MonthlyOTC 上櫃股票查詢 http://www.tpex.org.tw/ch/stock/aftertrading/daily_trading_info/st43_download.php?d=108/02&stkno=4433&r=%d csv type
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
