Documentation
¶
Index ¶
- Constants
- Variables
- func FormatSubscriptionTarget(networkID, address string) string
- type AuthMode
- type CGSimplePriceUpdate
- type Channel
- type Client
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) CloseWithStatus(code coderws.StatusCode, reason string) error
- func (c *Conn) Raw() *coderws.Conn
- func (c *Conn) Read(ctx context.Context) (Message, error)
- func (c *Conn) ReadRaw(ctx context.Context) ([]byte, error)
- func (c *Conn) SetCGSimplePrice(ctx context.Context, coinIDs []string, vsCurrencies ...string) error
- func (c *Conn) SetOnchainOHLCV(ctx context.Context, targets []string, interval OHLCVInterval, ...) error
- func (c *Conn) SetOnchainSimpleTokenPrice(ctx context.Context, targets []string) error
- func (c *Conn) SetOnchainTrade(ctx context.Context, targets []string) error
- func (c *Conn) Subscribe(ctx context.Context, channel Channel) error
- func (c *Conn) UnsetCGSimplePrice(ctx context.Context, coinIDs []string, vsCurrencies ...string) error
- func (c *Conn) UnsetOnchainOHLCV(ctx context.Context, targets []string, interval OHLCVInterval, ...) error
- func (c *Conn) UnsetOnchainSimpleTokenPrice(ctx context.Context, targets []string) error
- func (c *Conn) UnsetOnchainTrade(ctx context.Context, targets []string) error
- func (c *Conn) Unsubscribe(ctx context.Context, channel Channel) error
- type EventMessage
- type Message
- type Number
- type OHLCVInterval
- type OHLCVToken
- type OnchainOHLCVUpdate
- type OnchainSimpleTokenPriceUpdate
- type OnchainTradeUpdate
- type Option
- type StatusMessage
- type UnknownMessage
Constants ¶
const (
// BaseURL is CoinGecko's websocket endpoint.
BaseURL = "wss://stream.coingecko.com/v1"
)
Variables ¶
var ( // ErrMissingAPIKey is returned when the websocket client is missing a Pro API key. ErrMissingAPIKey = errors.New("coingecko websocket api key is required") // ErrInvalidAuthMode is returned when the websocket client is configured with an unsupported auth mode. ErrInvalidAuthMode = errors.New("invalid websocket auth mode") )
var ( // ErrMissingTargets is returned when a channel action is sent without any target ids. ErrMissingTargets = errors.New("at least one subscription target is required") // ErrInvalidOHLCVInterval is returned when the requested OHLCV interval is unsupported by CoinGecko. ErrInvalidOHLCVInterval = errors.New("invalid ohlcv interval") // ErrInvalidOHLCVToken is returned when the requested OHLCV token side is unsupported by CoinGecko. ErrInvalidOHLCVToken = errors.New("invalid ohlcv token side") )
Functions ¶
func FormatSubscriptionTarget ¶
FormatSubscriptionTarget returns the network-scoped identifier CoinGecko expects for on-chain subscriptions.
Types ¶
type AuthMode ¶
type AuthMode string
AuthMode controls how the CoinGecko Pro API key is sent during the websocket handshake.
type CGSimplePriceUpdate ¶
type CGSimplePriceUpdate struct {
ChannelType string
CoinID string
VSCurrency string
MarketCapUSD *Number
Price *Number
Price24hChangePercentage *Number
LastUpdatedAt *Number
Volume24h *Number
}
CGSimplePriceUpdate represents a CGSimplePrice update payload.
func (*CGSimplePriceUpdate) UnmarshalJSON ¶
func (u *CGSimplePriceUpdate) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Channel ¶
type Channel string
Channel identifies a CoinGecko websocket channel.
const ( // ChannelCGSimplePrice streams CoinGecko simple price updates. ChannelCGSimplePrice Channel = "CGSimplePrice" // ChannelOnchainSimpleTokenPrice streams GeckoTerminal token price updates. ChannelOnchainSimpleTokenPrice Channel = "OnchainSimpleTokenPrice" // ChannelOnchainTrade streams GeckoTerminal trade updates. ChannelOnchainTrade Channel = "OnchainTrade" // ChannelOnchainOHLCV streams GeckoTerminal OHLCV updates. ChannelOnchainOHLCV Channel = "OnchainOHLCV" )
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client manages websocket connection setup for CoinGecko's streaming API.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn wraps an active CoinGecko websocket connection.
func (*Conn) CloseWithStatus ¶
func (c *Conn) CloseWithStatus(code coderws.StatusCode, reason string) error
CloseWithStatus closes the websocket connection with a caller-provided status and reason.
func (*Conn) Read ¶
Read reads and decodes the next websocket JSON message into one of the typed message variants.
func (*Conn) SetCGSimplePrice ¶
func (c *Conn) SetCGSimplePrice(ctx context.Context, coinIDs []string, vsCurrencies ...string) error
SetCGSimplePrice configures the CGSimplePrice channel for the provided coin ids and quote currencies.
func (*Conn) SetOnchainOHLCV ¶
func (c *Conn) SetOnchainOHLCV(ctx context.Context, targets []string, interval OHLCVInterval, token OHLCVToken) error
SetOnchainOHLCV configures the OnchainOHLCV channel for the provided pool targets.
func (*Conn) SetOnchainSimpleTokenPrice ¶
SetOnchainSimpleTokenPrice configures the OnchainSimpleTokenPrice channel for the provided token targets.
func (*Conn) SetOnchainTrade ¶
SetOnchainTrade configures the OnchainTrade channel for the provided pool targets.
func (*Conn) UnsetCGSimplePrice ¶
func (c *Conn) UnsetCGSimplePrice(ctx context.Context, coinIDs []string, vsCurrencies ...string) error
UnsetCGSimplePrice removes specific CGSimplePrice subscriptions for the provided coin ids and quote currencies.
func (*Conn) UnsetOnchainOHLCV ¶
func (c *Conn) UnsetOnchainOHLCV(ctx context.Context, targets []string, interval OHLCVInterval, token OHLCVToken) error
UnsetOnchainOHLCV removes specific OnchainOHLCV subscriptions for the provided pool targets.
func (*Conn) UnsetOnchainSimpleTokenPrice ¶
UnsetOnchainSimpleTokenPrice removes specific OnchainSimpleTokenPrice subscriptions for the provided token targets.
func (*Conn) UnsetOnchainTrade ¶
UnsetOnchainTrade removes specific OnchainTrade subscriptions for the provided pool targets.
type EventMessage ¶
type EventMessage struct {
Type string `json:"type"`
Identifier string `json:"identifier,omitempty"`
}
EventMessage represents websocket lifecycle events such as welcome or confirm_subscription.
type Message ¶
type Message interface {
// contains filtered or unexported methods
}
Message is a typed websocket payload returned by Read or ParseMessage.
func ParseMessage ¶
ParseMessage decodes a raw websocket payload into a typed message.
type Number ¶
type Number float64
Number decodes CoinGecko websocket numbers that may be emitted as JSON numbers or quoted strings.
func (*Number) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type OHLCVInterval ¶
type OHLCVInterval string
OHLCVInterval identifies a supported OHLCV candle interval.
const ( OHLCVInterval1s OHLCVInterval = "1s" OHLCVInterval1m OHLCVInterval = "1m" OHLCVInterval5m OHLCVInterval = "5m" OHLCVInterval15m OHLCVInterval = "15m" OHLCVInterval1h OHLCVInterval = "1h" OHLCVInterval2h OHLCVInterval = "2h" OHLCVInterval4h OHLCVInterval = "4h" OHLCVInterval8h OHLCVInterval = "8h" OHLCVInterval12h OHLCVInterval = "12h" OHLCVInterval1d OHLCVInterval = "1d" )
type OHLCVToken ¶
type OHLCVToken string
OHLCVToken identifies whether OHLCV updates are streamed for the base or quote token of a pool.
const ( OHLCVTokenBase OHLCVToken = "base" OHLCVTokenQuote OHLCVToken = "quote" )
type OnchainOHLCVUpdate ¶
type OnchainOHLCVUpdate struct {
ChannelType string
NetworkID string
PoolAddress string
Token OHLCVToken
Interval OHLCVInterval
Open *Number
High *Number
Low *Number
Close *Number
Volume *Number
Timestamp *Number
}
OnchainOHLCVUpdate represents an OnchainOHLCV update payload.
func (*OnchainOHLCVUpdate) UnmarshalJSON ¶
func (u *OnchainOHLCVUpdate) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type OnchainSimpleTokenPriceUpdate ¶
type OnchainSimpleTokenPriceUpdate struct {
ChannelType string
NetworkID string
TokenAddress string
PriceUSD *Number
Price24hChangePercentage *Number
MarketCapUSD *Number
Volume24h *Number
LastUpdatedAt *Number
}
OnchainSimpleTokenPriceUpdate represents an OnchainSimpleTokenPrice update payload.
func (*OnchainSimpleTokenPriceUpdate) UnmarshalJSON ¶
func (u *OnchainSimpleTokenPriceUpdate) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type OnchainTradeUpdate ¶
type OnchainTradeUpdate struct {
ChannelType string
NetworkID string
PoolAddress string
TransactionHash string
TradeType string
TokenAmount *Number
QuoteTokenAmount *Number
VolumeUSD *Number
PriceInNativeCurrency *Number
PriceUSD *Number
LastUpdatedAt *Number
}
OnchainTradeUpdate represents an OnchainTrade update payload.
func (*OnchainTradeUpdate) UnmarshalJSON ¶
func (u *OnchainTradeUpdate) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Option ¶
type Option func(*Client)
Option configures a websocket client.
func WithAuthMode ¶
WithAuthMode configures whether authentication is sent as a query parameter or request header.
func WithHTTPClient ¶
WithHTTPClient configures the HTTP client used during the websocket handshake.
func WithHeader ¶
WithHeader merges additional headers into the websocket handshake request.
type StatusMessage ¶
StatusMessage represents a command acknowledgement or server-side error payload.
type UnknownMessage ¶
type UnknownMessage struct {
Raw json.RawMessage
}
UnknownMessage captures payloads the client does not recognize yet.