Documentation
¶
Overview ¶
Package mmt provides a complete Go client for the MMT Market Data API. It includes support for all REST endpoints, WebSocket streaming, CBOR encoding, rate limit management, and automatic retry with exponential backoff.
Index ¶
- Constants
- Variables
- func IsRetryable(err error) bool
- func IsRetryableError(code ErrorCode) bool
- func IsValidVDBucket(bucket VDBucket) bool
- type ActiveSubscription
- type AggNotAllowedError
- type AlreadySubscribedError
- type BaseError
- type BucketGroupInfo
- type Candle
- type CandlesResponse
- type EncodingType
- type ErrorCode
- type ErrorDetail
- type ErrorResponse
- type Exchange
- type FlatHeatmap
- type FlatHeatmapHDResponse
- type FlatHeatmapSDResponse
- type Heatmap
- type HeatmapHDResponse
- type HeatmapSDResponse
- type InternalError
- type InvalidAPIKeyError
- type InvalidBucketError
- type InvalidExchangeError
- type InvalidJSONError
- type InvalidParamsError
- type InvalidSymbolError
- type InvalidTimeframeError
- type Liquidation
- type LiquidationHeatmapResponse
- type ListSubscriptionsMessage
- type MMTError
- type Market
- type MarketsResponse
- type MaxConnsExceededError
- type MaxPointsExceededError
- type MaxSubsExceededError
- type NotConnectedError
- type NotSubscribedError
- type OICandle
- type OIResponse
- type Orderbook
- type OrderbookLevel
- type OrderbookLevels
- type OrderbookOption
- type OrderbookResponse
- type RateLimitError
- type RestClient
- func (c *RestClient) Config() RestClientConfig
- func (c *RestClient) ContentType() string
- func (c *RestClient) GetAggregatedFlatHeatmapHD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*FlatHeatmapHDResponse, error)
- func (c *RestClient) GetAggregatedFlatHeatmapSD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*FlatHeatmapSDResponse, error)
- func (c *RestClient) GetAggregatedHeatmapHD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*HeatmapHDResponse, error)
- func (c *RestClient) GetAggregatedHeatmapSD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*HeatmapSDResponse, error)
- func (c *RestClient) GetAggregatedOI(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*OIResponse, error)
- func (c *RestClient) GetAggregatedStats(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*StatsResponse, error)
- func (c *RestClient) GetAggregatedVD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*VDResponse, error)
- func (c *RestClient) GetAggregatedVolumes(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, ...) (*VolumesResponse, error)
- func (c *RestClient) GetCandles(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*CandlesResponse, error)
- func (c *RestClient) GetFlatHeatmapHD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*FlatHeatmapHDResponse, error)
- func (c *RestClient) GetFlatHeatmapSD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*FlatHeatmapSDResponse, error)
- func (c *RestClient) GetHeatmapHD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*HeatmapHDResponse, error)
- func (c *RestClient) GetHeatmapSD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*HeatmapSDResponse, error)
- func (c *RestClient) GetLiquidationHeatmap(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*LiquidationHeatmapResponse, error)
- func (c *RestClient) GetMarkets(ctx context.Context) (*MarketsResponse, error)
- func (c *RestClient) GetOI(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*OIResponse, error)
- func (c *RestClient) GetOrderbook(ctx context.Context, exchange string, symbol string, opts ...OrderbookOption) (*OrderbookResponse, error)
- func (c *RestClient) GetStats(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*StatsResponse, error)
- func (c *RestClient) GetStopHeatmap(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*StopHeatmapResponse, error)
- func (c *RestClient) GetTPHeatmap(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*TPHeatmapResponse, error)
- func (c *RestClient) GetUsage(ctx context.Context) (*UsageResponse, error)
- func (c *RestClient) GetVD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*VDResponse, error)
- func (c *RestClient) GetVolumes(ctx context.Context, exchange string, symbol string, timeframe Timeframe, ...) (*VolumesResponse, error)
- func (c *RestClient) HTTPClient() *http.Client
- type RestClientConfig
- type ServiceUnavailableError
- type Stat
- type StatsResponse
- type StopHeatmapResponse
- type StreamInfo
- type SubscribeMessage
- type SubscribeOption
- type Subscription
- type SubscriptionCallbacks
- type SubscriptionHandler
- type Symbol
- type TPHeatmapResponse
- type TierInfo
- type TierRestrictedError
- type Timeframe
- type TimeoutError
- type Trade
- type UnknownTypeError
- type UnsubscribeMessage
- type UsageResponse
- type VDBucket
- type VDBucketInfo
- type VDCandle
- type VDResponse
- type Volume
- type VolumesResponse
- type WSCandleMessage
- type WSChannel
- type WSClient
- func (c *WSClient) Close() error
- func (c *WSClient) Config() WSClientConfig
- func (c *WSClient) Connect(ctx context.Context) error
- func (c *WSClient) GetSubscriptionCount() int
- func (c *WSClient) GetSubscriptions() []*ActiveSubscription
- func (c *WSClient) IsConnected() bool
- func (c *WSClient) ListSubscriptions() error
- func (c *WSClient) MaxSubscriptions() int
- func (c *WSClient) Subscribe(channel WSChannel, exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedFlatHeatmapHD(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedFlatHeatmapSD(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedHeatmapHD(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedHeatmapSD(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedLiquidations(exchanges []string, symbol string, handler SubscriptionHandler) error
- func (c *WSClient) SubscribeAggregatedMarkets(exchanges []string, symbol string, handler SubscriptionHandler) error
- func (c *WSClient) SubscribeAggregatedOI(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedStats(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeAggregatedVD(exchanges []string, symbol string, timeframe Timeframe, bucket VDBucket, ...) error
- func (c *WSClient) SubscribeAggregatedVolumes(exchanges []string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeCandles(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeFlatHeatmapHD(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeFlatHeatmapSD(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeHeatmapHD(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeHeatmapSD(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeLiquidationHeatmap(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeLiquidations(exchange string, symbol string, handler SubscriptionHandler) error
- func (c *WSClient) SubscribeMarkets(exchange string, symbol string, handler SubscriptionHandler) error
- func (c *WSClient) SubscribeOI(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeOrderbook(exchange string, symbol string, handler SubscriptionHandler) error
- func (c *WSClient) SubscribeStats(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeStopHeatmap(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeTPHeatmap(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) SubscribeTrades(exchange string, symbol string, handler SubscriptionHandler) error
- func (c *WSClient) SubscribeVD(exchange string, symbol string, timeframe Timeframe, bucket VDBucket, ...) error
- func (c *WSClient) SubscribeVolumes(exchange string, symbol string, timeframe Timeframe, ...) error
- func (c *WSClient) Tier() string
- func (c *WSClient) Unsubscribe(sub *ActiveSubscription) error
- type WSClientConfig
- type WSConnectedMessage
- type WSDisconnectingMessage
- type WSErrorMessage
- type WSFlatHeatmapMessage
- type WSHeatmapMessage
- type WSLiquidationMessage
- type WSMarketMessage
- type WSMessageBase
- type WSMessageType
- type WSOIMessage
- type WSOrderbookMessage
- type WSStatMessage
- type WSSubscribedMessage
- type WSSubscriptionsMessage
- type WSTradeMessage
- type WSUnsubscribedMessage
- type WSVDMessage
- type WSVolumesMessage
Constants ¶
const ( DefaultRestURL = "https://eu-central-1.mmt.gg/api/v1" DefaultRestEncoding = EncodingCBOR DefaultRestTimeout = 30 * time.Second DefaultRestMaxRetries = 2 DefaultRestRetryInitialDelay = 500 * time.Millisecond DefaultRestMaxDelay = 5 * time.Second )
const ( DefaultWSURL = "wss://eu-central-1.mmt.gg/api/v1/ws" DefaultWSEncoding = EncodingCBOR DefaultWSTimeout = 10 * time.Second DefaultWSReconnectDelay = 1 * time.Second DefaultWSMaxReconnectDelay = 30 * time.Second DefaultWSSubscribeTimeout = 5 * time.Second DefaultWSMaxReconnectAttempts = 10 )
Variables ¶
var VDBucketInfos = []VDBucketInfo{ {VDBucketAll, "all", "All trades"}, {VDBucket1To1K, "1-1K", "$1 - $1,000"}, {VDBucket1KTo10K, "1K-10K", "$1,000 - $10,000"}, {VDBucket10KTo25K, "10K-25K", "$10,000 - $25,000"}, {VDBucket25KTo50K, "25K-50K", "$25,000 - $50,000"}, {VDBucket50KTo100K, "50K-100K", "$50,000 - $100,000"}, {VDBucket100KTo250K, "100K-250K", "$100,000 - $250,000"}, {VDBucket250KTo500K, "250K-500K", "$250,000 - $500,000"}, {VDBucket500KTo1M, "500K-1M", "$500,000 - $1,000,000"}, {VDBucket1MTo5M, "1M-5M", "$1,000,000 - $5,000,000"}, {VDBucket5MPlus, "5M+", "$5,000,000+"}, }
VDBucketInfos contains all bucket information
Functions ¶
func IsRetryable ¶
IsRetryable reports whether an error warrants a retry. Context cancellation and non-MMT errors are not retryable.
func IsRetryableError ¶
IsRetryableError returns whether an error code is retryable Based on MMT API best practices
func IsValidVDBucket ¶
IsValidVDBucket checks if a bucket is valid
Types ¶
type ActiveSubscription ¶
type ActiveSubscription struct {
ID string // server-generated ID (learned from first data message)
Channel WSChannel
Exchange string
Symbol string
Tf Timeframe
Bucket VDBucket
CreatedAt time.Time
}
ActiveSubscription represents an active subscription with additional metadata. The ID is server-assigned and only populated after the first data message arrives.
type AggNotAllowedError ¶
type AggNotAllowedError struct {
BaseError
}
AggNotAllowedError is returned when the current plan does not support multi-exchange aggregated requests.
func NewAggNotAllowedError ¶
func NewAggNotAllowedError(message string) *AggNotAllowedError
NewAggNotAllowedError constructs an AggNotAllowedError. The caller must upgrade their plan or use single-exchange requests.
type AlreadySubscribedError ¶
AlreadySubscribedError is returned when attempting to subscribe to a stream that is already active.
func NewAlreadySubscribedError ¶
func NewAlreadySubscribedError(message string, id string) *AlreadySubscribedError
NewAlreadySubscribedError constructs an AlreadySubscribedError with the subscription ID that caused the conflict.
type BaseError ¶
type BaseError struct {
// contains filtered or unexported fields
}
BaseError provides the core fields shared by all MMT error types: code, message, retry timing, and structured details.
func NewBaseError ¶
func NewBaseError(code ErrorCode, message string, retryAfter time.Duration, details map[string]interface{}) *BaseError
NewBaseError constructs a generic MMT error. Prefer the typed constructors (NewRateLimitError, etc.) for specific error codes.
func (*BaseError) Details ¶
Details returns additional error details. The returned map is a copy — modifying it does not affect the error.
func (*BaseError) IsRetryable ¶
IsRetryable reports whether the caller should retry the request after this error.
func (*BaseError) RetryAfter ¶
RetryAfter returns the duration to wait before retrying.
type BucketGroupInfo ¶
type BucketGroupInfo struct {
ID int `json:"id" cbor:"id"` // Bucket group ID (1-11)
Name string `json:"name" cbor:"name"` // Short name (e.g., "1K-10K")
Description string `json:"description" cbor:"description"` // Full description
}
BucketGroupInfo represents a volume delta bucket group definition
type Candle ¶
type Candle struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
O float64 `json:"o" cbor:"o"` // Open price
H float64 `json:"h" cbor:"h"` // High price
L float64 `json:"l" cbor:"l"` // Low price
C float64 `json:"c" cbor:"c"` // Close price
Vb float64 `json:"vb" cbor:"vb"` // Buy volume (USD)
Vs float64 `json:"vs" cbor:"vs"` // Sell volume (USD)
Tb int64 `json:"tb" cbor:"tb"` // Buy trade count
Ts int64 `json:"ts" cbor:"ts"` // Sell trade count
}
Candle represents OHLCVT candle data (returned by candles endpoint/channel)
type CandlesResponse ¶
type CandlesResponse struct {
Data []Candle `json:"data" cbor:"data"` // Array of candles
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
CandlesResponse represents the response from GET /candles
type EncodingType ¶
type EncodingType string
EncodingType represents the content encoding type for WebSocket and REST traffic. CBOR is the default — it is more bandwidth-efficient than JSON.
const ( // EncodingCBOR uses CBOR encoding (default, recommended) EncodingCBOR EncodingType = "cbor" // EncodingJSON uses JSON encoding EncodingJSON EncodingType = "json" )
type ErrorCode ¶
type ErrorCode string
ErrorCode is a string identifying a specific MMT API error condition.
const ( // Authentication Errors ErrCodeInvalidAPIKey ErrorCode = "INVALID_API_KEY" // Validation Errors ErrCodeInvalidParams ErrorCode = "INVALID_PARAMS" ErrCodeInvalidExchange ErrorCode = "INVALID_EXCHANGE" ErrCodeInvalidSymbol ErrorCode = "INVALID_SYMBOL" ErrCodeInvalidTimeframe ErrorCode = "INVALID_TIMEFRAME" ErrCodeInvalidBucket ErrorCode = "INVALID_BUCKET" ErrCodeInvalidStream ErrorCode = "INVALID_STREAM" ErrCodeMaxPointsExceeded ErrorCode = "MAX_POINTS_EXCEEDED" // Tier Restriction Errors ErrCodeTierRestricted ErrorCode = "TIER_RESTRICTED" ErrCodeAggNotAllowed ErrorCode = "AGG_NOT_ALLOWED" // Rate Limit Errors ErrCodeRateLimited ErrorCode = "RATE_LIMITED" // WebSocket Errors ErrCodeMaxSubsExceeded ErrorCode = "MAX_SUBS_EXCEEDED" ErrCodeMaxConnsExceeded ErrorCode = "MAX_CONNS_EXCEEDED" ErrCodeInvalidMessage ErrorCode = "INVALID_MESSAGE" ErrCodeUnknownChannel ErrorCode = "UNKNOWN_CHANNEL" ErrCodeAlreadySubscribed ErrorCode = "ALREADY_SUBSCRIBED" ErrCodeNotSubscribed ErrorCode = "NOT_SUBSCRIBED" ErrCodeInvalidJSON ErrorCode = "INVALID_JSON" ErrCodeUnknownType ErrorCode = "UNKNOWN_TYPE" // Server Errors ErrCodeTimeout ErrorCode = "TIMEOUT" ErrCodeInternalError ErrorCode = "INTERNAL_ERROR" ErrCodeNotFound ErrorCode = "NOT_FOUND" ErrCodeForbidden ErrorCode = "FORBIDDEN" ErrCodeUnexpectedHTTP ErrorCode = "UNEXPECTED_HTTP" // Client-side Errors (transport, I/O, state) ErrCodeReadFailed ErrorCode = "READ_FAILED" ErrCodeDecodeFailed ErrorCode = "DECODE_FAILED" ErrCodeNotConnected ErrorCode = "NOT_CONNECTED" )
type ErrorDetail ¶
type ErrorDetail struct {
Code string `json:"code" cbor:"code"`
Message string `json:"message" cbor:"message"`
Details map[string]interface{} `json:"details,omitempty" cbor:"details,omitempty"`
}
ErrorDetail represents the error details
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error" cbor:"error"`
}
ErrorResponse represents an error response from REST API
type Exchange ¶
type Exchange struct {
ID string `json:"id" cbor:"id"` // Exchange ID (e.g., "binancef")
Symbols []Symbol `json:"symbols" cbor:"symbols"` // Available symbols
}
Exchange represents an exchange with its available symbols
type FlatHeatmap ¶
type FlatHeatmap struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
Pg float64 `json:"pg" cbor:"pg"` // Price granularity
S []float64 `json:"s" cbor:"s"` // Sizes (ordered from minp to maxp)
Lp float64 `json:"lp" cbor:"lp"` // Last price
Si int64 `json:"si" cbor:"si"` // Split index (bids/asks boundary)
Minp float64 `json:"minp" cbor:"minp"` // Minimum price
Maxp float64 `json:"maxp" cbor:"maxp"` // Maximum price
Mins float64 `json:"mins" cbor:"mins"` // Minimum size
Maxs float64 `json:"maxs" cbor:"maxs"` // Maximum size
}
FlatHeatmap represents orderbook heatmap with dense size array (returned by flat_heatmap_sd, flat_heatmap_hd, stop_heatmap, tp_heatmap, and liquidation_heatmap REST endpoints and WebSocket channels)
func (FlatHeatmap) PriceAt ¶
func (fh FlatHeatmap) PriceAt(index int) float64
PriceAt returns the price at a given index in the flat heatmap Price at index i = minp + (i * pg)
type FlatHeatmapHDResponse ¶
type FlatHeatmapHDResponse = FlatHeatmapSDResponse
FlatHeatmapHDResponse represents the response from GET /flat_heatmap_hd
type FlatHeatmapSDResponse ¶
type FlatHeatmapSDResponse struct {
Data []FlatHeatmap `json:"data" cbor:"data"` // Array of flat heatmaps (dense S array, no P)
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID (or aggregated)
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
FlatHeatmapSDResponse represents the response from GET /flat_heatmap_sd
type Heatmap ¶
type Heatmap struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
Pg float64 `json:"pg" cbor:"pg"` // Price granularity
P []float64 `json:"p" cbor:"p"` // Price levels
S []float64 `json:"s" cbor:"s"` // Sizes at each price level
Si int64 `json:"si" cbor:"si"` // Split index (bids/asks boundary)
Lp float64 `json:"lp" cbor:"lp"` // Last price
Minp float64 `json:"minp" cbor:"minp"` // Minimum price
Maxp float64 `json:"maxp" cbor:"maxp"` // Maximum price
Mins float64 `json:"mins" cbor:"mins"` // Minimum size
Maxs float64 `json:"maxs" cbor:"maxs"` // Maximum size
}
Heatmap represents orderbook heatmap with explicit price array (returned by heatmap_sd and heatmap_hd REST endpoints and WebSocket channels)
type HeatmapHDResponse ¶
type HeatmapHDResponse = HeatmapSDResponse
HeatmapHDResponse represents the response from GET /heatmap_hd
type HeatmapSDResponse ¶
type HeatmapSDResponse struct {
Data []Heatmap `json:"data" cbor:"data"` // Array of heatmaps (with explicit P price array)
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID (or aggregated)
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
HeatmapSDResponse represents the response from GET /heatmap_sd
type InternalError ¶
InternalError is returned when the server encounters an unexpected problem. These are typically retryable.
func NewInternalError ¶
func NewInternalError(message string, requestID string) *InternalError
NewInternalError constructs an InternalError with an optional request ID for server-side correlation.
type InvalidAPIKeyError ¶
type InvalidAPIKeyError struct {
BaseError
}
InvalidAPIKeyError is returned when the API key is missing, expired, or not recognized. This is not retryable.
func NewInvalidAPIKeyError ¶
func NewInvalidAPIKeyError(message string) *InvalidAPIKeyError
NewInvalidAPIKeyError constructs an InvalidAPIKeyError. This is a permanent error — the caller must obtain a valid key.
type InvalidBucketError ¶
InvalidBucketError is returned when the volume delta bucket is outside the 1-11 range or not allowed by the current plan.
func NewInvalidBucketError ¶
func NewInvalidBucketError(message string, bucket VDBucket, validBuckets []VDBucket) *InvalidBucketError
NewInvalidBucketError constructs an InvalidBucketError with the rejected bucket and valid range.
type InvalidExchangeError ¶
InvalidExchangeError is returned when the exchange ID is unknown or the aggregate string is malformed. ValidExchanges lists supported IDs.
func NewInvalidExchangeError ¶
func NewInvalidExchangeError(message string, exchange string, validExchanges []string) *InvalidExchangeError
NewInvalidExchangeError constructs an InvalidExchangeError with the rejected ID and supported alternatives.
type InvalidJSONError ¶
type InvalidJSONError struct {
BaseError
}
InvalidJSONError is returned when a WebSocket message is not valid JSON.
func NewInvalidJSONError ¶
func NewInvalidJSONError(message string) *InvalidJSONError
NewInvalidJSONError constructs an InvalidJSONError for malformed WebSocket messages.
type InvalidParamsError ¶
InvalidParamsError is returned when a request has missing or malformed parameters. Field indicates which parameter failed validation.
func NewInvalidParamsError ¶
func NewInvalidParamsError(message string, field string) *InvalidParamsError
NewInvalidParamsError constructs an InvalidParamsError identifying which field failed validation.
type InvalidSymbolError ¶
InvalidSymbolError is returned when the trading pair symbol is not recognized by the exchange.
func NewInvalidSymbolError ¶
func NewInvalidSymbolError(message string, symbol string) *InvalidSymbolError
NewInvalidSymbolError constructs an InvalidSymbolError with the rejected symbol.
type InvalidTimeframeError ¶
InvalidTimeframeError is returned when the timeframe string is not supported or outside the allowed range.
func NewInvalidTimeframeError ¶
func NewInvalidTimeframeError(message string, timeframe Timeframe) *InvalidTimeframeError
NewInvalidTimeframeError constructs an InvalidTimeframeError with the rejected timeframe value.
type Liquidation ¶
type Liquidation struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
P float64 `json:"p" cbor:"p"` // Liquidation price
Q float64 `json:"q" cbor:"q"` // Quantity
S string `json:"s" cbor:"s"` // Side ("buy" or "sell")
}
Liquidation represents a liquidation event (returned by liquidations WebSocket channel)
type LiquidationHeatmapResponse ¶
type LiquidationHeatmapResponse struct {
Data []FlatHeatmap `json:"data" cbor:"data"` // Array of flat heatmaps
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
LiquidationHeatmapResponse represents the response from GET /liquidation_heatmap
type ListSubscriptionsMessage ¶
type ListSubscriptionsMessage struct {
Type string `json:"type" cbor:"type"` // "list_subscriptions"
}
ListSubscriptionsMessage represents a list subscriptions request to WebSocket
type MMTError ¶
type MMTError interface {
error
Code() ErrorCode
IsRetryable() bool
RetryAfter() time.Duration
Details() map[string]interface{}
}
MMTError is the interface implemented by all MMT API errors. Use errors.As to access typed error data. All concrete error types embed BaseError, so errors.As(err, &baseError) always works.
func ParseError ¶
func ParseError(resp ErrorResponse, retryAfter time.Duration) MMTError
ParseError parses an error response into the appropriate error type
func ParseWSError ¶
func ParseWSError(msg WSErrorMessage) MMTError
ParseWSError parses a WebSocket error message into the appropriate error type.
type Market ¶
type Market struct {
T int64 `json:"t" cbor:"t"` // Timestamp
P float64 `json:"p" cbor:"p"` // Current price
P24 float64 `json:"p24" cbor:"p24"` // Price 24h ago
Pc float64 `json:"pc" cbor:"pc"` // Price change (24h %)
Vb24 float64 `json:"vb24" cbor:"vb24"` // Buy volume (24h)
Vs24 float64 `json:"vs24" cbor:"vs24"` // Sell volume (24h)
Tb24 float64 `json:"tb24" cbor:"tb24"` // Buy trades (24h)
Ts24 float64 `json:"ts24" cbor:"ts24"` // Sell trades (24h)
Mc float64 `json:"mc" cbor:"mc"` // Market cap
Fdv float64 `json:"fdv" cbor:"fdv"` // Fully diluted valuation
Cs float64 `json:"cs" cbor:"cs"` // Circulating supply
Ts float64 `json:"ts" cbor:"ts"` // Total supply
Ms float64 `json:"ms" cbor:"ms"` // Max supply
}
Market represents market overview data (returned by markets WebSocket channel)
type MarketsResponse ¶
type MarketsResponse struct {
Exchanges []Exchange `json:"exchanges" cbor:"exchanges"` // Available exchanges and symbols
Streams []StreamInfo `json:"streams" cbor:"streams"` // Available data streams
BucketGroups []BucketGroupInfo `json:"bucket_groups" cbor:"bucket_groups"` // Volume delta bucket group definitions
Tier TierInfo `json:"tier" cbor:"tier"` // Your API key's tier information
}
MarketsResponse represents the response from GET /markets
type MaxConnsExceededError ¶
type MaxConnsExceededError struct {
BaseError
}
MaxConnsExceededError is returned when too many concurrent WebSocket connections are open for this API key.
func NewMaxConnsExceededError ¶
func NewMaxConnsExceededError(message string) *MaxConnsExceededError
NewMaxConnsExceededError constructs a MaxConnsExceededError. The caller should close unused connections before retrying.
type MaxPointsExceededError ¶
MaxPointsExceededError is returned when a request asks for more data points than the endpoint allows.
func NewMaxPointsExceededError ¶
func NewMaxPointsExceededError(message string, requested, max int) *MaxPointsExceededError
NewMaxPointsExceededError constructs a MaxPointsExceededError with the requested and maximum allowed points.
type MaxSubsExceededError ¶
MaxSubsExceededError is returned when a WebSocket connection has reached its subscription limit.
func NewMaxSubsExceededError ¶
func NewMaxSubsExceededError(message string, current, max int) *MaxSubsExceededError
NewMaxSubsExceededError constructs a MaxSubsExceededError with current and maximum subscription counts.
type NotConnectedError ¶
type NotConnectedError struct {
BaseError
}
NotConnectedError is returned when an operation requires an active connection but the client is disconnected.
func NewNotConnectedError ¶
func NewNotConnectedError(message string) *NotConnectedError
NewNotConnectedError constructs a NotConnectedError. The caller should establish a connection before retrying the operation.
type NotSubscribedError ¶
NotSubscribedError is returned when attempting to unsubscribe from a stream that is not currently active.
func NewNotSubscribedError ¶
func NewNotSubscribedError(message string, id string) *NotSubscribedError
NewNotSubscribedError constructs a NotSubscribedError with the subscription ID that was not found.
type OICandle ¶
type OICandle struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
O float64 `json:"o" cbor:"o"` // Open
H float64 `json:"h" cbor:"h"` // High
L float64 `json:"l" cbor:"l"` // Low
C float64 `json:"c" cbor:"c"` // Close
N int64 `json:"n" cbor:"n"` // Count (number of samples)
}
OICandle represents OHLC candle for Open Interest (returned by oi endpoint/channel)
type OIResponse ¶
type OIResponse struct {
Data []OICandle `json:"data" cbor:"data"` // Array of OI candles
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID (or aggregated)
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
OIResponse represents the response from GET /oi
type Orderbook ¶
type Orderbook struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix milliseconds)
A []OrderbookLevel `json:"a" cbor:"a"` // Asks [price, size] pairs (ascending)
B []OrderbookLevel `json:"b" cbor:"b"` // Bids [price, size] pairs (descending)
Lp float64 `json:"lp" cbor:"lp"` // Last price
Snapshot bool `json:"snapshot" cbor:"snapshot"` // Is full snapshot
Seq int64 `json:"seq" cbor:"seq"` // Sequence number
}
Orderbook represents an orderbook snapshot/update (returned by GET /orderbook and orderbook WebSocket channel)
type OrderbookLevel ¶
type OrderbookLevel [2]float64 // [price, size]
OrderbookLevel represents a single price level in the orderbook
type OrderbookLevels ¶
type OrderbookLevels string
OrderbookLevels represents the number of price levels to request for an orderbook. Use the predefined constants: OrderbookLevelsFull, OrderbookLevels100, etc.
const ( OrderbookLevelsFull OrderbookLevels = "full" OrderbookLevels100 OrderbookLevels = "100" OrderbookLevels1000 OrderbookLevels = "1000" OrderbookLevels5000 OrderbookLevels = "5000" )
type OrderbookOption ¶
type OrderbookOption func(*orderbookParams)
OrderbookOption configures an orderbook request.
func WithLevels ¶
func WithLevels(levels OrderbookLevels) OrderbookOption
WithLevels sets the number of price levels to return. Valid values: OrderbookLevels100, OrderbookLevels1000, OrderbookLevels5000. Omit this option to use the server default (full orderbook).
type OrderbookResponse ¶
type OrderbookResponse = Orderbook
OrderbookResponse represents the response from GET /orderbook
type RateLimitError ¶
RateLimitError is returned when the API rate limit is exceeded. Check RetryAfter for the recommended wait duration.
func NewRateLimitError ¶
func NewRateLimitError(message string, retryAfter time.Duration, limit, remaining, reset, used int64) *RateLimitError
NewRateLimitError constructs a RateLimitError with quota details.
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
RestClient is the MMT API REST client. It is safe for concurrent use.
func NewRestClient ¶
func NewRestClient(apiKey string, config RestClientConfig) *RestClient
NewRestClient creates a new REST client with the given API key and configuration. Panics if apiKey is empty or the configuration is invalid. Use DefaultRestClientConfig() to get a valid default configuration.
func (*RestClient) Config ¶
func (c *RestClient) Config() RestClientConfig
Config returns the client's configuration.
func (*RestClient) ContentType ¶
func (c *RestClient) ContentType() string
func (*RestClient) GetAggregatedFlatHeatmapHD ¶
func (c *RestClient) GetAggregatedFlatHeatmapHD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*FlatHeatmapHDResponse, error)
GetAggregatedFlatHeatmapHD returns aggregated high density heatmap data in flat format across multiple exchanges.
func (*RestClient) GetAggregatedFlatHeatmapSD ¶
func (c *RestClient) GetAggregatedFlatHeatmapSD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*FlatHeatmapSDResponse, error)
GetAggregatedFlatHeatmapSD returns aggregated standard density heatmap data in flat format across multiple exchanges.
func (*RestClient) GetAggregatedHeatmapHD ¶
func (c *RestClient) GetAggregatedHeatmapHD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*HeatmapHDResponse, error)
GetAggregatedHeatmapHD returns aggregated high density heatmap data across multiple exchanges.
func (*RestClient) GetAggregatedHeatmapSD ¶
func (c *RestClient) GetAggregatedHeatmapSD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*HeatmapSDResponse, error)
GetAggregatedHeatmapSD returns aggregated standard density heatmap data across multiple exchanges.
func (*RestClient) GetAggregatedOI ¶
func (c *RestClient) GetAggregatedOI(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*OIResponse, error)
GetAggregatedOI returns aggregated open interest data across multiple exchanges.
func (*RestClient) GetAggregatedStats ¶
func (c *RestClient) GetAggregatedStats(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*StatsResponse, error)
GetAggregatedStats returns aggregated market statistics across multiple exchanges. Note: mark price (mp) and funding rate (fr) are 0 for aggregated requests.
func (*RestClient) GetAggregatedVD ¶
func (c *RestClient) GetAggregatedVD(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, bucket VDBucket, from, to int64) (*VDResponse, error)
GetAggregatedVD returns aggregated volume delta across multiple exchanges filtered by trade size bucket.
func (*RestClient) GetAggregatedVolumes ¶
func (c *RestClient) GetAggregatedVolumes(ctx context.Context, exchanges []string, symbol string, timeframe Timeframe, from, to int64) (*VolumesResponse, error)
GetAggregatedVolumes returns aggregated volume profile data across multiple exchanges.
func (*RestClient) GetCandles ¶
func (c *RestClient) GetCandles(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*CandlesResponse, error)
GetCandles returns historical OHLCVT candle data for a single exchange. This endpoint does not support aggregation — use a single exchange ID.
func (*RestClient) GetFlatHeatmapHD ¶
func (c *RestClient) GetFlatHeatmapHD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*FlatHeatmapHDResponse, error)
GetFlatHeatmapHD returns high density heatmap data in flat format optimized for rendering. Recommended for new integrations.
func (*RestClient) GetFlatHeatmapSD ¶
func (c *RestClient) GetFlatHeatmapSD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*FlatHeatmapSDResponse, error)
GetFlatHeatmapSD returns standard density heatmap data in flat format optimized for rendering. Recommended for new integrations.
func (*RestClient) GetHeatmapHD ¶
func (c *RestClient) GetHeatmapHD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*HeatmapHDResponse, error)
GetHeatmapHD returns orderbook heatmap data at high density (finer price grouping) for a single exchange. Consider using GetFlatHeatmapHD for new integrations.
func (*RestClient) GetHeatmapSD ¶
func (c *RestClient) GetHeatmapSD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*HeatmapSDResponse, error)
GetHeatmapSD returns orderbook heatmap data at standard density (wider price grouping) for a single exchange. Consider using GetFlatHeatmapSD for new integrations.
func (*RestClient) GetLiquidationHeatmap ¶
func (c *RestClient) GetLiquidationHeatmap(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*LiquidationHeatmapResponse, error)
GetLiquidationHeatmap returns liquidation heatmap data in flat format. Available only for hyperliquid and hyperliquid-xyz. This endpoint does not support aggregation.
func (*RestClient) GetMarkets ¶
func (c *RestClient) GetMarkets(ctx context.Context) (*MarketsResponse, error)
GetMarkets returns available exchanges, symbols, data streams, bucket group definitions, and your API tier information. This endpoint has no rate limit cost.
func (*RestClient) GetOI ¶
func (c *RestClient) GetOI(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*OIResponse, error)
GetOI returns historical open interest data as OHLC candles for a single exchange.
func (*RestClient) GetOrderbook ¶
func (c *RestClient) GetOrderbook(ctx context.Context, exchange string, symbol string, opts ...OrderbookOption) (*OrderbookResponse, error)
GetOrderbook returns a real-time orderbook snapshot for a single exchange. Omitting WithLevels returns the full orderbook (server default). Use WithLevels(OrderbookLevels100) or similar to limit price levels.
func (*RestClient) GetStats ¶
func (c *RestClient) GetStats(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*StatsResponse, error)
GetStats returns market statistics for a single exchange including funding rate, liquidations, orderbook depth, and TPS metrics.
func (*RestClient) GetStopHeatmap ¶
func (c *RestClient) GetStopHeatmap(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*StopHeatmapResponse, error)
GetStopHeatmap returns stop heatmap data in flat format. Available only for hyperliquid and hyperliquid-xyz. This endpoint does not support aggregation.
func (*RestClient) GetTPHeatmap ¶
func (c *RestClient) GetTPHeatmap(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*TPHeatmapResponse, error)
GetTPHeatmap returns take-profit heatmap data in flat format. Available only for hyperliquid and hyperliquid-xyz. This endpoint does not support aggregation.
func (*RestClient) GetUsage ¶
func (c *RestClient) GetUsage(ctx context.Context) (*UsageResponse, error)
GetUsage returns your current rate limit quota status without consuming any weight. Use this to monitor quota before making requests.
func (*RestClient) GetVD ¶
func (c *RestClient) GetVD(ctx context.Context, exchange string, symbol string, timeframe Timeframe, bucket VDBucket, from, to int64) (*VDResponse, error)
GetVD returns volume delta (buy minus sell volume) as OHLC candles filtered by trade size bucket for a single exchange. The bucket must be 1-11 (see VDBucket constants).
func (*RestClient) GetVolumes ¶
func (c *RestClient) GetVolumes(ctx context.Context, exchange string, symbol string, timeframe Timeframe, from, to int64) (*VolumesResponse, error)
GetVolumes returns volume profile data showing buy and sell volumes distributed across price levels for a single exchange.
func (*RestClient) HTTPClient ¶
func (c *RestClient) HTTPClient() *http.Client
HTTPClient returns the underlying HTTP client.
type RestClientConfig ¶
type RestClientConfig struct {
// RestURL is the API base URL (defaults to the MMT production REST URL)
RestURL string
// Encoding is the content encoding (defaults to CBOR)
Encoding EncodingType
// HTTPClient is the HTTP client to use (defaults to http.DefaultClient with 30s timeout)
HTTPClient *http.Client
// MaxRetries is the maximum number of retries for transient failures (defaults to 2)
MaxRetries int
// RetryInitialDelay is the initial delay between retries (defaults to 500ms)
RetryInitialDelay time.Duration
// RetryMaxDelay is the maximum delay between retries (defaults to 5s)
RetryMaxDelay time.Duration
}
RestClientConfig configures the MMT API REST client. HTTPClient must not be nil — use DefaultRestClientConfig() to get a valid one.
func DefaultRestClientConfig ¶
func DefaultRestClientConfig() RestClientConfig
type ServiceUnavailableError ¶
type ServiceUnavailableError struct {
}
ServiceUnavailableError is returned when the server is temporarily unable to handle requests. RetryAfter suggests when to retry.
func NewServiceUnavailableError ¶
func NewServiceUnavailableError(message string, retryAfter time.Duration) *ServiceUnavailableError
NewServiceUnavailableError constructs a ServiceUnavailableError with a suggested retry duration.
type Stat ¶
type Stat struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
Mp float64 `json:"mp" cbor:"mp"` // Mark price
Lp float64 `json:"lp" cbor:"lp"` // Last price
Fr float64 `json:"fr" cbor:"fr"` // Funding rate
Lb float64 `json:"lb" cbor:"lb"` // Liquidation buy volume
Ls float64 `json:"ls" cbor:"ls"` // Liquidation sell volume
Tlb int64 `json:"tlb" cbor:"tlb"` // Total liquidation buy count
Tls int64 `json:"tls" cbor:"tls"` // Total liquidation sell count
Vb float64 `json:"vb" cbor:"vb"` // Buy volume
Vs float64 `json:"vs" cbor:"vs"` // Sell volume
Tb int64 `json:"tb" cbor:"tb"` // Buy trade count
Ts int64 `json:"ts" cbor:"ts"` // Sell trade count
Sk []float64 `json:"sk" cbor:"sk"` // Skew data
As []float64 `json:"as" cbor:"as"` // Ask sizes
Bs []float64 `json:"bs" cbor:"bs"` // Bid sizes
Mxt int64 `json:"mxt" cbor:"mxt"` // Max TPS in period
Mnt int64 `json:"mnt" cbor:"mnt"` // Min TPS in period
Avt float64 `json:"avt" cbor:"avt"` // Average trade size
It int64 `json:"it" cbor:"it"` // Instant TPS
}
Stat represents comprehensive market statistics (returned by stats endpoint/channel)
type StatsResponse ¶
type StatsResponse struct {
Data []Stat `json:"data" cbor:"data"` // Array of stats
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID (or aggregated)
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
StatsResponse represents the response from GET /stats
type StopHeatmapResponse ¶
type StopHeatmapResponse = LiquidationHeatmapResponse
StopHeatmapResponse represents the response from GET /stop_heatmap
type StreamInfo ¶
type StreamInfo struct {
ID string `json:"id" cbor:"id"` // Stream identifier
Name string `json:"name" cbor:"name"` // Stream display name
MaxPoints int64 `json:"max_points" cbor:"max_points"` // Maximum data points per request (0 = realtime only)
CostMultiplier int `json:"cost_multiplier" cbor:"cost_multiplier"` // Rate limit cost multiplier
Available bool `json:"available" cbor:"available"` // Whether stream is available for your tier
}
StreamInfo represents a data stream with rate limit and availability info
type SubscribeMessage ¶
type SubscribeMessage struct {
Type string `json:"type"` // "subscribe"
ID string `json:"id,omitempty"` // client-generated UUID for correlation
Channel string `json:"channel"` // Channel name
Exchange string `json:"exchange"` // Exchange ID
Symbol string `json:"symbol"` // Trading pair
Tf Timeframe `json:"tf,omitempty"` // Timeframe (if applicable)
Bucket VDBucket `json:"bucket,omitempty"` // Bucket for VD (if applicable)
}
SubscribeMessage represents a subscribe request to WebSocket. Note: control messages are always encoded as JSON regardless of the configured encoding. CBOR tags are omitted on all fields because the JSON encoder is used for all control messages.
type SubscribeOption ¶
type SubscribeOption func(*subscribeConfig)
SubscribeOption is an optional parameter for Subscribe.
func WithBucket ¶
func WithBucket(bucket VDBucket) SubscribeOption
WithBucket sets the volume delta bucket for a subscription. Only applies to volume delta (VD) channels.
type Subscription ¶
type Subscription struct {
Channel WSChannel `json:"channel" cbor:"channel"` // Channel name
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf,omitempty" cbor:"tf,omitempty"` // Timeframe (if applicable)
Bucket VDBucket `json:"bucket,omitempty" cbor:"bucket,omitempty"` // Bucket for VD (if applicable)
}
Subscription represents a WebSocket subscription
type SubscriptionCallbacks ¶
type SubscriptionCallbacks struct {
OnMessageFunc func(msg interface{})
OnSubscribedFunc func(sub *ActiveSubscription)
OnUnsubscribedFunc func(sub *ActiveSubscription)
}
SubscriptionCallbacks is a convenience struct that implements SubscriptionHandler by calling the provided callback functions. Any nil callback is a no-op.
func (SubscriptionCallbacks) OnMessage ¶
func (f SubscriptionCallbacks) OnMessage(msg interface{})
OnMessage implements SubscriptionHandler. Delegates to OnMessageFunc if set.
func (SubscriptionCallbacks) OnSubscribed ¶
func (f SubscriptionCallbacks) OnSubscribed(sub *ActiveSubscription)
OnSubscribed implements SubscriptionHandler. Delegates to OnSubscribedFunc if set.
func (SubscriptionCallbacks) OnUnsubscribed ¶
func (f SubscriptionCallbacks) OnUnsubscribed(sub *ActiveSubscription)
OnUnsubscribed implements SubscriptionHandler. Delegates to OnUnsubscribedFunc if set.
type SubscriptionHandler ¶
type SubscriptionHandler interface {
OnMessage(msg interface{})
OnSubscribed(sub *ActiveSubscription)
OnUnsubscribed(sub *ActiveSubscription)
}
SubscriptionHandler handles messages for a subscription
type Symbol ¶
type Symbol struct {
// Symbol is the MMT-normalized format REQUIRED for ALL API calls (e.g., "btc/usd", "eth/usd")
// Use this field when calling GetCandles, GetStats, SubscribeCandles, etc.
Symbol string `json:"symbol" cbor:"symbol"`
// ExchangeTicker is the exchange's native format (e.g., "BTCUSDT", "ETHUSDT")
// This is for reference/display ONLY - DO NOT use for API calls.
ExchangeTicker string `json:"exchange_ticker" cbor:"exchange_ticker"`
Base string `json:"base" cbor:"base"` // Base asset (e.g., "BTC")
Quote string `json:"quote" cbor:"quote"` // Quote asset (e.g., "USDT")
NormalisedBase string `json:"normalised_base" cbor:"normalised_base"` // Normalized base (e.g., "btc")
NormalisedQuote string `json:"normalised_quote" cbor:"normalised_quote"` // Normalized quote (e.g., "usd")
TickSize float64 `json:"tick_size" cbor:"tick_size"` // Minimum price increment
StepSize float64 `json:"step_size" cbor:"step_size"` // Minimum quantity increment
}
Symbol represents a trading pair on an exchange. When calling API methods, ALWAYS use the Symbol field (e.g., "btc/usd"), NOT the ExchangeTicker field (e.g., "BTCUSDT").
type TPHeatmapResponse ¶
type TPHeatmapResponse = LiquidationHeatmapResponse
TPHeatmapResponse represents the response from GET /tp_heatmap
type TierInfo ¶
type TierInfo struct {
Name string `json:"name" cbor:"name"` // Tier name (basic, pro)
MaxHistoryDays int `json:"max_history_days" cbor:"max_history_days"` // Maximum historical data access in days (0 = unlimited)
WeightPerMin int `json:"weight_per_min,omitempty" cbor:"weight_per_min,omitempty"` // Rate limit weight per minute
MaxWSConnections int `json:"max_ws_connections" cbor:"max_ws_connections"` // Maximum concurrent WebSocket connections
MaxSubsPerConnection int `json:"max_subs_per_connection" cbor:"max_subs_per_connection"` // Maximum subscriptions per WebSocket connection
AllowedBuckets []int `json:"allowed_buckets" cbor:"allowed_buckets"` // VD bucket group IDs available for your tier
}
TierInfo represents API tier limits and quotas
type TierRestrictedError ¶
TierRestrictedError is returned when a request exceeds the API key's plan limits. MaxHistoryDays indicates how far back data is accessible.
func NewTierRestrictedError ¶
func NewTierRestrictedError(message string, maxHistoryDays int, earliestAllowed int64) *TierRestrictedError
NewTierRestrictedError constructs a TierRestrictedError with plan limit details.
type Timeframe ¶
type Timeframe string
const ( Timeframe1s Timeframe = "1s" Timeframe5s Timeframe = "5s" Timeframe10s Timeframe = "10s" Timeframe15s Timeframe = "15s" Timeframe30s Timeframe = "30s" Timeframe1m Timeframe = "1m" Timeframe3m Timeframe = "3m" Timeframe5m Timeframe = "5m" Timeframe15m Timeframe = "15m" Timeframe30m Timeframe = "30m" Timeframe1h Timeframe = "1h" Timeframe2h Timeframe = "2h" Timeframe4h Timeframe = "4h" Timeframe6h Timeframe = "6h" Timeframe8h Timeframe = "8h" Timeframe12h Timeframe = "12h" Timeframe1d Timeframe = "1d" Timeframe3d Timeframe = "3d" Timeframe1W Timeframe = "1W" Timeframe1M Timeframe = "1M" )
Timeframes available at the time of writing. If support for new timeframes is added to the MMT API, they can be created manually with Timeframe("value").
type TimeoutError ¶
TimeoutError is returned when the server does not respond within the configured deadline.
func NewTimeoutError ¶
func NewTimeoutError(message string, requestID string) *TimeoutError
NewTimeoutError constructs a TimeoutError with an optional request ID for server-side correlation.
type Trade ¶
type Trade struct {
ID string `json:"id" cbor:"id"` // Trade ID
T int64 `json:"t" cbor:"t"` // Timestamp (Unix milliseconds)
P float64 `json:"p" cbor:"p"` // Price
Q float64 `json:"q" cbor:"q"` // Quantity (base)
B bool `json:"b" cbor:"b"` // true = buy side, false = sell side
}
Trade represents a real-time trade (returned by trades WebSocket channel)
type UnknownTypeError ¶
type UnknownTypeError struct {
BaseError
}
UnknownTypeError is returned when a WebSocket message has an unrecognized type field.
func NewUnknownTypeError ¶
func NewUnknownTypeError(message string) *UnknownTypeError
NewUnknownTypeError constructs an UnknownTypeError for WebSocket messages with unrecognized type fields.
type UnsubscribeMessage ¶
type UnsubscribeMessage struct {
Type string `json:"type"` // "unsubscribe"
Channel string `json:"channel"` // Channel name
Exchange string `json:"exchange"` // Exchange ID
Symbol string `json:"symbol"` // Trading pair
Tf Timeframe `json:"tf,omitempty"` // Timeframe (if applicable)
Bucket VDBucket `json:"bucket,omitempty"` // Bucket for VD (if applicable)
}
UnsubscribeMessage represents an unsubscribe request to WebSocket. Note: control messages are always encoded as JSON regardless of the configured encoding. CBOR tags are omitted on all fields because the JSON encoder is used for all control messages.
type UsageResponse ¶
type UsageResponse struct {
Limit int64 `json:"limit" cbor:"limit"` // Max weight per minute
Remaining int64 `json:"remaining" cbor:"remaining"` // Remaining weight
Used int64 `json:"used" cbor:"used"` // Weight consumed
Reset int64 `json:"reset" cbor:"reset"` // Window reset timestamp
WindowSeconds int64 `json:"window_seconds" cbor:"window_seconds"` // Window duration
}
UsageResponse represents the response from GET /usage
func (UsageResponse) ResetTime ¶
func (u UsageResponse) ResetTime() time.Time
ResetTime returns the reset time as time.Time
type VDBucket ¶
type VDBucket int
VDBucket represents a volume delta bucket group
const ( VDBucketAll VDBucket = 1 // All trades VDBucket1To1K VDBucket = 2 // $1 - $1,000 VDBucket1KTo10K VDBucket = 3 // $1,000 - $10,000 VDBucket10KTo25K VDBucket = 4 // $10,000 - $25,000 VDBucket25KTo50K VDBucket = 5 // $25,000 - $50,000 VDBucket50KTo100K VDBucket = 6 // $50,000 - $100,000 VDBucket100KTo250K VDBucket = 7 // $100,000 - $250,000 VDBucket250KTo500K VDBucket = 8 // $250,000 - $500,000 VDBucket500KTo1M VDBucket = 9 // $500,000 - $1,000,000 VDBucket1MTo5M VDBucket = 10 // $1,000,000 - $5,000,000 VDBucket5MPlus VDBucket = 11 // $5,000,000+ )
type VDBucketInfo ¶
VDBucketInfo returns information about a bucket
func GetVDBucketInfo ¶
func GetVDBucketInfo(bucket VDBucket) (VDBucketInfo, bool)
GetVDBucketInfo returns information about a bucket
type VDCandle ¶
type VDCandle = OICandle
VDCandle represents OHLC candle for Volume Delta (returned by vd endpoint/channel) Same structure as OICandle
type VDResponse ¶
type VDResponse struct {
Data []VDCandle `json:"data" cbor:"data"` // Array of VD candles
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID (or aggregated)
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
Bucket VDBucket `json:"bucket,omitempty" cbor:"bucket,omitempty"` // Bucket group used
}
VDResponse represents the response from GET /vd
type Volume ¶
type Volume struct {
T int64 `json:"t" cbor:"t"` // Timestamp (Unix seconds)
P []float64 `json:"p" cbor:"p"` // Price levels
B []float64 `json:"b" cbor:"b"` // Buy volume at each level
S []float64 `json:"s" cbor:"s"` // Sell volume at each level
Pg float64 `json:"pg" cbor:"pg"` // Price granularity
}
Volume represents price-level volume distribution (returned by volumes endpoint/channel)
type VolumesResponse ¶
type VolumesResponse struct {
Data []Volume `json:"data" cbor:"data"` // Array of volume profiles
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID (or aggregated)
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf" cbor:"tf"` // Timeframe
From int64 `json:"from" cbor:"from"` // Start timestamp
To int64 `json:"to" cbor:"to"` // End timestamp
Points int `json:"points" cbor:"points"` // Number of data points
}
VolumesResponse represents the response from GET /volumes
type WSCandleMessage ¶
type WSCandleMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data Candle `json:"data" cbor:"data"`
}
WSCandleMessage represents a candle data message from WebSocket
type WSChannel ¶
type WSChannel string
WSChannel represents a WebSocket data channel
const ( WSChannelCandles WSChannel = "candles" WSChannelTrades WSChannel = "trades" WSChannelStats WSChannel = "stats" WSChannelOI WSChannel = "oi" WSChannelVD WSChannel = "vd" WSChannelVolumes WSChannel = "volumes" WSChannelHeatmapSD WSChannel = "heatmap_sd" WSChannelHeatmapHD WSChannel = "heatmap_hd" WSChannelFlatHeatmapSD WSChannel = "flat_heatmap_sd" WSChannelFlatHeatmapHD WSChannel = "flat_heatmap_hd" WSChannelOrderbook WSChannel = "depth" // WebSocket channel name is "depth", REST endpoint is /orderbook WSChannelMarkets WSChannel = "markets" WSChannelLiquidations WSChannel = "liquidations" WSChannelLiquidationHeatmap WSChannel = "liquidation_heatmap" WSChannelStopHeatmap WSChannel = "stop_heatmap" WSChannelTPHeatmap WSChannel = "tp_heatmap" )
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
WSClient is the MMT API WebSocket client. It is safe for concurrent use. After Close(), the client cannot be reused; create a new instance instead.
func NewWSClient ¶
func NewWSClient(apiKey string, config WSClientConfig) *WSClient
NewWSClient creates a new WebSocket client with the given API key and configuration. Panics if apiKey is empty or the WebSocket URL is invalid. Use DefaultWSClientConfig() to get a valid default configuration.
func (*WSClient) Close ¶
Close disconnects the WebSocket and releases resources. Returns any error from closing the underlying connection. After Close, the client cannot be reused.
func (*WSClient) Config ¶
func (c *WSClient) Config() WSClientConfig
Config returns the WebSocket client configuration.
func (*WSClient) Connect ¶
Connect establishes the WebSocket connection. It is safe to call multiple times — returns nil if already connected. On success, stored subscriptions are automatically resubscribed.
func (*WSClient) GetSubscriptionCount ¶
GetSubscriptionCount returns the number of active (server-confirmed) subscriptions. Pending subscriptions are not included.
func (*WSClient) GetSubscriptions ¶
func (c *WSClient) GetSubscriptions() []*ActiveSubscription
GetSubscriptions returns all active (server-confirmed) subscriptions. Pending subscriptions are not included.
func (*WSClient) IsConnected ¶
IsConnected returns whether the client is connected
func (*WSClient) ListSubscriptions ¶
ListSubscriptions sends a list_subscriptions message to the server This queries the server for current subscriptions (useful for syncing state)
func (*WSClient) MaxSubscriptions ¶
MaxSubscriptions returns the server-reported subscription limit, or 0 if not yet connected.
func (*WSClient) Subscribe ¶
func (c *WSClient) Subscribe(channel WSChannel, exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler, opts ...SubscribeOption) error
Subscribe subscribes to a channel. The subscription is stored and automatically resubscribed after reconnection. Returns AlreadySubscribedError if the same channel+exchange+symbol+timeframe+bucket combination is already active. Use OnSubscribed to know when the server has confirmed the subscription.
func (*WSClient) SubscribeAggregatedFlatHeatmapHD ¶
func (c *WSClient) SubscribeAggregatedFlatHeatmapHD(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedFlatHeatmapHD subscribes to aggregated high density flat heatmap updates.
func (*WSClient) SubscribeAggregatedFlatHeatmapSD ¶
func (c *WSClient) SubscribeAggregatedFlatHeatmapSD(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedFlatHeatmapSD subscribes to aggregated standard density flat heatmap updates.
func (*WSClient) SubscribeAggregatedHeatmapHD ¶
func (c *WSClient) SubscribeAggregatedHeatmapHD(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedHeatmapHD subscribes to aggregated high density heatmap updates.
func (*WSClient) SubscribeAggregatedHeatmapSD ¶
func (c *WSClient) SubscribeAggregatedHeatmapSD(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedHeatmapSD subscribes to aggregated standard density heatmap updates.
func (*WSClient) SubscribeAggregatedLiquidations ¶
func (c *WSClient) SubscribeAggregatedLiquidations(exchanges []string, symbol string, handler SubscriptionHandler) error
SubscribeAggregatedLiquidations subscribes to aggregated liquidation events.
func (*WSClient) SubscribeAggregatedMarkets ¶
func (c *WSClient) SubscribeAggregatedMarkets(exchanges []string, symbol string, handler SubscriptionHandler) error
SubscribeAggregatedMarkets subscribes to aggregated market overview updates across multiple exchanges.
func (*WSClient) SubscribeAggregatedOI ¶
func (c *WSClient) SubscribeAggregatedOI(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedOI subscribes to aggregated open interest across multiple exchanges.
func (*WSClient) SubscribeAggregatedStats ¶
func (c *WSClient) SubscribeAggregatedStats(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedStats subscribes to aggregated market statistics across multiple exchanges.
func (*WSClient) SubscribeAggregatedVD ¶
func (c *WSClient) SubscribeAggregatedVD(exchanges []string, symbol string, timeframe Timeframe, bucket VDBucket, handler SubscriptionHandler) error
SubscribeAggregatedVD subscribes to aggregated volume delta across multiple exchanges.
func (*WSClient) SubscribeAggregatedVolumes ¶
func (c *WSClient) SubscribeAggregatedVolumes(exchanges []string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeAggregatedVolumes subscribes to aggregated volume profile updates.
func (*WSClient) SubscribeCandles ¶
func (c *WSClient) SubscribeCandles(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeCandles subscribes to real-time OHLCVT candle updates.
func (*WSClient) SubscribeFlatHeatmapHD ¶
func (c *WSClient) SubscribeFlatHeatmapHD(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeFlatHeatmapHD subscribes to high density flat heatmap updates. Recommended for new integrations.
func (*WSClient) SubscribeFlatHeatmapSD ¶
func (c *WSClient) SubscribeFlatHeatmapSD(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeFlatHeatmapSD subscribes to standard density flat heatmap updates. Recommended for new integrations.
func (*WSClient) SubscribeHeatmapHD ¶
func (c *WSClient) SubscribeHeatmapHD(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeHeatmapHD subscribes to high density orderbook heatmap updates.
func (*WSClient) SubscribeHeatmapSD ¶
func (c *WSClient) SubscribeHeatmapSD(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeHeatmapSD subscribes to standard density orderbook heatmap updates.
func (*WSClient) SubscribeLiquidationHeatmap ¶
func (c *WSClient) SubscribeLiquidationHeatmap(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeLiquidationHeatmap subscribes to liquidation heatmap updates. Available only for hyperliquid and hyperliquid-xyz.
func (*WSClient) SubscribeLiquidations ¶
func (c *WSClient) SubscribeLiquidations(exchange string, symbol string, handler SubscriptionHandler) error
SubscribeLiquidations subscribes to liquidation events.
func (*WSClient) SubscribeMarkets ¶
func (c *WSClient) SubscribeMarkets(exchange string, symbol string, handler SubscriptionHandler) error
SubscribeMarkets subscribes to market overview updates (price, 24h change, volume, market cap).
func (*WSClient) SubscribeOI ¶
func (c *WSClient) SubscribeOI(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeOI subscribes to real-time open interest updates.
func (*WSClient) SubscribeOrderbook ¶
func (c *WSClient) SubscribeOrderbook(exchange string, symbol string, handler SubscriptionHandler) error
SubscribeOrderbook subscribes to real-time orderbook depth updates.
func (*WSClient) SubscribeStats ¶
func (c *WSClient) SubscribeStats(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeStats subscribes to real-time market statistics updates.
func (*WSClient) SubscribeStopHeatmap ¶
func (c *WSClient) SubscribeStopHeatmap(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeStopHeatmap subscribes to stop heatmap updates. Available only for hyperliquid and hyperliquid-xyz.
func (*WSClient) SubscribeTPHeatmap ¶
func (c *WSClient) SubscribeTPHeatmap(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeTPHeatmap subscribes to take-profit heatmap updates. Available only for hyperliquid and hyperliquid-xyz.
func (*WSClient) SubscribeTrades ¶
func (c *WSClient) SubscribeTrades(exchange string, symbol string, handler SubscriptionHandler) error
SubscribeTrades subscribes to individual trade events as they occur.
func (*WSClient) SubscribeVD ¶
func (c *WSClient) SubscribeVD(exchange string, symbol string, timeframe Timeframe, bucket VDBucket, handler SubscriptionHandler) error
SubscribeVD subscribes to real-time volume delta updates filtered by trade size bucket.
func (*WSClient) SubscribeVolumes ¶
func (c *WSClient) SubscribeVolumes(exchange string, symbol string, timeframe Timeframe, handler SubscriptionHandler) error
SubscribeVolumes subscribes to real-time volume profile updates.
func (*WSClient) Tier ¶
Tier returns the server-reported tier, or empty string if not yet connected.
func (*WSClient) Unsubscribe ¶
func (c *WSClient) Unsubscribe(sub *ActiveSubscription) error
Unsubscribe unsubscribes from a channel. Returns NotSubscribedError if the subscription is not currently active. Calls OnUnsubscribed on the handler before returning.
type WSClientConfig ¶
type WSClientConfig struct {
// WsURL is the WebSocket URL (defaults to DefaultWSURL)
WsURL string
// Encoding is the content encoding (defaults to CBOR)
Encoding EncodingType
// Timeout is the read/write timeout (defaults to 10s)
Timeout time.Duration
// SubscribeTimeout is the timeout for subscribe/unsubscribe operations (defaults to 5s)
SubscribeTimeout time.Duration
// ReconnectDelay is the initial reconnect delay (defaults to 1s)
ReconnectDelay time.Duration
// MaxReconnectDelay is the maximum reconnect delay (defaults to 30s)
MaxReconnectDelay time.Duration
// MaxReconnectAttempts is the maximum number of reconnection attempts after
// a disconnect. 0 disables auto-reconnection.
MaxReconnectAttempts int
// SendChanBuffer is the buffer size for outgoing messages before writeLoop
// consumes them. Defaults to 500, which matches the top-tier subscription limit.
SendChanBuffer int
// OnConnect is called when the connection is established, after stored
// subscriptions have been automatically resubscribed.
OnConnect func()
// OnDisconnect is called when the connection drops unexpectedly.
// It is NOT called when Close() is invoked explicitly.
OnDisconnect func()
// OnError is called on errors. May be invoked concurrently from multiple
// goroutines.
OnError func(error)
// OnMessage is called for every incoming WebSocket message after routing.
// For data messages, plus subscribed/unsubscribed control messages, channel
// is populated; for other control messages, it is not.
OnMessage func(msgType WSMessageType, channel WSChannel, data []byte)
// OnSubscriptionsListed is called when the server sends a subscriptions list
// in response to ListSubscriptions or on its own initiative.
OnSubscriptionsListed func([]Subscription)
}
WSClientConfig configures the WebSocket client. All callbacks are called from the client's internal goroutines — keep them short or spawn your own goroutine for heavy work.
func DefaultWSClientConfig ¶
func DefaultWSClientConfig() WSClientConfig
DefaultWSClientConfig returns a default WebSocket client configuration
type WSConnectedMessage ¶
type WSConnectedMessage struct {
Type WSMessageType `json:"type" cbor:"type"` // "connected"
Tier string `json:"tier" cbor:"tier"` // Your tier
MaxSubscriptions int `json:"max_subscriptions" cbor:"max_subscriptions"` // Max subscriptions allowed
Format string `json:"format" cbor:"format"` // "json" or "cbor"
}
WSConnectedMessage represents the connected message from WebSocket
type WSDisconnectingMessage ¶
type WSDisconnectingMessage struct {
Type WSMessageType `json:"type" cbor:"type"` // "disconnecting"
Reason string `json:"reason" cbor:"reason"` // Reason: "backpressure", "timeout", "server_shutdown", "normal"
}
WSDisconnectingMessage represents the disconnecting message from WebSocket
type WSErrorMessage ¶
type WSErrorMessage struct {
Type WSMessageType `json:"type" cbor:"type"` // "error"
Code string `json:"code" cbor:"code"` // Error code
Message string `json:"message" cbor:"message"` // Error message
ID string `json:"id,omitempty" cbor:"id,omitempty"` // Subscription UUID (if server includes it)
Details map[string]interface{} `json:"details,omitempty" cbor:"details,omitempty"` // Additional error details
}
WSErrorMessage represents an error message from WebSocket
type WSFlatHeatmapMessage ¶
type WSFlatHeatmapMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data FlatHeatmap `json:"data" cbor:"data"`
}
WSFlatHeatmapMessage represents a flat heatmap data message from WebSocket
type WSHeatmapMessage ¶
type WSHeatmapMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data Heatmap `json:"data" cbor:"data"`
}
WSHeatmapMessage represents a heatmap data message from WebSocket
type WSLiquidationMessage ¶
type WSLiquidationMessage struct {
WSMessageBase
Data Liquidation `json:"data" cbor:"data"`
}
WSLiquidationMessage represents a liquidation data message from WebSocket
type WSMarketMessage ¶
type WSMarketMessage struct {
WSMessageBase
Data Market `json:"data" cbor:"data"`
}
WSMarketMessage represents a market data message from WebSocket
type WSMessageBase ¶
type WSMessageBase struct {
Type WSMessageType `json:"type" cbor:"type"`
Channel WSChannel `json:"channel" cbor:"channel"`
Exchange string `json:"exchange" cbor:"exchange"`
Symbol string `json:"symbol" cbor:"symbol"`
Tf Timeframe `json:"tf,omitempty" cbor:"tf,omitempty"`
ID string `json:"id" cbor:"id"`
Bucket VDBucket `json:"bucket,omitempty" cbor:"bucket,omitempty"`
}
WSMessageBase contains the common fields present in every data message. It is embedded in all concrete message types (WSCandleMessage, etc.) and is also decoded alone for one-shot routing of incoming messages.
type WSMessageType ¶
type WSMessageType string
WSMessageType represents the type of WebSocket message
const ( WSMessageTypeData WSMessageType = "data" WSMessageTypeError WSMessageType = "error" WSMessageTypeConnected WSMessageType = "connected" WSMessageTypeSubscribed WSMessageType = "subscribed" WSMessageTypeUnsubscribed WSMessageType = "unsubscribed" WSMessageTypeSubscriptions WSMessageType = "subscriptions" WSMessageTypeDisconnecting WSMessageType = "disconnecting" )
type WSOIMessage ¶
type WSOIMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data OICandle `json:"data" cbor:"data"`
}
WSOIMessage represents an OI data message from WebSocket
type WSOrderbookMessage ¶
type WSOrderbookMessage struct {
WSMessageBase
Data Orderbook `json:"data" cbor:"data"`
}
WSOrderbookMessage represents an orderbook data message from WebSocket
type WSStatMessage ¶
type WSStatMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data Stat `json:"data" cbor:"data"`
}
WSStatMessage represents a stat data message from WebSocket
type WSSubscribedMessage ¶
type WSSubscribedMessage struct {
Type WSMessageType `json:"type" cbor:"type"` // "subscribed"
ID string `json:"id" cbor:"id"` // Subscription ID
Channel WSChannel `json:"channel" cbor:"channel"` // Channel name
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf,omitempty" cbor:"tf,omitempty"` // Timeframe
Bucket VDBucket `json:"bucket,omitempty" cbor:"bucket,omitempty"` // Bucket number
}
WSSubscribedMessage represents the subscribed confirmation from WebSocket
type WSSubscriptionsMessage ¶
type WSSubscriptionsMessage struct {
Type WSMessageType `json:"type" cbor:"type"` // "subscriptions"
Count int `json:"count" cbor:"count"` // Current subscription count
Max int `json:"max" cbor:"max"` // Max allowed
Subscriptions []Subscription `json:"subscriptions" cbor:"subscriptions"` // Active subscriptions
}
WSSubscriptionsMessage represents the subscriptions list from WebSocket
type WSTradeMessage ¶
type WSTradeMessage struct {
WSMessageBase
Data Trade `json:"data" cbor:"data"`
}
WSTradeMessage represents a trade data message from WebSocket
type WSUnsubscribedMessage ¶
type WSUnsubscribedMessage struct {
Type WSMessageType `json:"type" cbor:"type"` // "unsubscribed"
ID string `json:"id" cbor:"id"` // Subscription ID
Channel WSChannel `json:"channel" cbor:"channel"` // Channel name
Exchange string `json:"exchange" cbor:"exchange"` // Exchange ID
Symbol string `json:"symbol" cbor:"symbol"` // Trading pair
Tf Timeframe `json:"tf,omitempty" cbor:"tf,omitempty"` // Timeframe
Bucket VDBucket `json:"bucket,omitempty" cbor:"bucket,omitempty"` // Bucket number
}
WSUnsubscribedMessage represents the unsubscribed confirmation from WebSocket
type WSVDMessage ¶
type WSVDMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data VDCandle `json:"data" cbor:"data"`
}
WSVDMessage represents a VD data message from WebSocket
type WSVolumesMessage ¶
type WSVolumesMessage struct {
WSMessageBase
Tf Timeframe `json:"tf" cbor:"tf"`
Data Volume `json:"data" cbor:"data"`
}
WSVolumesMessage represents a volumes data message from WebSocket