Documentation
¶
Index ¶
- Constants
- type Config
- type Mode
- type Service
- func (s *Service) GetStatus(email string) (*Status, error)
- func (s *Service) IsRunning(email string) bool
- func (s *Service) ListAll() []UserTickerInfo
- func (s *Service) Shutdown()
- func (s *Service) Start(email, apiKey, accessToken string) error
- func (s *Service) Stop(email string) error
- func (s *Service) Subscribe(email string, tokens []uint32, mode brokerticker.Mode) error
- func (s *Service) Unsubscribe(email string, tokens []uint32) error
- func (s *Service) UpdateToken(email, apiKey, accessToken string) error
- type Status
- type SubscriptionInfo
- type TickCallback
- type UserTicker
- type UserTickerInfo
Constants ¶
const ( ModeLTP = brokerticker.ModeLTP ModeQuote = brokerticker.ModeQuote ModeFull = brokerticker.ModeFull )
Mode aliases for the broker-agnostic mode constants. Same byte values as kiteticker.ModeLTP/ModeQuote/ModeFull (typed string "ltp"/"quote"/"full"); existing kc/ticker.ModeLTP callsites continue to work unchanged.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Logger *slog.Logger
OnTick TickCallback // optional: global tick handler (e.g. alert evaluator)
}
Config holds configuration for creating a new ticker Service.
type Mode ¶
type Mode = brokerticker.Mode
Mode aliases the broker-agnostic broker/ticker.Mode so external consumers (mcp/ticker_tools.go, mcp/alert_tools.go, mcp/trailing_ tools.go) keep using kc/ticker.Mode unchanged. Migration target for post-launch cleanup: callsites import broker/ticker directly.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages per-user WebSocket ticker connections.
func (*Service) ListAll ¶
func (s *Service) ListAll() []UserTickerInfo
ListAll returns a summary of all active ticker connections.
func (*Service) Start ¶
Start creates and starts a WebSocket ticker for the given user. If a ticker is already running for this email, it returns an error.
func (*Service) Subscribe ¶
Subscribe subscribes the user's ticker to the given instrument tokens with the specified mode.
func (*Service) Unsubscribe ¶
Unsubscribe removes instrument tokens from the user's ticker.
func (*Service) UpdateToken ¶
UpdateToken stops the existing ticker and starts a new one with the fresh token. Preserves subscriptions across the restart. The entire operation is serialized under s.mu to prevent concurrent callers from seeing inconsistent state between stop and start.
type Status ¶
type Status struct {
Running bool `json:"running"`
Connected bool `json:"connected"`
StartedAt time.Time `json:"started_at,omitempty"`
Uptime string `json:"uptime,omitempty"`
Subscriptions []SubscriptionInfo `json:"subscriptions,omitempty"`
}
Status represents the current state of a user's ticker connection.
type SubscriptionInfo ¶
type SubscriptionInfo struct {
InstrumentToken uint32 `json:"instrument_token"`
Mode string `json:"mode"`
}
SubscriptionInfo represents a subscribed instrument.
type TickCallback ¶
TickCallback is invoked on each incoming tick for a user. Carries gokiteconnect models.Tick because kc/alerts.Evaluator.Evaluate takes that signature today; the broker/ticker.Tick translation happens INSIDE wireCallbacks so the kiteticker dependency stays hidden from anything outside this package + kc/alerts.
Future cleanup (out of scope for the multi-broker port-adapter commit): kc/alerts.Evaluator.Evaluate accepts broker/ticker.Tick; this signature swaps too; the round-trip translation in wireCallbacks is dropped.
type UserTicker ¶
type UserTicker struct {
Email string
APIKey string
AccessToken string
Ticker brokerticker.Ticker
Cancel context.CancelFunc
Connected bool
StartedAt time.Time
Subscribed map[uint32]brokerticker.Mode // token -> mode
// contains filtered or unexported fields
}
UserTicker holds a single user's WebSocket ticker connection.
Ticker holds a broker/ticker.Ticker port — production wires *zerodha.TickerAdapter (which wraps *kiteticker.Ticker); future non-Zerodha adapters slot in here without touching this struct.