Help us shape the future of Go! Take the 2026 Go Developer Survey

infoway

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 18 Imported by: 0

README

Infoway Go SDK

Go Reference Go

English | 中文

Official Infoway Go SDK for REST market data, fundamentals, and WebSocket streams.

Item Description
Module github.com/infoway-api/infoway-sdk-go@v0.4.1
Runtime Go 1.22+
REST https://data.infoway.io
Quotes WebSocket wss://data.infoway.io/ws
News WebSocket wss://data.infoway.io/news
Rate limits REST · WebSocket
Error codes REST · WebSocket
Endpoints Endpoints

If APIKey is omitted, the SDK reads INFOWAY_API_KEY. REST methods take context.Context and return errors as values.

Contents

Install

go get github.com/infoway-api/infoway-sdk-go@v0.4.1

Quick start

package main

import (
    "context"
    "fmt"
    "os"

    infoway "github.com/infoway-api/infoway-sdk-go"
)

func main() {
    client := infoway.New(infoway.Options{APIKey: os.Getenv("INFOWAY_API_KEY")})
    defer client.Close()

    trades, err := client.Stock.GetTrade(context.Background(), "AAPL.US")
    if err != nil {
        panic(err)
    }
    fmt.Println(trades)
}

Symbols

Market Format Valid Invalid
US {code}.US AAPL.US AAPL
Hong Kong 5-digit + .HK 00700.HK 700.HK
Shanghai {code}.SH 600519.SH 600519.CN
Shenzhen {code}.SZ 000001.SZ 000001.CN
Japan {code}.JP 7203.JP
Korea {code}.KS 005930.KS
India {code}.IN RELIANCE.IN
Taiwan {code}.TW 2330.TW
Crypto Pair BTCUSDT
FX Pair USDJPY

Basic / Financial take a product type such as STOCK_US or CRYPTO, not a market code like US.

Client

Option Default Description
APIKey INFOWAY_API_KEY API key
BaseURL https://data.infoway.io REST base URL
Timeout 15s Per-request timeout
MaxRetries 3 Retry count

Clients: Stock / Crypto / Japan / India / Korea / Taiwan / Common / Basic / Packages / Market / Plate / StockInfo / Financial.

REST

Join symbols with commas. Rate limits: REST API Limitation.

Quotes
Method Description
GetTrade(ctx, codes) Latest trade
GetDepth(ctx, codes) Order book
GetKline(ctx, codes, klineType, count, timestamp) Candles. Pass nil for the latest
ctx := context.Background()
client.Stock.GetTrade(ctx, "AAPL.US,TSLA.US")
client.Crypto.GetDepth(ctx, "BTCUSDT")
client.Korea.GetTrade(ctx, "005930.KS")
client.Taiwan.GetTrade(ctx, "2330.TW")
client.Crypto.GetKline(ctx, "BTCUSDT", infoway.KlineMin1, 100, nil)
Constant Value Interval
KlineMin1 / KlineMin5 / KlineMin15 / KlineMin30 1–4 Minutes
KlineHour1 / KlineHour2 / KlineHour4 5–7 Hours
KlineDay / KlineWeek / KlineMonth / KlineQuarter / KlineYear 8–12 Daily and above

Up to 500 bars per symbol; multi-symbol calls return 2 bars each. vw is turnover.

Basic info

Dates use YYYYMMDD.

client.Basic.GetSymbols(ctx, infoway.SymbolStockUS, "")
client.Basic.GetSymbolInfo(ctx, infoway.SymbolStockUS, "AAPL.US")
client.Basic.GetStockDetail(ctx, infoway.SymbolStockUS, "AAPL.US")
client.Basic.GetAdjustmentFactors(ctx, "AAPL.US", "US", "20260801", "20260815")
client.Basic.GetTradingDays(ctx, "US", "20260801", "20260815")
client.Basic.GetTradingSchedule(ctx)
client.Basic.GetTradingScheduleByType(ctx, "ENERGY")
client.Basic.GetMarkets(ctx)
client.Packages.GetInfo(ctx)
Overview / sectors / stock info / financials
client.Market.GetTemperature(ctx, infoway.JoinMarkets(infoway.MarketHK, infoway.MarketUS), "zh-CN")
client.Market.GetBreadth(ctx, "US", "zh-CN")
client.Market.GetTurnover(ctx, "US", "")
client.Market.GetIndexes(ctx, "en")
client.Market.GetLeaders(ctx, "US", 10, "")
client.Market.GetOverview(ctx, "US", "zh-CN")
client.Market.GetRankCategories(ctx, "US", "")
client.Market.GetRank(ctx, "US", "all", &infoway.RankOptions{
    Sort: "chg", Order: "desc", Limit: 30, Lang: "en",
})

