fugle

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version = "1.2.0"
)

Variables

This section is empty.

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 `json:"price"`  // 價格
	Volume int             `json:"volume"` // 數量
}

type Candle

type Candle struct {
	Date   Date            `json:"date"`   // 本筆資料所屬日期
	Open   decimal.Decimal `json:"open"`   // 開盤價
	High   decimal.Decimal `json:"high"`   // 最高價
	Low    decimal.Decimal `json:"low"`    // 最低價
	Close  decimal.Decimal `json:"close"`  // 收盤價
	Volume int             `json:"volume"` // 成交量
}

type CandlesResponse

type CandlesResponse struct {
	SymbolID string   `json:"symbolId"` // 個股、指數識別代碼
	Type     string   `json:"type"`     // ticker 類別
	Exchange string   `json:"exchange"` // 交易所
	Market   string   `json:"market"`   // 市場別
	Candles  []Candle `json:"candles"`  // 歷史股價資料
}

type Chart

type Chart struct {
	Averages   []decimal.Decimal `json:"a"` // 當日個股於此分鐘的成交均價
	Opens      []decimal.Decimal `json:"o"` // 此分鐘的開盤價
	Highs      []decimal.Decimal `json:"h"` // 此分鐘的最高價
	Lows       []decimal.Decimal `json:"l"` // 此分鐘的最低價
	Closes     []decimal.Decimal `json:"c"` // 此分鐘的收盤價
	Volumes    []int             `json:"v"` // 此分鐘的成交量 (指數:金額;個股:張數;興櫃股票及零股:股數)
	Timestamps []Timestamp       `json:"t"`
}

type ChartData

type ChartData struct {
	Info  `json:"info"`
	Chart `json:"chart"`
}

type ChartResponse

type ChartResponse struct {
	APIVersion string    `json:"apiVersion"`
	Data       ChartData `json:"data"`
}

type Client

type Client struct {

	// Services used for talking to different parts of the API
	Intrady    *IntradayService
	MarketData *MarketDataService
	// contains filtered or unexported fields
}

A Client manages communication with the Fugle API.

func NewClient

func NewClient(apiToken string) *Client

NewClient returns a new Fugle API client.

func (*Client) Call

func (c *Client) Call(url string, opts interface{}, resp interface{}) error

Call first creates an API request then sends it and returns the API response.

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) NewRequest

func (c *Client) NewRequest(method, urlStr string) (*http.Request, error)

NewRequest creates an API request.

type Date added in v1.2.0

type Date struct {
	Year  int
	Month time.Month
	Day   int
}

func (Date) String added in v1.2.0

func (d Date) String() string

func (*Date) UnmarshalJSON added in v1.2.0

func (d *Date) UnmarshalJSON(b []byte) error

UnmarshalJSON handles incoming JSON.

type Dealt

type Dealt struct {
	At     time.Time       `json:"at"`     // 此筆交易的成交時間
	Bid    decimal.Decimal `json:"bid"`    // 此筆交易的買進價
	Ask    decimal.Decimal `json:"ask"`    // 此筆交易的賣出價
	Price  decimal.Decimal `json:"price"`  // 此筆交易的成交價
	Volume int             `json:"volume"` // 此筆交易的成交量
	Serial int             `json:"serial"` // 此筆交易的序號
}

type DealtData

type DealtData struct {
	Info   `json:"info"`
	Dealts []Dealt `json:"dealts"`
}

type DealtsOptions

type DealtsOptions struct {
	SymbolID string `url:"symbolId"` // 個股、指數識別代碼
	APIToken string `url:"apiToken"`
	Limit    int    `url:"limit"`  // 限制最多回傳的資料筆數
	Offset   int    `url:"offset"` // 指定從第幾筆後開始回傳
	OddLot   bool   `url:"oddLot"` // 是否回傳零股行情
}

type DealtsResponse

type DealtsResponse struct {
	APIVersion string    `json:"apiVersion"`
	Data       DealtData `json:"data"`
}

See https://developer.fugle.tw/docs/data/intraday/dealts

type Error

