quote

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: Apache-2.0, MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// SubType
	SubTypeUnknown SubType = SubType(quotev1.SubType_UNKNOWN_TYPE)
	SubTypeQuote   SubType = SubType(quotev1.SubType_QUOTE)
	SubTypeDepth   SubType = SubType(quotev1.SubType_DEPTH)
	SubTypeBrokers SubType = SubType(quotev1.SubType_BROKERS)
	SubTypeTrade   SubType = SubType(quotev1.SubType_TRADE)

	// SubEvent
	EventQuote EventType = iota
	EventBroker
	EventTrade
	EventDepth

	// Period
	PeriodOneMinute     = Period(quotev1.Period_ONE_MINUTE)
	PeriodFiveMinute    = Period(quotev1.Period_FIVE_MINUTE)
	PeriodFifteenMinute = Period(quotev1.Period_FIFTEEN_MINUTE)
	PeriodThirtyMinute  = Period(quotev1.Period_THIRTY_MINUTE)
	PeriodSixtyMinute   = Period(quotev1.Period_SIXTY_MINUTE)
	PeriodDay           = Period(quotev1.Period_DAY)
	PeriodWeek          = Period(quotev1.Period_WEEK)
	PeriodMonth         = Period(quotev1.Period_MONTH)
	PeriodYear          = Period(quotev1.Period_YEAR)

	// AdjustType
	AdjustTypeNo      = AdjustType(quotev1.AdjustType_NO_ADJUST)
	AdjustTypeForward = AdjustType(quotev1.AdjustType_FORWARD_ADJUST)

	// TradeSession
	TradeSessionNormal    = TradeSession(quotev1.TradeSession_NORMAL_TRADE)
	TradeSessionPreTrade  = TradeSession(quotev1.TradeSession_PRE_TRADE)
	TradeSessionPostTrade = TradeSession(quotev1.TradeSession_POST_TRADE)
	TradeSessionOvernight = TradeSession(quotev1.TradeSession_OVERNIGHT_TRADE)

	// CandlestickTradeSessionNormal includes normal trade session
	CandlestickTradeSessionNormal = CandlestickTradeSession(0)
	// CandlestickTradeSessionAll includes all trade sessions
	CandlestickTradeSessionAll = CandlestickTradeSession(100)

	// CalcIndex
	CalcIndexUnknown               CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_UNKNOWN)
	CalcIndexLastDone              CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_LAST_DONE)
	CalcIndexChangeVal             CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_CHANGE_VAL)
	CalcIndexChangeRate            CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_CHANGE_RATE)
	CalcIndexVolume                CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_VOLUME)
	CalcIndexTurnover              CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_TURNOVER)
	CalcIndexYtdChangeRate         CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_YTD_CHANGE_RATE)
	CalcIndexTurnoverRate          CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_TURNOVER_RATE)
	CalcIndexTotalMarketValue      CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_TOTAL_MARKET_VALUE)
	CalcIndexCapitalFlow           CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_CAPITAL_FLOW)
	CalcIndexAmplitude             CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_AMPLITUDE)
	CalcIndexVolumeRatio           CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_VOLUME_RATIO)
	CalcIndexPeTTMRatio            CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_PE_TTM_RATIO)
	CalcIndexPbRatio               CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_PB_RATIO)
	CalcIndexDividendRatioTTM      CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_DIVIDEND_RATIO_TTM)
	CalcIndexFiveDayChangeRate     CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_FIVE_DAY_CHANGE_RATE)
	CalcIndexTenDayChangeRate      CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_TEN_DAY_CHANGE_RATE)
	CalcIndexHalfYearChangeRate    CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_HALF_YEAR_CHANGE_RATE)
	CalcIndexFiveMinutesChangeRate CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_FIVE_MINUTES_CHANGE_RATE)
	CalcIndexExpiryDate            CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_EXPIRY_DATE)
	CalcIndexStrikePrice           CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_STRIKE_PRICE)
	CalcIndexUpperStrikePrice      CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_UPPER_STRIKE_PRICE)
	CalcIndexLowerStrikePrice      CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_LOWER_STRIKE_PRICE)
	CalcIndexOutstandingQTY        CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_OUTSTANDING_QTY)
	CalcIndexOutstandingRatio      CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_OUTSTANDING_RATIO)
	CalcIndexPremium               CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_PREMIUM)
	CalcIndexItmOtm                CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_ITM_OTM)
	CalcIndexImpliedVolatility     CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_IMPLIED_VOLATILITY)
	CalcIndexWarrantDelta          CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_WARRANT_DELTA)
	CalcIndexCallPrice             CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_CALL_PRICE)
	CalcIndexToCallPrice           CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_TO_CALL_PRICE)
	CalcIndexEffectiveLeverage     CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_EFFECTIVE_LEVERAGE)
	CalcIndexLeverageRatio         CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_LEVERAGE_RATIO)
	CalcIndexConversionRatio       CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_CONVERSION_RATIO)
	CalcIndexBalancePoint          CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_BALANCE_POINT)
	CalcIndexOpenInterest          CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_OPEN_INTEREST)
	CalcIndexDELTA                 CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_DELTA)
	CalcIndexGAMMA                 CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_GAMMA)
	CalcIndexTHETA                 CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_THETA)
	CalcIndexVEGA                  CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_VEGA)
	CalcIndexRHO                   CalcIndex = CalcIndex(quotev1.CalcIndex_CALCINDEX_RHO)
)
View Source
const (
	DefaultQuoteUrl = "wss://openapi-quote.longportapp.com/v2"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AdjustType

type AdjustType int32

type Brokers

type Brokers struct {
	Position  int32
	BrokerIds []int32
}

type BrokersData

type BrokersData struct {
	Sequence   int64
	AskBrokers []*Brokers
	BidBrokers []*Brokers
}

type CalcIndex

type CalcIndex int32

type Candlestick

type Candlestick struct {
	Close     *decimal.Decimal
	Open      *decimal.Decimal
	Low       *decimal.Decimal
	High      *decimal.Decimal
	Volume    int64
	Turnover  *decimal.Decimal
	Timestamp int64
}

Candlestick is candlestick details

type CandlestickRequestOption added in v0.17.0

type CandlestickRequestOption func(*quotev1.SecurityHistoryCandlestickRequest)

CandlestickRequestOption is the option for the candlestick request

func CandlestickRequestTradeSession added in v0.17.0

func CandlestickRequestTradeSession(session CandlestickTradeSession) CandlestickRequestOption

CandlestickRequestTradeSession sets the trade session of the candlestick request

type CandlestickTradeSession added in v0.17.1

type CandlestickTradeSession int32

type Capital

type Capital struct {
	Large  *decimal.Decimal
	Medium *decimal.Decimal
	Small  *decimal.Decimal
}

Capital infomartion

type CapitalDistribution

type CapitalDistribution struct {
	Symbol     string
	Timestamp  int64   // data update timestamp
	CapitalIn  Capital // inflow capital data
	CapitalOut Capital // outflow capital data
}

CapitalDistribution information

type CapitalFlowLine

type CapitalFlowLine struct {
	Inflow    *decimal.Decimal
	Timestamp int64
}

CapitalFlowLine

type Depth

type Depth struct {
	Position int32
	Price    *decimal.Decimal
	Volume   int64
	OrderNum int64
}

Depth store depth details

type DepthData

type DepthData struct {
	Sequence int64
	Ask      []*Depth
	Bid      []*Depth
}

type EventType

type EventType int8

type IntradayLine

type IntradayLine struct {
	Price     *decimal.Decimal
	Timestamp int64
	Volume    int64
	Turnover  *decimal.Decimal
	AvgPrice  *decimal.Decimal
}

IntradayLine is k line

type Issuer

type Issuer struct {
	ID     int32
	NameCn string
	NameEn string
	NameHk string
}

Issuer to save issuer id

type IssuerInfo

type IssuerInfo struct {
	Id     int32
	NameCn string
	NameEn string
	NameHk string
}

IssuerInfo is issuer infomation

type MarketPackageDetail added in v0.16.0

type MarketPackageDetail struct {
	MarketCode string
	Limit      int32
	Burst      int32
}

type MarketTradingDay

type MarketTradingDay struct {
	TradeDay     []time.Time
	HalfTradeDay []time.Time
}

MarketTradingDay contains market open trade days

type MarketTradingSession

type MarketTradingSession struct {
	Market       openapi.Market
	TradeSession []*TradePeriod
}

MarketTradingSession is market's session details

type Option

type Option func(*Options)

Option for quote context

func OnReconnect added in v0.16.2

func OnReconnect(fn func(successResub bool)) Option

OnReconnect to set reconnect callbacks for quote context

func WithEnableOvernight added in v0.13.0

func WithEnableOvernight(enable bool) Option

WithEnableOvernight to set enable overnight for quote context

func WithHttpClient

func WithHttpClient(client *http.Client) Option

WithHttpClient to set http client for quote context

func WithLanguage added in v0.16.0

func WithLanguage(language openapi.Language) Option

WithLanguage to set language for quote context

func WithLbOptions

func WithLbOptions(opts *longbridge.Options) Option

WithLbOptions to set longbridge options for quote context

func WithLogLevel

func WithLogLevel(level string) Option

WithLogLevel to set log level for quote context

func WithLogger

func WithLogger(l log.Logger) Option

WithLogger to set logger for quote context

func WithQuoteURL

func WithQuoteURL(url string) Option

WithQuoteURL to set url for quote context

type OptionExtend

type OptionExtend struct {
	ImpliedVolatility    string
	OpenInterest         int64
	ExpiryDate           string // YYMMDD
	StrikePrice          *decimal.Decimal
	ContractMultiplier   string
	ContractType         string
	ContractSize         string
	Direction            string
	HistoricalVolatility string
	UnderlyingSymbol     string
}

OptionExtend is option extended properties

type OptionQuote

type OptionQuote struct {
	Symbol       string
	LastDone     *decimal.Decimal
	PrevClose    *decimal.Decimal
	Open         *decimal.Decimal
	High         *decimal.Decimal
	Low          *decimal.Decimal
	Timestamp    int64
	Volume       int64
	Turnover     *decimal.Decimal
	TradeStatus  TradeStatus
	OptionExtend *OptionExtend
}

OptionQuote to option quote details

type Options

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

Options for quote context

type PackageDetail added in v0.16.0

type PackageDetail struct {
	PackageKey string
	Limit      int32
	Burst      int32
}

type ParticipantInfo

type ParticipantInfo struct {
	BrokerIds         []int32
	ParticipantNameCn string
	ParticipantNameEn string
	ParticipantNameHk string
}

ParticipantInfo has all participant brokers

type Period

type Period int32

type PrePostQuote

type PrePostQuote struct {
	LastDone  *decimal.Decimal
	Timestamp int64
	Volume    int64
	Turnover  *decimal.Decimal
	High      *decimal.Decimal
	Low       *decimal.Decimal
	PrevClose *decimal.Decimal
}

PrePostQuote is pre or post quote details

type PushBrokers

type PushBrokers struct {
	Symbol     string
	Sequence   int64
	AskBrokers []*Brokers
	BidBrokers []*Brokers
}

PushBrokers is brokers info push from server

type PushDepth

type PushDepth struct {
	Symbol   string
	Sequence int64
	Ask      []*Depth
	Bid      []*Depth
}

PushDepth is depth info push from server

type PushQuote

type PushQuote struct {
	Symbol       string
	Sequence     int64
	LastDone     *decimal.Decimal
	Open         *decimal.Decimal
	High         *decimal.Decimal
	Low          *decimal.Decimal
	Timestamp    int64
	Volume       int64
	Turnover     *decimal.Decimal
	TradeStatus  TradeStatus
	TradeSession TradeSessionType
}

PushQuote is quote info push from server

type PushTrade

type PushTrade struct {
	Symbol   string
	Sequence int64
	Trade    []*Trade
}

PushTrade is trade info push from server

type Quote

type Quote struct {
	Symbol       string
	LastDone     *decimal.Decimal
	Open         *decimal.Decimal
	High         *decimal.Decimal
	Low          *decimal.Decimal
	Timestamp    int64
	Volume       int64
	Turnover     *decimal.Decimal
	TradeStatus  TradeStatus
	TradeSession TradeSessionType
}

Quote is quote details

type QuoteContext

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

func New

func New(opt ...Option) (*QuoteContext, error)

New return QuoteContext with option. A connection will be created with quote server.

func NewFormEnv deprecated

func NewFormEnv() (*QuoteContext, error)

Deprecated: NewFromEnv return QuoteContext, use NewFromCfg plz

func NewFromCfg

func NewFromCfg(cfg *config.Config) (*QuoteContext, error)

NewFromCfg return QuoteContext with config.Config

func (*QuoteContext) Brokers

func (c *QuoteContext) Brokers(ctx context.Context, symbol string) (securityBrokers *SecurityBrokers, err error)

Brokers obtain the real-time broker queue data of security. Reference: https://open.longportapp.com/en/docs/quote/pull/brokers

Example:

qctx, err := quote.NewFromEnv()
brokers, err := qctx.Brokers(context.Background(), "AAPL.HK")

func (*QuoteContext) CalcIndex

func (c *QuoteContext) CalcIndex(ctx context.Context, symbols []string, indexes []CalcIndex) (calcIndexes []*SecurityCalcIndex, err error)

CalcIndex is used to obtain the calculate indexes of securities. Reference: https://open.longportapp.com/en/docs/quote/pull/calc-index

Example:

qctx, err := quote.NewFromEnv()
flowlines, err := qctx.CapitalFlow(context.Background(), "700.HK")

func (*QuoteContext) Candlesticks

func (c *QuoteContext) Candlesticks(ctx context.Context, symbol string, period Period, count int32, adjustType AdjustType) (sticks []*Candlestick, err error)

Candlesticks obtain the candlestick data of security. Reference: https://open.longportapp.com/en/docs/quote/pull/candlestick periond support values:

  • quote.PeriodOneMinute - 1m
  • quote.PeriodFiveMinute - 5m
  • quote.PeriodFifteenMinute - 15m
  • quote.PeriodThirtyMinute - 40m
  • quote.PeriodDay - 1 day
  • quote.PeriodWeek - 1 week
  • quote.PeriodMonth - 1 month
  • quote.PeriodYear - 1 year

adjustType support values:

  • quote.AdjustTypeNo
  • quote.AdjustTypeForward

Example:

qctx, err := quote.NewFromEnv()
klines, err := qctx.Candlesticks(context.Background(), "AAPL.US", quote.PeriodDay, 10, quote.AdjustTypeNo)

func (*QuoteContext) CapitalDistribution

func (c *QuoteContext) CapitalDistribution(ctx context.Context, symbol string) (capitalDib CapitalDistribution, err error)

CapitalDistribution is used to obtain the daily capital distribution of security. Reference: https://open.longportapp.com/en/docs/quote/pull/capital-distribution

Example:

qctx, err := quote.NewFromEnv()
dist, err := qctx.CapitalDistribution(context.Background(), "700.HK")

func (*QuoteContext) CapitalFlow

func (c *QuoteContext) CapitalFlow(ctx context.Context, symbol string) (capitalFlowLines []CapitalFlowLine, err error)

CapitalFlow is used to obtain the daily capital flow intraday of security. Reference: https://open.longportapp.com/en/docs/quote/pull/capital-flow-intraday

Example:

qctx, err := quote.NewFromEnv()
flowlines, err := qctx.CapitalFlow(context.Background(), "700.HK")

func (*QuoteContext) Close

func (c *QuoteContext) Close() error

Close

func (*QuoteContext) CreateWatchlistGroup added in v0.12.0

func (c *QuoteContext) CreateWatchlistGroup(ctx context.Context, name string, symbols []string) (gid int64, err error)

CreateWatchlistGroup use to create watchlist group. Doc: https://open.longportapp.com/en/docs/quote/individual/watchlist_create_group

Example:

qctx, err := quote.NewFromCfg(conf)
// handle error
err = qctx.CreateWatchlistGroup(context.Background(), "test", []string{"AAPL.US"})
qctx, err := quote.NewFromCfg(conf)
// ignore handle error
err = qctx.CreateWatchlistGroup(context.Background(), "test", []string{"AAPL.US"})

func (*QuoteContext) DeleteWatchlistGroup added in v0.12.0

func (c *QuoteContext) DeleteWatchlistGroup(ctx context.Context, id int64, purge bool) (err error)

func (*QuoteContext) Depth

func (c *QuoteContext) Depth(ctx context.Context, symbol string) (securityDepth *SecurityDepth, err error)

Depth obtain the depth data of security. Reference: https://open.longportapp.com/en/docs/quote/pull/depth

Example:

qctx, err := quote.NewFromEnv()
depth, err := qctx.Depth(context.Background(), []string{"AAPL.HK"})

func (*QuoteContext) HistoryCandlesticksByDate added in v0.13.0

func (c *QuoteContext) HistoryCandlesticksByDate(ctx context.Context, symbol string, period Period, adjustType AdjustType, startDate *time.Time, endDate *time.Time, opts ...CandlestickRequestOption) (sticks []*Candlestick, err error)

HistoryCandlesticksByOffset obtains the history candlestick data of security after or before an offset time. Reference: https://open.longportapp.com/en/docs/quote/pull/history-candlestick periond support values:

  • quote.PeriodOneMinute - 1m
  • quote.PeriodFiveMinute - 5m
  • quote.PeriodFifteenMinute - 15m
  • quote.PeriodThirtyMinute - 40m
  • quote.PeriodDay - 1 day
  • quote.PeriodWeek - 1 week
  • quote.PeriodMonth - 1 month
  • quote.PeriodYear - 1 year

adjustType support values:

  • quote.AdjustTypeNo
  • quote.AdjustTypeForward

Example:

qctx, err := quote.NewFromEnv()
startDate := time.Date(2022, 5, 10, 0, 0, 0, 0, time.UTC)
endDate := time.Date(2022, 6, 10, 0, 0, 0, 0, time.UTC)
klines, err := qctx.HistoryCandlesticksByDate(context.Background(), "AAPL.US", quote.PeriodDay, quote.AdjustTypeNo, &startDate, &endDate)

func (*QuoteContext) HistoryCandlesticksByOffset added in v0.13.0

func (c *QuoteContext) HistoryCandlesticksByOffset(ctx context.Context, symbol string, period Period, adjustType AdjustType, isForward bool, dateTime *time.Time, count int32, opts ...CandlestickRequestOption) (sticks []*Candlestick, err error)

HistoryCandlesticksByDate obtains the history candlestick data of security within a date range. Reference: https://open.longportapp.com/en/docs/quote/pull/history-candlestick periond support values:

  • quote.PeriodOneMinute - 1m
  • quote.PeriodFiveMinute - 5m
  • quote.PeriodFifteenMinute - 15m
  • quote.PeriodThirtyMinute - 40m
  • quote.PeriodDay - 1 day
  • quote.PeriodWeek - 1 week
  • quote.PeriodMonth - 1 month
  • quote.PeriodYear - 1 year

adjustType support values:

  • quote.AdjustTypeNo
  • quote.AdjustTypeForward

Example:

qctx, err := quote.NewFromEnv()
dateTime := time.Date(2022, 5, 10, 11, 10, 0, 0, time.UTC)
klines, err := qctx.HistoryCandlesticksByOffset(context.Background(), "AAPL.US", quote.PeriodDay, quote.AdjustTypeNo, true, &dateTime, 100)

func (*QuoteContext) Intraday

func (c *QuoteContext) Intraday(ctx context.Context, symbol string) (lines []*IntradayLine, err error)

Intraday obtain the intraday data of security. Reference: https://open.longportapp.com/en/docs/quote/pull/intraday Example:

qctx, err := quote.NewFromEnv()
trades, err := qctx.Intraday(context.Background(), "AAPL.US")

func (*QuoteContext) OnBrokers

func (c *QuoteContext) OnBrokers(f func(*PushBrokers))

OnBrokers set callback function which will be called when server push brokers events.

func (*QuoteContext) OnDepth

func (c *QuoteContext) OnDepth(f func(*PushDepth))

OnDepth set callback function which will be called when server push depth events.

func (*QuoteContext) OnQuote

func (c *QuoteContext) OnQuote(f func(*PushQuote))

OnQuote set callback function which will be called when server push quote events.

func (*QuoteContext) OnTrade

func (c *QuoteContext) OnTrade(f func(*PushTrade))

OnTrade set callback function which will be called when server push trade events.

func (*QuoteContext) OptionChainExpiryDateList

func (c *QuoteContext) OptionChainExpiryDateList(ctx context.Context, symbol string) (times []time.Time, err error)

OptionChainExpiryDateList obtain the the list of expiration dates of option chain Reference: https://open.longportapp.com/en/docs/quote/pull/optionchain-date

Example:

qctx, err := quote.NewFromEnv()
list, err := qctx.OptionChainExpiryDateList(context.Background(), "AAPL.US")

func (*QuoteContext) OptionChainInfoByDate

func (c *QuoteContext) OptionChainInfoByDate(ctx context.Context, symbol string, expiryDate *time.Time) (strikePriceInfos []*StrikePriceInfo, err error)

OptionChainInfoByDate obtain a list of option securities by the option chain expiry date. Reference: https://open.longportapp.com/en/docs/quote/pull/optionchain-date-strike

Example:

qctx, err := quote.NewFromEnv()
date := time.Date(2022, 5, 10, 0, 0, 0, 0, time.UTC)
list, err := qctx.OptionChainInfoByDate(context.Background(), "AAPL.US", &date)

func (*QuoteContext) OptionQuote

func (c *QuoteContext) OptionQuote(ctx context.Context, symbols []string) (optionQuotes []*OptionQuote, err error)

OptionQuote obtain the real-time quotes of US stock options, including the option-specific data. Reference: https://open.longportapp.com/en/docs/quote/pull/option-quote

Example:

qctx, err := quote.NewFromEnv()
optionQuotes, err := qctx.OptionQuote(context.Background(), []string{"AAPL240531P192500.US"})

func (*QuoteContext) Participants

func (c *QuoteContext) Participants(ctx context.Context) (infos []*ParticipantInfo, err error)

Participants obtain participant IDs data (which can be synchronized once a day). Reference: https://open.longportapp.com/en/docs/quote/pull/broker-ids

Example:

qctx, err := quote.NewFromEnv()
participants, err := qctx.Participants(context.Background())

func (*QuoteContext) Profile added in v0.16.0

func (c *QuoteContext) Profile() *UserProfile

Profile obtain the user quote profile

func (*QuoteContext) Quote

func (c *QuoteContext) Quote(ctx context.Context, symbols []string) (quotes []*SecurityQuote, err error)

Quote obtain the real-time quotes of securities, and supports all types of securities. Reference: https://open.longportapp.com/en/docs/quote/pull/quote

Example:

qctx, err := quote.NewFromEnv()
quotes, err := qctx.Quote(context.Background(), []string{"AAPL.US"})

func (*QuoteContext) RealtimeBrokers

func (c *QuoteContext) RealtimeBrokers(ctx context.Context, symbol string) (*SecurityBrokers, error)

RealtimeBrokers to get broker infomations on local store

Example:

qctx, err := quote.NewFromEnv()
brokers, err := qctx.RealtimeBrokers(context.Background(), "700.HK")

func (*QuoteContext) RealtimeDepth

func (c *QuoteContext) RealtimeDepth(ctx context.Context, symbol string) (*SecurityDepth, error)

RealtimeDepth to get depth infomations on local store

Example:

qctx, err := quote.NewFromEnv()
depth, err := qctx.RealtimeDepth(context.Background(), "700.HK")

func (*QuoteContext) RealtimeQuote

func (c *QuoteContext) RealtimeQuote(ctx context.Context, symbols []string) ([]*Quote, error)

RealtimeQuote to get quote infomations on local store

Example:

qctx, err := quote.NewFromEnv()
flowlines, err := qctx.RealtimeQuote(context.Background(), []string{"700.HK", "9988.HK"})

func (*QuoteContext) RealtimeTrades

func (c *QuoteContext) RealtimeTrades(ctx context.Context, symbol string) ([]*Trade, error)

RealtimeTrades to get trade infomations on local store

Example:

qctx, err := quote.NewFromEnv()
trades, err := qctx.RealtimeTrades(context.Background(), "700.HK")

func (*QuoteContext) SecurityList added in v0.12.0

func (c *QuoteContext) SecurityList(ctx context.Context, market openapi.Market, category SecurityListCategory) (list []*Security, err error)

SecurityList used to list securities. Doc: https://open.longportapp.com/en/docs/quote/security/security_list

func (*QuoteContext) StaticInfo

func (c *QuoteContext) StaticInfo(ctx context.Context, symbols []string) (staticInfos []*StaticInfo, err error)

func (*QuoteContext) Subscribe

func (c *QuoteContext) Subscribe(ctx context.Context, symbols []string, subTypes []SubType, isFirstPush bool) (err error)

Subscribe quote Reference: https://open.longportapp.com/en/docs/quote/subscribe/subscribe

func (*QuoteContext) Subscriptions

func (c *QuoteContext) Subscriptions(ctx context.Context) (subscriptions map[string][]SubType, err error)

Subscriptions obtain the subscription information. Reference: https://open.longportapp.com/en/docs/quote/subscribe/subscription

Example:

qctx, err := quote.NewFromEnv()
subs, err := qctx.Subscriptions(context.Background())

func (*QuoteContext) Trades

func (c *QuoteContext) Trades(ctx context.Context, symbol string, count int32) (trades []*Trade, err error)

Trades obtain the trades data of security. Reference: https://open.longportapp.com/en/docs/quote/pull/trade

Example:

qctx, err := quote.NewFromEnv()
trades, err := qctx.Trades(context.Background())

func (*QuoteContext) TradingDays

func (c *QuoteContext) TradingDays(ctx context.Context, market openapi.Market, begin *time.Time, end *time.Time) (days *MarketTradingDay, err error)

TradingDays obtain the trading days of the market. Reference: https://open.longportapp.com/en/docs/quote/pull/trade-day

Example:

qctx, err := quote.NewFromEnv()
begin := time.Date(2024, 5, 1, 0, 0, 0, 0, time.UTC)
end := time.Date(2024, 6, 1, 0, 0, 0, 0, time.UTC)
days, err := qctx.TradingDays(context.Background(), openapi.MarketUS, &begin, &end)

func (*QuoteContext) TradingSession

func (c *QuoteContext) TradingSession(ctx context.Context) (sessions []*MarketTradingSession, err error)

TradingSession obtain the daily trading hours of each market. Reference: https://open.longportapp.com/en/docs/quote/pull/trade-session

Example:

qctx, err := quote.NewFromEnv()
sess, err := qctx.TradingSession(context.Background())

func (*QuoteContext) Unsubscribe

func (c *QuoteContext) Unsubscribe(ctx context.Context, unSubAll bool, symbols []string, subTypes []SubType) (err error)

Unsubscribe quote Reference: https://open.longportapp.com/en/docs/quote/subscribe/unsubscribe

func (*QuoteContext) UpdateWatchlistGroup added in v0.12.0

func (c *QuoteContext) UpdateWatchlistGroup(ctx context.Context, id int64, name string, symbols []string, mode WatchlistUpdateMode) (err error)

func (*QuoteContext) WarrantIssuers

func (c *QuoteContext) WarrantIssuers(ctx context.Context) (infos []*IssuerInfo, err error)

WarrantIssuers obtain the warrant issuer IDs data (which can be synchronized once a day). Reference: https://open.longportapp.com/en/docs/quote/pull/issuer

Example:

qctx, err := quote.NewFromEnv()
infos, err := qctx.WarrantIssuers(context.Background())

func (*QuoteContext) WarrantList added in v0.10.0

func (c *QuoteContext) WarrantList(ctx context.Context, symbol string, config WarrantFilter, lang WarrantLanguage) (infos []*WarrantInfo, err error)

WarrantIssuers obtain the quotes of HK warrants, and supports sorting and filtering. Reference: https://open.longportapp.com/en/docs/quote/pull/warrant-filter

Example:

qctx, err := quote.NewFromEnv()
list, err := qctx.WarrantList(context.Background(), "9988.HK", quote.WarrantFilter{
  SortBy: quote.WarrantLastDone,
  SortOrder quote.WarrantAsc,
  SortOffset: 0,
  SortCount: 20,
  Type: []quote.WarrantType{quote.WarrantCall, quote.WarrantPut},
}, quote. WarrantZH_CN)

func (*QuoteContext) WarrantQuote

func (c *QuoteContext) WarrantQuote(ctx context.Context, symbols []string) (warrantQuotes []*WarrantQuote, err error)

WarrantQuote obtain the real-time quotes of HK warrants, including the warrant-specific data. Reference: https://open.longportapp.com/en/docs/quote/pull/warrant-quote

Example:

qctx, err := quote.NewFromEnv()
warrantQuotes, err := qctx.WarrantQuote(context.Background(), []string{"9988.HK"})

func (*QuoteContext) WatchedGroups

func (c *QuoteContext) WatchedGroups(ctx context.Context) (groupList []*WatchedGroup, err error)

type QuoteData

type QuoteData struct {
	Sequence int64
	Quote    *PushQuote
}

type RateLimit added in v0.16.0

type RateLimit struct {
	Cmd   uint32
	Limit int32
	Burst int32
}

type Security added in v0.12.0

type Security = jsontypes.Security

Security is base info contains symbol and name

type SecurityBrokers

type SecurityBrokers struct {
	Symbol     string
	AskBrokers []*Brokers
	BidBrokers []*Brokers
}

SecurityBrokers is security brokers details

type SecurityCalcIndex

type SecurityCalcIndex struct {
	Symbol                string
	LastDone              *decimal.Decimal
	ChangeVal             *decimal.Decimal
	ChangeRate            *decimal.Decimal
	Volume                int64
	Turnover              *decimal.Decimal
	YtdChangeRate         *decimal.Decimal
	TurnoverRate          *decimal.Decimal
	TotalMarketValue      *decimal.Decimal
	CapitalFlow           *decimal.Decimal
	Amplitude             *decimal.Decimal
	VolumeRatio           *decimal.Decimal
	PeTtmRatio            *decimal.Decimal
	PbRatio               *decimal.Decimal
	DividendRatioTtm      *decimal.Decimal
	FiveDayChangeRate     *decimal.Decimal
	TenDayChangeRate      *decimal.Decimal
	HalfYearChangeRate    *decimal.Decimal
	FiveMinutesChangeRate *decimal.Decimal
	ExpiryDate            string
	StrikePrice           *decimal.Decimal
	UpperStrikePrice      *decimal.Decimal
	LowerStrikePrice      *decimal.Decimal
	OutstandingQty        *decimal.Decimal
	OutstandingRatio      *decimal.Decimal
	Premium               *decimal.Decimal
	ItmOtm                *decimal.Decimal
	ImpliedVolatility     *decimal.Decimal
	WarrantDelta          *decimal.Decimal
	CallPrice             *decimal.Decimal
	ToCallPrice           *decimal.Decimal
	EffectiveLeverage     *decimal.Decimal
	LeverageRatio         *decimal.Decimal
	ConversionRatio       *decimal.Decimal
	BalancePoint          *decimal.Decimal
	OpenInterest          int64
	Delta                 *decimal.Decimal
	Gamma                 *decimal.Decimal
	Theta                 *decimal.Decimal
	Vega                  *decimal.Decimal
	Rho                   *decimal.Decimal
}

SecurityCalcIndex the infomation of calculate indexes's security

type SecurityDepth

type SecurityDepth struct {
	Symbol string
	Ask    []*Depth
	Bid    []*Depth
}

SecurityDepth

type SecurityListCategory added in v0.12.0

type SecurityListCategory string
const (
	Overnight SecurityListCategory = "Overnight"
)

type SecurityQuote

type SecurityQuote struct {
	Symbol          string
	LastDone        *decimal.Decimal
	PrevClose       *decimal.Decimal
	Open            *decimal.Decimal
	High            *decimal.Decimal
	Low             *decimal.Decimal
	Timestamp       int64
	Volume          int64
	Turnover        *decimal.Decimal
	TradeStatus     TradeStatus
	PreMarketQuote  *PrePostQuote
	PostMarketQuote *PrePostQuote
	OverNightQuote  *PrePostQuote
}

SecurityQuote is quote details with pre market and post market

type StaticInfo

type StaticInfo struct {
	Symbol            string
	NameCn            string
	NameEn            string
	NameHk            string
	Exchange          string
	Currency          string
	LotSize           int32
	TotalShares       int64
	CirculatingShares int64
	HkShares          int64
	Eps               *decimal.Decimal
	EpsTtm            *decimal.Decimal
	Bps               *decimal.Decimal
	DividendYield     string
	StockDerivatives  []int32
}

StaticInfo store static details

type StrikePriceInfo

type StrikePriceInfo struct {
	Price      *decimal.Decimal
	CallSymbol string
	PutSymbol  string
	Standard   bool
}

StrikePriceInfo is strike price details

type SubType

type SubType uint8

type Trade

type Trade struct {
	Price     string
	Volume    int64
	Timestamp int64
	// TradeType
	// HK
	//
	// - `*` - Overseas trade
	// - `D` - Odd-lot trade
	// - `M` - Non-direct off-exchange trade
	// - `P` - Late trade (Off-exchange previous day)
	// - `U` - Auction trade
	// - `X` - Direct off-exchange trade
	// - `Y` - Automatch internalized
	// - `<empty string>` -  Automatch normal
	//
	// US
	//
	// - `<empty string>` - Regular sale
	// - `A` - Acquisition
	// - `B` - Bunched trade
	// - `D` - Distribution
	// - `F` - Intermarket sweep
	// - `G` - Bunched sold trades
	// - `H` - Price variation trade
	// - `I` - Odd lot trade
	// - `K` - Rule 155 trde(NYSE MKT)
	// - `M` - Market center close price
	// - `P` - Prior reference price
	// - `Q` - Market center open price
	// - `S` - Split trade
	// - `V` - Contingent trade
	// - `W` - Average price trade
	// - `X` - Cross trade
	// - `1` - Stopped stock(Regular trade)
	TradeType    string
	Direction    int32
	TradeSession TradeSession
}

Trade store trade details

type TradeDate

type TradeDate struct {
	Date          string
	TradeDateType int32 // 0 full day, 1 morning only, 2 afternoon only(not happened before)
}

TradeDate

type TradePeriod

type TradePeriod struct {
	BegTime      int32
	EndTime      int32
	TradeSession TradeSession
}

TradePeriod

type TradeSession

type TradeSession int32

type TradeSessionType

type TradeSessionType int32

type TradeStatus

type TradeStatus int32

type TradesData

type TradesData struct {
	Sequence int64
	Trades   []*Trade
}

type UserProfile added in v0.16.0

type UserProfile struct {
	MemberId                int64
	QuoteLevel              string
	SubscribeLimit          int32
	HistoryCandlestickLimit int32
	RateLimit               []*RateLimit
	QuoteLevelDetail        *UserQuoteLevelDetail
}

type UserQuoteLevelDetail added in v0.16.0

type UserQuoteLevelDetail struct {
	ByPackageKey map[string]*PackageDetail
	ByMarketCode map[string]*MarketPackageDetail
}

type WarrantExpiryDateType added in v0.10.0

type WarrantExpiryDateType int32
const (
	WarrantLT3    WarrantExpiryDateType = iota + 1 // Less than three months
	WarrantBT3_6                                   // between three and six months
	WarrantBT6_12                                  // between six and twelve months
	WarrantGT12                                    // greate than twelve months
)

type WarrantExtend

type WarrantExtend struct {
	ImpliedVolatility string
	ExpiryDate        string
	LastTradeDate     string
	OutstandingRatio  string
	OutstandingQty    int64
	ConversionRatio   string
	Category          string
	StrikePrice       *decimal.Decimal
	UpperStrikePrice  *decimal.Decimal
	LowerStrikePrice  *decimal.Decimal
	CallPrice         *decimal.Decimal
	UnderlyingSymbol  string
}

WarrantExtend is warrant extended properties

type WarrantFilter added in v0.10.0

type WarrantFilter struct {
	SortBy     WarrantSortBy
	SortOrder  WarrantSortOrder
	SortOffset int32
	SortCount  int32
	Type       []WarrantType
	Issuer     []int32
	ExpiryDate []WarrantExpiryDateType
	PriceType  []WarrantInOutBoundsType
	Status     []WarrantStatus
	Language   WarrantLanguage
}

type WarrantInOutBoundsType added in v0.10.0

type WarrantInOutBoundsType int32
const (
	WarrantInBounds WarrantInOutBoundsType = iota + 1
	WarrantOutBounds
)

type WarrantInfo added in v0.10.0

type WarrantInfo struct {
	Symbol            string
	Name              string
	LastDone          *decimal.Decimal
	ChangeRate        *decimal.Decimal
	ChangeVal         *decimal.Decimal
	Volume            int64
	Turnover          *decimal.Decimal
	ExpiryDate        string
	StrikePrice       *decimal.Decimal
	UpperStrikePrice  *decimal.Decimal
	LowerStrikePrice  *decimal.Decimal
	OutstandingQty    *decimal.Decimal
	OutstandingRatio  *decimal.Decimal
	Premium           *decimal.Decimal
	ItmOtm            *decimal.Decimal
	ImpliedVolatility *decimal.Decimal
	Delta             *decimal.Decimal
	CallPrice         *decimal.Decimal
	ToCallPrice       *decimal.Decimal
	EffectiveLeverage *decimal.Decimal
	LeverageRatio     *decimal.Decimal
	ConversionRatio   *decimal.Decimal
	BalancePoint      *decimal.Decimal
	Status            WarrantStatus
}

WarrantInfo is info of warrant asset

type WarrantLanguage added in v0.10.0

type WarrantLanguage int32
const (
	WarrantZH_CN WarrantLanguage = iota
	WarrantEN
	WarrantHK_CN
)

type WarrantQuote

type WarrantQuote struct {
	Symbol        string
	LastDone      *decimal.Decimal
	PrevClose     *decimal.Decimal
	Open          *decimal.Decimal
	High          *decimal.Decimal
	Low           *decimal.Decimal
	Timestamp     int64
	Volume        int64
	Turnover      *decimal.Decimal
	TradeStatus   TradeStatus
	WarrantExtend *WarrantExtend
}

WarrantQuote is warrant quote details

type WarrantSortBy added in v0.10.0

type WarrantSortBy int32
const (
	WarrantLastDone WarrantSortBy = iota
	WarrantChangeRate
	WarrantChangeVal
	WarrantVolume
	WarrantTurnover
	WarrantExpiryDate
	WarrantStrikePrice
	WarrantUpperStrikePrice
	WarrantLowerStrikePrice
	WarrantOutstandingQty
	WarrantOutstandingRatio
	WarrantPremiun
	WarrantItmOtm
	WarrantImpliedVolatility
	WarrantDelta
	WarrantCallPrice
	WarrantToCallPrice
	WarrantEffectiveLeverage
	WarrantLeverageRatio
	WarrantConversionRatio
	WarrantBalancePoint
	WarrantSortStatus
)

type WarrantSortOrder added in v0.10.0

type WarrantSortOrder int32
const (
	WarrantAsc WarrantSortOrder = iota
	WarrantDesc
)

type WarrantStatus added in v0.10.0

type WarrantStatus int32
const (
	WarrantSuspend    WarrantStatus = iota + 2 // can't trade
	WarrantPapareList                          // wait to be listed
	WarrantNormal                              // Tradable
)

Warrant status

type WarrantType added in v0.10.0

type WarrantType int32
const (
	WarrantCall WarrantType = iota
	WarrantPut
	WarrantBull
	WarrantBear
	WarrantInline
)

type WatchedGroup

type WatchedGroup struct {
	Id        int64  // group id
	Name      string // group name
	Securites []*WatchedSecurity
}

WatchedGroup a group of the security is watched

type WatchedSecurity

type WatchedSecurity struct {
	Symbol    string
	Market    string
	Name      string
	Price     *decimal.Decimal
	WatchedAt int64 // timestamp
}

WatchedSecurity the security is watched

type WatchlistUpdateMode added in v0.12.0

type WatchlistUpdateMode string
const (
	// AddWatchlist will add securities to watchlist group
	AddWatchlist WatchlistUpdateMode = "add"
	// RemoveWatchlist will remove securities from watchlist group
	RemoveWatchlist WatchlistUpdateMode = "remove"
	// ReplaceWatchlist will replace securities in watchlist group
	// For example:
	//   If the original group contains APPL.US, BABA.US, TSLA.US,
	//   and it is updated with ["BABA.US", "AAPL.US", "MSFT.US"],
	//   it will become BABA.US, AAPL.US, MSFT.US,
	//   removing TSLA.US and adding MSFT.US, while adjusting the order of BABA.US and AAPL.US.
	ReplaceWatchlist WatchlistUpdateMode = "replace"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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