client.Plate.GetIndustry(ctx, "HK", 200)
client.Plate.GetConcept(ctx, "HK", 100)
client.Plate.GetMembers(ctx, "IN20293.HK", 0, 50)
client.Plate.GetIntro(ctx, "IN20293.HK")
client.Plate.GetChart(ctx, "HK", 50)

client.StockInfo.GetValuation(ctx, "AAPL.US", "")
client.StockInfo.GetRatings(ctx, "AAPL.US", "")
client.StockInfo.GetCompany(ctx, "AAPL.US", "zh-CN")
client.StockInfo.GetPanorama(ctx, "AAPL.US", "")
client.StockInfo.GetConcepts(ctx, "AAPL.US", "")
client.StockInfo.GetEvents(ctx, "AAPL.US", 20, "")
client.StockInfo.GetDrivers(ctx, "AAPL.US", "")

typ := infoway.SymbolStockUS
client.Financial.GetEarningStatus(ctx, "AAPL.US", typ)
client.Financial.GetIncomeStatement(ctx, "AAPL.US", typ, infoway.PeriodFQ)
client.Financial.GetRevenue(ctx, "AAPL.US", typ, "")
client.Financial.GetCashFlow(ctx, "AAPL.US", typ, infoway.PeriodFY)
client.Financial.GetBalanceSheet(ctx, "AAPL.US", typ, "")
client.Financial.GetStatistics(ctx, "AAPL.US", typ, "")
client.Financial.GetDividend(ctx, "00700.HK", infoway.SymbolStockHK, "")
client.Financial.GetDividendPayout(ctx, "AAPL.US", typ)
client.Financial.GetEarnings(ctx, "AAPL.US", typ, infoway.PeriodFQ)

Rank key values come from GetRankCategories. Financial methods require symbol and type. period_type: fq quarter, fy year, fh half-year.

Return values

REST methods decode JSON into any ([]any or map[string]any). Numbers are float64; prices remain strings on the wire. Trade t is milliseconds; candle t is a seconds string; book a/b is [[price…],[qty…]].

WebSocket

Quotes

Business must match the symbol market. Connect blocks — run it in a goroutine. 60 frames per minute per connection. See WebSocket Limitation. Subscribe fail / 516 go to OnError and the same socket resubscribes; the previous socket is closed before reconnect; after this socket has seen ticks, about 90s of silence triggers another subscribe (StaleAfter is configurable).

ws, err := infoway.NewWebSocket(infoway.WSOptions{
    APIKey:   os.Getenv("INFOWAY_API_KEY"),
    Business: infoway.BusinessCrypto,
})
if err != nil {
    panic(err)
}
ws.OnTrade = func(data map[string]any) { fmt.Println(data["s"], data["p"]) }
ws.OnError = func(err error) { fmt.Fprintln(os.Stderr, err) }

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() { _ = ws.Connect(ctx) }()
ws.SubscribeTrade("BTCUSDT,ETHUSDT", false)
ws.SubscribeKline("BTCUSDT", infoway.KlineMin1)
ws.UnsubscribeKline("BTCUSDT", infoway.KlineMin1)
_ = ws.Close()

Equity trade types: SubscribeTrade(codes, true).

Behavior Description
Heartbeat 10010 every 30 seconds; server does not reply
Reconnect Replays the current subscription set
OnReconnect After a later successful open
OnDisconnect Unexpected drop only. Close() does not fire it
HTTP 401 Stops reconnecting
Dir Code Description
out 10000 / 10003 / 10006 Subscribe trade / depth / kline
out 11000 / 11001 / 11002 Unsubscribe
out 10010 Heartbeat
in 10002 / 10005 / 10008 Push
in 11010 Unsubscribe ack
in 200 Connected
News

wss://data.infoway.io/news requires a separate entitlement. One news connection per key.

news, err := infoway.NewNewsWebSocket(infoway.NewsOptions{
    APIKey: os.Getenv("INFOWAY_API_KEY"),
    Lang:   string(infoway.NewsZHHans),
})
if err != nil {
    panic(err)
}
news.OnNews = func(item map[string]any) { fmt.Println(item["title"]) }

Subscribe 10020, unsubscribe 11020, push 10022.

Error codes

REST uses ret. WebSocket uses code. 508–514 mean different things on each side. Full tables: REST API Error Codes and WebSocket Error Codes.

