ws

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultWSURL is the CoinGecko WebSocket streaming endpoint.
	DefaultWSURL = "wss://stream.coingecko.com/v1"
	// ChannelID is the ActionCable channel identifier for price streaming.
	ChannelID = `{"channel":"CGSimplePrice"}`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client manages a WebSocket connection to CoinGecko's streaming API.

func NewClient

func NewClient(cfg *config.Config, coinIDs []string) *Client

NewClient creates a new WebSocket streaming client.

func (*Client) Close

func (c *Client) Close() error

Close gracefully shuts down the WebSocket connection. It is idempotent.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) (<-chan *CoinUpdate, error)

Connect establishes the WebSocket connection and starts reading updates. Returns a channel that receives price updates. The channel is closed when the client is shut down or the context is canceled.

func (*Client) SetURL

func (c *Client) SetURL(url string)

SetURL overrides the WebSocket URL (for testing).

type CoinUpdate

type CoinUpdate struct {
	CoinID    string  `json:"coin_id"`
	Price     float64 `json:"price"`
	Change24h float64 `json:"change_24h_pct"`
	MarketCap float64 `json:"market_cap"`
	Volume24h float64 `json:"volume_24h"`
	UpdatedAt int64   `json:"updated_at"`
}

CoinUpdate represents a parsed price update from the WebSocket stream.

Jump to

Keyboard shortcuts

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