type Error struct {
	Code    int    `json:"code"`    // error code
	Message string `json:"message"` // error message
}

func (*Error) Error

func (e *Error) Error() string

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response // HTTP response that caused this error
	Details  Error          `json:"error"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type Info

type Info struct {
	Date          Date      `json:"date"`          // 本筆資料所屬日期
	Type          string    `json:"type"`          // ticker 類別
	Exchange      string    `json:"exchange"`      // 交易所
	Market        string    `json:"market"`        // 市場別
	SymbolID      string    `json:"symbolId"`      // 股票代號
	CountryCode   string    `json:"countryCode"`   // 股票所屬國家ISO2代碼
	TimeZone      string    `json:"timeZone"`      // 股票所屬時區
	LastUpdatedAt time.Time `json:"lastUpdatedAt"` // 本筆資料最後更新時間
}

type IntradayService

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

IntradayService handles communication with the intraday related methods of the Fugle API.

Fugle API docs: https://developer.fugle.tw/docs/data/intraday/overview

func (*IntradayService) Chart

func (s *IntradayService) Chart(symbolID string, oddLot bool) (*ChartResponse, error)

提供盤中個股/指數 線圖時所需的各項即時資訊 See https://developer.fugle.tw/docs/data/intraday/chart

func (*IntradayService) Dealts

func (s *IntradayService) Dealts(symbolID string, limit int, offset int, oddLot bool) (*DealtsResponse, error)

取得個股當日所有成交資訊(ex: 個股價量、大盤總量) See https://developer.fugle.tw/docs/data/intraday/dealts

func (*IntradayService) Meta

func (s *IntradayService) Meta(symbolID string, oddLot bool) (*MetaResponse, error)

提供盤中個股/指數當日基本資訊 See https://developer.fugle.tw/docs/data/intraday/meta

func (*IntradayService) Quote

func (s *IntradayService) Quote(symbolID string, oddLot bool) (*QuoteResponse, error)

提供盤中個股/指數逐筆交易金額、狀態、最佳五檔及統計資訊 See https://developer.fugle.tw/docs/data/intraday/quote

func (*IntradayService) Volumes

func (s *IntradayService) Volumes(symbolID string, oddLot bool) (*VolumesResponse, error)

提供盤中個股即時分價量 See https://developer.fugle.tw/docs/data/intraday/volumes

type IntradyOptions

type IntradyOptions struct {
	SymbolID string `url:"symbolId"` // 個股、指數識別代碼
	APIToken string `url:"apiToken"`
	OddLot   bool   `url:"oddLot"` // 是否回傳零股行情
}

type Last

type Last struct {
	At          time.Time       `json:"at"`          // 最新一筆成交時間
	Transaction int             `json:"transaction"` // 總成交筆數
	TradeValue  decimal.Decimal `json:"tradeValue"`  // 總成交金額
	TradeVolume int             `json:"tradeVolume"` // 總成交數量
	BidOrders   int             `json:"bidOrders"`   // 總委買筆數
	AskOrders   int             `json:"askOrders"`   // 總委賣筆數
	BidVolume   int             `json:"bidVolume"`   // 總委買數量
	AskVolume   int             `json:"askVolume"`   // 總委賣數量
	Serial      int             `json:"serial"`      // 最新一筆成交之序號
}

type MarketDataOptions

type MarketDataOptions struct {
	SymbolID string `url:"symbolId"` // 個股、指數識別代碼
	APIToken string `url:"apiToken"`
	From     string `url:"from"` // 開始日期
	To       string `url:"to"`   // 結束日期
}

type MarketDataService

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

MarketDataService handles communication with the marketdata related methods of the Fugle API.

Fugle API docs: https://developer.fugle.tw/docs/data/marketdata/candles

func (*MarketDataService) Candles

func (s *MarketDataService) Candles(symbolID string, from Date, to Date) (*CandlesResponse, error)

提供歷史股價資料,包含開高低收量 (OHLCV)。歷史資料目前設計單次呼叫的資料區間以一年為限;資料區間最遠可回溯至 2010 年! See https://developer.fugle.tw/docs/data/marketdata/candles

type Meta

type Meta struct {
	Market                 string          `json:"market"`                 // 股票所屬市場別
	NameZhTw               string          `json:"nameZhTw"`               // 股票中文簡稱
	IndustryZhTw           string          `json:"industryZhTw"`           // 股票所屬產業別
	PreviousClose          decimal.Decimal `json:"previousClose"`          // 上次收盤價
	PriceReference         decimal.Decimal `json:"priceReference"`         // 今日參考價
	PriceHighLimit         decimal.Decimal `json:"priceHighLimit"`         // 漲停價
	PriceLowLimit          decimal.Decimal `json:"priceLowLimit"`          // 跌停價
	CanDayBuySell          bool            `json:"canDayBuySell"`          // 是否可先買後賣現股當沖
	CanDaySellBuy          bool            `json:"canDaySellBuy"`          // 是否可先賣後買現股當沖
	CanShortMargin         bool            `json:"canShortMargin"`         // 是否豁免平盤下融券賣出
	CanShortLend           bool            `json:"canShortLend"`           // 是否豁免平盤下借券賣出
	TradingUnit            int             `json:"tradingUnit"`            // 交易單位
	Currency               string          `json:"currency"`               // 交易幣別代號
	IsTerminated           bool            `json:"isTerminated"`           // 今日是否已終止上市
	IsSuspended            bool            `json:"isSuspended"`            // 今日是否暫停買賣
	TypeZhTw               string          `json:"typeZhTw"`               // 股票類別
	Abnormal               string          `json:"abnormal"`               // 警示或處置股標示 (正常、注意、處置、注意及處置、再次處置、注意及再次處置、彈性處置、注意及彈性處置)
	IsUnusuallyRecommended bool            `json:"isUnusuallyRecommended"` // 是否為投資理財節目異常推介個股
	IsNewlyCompiled        bool            `json:"isNewlyCompiled"`        // 是否為新編指數 (僅指數類別)
}

type MetaData

type MetaData struct {
	Info Info `json:"info"`
	Meta Meta `json:"meta"`
}

type MetaResponse

type MetaResponse struct {
	APIVersion string   `json:"apiVersion"`
	Data       MetaData `json:"data"`
}

type Order

type Order struct {
	At   time.Time `json:"at"` // 最新一筆最佳五檔更新時間
	Bids []BidAsk  // 委買資料
	Asks []BidAsk  // 委賣資料
}

type Price

type Price struct {
	At    time.Time       `json:"at"`    // 時間
	Price decimal.Decimal `json:"price"` // 價格
}

type PriceLimit

type PriceLimit int
const (
	Normal    PriceLimit = 0 // 正常
	LimitDown PriceLimit = 1 // 跌停
	LimitUp   PriceLimit = 2 // 漲停
)

type Quote

type Quote struct {
	IsCurbing      bool `json:"isCurbing"`      // 最近一次更新是否為瞬間價格穩定措施
	IsCurbingFall  bool `json:"isCurbingFall"`  // 最近一次更新是否為暫緩撮合且瞬間趨跌
	IsCurbingRise  bool `json:"isCurbingRise"`  // 最近一次更新是否為暫緩撮合且瞬間趨漲
	IsTrial        bool `json:"isTrial"`        // 最近一次更新是否為試算
	IsOpenDelayed  bool `json:"isOpenDelayed"`  // 最近一次更新是否為延後開盤狀態
	IsCloseDelayed bool `json:"isCloseDelayed"` // 最近一次更新是否為延後收盤狀態
	IsHalting      bool `json:"isHalting"`      // 最近一次更新是否為暫停交易
	IsDealt        bool `json:"isDealt"`        // 最近一次更新是否包含最新成交(試撮)價
	IsClosed       bool `json:"isClosed"`       // 當日是否為已收盤

	Total Total `json:"total"`
	Trial Trial `json:"trial"`
	Trade Trade `json:"trade"`
	Order Order `json:"order"`
	Last  Last  `json:"last"`

	PriceHigh    Price `json:"priceHigh"` // 當日之最高價,第一次到達當日最高價之時間
	PriceLow     Price `json:"priceLow"`  // 當日之最低價,第一次到達當日最低價之時間
	PriceOpen    Price `json:"priceOpen"` // 當日之開盤價,開盤定義:當天第一筆成交時才開盤,當日第一筆成交時間
	PriceAverage Price `json:"priceAvg"`  // 當日之成交均價,當日最後一筆成交時間

	Change        decimal.Decimal `json:"change"`        // 當日股價之漲跌
	ChangePercent decimal.Decimal `json:"changePercent"` // 當日股價之漲跌幅
	Amplitude     decimal.Decimal `json:"amplitude"`     // 當日股價之振幅
	PriceLimit    PriceLimit      `json:"priceLimit"`
}

type QuoteData

type QuoteData struct {
	Info  `json:"info"`
	Quote `json:"quote"`
}

type QuoteResponse

type QuoteResponse struct {
	APIVersion string    `json:"apiVersion"`
	Data       QuoteData `json:"data"`
}

type Timestamp

type Timestamp struct {
	time.Time
}

func (*Timestamp) UnmarshalJSON

func (p *Timestamp) UnmarshalJSON(bytes []byte) error

UnmarshalJSON handles incoming JSON.

type Total

type Total struct {
	At               time.Time       `json:"at"`               // 最新一筆成交時間
	Transaction      int             `json:"transaction"`      // 總成交筆數
	TradeValue       decimal.Decimal `json:"tradeValue"`       // 總成交金額
	TradeVolume      int             `json:"tradeVolume"`      // 總成交數量
	TradeVolumeAtBid int             `json:"tradeVolumeAtBid"` // 個股內盤成交量
	TradeVolumeAtAsk int             `json:"tradeVolumeAtAsk"` // 個股外盤成交量
	BidOrders        int             `json:"bidOrders"`        // 總委買筆數 (僅加權、櫃買指數)
	AskOrders        int             `json:"askOrders"`        // 總委賣筆數 (僅加權、櫃買指數)
	BidVolume        int             `json:"bidVolume"`        // 總委買數量 (僅加權、櫃買指數)
	AskVolume        int             `json:"askVolume"`        // 總委賣數量 (僅加權、櫃買指數)
	Serial           int             `json:"serial"`           // 最新一筆成交之序號
}

type Trade

type Trade struct {
	At     time.Time       `json:"at"`     // 最新一筆成交時間
	Bid    decimal.Decimal `json:"bid"`    // 最新一筆成交買進價
	Ask    decimal.Decimal `json:"ask"`    // 最新一筆成交賣出價
	Price  decimal.Decimal `json:"price"`  // 最新一筆成交價
	Volume int             `json:"volume"` // 最新一筆成交量
	Serial int             `json:"serial"` // 最新一筆成交之序號
}

type Trial

type Trial struct {
	At     time.Time       `json:"at"`     // 最新一筆試撮時間
	Bid    decimal.Decimal `json:"bid"`    // 最新一筆試撮買進價
	Ask    decimal.Decimal `json:"ask"`    // 最新一筆試撮賣出價
	Price  decimal.Decimal `json:"price"`  // 最新一筆試撮成交價
	Volume int             `json:"volume"` // 最新一筆試撮成交量
	Serial int             `json:"serial"` // 最新一筆試撮之序號
}

type Volume

type Volume struct {
	Price       decimal.Decimal `json:"price"`       // 成交價
	Volume      int             `json:"volume"`      // 成交量
	VolumeAtBid int             `json:"volumeAtBid"` // 內盤成交量
	VolumeAtAsk int             `json:"volumeAtAsk"` // 外盤成交量
}

type VolumesData

type VolumesData struct {
	Info    Info     `json:"info"`
	Volumes []Volume `json:"volumes"`
}

type VolumesResponse

type VolumesResponse struct {
	APIVersion string      `json:"apiVersion"`
	Data       VolumesData `json:"data"`
}

Jump to

Keyboard shortcuts

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