_, err := client.Stock.GetTrade(ctx, "INVALID")
switch e := err.(type) {
case *infoway.AuthError:
    fmt.Println(e.Msg)
case *infoway.RateLimitError:
    fmt.Println(e.Ret, e.Msg)
case *infoway.APIError:
    fmt.Println(e.Error(), e.TraceID)
}

REST budget is about 1200 calls/minute/key. An invalid key is *AuthError on REST; WebSocket handshake HTTP 401 does not reconnect.

REST ret Description
200 Success
400 Bad request
500 Server error
501 / 502 Rate limit
503 Candle count exceeded
505 Symbol count exceeded
506 / 507 Invalid / missing parameter
508 Symbol not found
509 Permission expired
513 Timestamp outside plan history
514 No permission
WebSocket code Description
501 / 502 Rate limit
505 / 516 Subscription count exceeded
506 / 507 Invalid / missing parameter
508–511 API key expired / invalid / empty / blacklisted
512 Connection count exceeded
513 Heartbeat timeout
515 Not JSON
517–521 Handshake failed

REST paths

{market} = stock / crypto / japan / india / korea / taiwan / common. Full list: Endpoints.

API Path
Latest trade GET /{market}/batch_trade/{codes}
Order book GET /{market}/batch_depth/{codes}
Candles POST /{market}/v2/batch_kline
Symbols / calendar / financials GET /common/basic/*
Overview / sectors / stock info GET /common/v2/basic/*
Package GET /package/info

License

MIT. API key: infoway.io.

Documentation

Overview

Package infoway is the official Go SDK for the Infoway real-time financial data API.

Index

Constants

View Source
const Version = "0.4.1"

Version is the SDK release version.

Variables

This section is empty.

Functions

func ClassifyRest added in v0.4.0

func ClassifyRest(ret int, msg string) int

ClassifyRest maps a wrapped ret=500 back to the business code carried in msg.

func IsSubscribeQuotaExceeded added in v0.4.1

func IsSubscribeQuotaExceeded(code int) bool

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

func IsTerminalWs(code int) bool

IsTerminalWs reports codes a reconnect cannot fix. 516 is recoverable.

func IsWsError

func IsWsError(code int) bool

IsWsError reports whether code is a gateway rejection (not a protocol frame).

func JoinMarkets

func JoinMarkets(markets ...Market) string

JoinMarkets joins market codes with commas.

func Ptr

func Ptr[T any](v T) *T

Ptr is a convenience for optional timestamp / paging values.

func RestErrorLabel

func RestErrorLabel(code int) string

RestErrorLabel returns the REST label, or "".

func RestErrorName

func RestErrorName(code int) string

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 WsErrorLabel

func WsErrorLabel(code int) string

WsErrorLabel returns the WS label, or "".

func WsErrorName

func WsErrorName(code int) string

WsErrorName returns the WS enum constant name, or "".

Types

type APIError

type APIError struct {
	Ret       int
	Msg       string
	TraceID   string
	ErrorName string
}

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

func OfHTTPStatus(status int, msg, traceID string) *APIError

OfHTTPStatus is a gateway / transport status. It must not look up RestErrorCode (HTTP 502 is not daily-quota 502).

func OfRest

func OfRest(ret int, msg, traceID string) *APIError

OfRest classifies a REST body ret/code with RestErrorCode.

func OfWS

func OfWS(ret int, msg, traceID string) *APIError

OfWS classifies a WebSocket error-frame code with WsErrorCode.

func (*APIError) Error

func (e *APIError) Error() string

type AuthError

type AuthError struct {
	*APIError
}

AuthError is HTTP / handshake 401.

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

func (b *Basic) GetMarkets(ctx context.Context) (any, error)

GetMarkets returns the per-market session table. Takes no parameters.

func (*Basic) GetStockDetail

func (b *Basic) GetStockDetail(ctx context.Context, typ SymbolType, symbol string) (any, error)

GetStockDetail is a single-name profile (logo, FIGI, ISIN, …).

func (*Basic) GetSymbolInfo

func (b *Basic) GetSymbolInfo(ctx context.Context, typ SymbolType, symbols string) (any, error)

GetSymbolInfo returns static fields for up to 500 codes.

func (*Basic) GetSymbols

func (b *Basic) GetSymbols(ctx context.Context, typ SymbolType, symbols string) (any, error)

GetSymbols lists instruments of one product type. symbols is optional.

func (*Basic) GetTradingDays

func (b *Basic) GetTradingDays(ctx context.Context, market, beginDay, endDay string) (any, error)

GetTradingDays returns trade_days / half_trade_days. Days are YYYYMMDD.

func (*Basic) GetTradingHours

func (b *Basic) GetTradingHours(ctx context.Context) (any, error)

GetTradingHours is a deprecated alias of GetTradingSchedule.

func (*Basic) GetTradingSchedule

func (b *Basic) GetTradingSchedule(ctx context.Context) (any, error)

GetTradingSchedule returns the full non-equity session table.

func (*Basic) GetTradingScheduleByType

func (b *Basic) GetTradingScheduleByType(ctx context.Context, typ string) (any, error)

GetTradingScheduleByType filters ENERGY/FOREX/FUTURES/METAL/INDICES. Equity types such as STOCK_US return an error before the request.

type Business

type Business string

Business is a quotes WebSocket channel.

const (
	BusinessStock  Business = "stock"
	BusinessJapan  Business = "japan"
	BusinessIndia  Business = "india"
	BusinessKorea  Business = "korea"
	BusinessTaiwan Business = "taiwan"
	BusinessCrypto Business = "crypto"
	BusinessCommon Business = "common"
)

func (Business) String

func (b Business) String() string

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.

func New

func New(opts Options) *Client

New builds a REST client. APIKey falls back to INFOWAY_API_KEY.

func (*Client) Close

func (c *Client) Close()

Close rejects later calls and releases idle HTTP connections.

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 (f *Financial) GetDividendPayout(ctx context.Context, symbol string, typ SymbolType) (any, error)

func (*Financial) GetEarningStatus

func (f *Financial) GetEarningStatus(ctx context.Context, symbol string, typ SymbolType) (any, error)

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 IOError

type IOError struct {
	Msg   string
	Cause error
}

IOError is a network failure after retries are exhausted.

func (*IOError) Error

func (e *IOError) Error() string

func (*IOError) Unwrap

func (e *IOError) Unwrap() 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 Lang

type Lang string

Lang is REST language for name-like fields.

const (
	LangEN   Lang = "en"
	LangZHCN Lang = "zh-CN"
)

func (Lang) String

func (l Lang) String() string

type Market

type Market string

Market is an equity market code.

const (
	MarketHK Market = "HK"
	MarketUS Market = "US"
	MarketCN Market = "CN"
	MarketJP Market = "JP"
	MarketKS Market = "KS"
	MarketTW Market = "TW"
	MarketIN Market = "IN"
)

func (Market) String

func (m Market) String() string

type MarketClient

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

MarketClient is temperature, breadth, turnover, ranks and commentary.

func (*MarketClient) GetBreadth

func (m *MarketClient) GetBreadth(ctx context.Context, market, lang string) (any, error)

func (*MarketClient) GetIndexes

func (m *MarketClient) GetIndexes(ctx context.Context, lang string) (any, error)

func (*MarketClient) GetLeaders

func (m *MarketClient) GetLeaders(ctx context.Context, market string, limit int, lang string) (any, error)

func (*MarketClient) GetOverview

func (m *MarketClient) GetOverview(ctx context.Context, market, lang string) (any, error)

func (*MarketClient) GetRank

func (m *MarketClient) GetRank(ctx context.Context, market, key string, opts *RankOptions) (any, error)

func (*MarketClient) GetRankCategories

func (m *MarketClient) GetRankCategories(ctx context.Context, market, lang string) (any, error)

func (*MarketClient) GetRankConfig

func (m *MarketClient) GetRankConfig(ctx context.Context, market string) (any, error)

GetRankConfig is deprecated: the path returns HTTP 404.

func (*MarketClient) GetTemperature

func (m *MarketClient) GetTemperature(ctx context.Context, market, lang string) (any, error)

GetTemperature defaults market to HK,US,CN when market is empty.

func (*MarketClient) GetTurnover

func (m *MarketClient) GetTurnover(ctx context.Context, market, lang string) (any, error)

type MarketData

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

MarketData is trade / depth / kline for one market prefix.

func (*MarketData) GetDepth

func (m *MarketData) GetDepth(ctx context.Context, codes string) (any, error)

GetDepth returns the transposed order book (a/b columns).

func (*MarketData) GetKline

func (m *MarketData) GetKline(ctx context.Context, codes string, klineType KlineType, count int, timestamp *int64) (any, error)

GetKline returns candles. timestamp is unix seconds for minute/hour bars; nil is latest.

func (*MarketData) GetTrade

func (m *MarketData) GetTrade(ctx context.Context, codes string) (any, error)

GetTrade returns real-time trades for comma-separated codes such as AAPL.US, 00700.HK, 7203.JP and RELIANCE.IN. Japan is .JP, not Yahoo .T. India is .IN, not Yahoo .NS. Those return 508.

type NewsLang

type NewsLang string

NewsLang is a news-channel language.

const (
	NewsEN     NewsLang = "en"
	NewsZHHans NewsLang = "zh-Hans"
	NewsZHHant NewsLang = "zh-Hant"
	NewsJA     NewsLang = "ja"
	NewsKO     NewsLang = "ko"
	NewsDE     NewsLang = "de"
	NewsFR     NewsLang = "fr"
	NewsES     NewsLang = "es"
	NewsPT     NewsLang = "pt"
	NewsRU     NewsLang = "ru"
	NewsTR     NewsLang = "tr"
)

func (NewsLang) String

func (l NewsLang) String() string

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

func (n *NewsWebSocket) Connect(ctx context.Context) error

func (*NewsWebSocket) Subscribe

func (n *NewsWebSocket) Subscribe(lang string)

func (*NewsWebSocket) Unsubscribe

func (n *NewsWebSocket) Unsubscribe()

type Options

type Options struct {
	APIKey     string
	BaseURL    string
	Timeout    time.Duration
	MaxRetries int
}

Options configures a Client.

type Packages

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

Packages is quota for the current API key.

func (*Packages) GetInfo

func (p *Packages) GetInfo(ctx context.Context) (any, error)

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

func (p *Plate) GetChart(ctx context.Context, market string, limit int) (any, error)

func (*Plate) GetConcept

func (p *Plate) GetConcept(ctx context.Context, market string, limit int) (any, error)

func (*Plate) GetIndustry

func (p *Plate) GetIndustry(ctx context.Context, market string, limit int) (any, error)

func (*Plate) GetIntro

func (p *Plate) GetIntro(ctx context.Context, plateSymbol string) (any, error)

func (*Plate) GetMembers

func (p *Plate) GetMembers(ctx context.Context, plateSymbol string, offset, limit int) (any, error)

type RankOptions

type RankOptions struct {
	Sort   string
	Order  string
	Limit  int
	Offset int
	Lang   string
}

RankOptions is optional paging for GetRank.

type RankSort

type RankSort string

RankSort is a rank-board sort key.

const (
	RankSortChg RankSort = "chg"
)

func (RankSort) String

func (s RankSort) String() string

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 SortOrder

type SortOrder string

SortOrder is asc/desc.

const (
	SortDesc SortOrder = "desc"
	SortAsc  SortOrder = "asc"
)

func (SortOrder) String

func (s SortOrder) String() string

type StockInfo

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

StockInfo is valuation, ratings, company overview and events.

func (*StockInfo) GetCompany

func (s *StockInfo) GetCompany(ctx context.Context, symbol, lang string) (any, error)

func (*StockInfo) GetConcepts

func (s *StockInfo) GetConcepts(ctx context.Context, symbol, lang string) (any, error)

func (*StockInfo) GetDrivers

func (s *StockInfo) GetDrivers(ctx context.Context, symbol, lang string) (any, error)

func (*StockInfo) GetEvents

func (s *StockInfo) GetEvents(ctx context.Context, symbol string, limit int, lang string) (any, error)

func (*StockInfo) GetPanorama

func (s *StockInfo) GetPanorama(ctx context.Context, symbol, lang string) (any, error)

func (*StockInfo) GetRatings

func (s *StockInfo) GetRatings(ctx context.Context, symbol, lang string) (any, error)

func (*StockInfo) GetValuation

func (s *StockInfo) GetValuation(ctx context.Context, symbol, lang string) (any, error)

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

func NewWebSocket(opts WSOptions) (*WebSocket, error)

NewWebSocket requires APIKey (or INFOWAY_API_KEY) and Business.

func (*WebSocket) Close

func (w *WebSocket) Close() error

Close stops reconnect and closes the socket.

func (*WebSocket) Connect

func (w *WebSocket) Connect(ctx context.Context) error

Connect runs the read loop until ctx is cancelled, Close is called, or a 401 handshake.

func (*WebSocket) SubscribeDepth

func (w *WebSocket) SubscribeDepth(codes string)

func (*WebSocket) SubscribeKline

func (w *WebSocket) SubscribeKline(codes string, klineType KlineType)

func (*WebSocket) SubscribeTrade

func (w *WebSocket) SubscribeTrade(codes string, includeTy bool)

SubscribeTrade records codes and sends 10000 when the socket is open.

func (*WebSocket) UnsubscribeDepth

func (w *WebSocket) UnsubscribeDepth(codes string)

func (*WebSocket) UnsubscribeKline

func (w *WebSocket) UnsubscribeKline(codes string, klineType KlineType)

func (*WebSocket) UnsubscribeTrade

func (w *WebSocket) UnsubscribeTrade(codes string)

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
)

Jump to

Keyboard shortcuts

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