mexc

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package mexc is the library behind the mexc command line: the HTTP client, request shaping, and the typed data models for MEXC public market data.

The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load. MEXC uses a Binance-compatible v3 API so endpoints are identical in shape.

Index

Constants

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "mexc-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to MEXC.

View Source
const Host = "api.mexc.com"

Host is the API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	// Rate is the minimum gap between requests. Zero means no pacing.
	Rate    time.Duration
	Retries int
	// contains filtered or unexported fields
}

Client talks to the MEXC public API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults: a 15s timeout, a 200ms minimum gap between requests, and three retries on transient errors.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.

func (*Client) GetDepth

func (c *Client) GetDepth(ctx context.Context, symbol string, limit int) ([]*Order, error)

GetDepth fetches the order book for a symbol and returns bids then asks.

func (*Client) GetKlines

func (c *Client) GetKlines(ctx context.Context, symbol, interval string, limit int) ([]*Kline, error)

GetKlines fetches candlestick data for a symbol.

func (*Client) GetSymbols

func (c *Client) GetSymbols(ctx context.Context, quote, status string, limit int) ([]*Symbol, error)

GetSymbols fetches all trading pairs from exchangeInfo, with optional quote and status filters. status should be the human-readable form: "TRADING" or "INACTIVE".

func (*Client) GetTicker

func (c *Client) GetTicker(ctx context.Context, symbol string) (*Ticker, error)

GetTicker fetches 24-hour rolling stats for a single symbol.

type Domain

type Domain struct{}

Domain is the MEXC driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Kline

type Kline struct {
	OpenTime  int64  `kit:"id" json:"open_time"`
	Open      string `json:"open"`
	High      string `json:"high"`
	Low       string `json:"low"`
	Close     string `json:"close"`
	Volume    string `json:"volume"`
	CloseTime int64  `json:"close_time"`
	QuoteVol  string `json:"quote_vol"`
}

Kline is one OHLCV candlestick bar.

type Order

type Order struct {
	Side  string `kit:"id" json:"side"`
	Price string `json:"price"`
	Size  string `json:"size"`
}

Order is one entry in the order book (bid or ask).

type Symbol

type Symbol struct {
	Symbol string `kit:"id" json:"symbol"`
	Base   string `json:"base"`
	Quote  string `json:"quote"`
	Status string `json:"status"`
}

Symbol describes a trading pair listed on MEXC.

type Ticker

type Ticker struct {
	Symbol        string `kit:"id" json:"symbol"`
	Last          string `json:"last"`
	Bid           string `json:"bid"`
	Ask           string `json:"ask"`
	Open          string `json:"open"`
	High          string `json:"high"`
	Low           string `json:"low"`
	Volume        string `json:"volume"`
	QuoteVolume   string `json:"quote_volume"`
	ChangePercent string `json:"change_percent"`
}

Ticker holds 24-hour rolling-window statistics for a symbol.

Jump to

Keyboard shortcuts

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