Documentation
¶
Overview ¶
Package phemex provides a Go client for the Phemex cryptocurrency exchange REST API.
The Client handles request signing, retries, and error mapping. Subpackages expose typed methods for each API domain (market data, spot, USDⓈ-M, etc.).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AuthenticationError ¶
type AuthenticationError struct {
APIError
}
AuthenticationError indicates an invalid or missing API key/secret.
func (*AuthenticationError) Error ¶
func (e *AuthenticationError) Error() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the central HTTP client for the Phemex REST API.
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method, path string, params map[string]any) (*Response, error)
Do sends an HTTP request with the provided method and path. Query and body parameters are supplied through params. It returns the raw JSON-decoded response envelope, or an error if the request fails.
For GET and DELETE requests params are encoded as query parameters. For POST/PUT/PATCH requests params are encoded as JSON in the request body.
type Config ¶
type Config struct {
// APIKey is the Phemex API key. Optional for public market endpoints.
APIKey string
// APISecret is the Phemex API secret. Required for private endpoints.
APISecret string
// BaseURI is the base URL for the Phemex REST API.
BaseURI string
// HTTPClient allows a custom http.Client to be supplied.
HTTPClient *http.Client
// Timeout is the default request timeout.
Timeout time.Duration
// Retries is the number of retries for transient failures and rate limits.
Retries int
// RetryDelay is the base delay used for exponential backoff.
RetryDelay time.Duration
// RequestTracing is an optional trace token sent with signed requests.
RequestTracing string
}
Config holds the settings used to configure a Client.
type FundingRateHistory ¶
type FundingRateHistory struct {
Symbol string `json:"symbol"`
Rate string `json:"rate"`
FundingTime int64 `json:"fundingTime"`
}
FundingRateHistory represents a single funding rate history entry.
type Kline ¶
type Kline struct {
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
Volume string `json:"volume"`
Turnover string `json:"turnover"`
Timestamp int64 `json:"timestamp"`
}
Kline represents a single candlestick entry.
type NotFoundError ¶
type NotFoundError struct {
APIError
}
NotFoundError indicates the requested resource was not found.
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
type OrderBook ¶
type OrderBook struct {
Asks []OrderBookEntry `json:"asks"`
Bids []OrderBookEntry `json:"bids"`
}
OrderBook represents a Phemex order book response.
type OrderBookEntry ¶
OrderBookEntry represents a price/quantity level in an order book.
type RateLimitError ¶
RateLimitError indicates the request was throttled and exposes retry info.
func (*RateLimitError) Error ¶
func (e *RateLimitError) Error() string
type Response ¶
type Response struct {
Raw map[string]json.RawMessage
}
Response is the raw JSON-decoded response returned by the REST client. Most endpoints reply with `{ "code": <int>, "msg": <string>, "data": <mixed> }`, while market-data endpoints under `/md` use `{ "error": null, "id": 0, "result": <mixed> }`.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer generates HMAC SHA256 request signatures for the Phemex API.
The signing material is constructed according to the official Phemex documentation: the URL path (including the leading slash), the raw query string (without the leading question mark), the request expiry timestamp in seconds, and the request body for POST/PUT requests.
type Ticker24h ¶
type Ticker24h struct {
Symbol string `json:"symbol"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
Volume string `json:"volume"`
Turnover string `json:"turnover"`
Timestamp int64 `json:"timestamp"`
}
Ticker24h represents a 24-hour ticker entry.
type TimeResponse ¶
type TimeResponse struct {
Timestamp int64 `json:"timestamp"`
}
TimeResponse is the response envelope for /public/time.
type Trade ¶
type Trade struct {
Symbol string `json:"symbol"`
Price string `json:"price"`
Size string `json:"size"`
Side string `json:"side"`
Timestamp int64 `json:"timestamp"`
}
Trade represents a single public trade.
type ValidationError ¶
type ValidationError struct {
APIError
}
ValidationError indicates the request parameters were rejected.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Directories
¶
| Path | Synopsis |
|---|---|
|
Package assets provides wallet operations and transfer endpoints for the Phemex API.
|
Package assets provides wallet operations and transfer endpoints for the Phemex API. |
|
Package coinm provides Coin-M perpetual contract endpoints for the Phemex API.
|
Package coinm provides Coin-M perpetual contract endpoints for the Phemex API. |
|
examples
|
|
|
assets
command
Example: asset transfers and wallet operations (requires API credentials).
|
Example: asset transfers and wallet operations (requires API credentials). |
|
coinm
command
Example: Coin-M perpetual contract endpoints (requires API credentials).
|
Example: Coin-M perpetual contract endpoints (requires API credentials). |
|
margin
command
Example: margin trading endpoints (requires API credentials).
|
Example: margin trading endpoints (requires API credentials). |
|
market
command
Example: public market data endpoints.
|
Example: public market data endpoints. |
|
spot
command
Example: spot trading endpoints (requires API credentials).
|
Example: spot trading endpoints (requires API credentials). |
|
usdtm
command
Example: USDⓈ-M perpetual contract endpoints (requires API credentials).
|
Example: USDⓈ-M perpetual contract endpoints (requires API credentials). |
|
ws
command
Example: WebSocket market feed.
|
Example: WebSocket market feed. |
|
Package margin provides margin trading endpoints for the Phemex API.
|
Package margin provides margin trading endpoints for the Phemex API. |
|
Package market provides public market-data endpoints for the Phemex API.
|
Package market provides public market-data endpoints for the Phemex API. |
|
Package spot provides spot trading endpoints for the Phemex API.
|
Package spot provides spot trading endpoints for the Phemex API. |
|
Package usdtm provides USDⓈ-M perpetual contract endpoints for the Phemex API.
|
Package usdtm provides USDⓈ-M perpetual contract endpoints for the Phemex API. |
|
Package ws provides a WebSocket client for the Phemex real-time API.
|
Package ws provides a WebSocket client for the Phemex real-time API. |
