stream

package
v0.0.0-...-03d6c46 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package stream ports the basics of schwab-py's StreamClient (schwab/streaming.py): it fetches streaming parameters from the client's user preferences, performs the ADMIN LOGIN handshake over a websocket, issues subscriptions, and delivers incoming messages.

Unlike the Python library — which dispatches messages to per-service handler callbacks that relabel numeric field keys — this port delivers each raw message to a single handler as it arrives. The services, commands, request envelope, and field-id ranges match schwab-py exactly.

Index

Constants

This section is empty.

Variables

View Source
var Feeds = map[string]Feed{
	"account-activity":          {Service: "ACCT_ACTIVITY", MaxField: 3, HasFields: true},
	"chart-equity":              {Service: "CHART_EQUITY", MaxField: 8, HasFields: true},
	"chart-futures":             {Service: "CHART_FUTURES", MaxField: 6, HasFields: true},
	"level-one-equity":          {Service: "LEVELONE_EQUITIES", MaxField: 51, HasFields: true},
	"level-one-option":          {Service: "LEVELONE_OPTIONS", MaxField: 55, HasFields: true},
	"level-one-futures":         {Service: "LEVELONE_FUTURES", MaxField: 40, HasFields: true},
	"level-one-forex":           {Service: "LEVELONE_FOREX", MaxField: 29, HasFields: true},
	"level-one-futures-options": {Service: "LEVELONE_FUTURES_OPTIONS", MaxField: 31, HasFields: true},
	"nyse-book":                 {Service: "NYSE_BOOK", MaxField: 3, HasFields: true},
	"nasdaq-book":               {Service: "NASDAQ_BOOK", MaxField: 3, HasFields: true},
	"options-book":              {Service: "OPTIONS_BOOK", MaxField: 3, HasFields: true},
	"screener-equity":           {Service: "SCREENER_EQUITY", MaxField: 4, HasFields: true},
	"screener-option":           {Service: "SCREENER_OPTION", MaxField: 4, HasFields: true},
}

Feeds mirrors the subscription surfaces of schwab-py's StreamClient. Command names are the kebab-case forms used by the CLI.

Functions

func AllFieldIDs

func AllFieldIDs(maxField int) string

AllFieldIDs returns "0,1,...,maxField" — the fields parameter schwab-py sends when no explicit field list is given (all_fields()).

Types

type Client

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

Client is a streaming session, analogous to schwab-py's StreamClient after login.

func New

func New(rest *client.Client) *Client

New creates an unlogged-in streaming client backed by the REST client (used for the user-preferences fetch and the access token).

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login fetches user preferences, opens the websocket, and performs the ADMIN LOGIN handshake (schwab-py: StreamClient.login).

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout sends the ADMIN LOGOUT request and closes the socket (schwab-py: StreamClient.logout).

func (*Client) Run

func (c *Client) Run(ctx context.Context, feed Feed, keys []string,
	fields string, handle func(json.RawMessage) error) error

Run subscribes and then invokes handle for every subsequent message until the context is cancelled or the socket fails. Responses to the subscription itself are consumed by Subscribe; heartbeats and data messages are all delivered, matching the raw message flow a schwab-py handler would observe.

func (*Client) RunLoop

func (c *Client) RunLoop(ctx context.Context,
	handle func(json.RawMessage) error) error

RunLoop delivers messages to handle until the context is cancelled or the socket fails. Use it after Login and one or more Subscribe calls to serve several feeds over one connection; Run is the single-feed convenience wrapper. A context cancellation is reported as a nil error.

func (*Client) Subscribe

func (c *Client) Subscribe(ctx context.Context, feed Feed, keys []string,
	fields string) error

Subscribe issues a SUBS request for one feed (schwab-py: the *_subs methods built on _service_op). keys are the subscription keys (symbols); for ACCT_ACTIVITY the key is the stream correl id, as in schwab-py. fields is the comma-separated field-id list; empty means all fields.

func (*Client) SubscribeParams

func (c *Client) SubscribeParams(ctx context.Context, feed Feed, keys []string,
	fields string, extra map[string]string) error

SubscribeParams is Subscribe with additional request parameters merged in — for example the screener services' mandatory "sort" parameter, which schwab-py's screener *_subs methods pass alongside keys and fields.

type Feed

type Feed struct {
	Service string
	// MaxField is the highest field id of the service's field enum in
	// schwab-py; field id ranges there are contiguous from 0.
	MaxField int
	// HasFields reports whether subscriptions for this service carry a
	// fields parameter.
	HasFields bool
}

Feed describes one subscribable streaming service.

Jump to

Keyboard shortcuts

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