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 ¶
- Variables
- func AllFieldIDs(maxField int) string
- type Client
- func (c *Client) Login(ctx context.Context) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Run(ctx context.Context, feed Feed, keys []string, fields string, ...) error
- func (c *Client) RunLoop(ctx context.Context, handle func(json.RawMessage) error) error
- func (c *Client) Subscribe(ctx context.Context, feed Feed, keys []string, fields string) error
- func (c *Client) SubscribeParams(ctx context.Context, feed Feed, keys []string, fields string, ...) error
- type Feed
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
Login fetches user preferences, opens the websocket, and performs the ADMIN LOGIN handshake (schwab-py: StreamClient.login).
func (*Client) Logout ¶
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 ¶
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 ¶
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.