Documentation
¶
Overview ¶
Package infoway is the official Go SDK for the Infoway real-time financial data API.
Index ¶
- Constants
- func ClassifyRest(ret int, msg string) int
- func IsSubscribeQuotaExceeded(code int) bool
- func IsTerminalWs(code int) bool
- func IsWsError(code int) bool
- func JoinMarkets(markets ...Market) string
- func Ptr[T any](v T) *T
- func RestErrorLabel(code int) string
- func RestErrorName(code int) string
- func ValidSymbolType(s SymbolType) bool
- func WsErrorLabel(code int) string
- func WsErrorName(code int) string
- type APIError
- type AuthError
- type Basic
- func (b *Basic) GetAdjustmentFactors(ctx context.Context, symbol, market, beginDay, endDay string) (any, error)
- func (b *Basic) GetMarkets(ctx context.Context) (any, error)
- func (b *Basic) GetStockDetail(ctx context.Context, typ SymbolType, symbol string) (any, error)
- func (b *Basic) GetSymbolInfo(ctx context.Context, typ SymbolType, symbols string) (any, error)
- func (b *Basic) GetSymbols(ctx context.Context, typ SymbolType, symbols string) (any, error)
- func (b *Basic) GetTradingDays(ctx context.Context, market, beginDay, endDay string) (any, error)
- func (b *Basic) GetTradingHours(ctx context.Context) (any, error)
- func (b *Basic) GetTradingSchedule(ctx context.Context) (any, error)
- func (b *Basic) GetTradingScheduleByType(ctx context.Context, typ string) (any, error)
- type Business
- type Client
- type Financial
- func (f *Financial) GetBalanceSheet(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- func (f *Financial) GetCashFlow(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- func (f *Financial) GetDividend(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- func (f *Financial) GetDividendPayout(ctx context.Context, symbol string, typ SymbolType) (any, error)
- func (f *Financial) GetEarningStatus(ctx context.Context, symbol string, typ SymbolType) (any, error)
- func (f *Financial) GetEarnings(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- func (f *Financial) GetIncomeStatement(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- func (f *Financial) GetRevenue(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- func (f *Financial) GetStatistics(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
- type IOError
- type KlineType
- type Lang
- type Market
- type MarketClient
- func (m *MarketClient) GetBreadth(ctx context.Context, market, lang string) (any, error)
- func (m *MarketClient) GetIndexes(ctx context.Context, lang string) (any, error)
- func (m *MarketClient) GetLeaders(ctx context.Context, market string, limit int, lang string) (any, error)
- func (m *MarketClient) GetOverview(ctx context.Context, market, lang string) (any, error)
- func (m *MarketClient) GetRank(ctx context.Context, market, key string, opts *RankOptions) (any, error)
- func (m *MarketClient) GetRankCategories(ctx context.Context, market, lang string) (any, error)
- func (m *MarketClient) GetRankConfig(ctx context.Context, market string) (any, error)
- func (m *MarketClient) GetTemperature(ctx context.Context, market, lang string) (any, error)
- func (m *MarketClient) GetTurnover(ctx context.Context, market, lang string) (any, error)
- type MarketData
- type NewsLang
- type NewsOptions
- type NewsWebSocket
- type Options
- type Packages
- type PeriodType
- type Plate
- func (p *Plate) GetChart(ctx context.Context, market string, limit int) (any, error)
- func (p *Plate) GetConcept(ctx context.Context, market string, limit int) (any, error)
- func (p *Plate) GetIndustry(ctx context.Context, market string, limit int) (any, error)
- func (p *Plate) GetIntro(ctx context.Context, plateSymbol string) (any, error)
- func (p *Plate) GetMembers(ctx context.Context, plateSymbol string, offset, limit int) (any, error)
- type RankOptions
- type RankSort
- type RateLimitError
- type RestErrorCode
- type ScheduleType
- type SortOrder
- type StockInfo
- func (s *StockInfo) GetCompany(ctx context.Context, symbol, lang string) (any, error)
- func (s *StockInfo) GetConcepts(ctx context.Context, symbol, lang string) (any, error)
- func (s *StockInfo) GetDrivers(ctx context.Context, symbol, lang string) (any, error)
- func (s *StockInfo) GetEvents(ctx context.Context, symbol string, limit int, lang string) (any, error)
- func (s *StockInfo) GetPanorama(ctx context.Context, symbol, lang string) (any, error)
- func (s *StockInfo) GetRatings(ctx context.Context, symbol, lang string) (any, error)
- func (s *StockInfo) GetValuation(ctx context.Context, symbol, lang string) (any, error)
- type SymbolType
- type TimeoutError
- type WSOptions
- type WebSocket
- func (w *WebSocket) Close() error
- func (w *WebSocket) Connect(ctx context.Context) error
- func (w *WebSocket) SubscribeDepth(codes string)
- func (w *WebSocket) SubscribeKline(codes string, klineType KlineType)
- func (w *WebSocket) SubscribeTrade(codes string, includeTy bool)
- func (w *WebSocket) UnsubscribeDepth(codes string)
- func (w *WebSocket) UnsubscribeKline(codes string, klineType KlineType)
- func (w *WebSocket) UnsubscribeTrade(codes string)
- type WsCode
- type WsErrorCode
Constants ¶
const Version = "0.4.1"
Version is the SDK release version.
Variables ¶
This section is empty.
Functions ¶
func ClassifyRest ¶ added in v0.4.0
ClassifyRest maps a wrapped ret=500 back to the business code carried in msg.
func IsSubscribeQuotaExceeded ¶ added in v0.4.1
IsSubscribeQuotaExceeded is WS 516. Old sockets may still hold quota after they stop heartbeating; retry subscribe on the same connection.
func IsTerminalWs ¶ added in v0.4.0
IsTerminalWs reports codes a reconnect cannot fix. 516 is recoverable.
func JoinMarkets ¶
JoinMarkets joins market codes with commas.
func RestErrorLabel ¶
RestErrorLabel returns the REST label, or "".
func RestErrorName ¶
RestErrorName returns the REST enum constant name, or "".
func ValidSymbolType ¶ added in v0.4.0
func ValidSymbolType(s SymbolType) bool
ValidSymbolType reports whether s is a type the financial and symbol APIs accept.
func WsErrorName ¶
WsErrorName returns the WS enum constant name, or "".
Types ¶
type APIError ¶
APIError is a non-success Infoway response.
Ret is the wire code (REST ret/code, WS code, or HTTP status). ErrorName is the matching RestErrorCode or WsErrorCode constant when known. 508–514 share numbers across the two channels but not meanings.
func OfHTTPStatus ¶
OfHTTPStatus is a gateway / transport status. It must not look up RestErrorCode (HTTP 502 is not daily-quota 502).
type Basic ¶
type Basic struct {
// contains filtered or unexported fields
}
Basic is symbols, calendar, schedule and single-name profile.
func (*Basic) GetAdjustmentFactors ¶
func (b *Basic) GetAdjustmentFactors(ctx context.Context, symbol, market, beginDay, endDay string) (any, error)
GetAdjustmentFactors returns forward factors. market is US/CN/HK/JP/IN/KS/TW. Days are YYYYMMDD.
func (*Basic) GetMarkets ¶
GetMarkets returns the per-market session table. Takes no parameters.
func (*Basic) GetStockDetail ¶
GetStockDetail is a single-name profile (logo, FIGI, ISIN, …).
func (*Basic) GetSymbolInfo ¶
GetSymbolInfo returns static fields for up to 500 codes.
func (*Basic) GetSymbols ¶
GetSymbols lists instruments of one product type. symbols is optional.
func (*Basic) GetTradingDays ¶
GetTradingDays returns trade_days / half_trade_days. Days are YYYYMMDD.
func (*Basic) GetTradingHours ¶
GetTradingHours is a deprecated alias of GetTradingSchedule.
func (*Basic) GetTradingSchedule ¶
GetTradingSchedule returns the full non-equity session table.
type Client ¶
type Client struct {
Stock *MarketData
Crypto *MarketData
Japan *MarketData // Tokyo: 7203.JP. Yahoo 7203.T returns 508.
India *MarketData // India: RELIANCE.IN. Yahoo RELIANCE.NS returns 508.
Korea *MarketData
Taiwan *MarketData
Common *MarketData
Basic *Basic
Packages *Packages
Market *MarketClient
Plate *Plate
StockInfo *StockInfo
Financial *Financial
// contains filtered or unexported fields
}
Client is the Infoway REST entry point.
type Financial ¶
type Financial struct {
// contains filtered or unexported fields
}
Financial is statements, dividends and earnings.
func (*Financial) GetBalanceSheet ¶
func (f *Financial) GetBalanceSheet(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
func (*Financial) GetCashFlow ¶
func (f *Financial) GetCashFlow(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
func (*Financial) GetDividend ¶
func (f *Financial) GetDividend(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
func (*Financial) GetDividendPayout ¶
func (*Financial) GetEarningStatus ¶
func (*Financial) GetEarnings ¶
func (f *Financial) GetEarnings(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
func (*Financial) GetIncomeStatement ¶
func (f *Financial) GetIncomeStatement(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
func (*Financial) GetRevenue ¶
func (f *Financial) GetRevenue(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
func (*Financial) GetStatistics ¶
func (f *Financial) GetStatistics(ctx context.Context, symbol string, typ SymbolType, period PeriodType) (any, error)
type KlineType ¶
type KlineType int
KlineType is a candlestick interval (1–12).
const ( KlineMin1 KlineType = 1 KlineMin5 KlineType = 2 KlineMin15 KlineType = 3 KlineMin30 KlineType = 4 KlineHour1 KlineType = 5 KlineHour2 KlineType = 6 KlineHour4 KlineType = 7 KlineDay KlineType = 8 KlineWeek KlineType = 9 KlineMonth KlineType = 10 KlineQuarter KlineType = 11 KlineYear KlineType = 12 )
type MarketClient ¶
type MarketClient struct {
// contains filtered or unexported fields
}
MarketClient is temperature, breadth, turnover, ranks and commentary.
func (*MarketClient) GetBreadth ¶
func (*MarketClient) GetIndexes ¶
func (*MarketClient) GetLeaders ¶
func (*MarketClient) GetOverview ¶
func (*MarketClient) GetRank ¶
func (m *MarketClient) GetRank(ctx context.Context, market, key string, opts *RankOptions) (any, error)
func (*MarketClient) GetRankCategories ¶
func (*MarketClient) GetRankConfig ¶
GetRankConfig is deprecated: the path returns HTTP 404.
func (*MarketClient) GetTemperature ¶
GetTemperature defaults market to HK,US,CN when market is empty.
func (*MarketClient) GetTurnover ¶
type MarketData ¶
type MarketData struct {
// contains filtered or unexported fields
}
MarketData is trade / depth / kline for one market prefix.
type NewsOptions ¶
type NewsOptions struct {
APIKey string
BaseURL string
Lang string // default en
MaxReconnectAttempts int
PrintFrames bool
HeartbeatInterval time.Duration
ReconnectBackoff time.Duration
}
NewsOptions configures the news channel.
type NewsWebSocket ¶
type NewsWebSocket struct {
OnNews func(map[string]any)
OnNewsParsed func(map[string]any)
OnFrame func(string)
OnError func(error)
OnReconnect func()
OnDisconnect func()
// contains filtered or unexported fields
}
NewsWebSocket is wss://data.infoway.io/news?apikey=… (separate entitlement).
func NewNewsWebSocket ¶
func NewNewsWebSocket(opts NewsOptions) (*NewsWebSocket, error)
func (*NewsWebSocket) Close ¶
func (n *NewsWebSocket) Close() error
func (*NewsWebSocket) Subscribe ¶
func (n *NewsWebSocket) Subscribe(lang string)
func (*NewsWebSocket) Unsubscribe ¶
func (n *NewsWebSocket) Unsubscribe()
type Packages ¶
type Packages struct {
// contains filtered or unexported fields
}
Packages is quota for the current API key.
type PeriodType ¶
type PeriodType string
PeriodType is a financial-statement period.
const ( PeriodFQ PeriodType = "fq" PeriodFY PeriodType = "fy" PeriodFH PeriodType = "fh" )
func (PeriodType) String ¶
func (p PeriodType) String() string
type Plate ¶
type Plate struct {
// contains filtered or unexported fields
}
Plate is industry / concept sectors.
func (*Plate) GetConcept ¶
func (*Plate) GetIndustry ¶
type RankOptions ¶
RankOptions is optional paging for GetRank.
type RankSort ¶
type RankSort string
RankSort is a rank-board sort key.
const (
RankSortChg RankSort = "chg"
)
type RateLimitError ¶
type RateLimitError struct {
*APIError
}
RateLimitError is HTTP 429, HTTP 200 + detail rate-limit, or REST/WS 501/502.
type RestErrorCode ¶
type RestErrorCode int
RestErrorCode is a REST business ret. 508–514 collide with WsErrorCode but mean different things.
const ( RestSuccess RestErrorCode = 200 RestBadRequest RestErrorCode = 400 RestServerError RestErrorCode = 500 RestRequestExceedLimit RestErrorCode = 501 RestRequestForDayLimit RestErrorCode = 502 RestKlineExceedsLimit RestErrorCode = 503 RestOrderBookDepthExceedsLimit RestErrorCode = 504 RestProductsExceedsLimit RestErrorCode = 505 RestParamError RestErrorCode = 506 RestParamLost RestErrorCode = 507 RestProductNotExists RestErrorCode = 508 RestTokenPermissionExpired RestErrorCode = 509 RestWebsocketExceedsLimit RestErrorCode = 510 RestWebsocketHeartbeatTimeout RestErrorCode = 511 RestWebsocketDisconnected RestErrorCode = 512 RestTimeLimitError RestErrorCode = 513 RestNoPermission RestErrorCode = 514 )
type ScheduleType ¶
type ScheduleType string
ScheduleType is accepted by /common/basic/markets/trading_schedule.
const ( ScheduleEnergy ScheduleType = "ENERGY" ScheduleForex ScheduleType = "FOREX" ScheduleFutures ScheduleType = "FUTURES" ScheduleMetal ScheduleType = "METAL" ScheduleIndices ScheduleType = "INDICES" )
func ParseScheduleType ¶
func ParseScheduleType(value string) (ScheduleType, bool)
ParseScheduleType maps ENERGY/FOREX/FUTURES/METAL/INDICES. Equity types return false.
func (ScheduleType) String ¶
func (s ScheduleType) String() string
type StockInfo ¶
type StockInfo struct {
// contains filtered or unexported fields
}
StockInfo is valuation, ratings, company overview and events.
func (*StockInfo) GetCompany ¶
func (*StockInfo) GetConcepts ¶
func (*StockInfo) GetDrivers ¶
func (*StockInfo) GetPanorama ¶
func (*StockInfo) GetRatings ¶
type SymbolType ¶
type SymbolType string
SymbolType is the product type for /common/basic/symbols and financials.
const ( SymbolStockUS SymbolType = "STOCK_US" SymbolStockCN SymbolType = "STOCK_CN" SymbolStockHK SymbolType = "STOCK_HK" SymbolStockJP SymbolType = "STOCK_JP" SymbolStockKS SymbolType = "STOCK_KS" SymbolStockIN SymbolType = "STOCK_IN" SymbolStockTW SymbolType = "STOCK_TW" SymbolCrypto SymbolType = "CRYPTO" SymbolForex SymbolType = "FOREX" SymbolFutures SymbolType = "FUTURES" SymbolEnergy SymbolType = "ENERGY" SymbolMetal SymbolType = "METAL" SymbolIndices SymbolType = "INDICES" )
func (SymbolType) String ¶
func (s SymbolType) String() string
type TimeoutError ¶
type TimeoutError struct {
Msg string
}
TimeoutError is a request timeout after retries are exhausted (or a single timeout).
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
type WSOptions ¶
type WSOptions struct {
APIKey string
Business Business
BaseURL string
MaxReconnectAttempts int // 0 = unlimited
PrintFrames bool
HeartbeatInterval time.Duration
ReconnectBackoff time.Duration
// StaleAfter resubscribes when this socket has seen ticks then gone silent.
// Default 90s. 0 disables the watchdog.
StaleAfter time.Duration
// SubscribeRetry is the first delay after a 516. Default 2s.
SubscribeRetry time.Duration
}
WSOptions configures a quotes WebSocket.
type WebSocket ¶
type WebSocket struct {
OnTrade func(map[string]any)
OnDepth func(map[string]any)
OnKline func(map[string]any)
OnFrame func(string)
OnError func(error)
OnReconnect func()
OnDisconnect func()
// contains filtered or unexported fields
}
WebSocket is the market-data socket (wss://data.infoway.io/ws?business=…).
func NewWebSocket ¶
NewWebSocket requires APIKey (or INFOWAY_API_KEY) and Business.
func (*WebSocket) Connect ¶
Connect runs the read loop until ctx is cancelled, Close is called, or a 401 handshake.
func (*WebSocket) SubscribeDepth ¶
func (*WebSocket) SubscribeKline ¶
func (*WebSocket) SubscribeTrade ¶
SubscribeTrade records codes and sends 10000 when the socket is open.
func (*WebSocket) UnsubscribeDepth ¶
func (*WebSocket) UnsubscribeKline ¶
func (*WebSocket) UnsubscribeTrade ¶
type WsCode ¶
type WsCode int
WsCode is a subscribe / push / heartbeat protocol number.
const ( WsSubTrade WsCode = 10000 WsSubTradeAck WsCode = 10001 WsPushTrade WsCode = 10002 WsSubDepth WsCode = 10003 WsSubDepthAck WsCode = 10004 WsPushDepth WsCode = 10005 WsSubKline WsCode = 10006 WsSubKlineAck WsCode = 10007 WsPushKline WsCode = 10008 WsHeartbeat WsCode = 10010 WsHeartApply WsCode = 10011 WsSubNews WsCode = 10020 WsSubNewsAck WsCode = 10021 WsPushNews WsCode = 10022 WsUnsubTrade WsCode = 11000 WsUnsubDepth WsCode = 11001 WsUnsubKline WsCode = 11002 WsUnsubAck WsCode = 11010 WsUnsubNews WsCode = 11020 WsConnectOK WsCode = 200 )
type WsErrorCode ¶
type WsErrorCode int
WsErrorCode is a WebSocket rejection code. Do not use it for REST ret.
const ( WsErrServerError WsErrorCode = 500 WsErrRequestFrequencyMinExceed WsErrorCode = 501 WsErrRequestFrequencyDayExceed WsErrorCode = 502 WsErrKlineQuantityExceed WsErrorCode = 503 WsErrOrderBookDepthExceed WsErrorCode = 504 WsErrProductsQuantityExceed WsErrorCode = 505 WsErrParamError WsErrorCode = 506 WsErrParamLost WsErrorCode = 507 WsErrAPIKeyExpired WsErrorCode = 508 WsErrAPIKeyInvalid WsErrorCode = 509 WsErrAPIKeyEmpty WsErrorCode = 510 WsErrAPIKeyBlacklist WsErrorCode = 511 WsErrWSConnExceed WsErrorCode = 512 WsErrWSHeartTimeout WsErrorCode = 513 WsErrWSURLWrong WsErrorCode = 514 WsErrParamNotJSON WsErrorCode = 515 WsErrAllProductsQuantityExceed WsErrorCode = 516 WsErrHandshakeAPIKeyMissing WsErrorCode = 517 WsErrHandshakeAPIKeyNotExist WsErrorCode = 518 WsErrHandshakeNoPermission WsErrorCode = 519 WsErrProductCodeOrAlreadyConnected WsErrorCode = 520 WsErrHandshakeMaxConnections WsErrorCode = 521 )