client

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_RECV_WINDOW = 5000
)

Variables

This section is empty.

Functions

func IsAPIError

func IsAPIError(e error) bool

IsAPIError check if e is an API error

Types

type APIError

type APIError struct {
	Code    int64  `json:"code"`
	Message string `json:"msg"`
}

func (APIError) Error

func (e APIError) Error() string

Error return error code and message

func (APIError) IsValid

func (e APIError) IsValid() bool

type Client

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

func NewClient

func NewClient(product Product, options ...Options) *Client

func (*Client) GetAuthError

func (c *Client) GetAuthError() error

func (*Client) GetChainID

func (c *Client) GetChainID() int64

func (*Client) GetHttpClient

func (c *Client) GetHttpClient() *resty.Client

func (*Client) GetLogger

func (c *Client) GetLogger() log.Logger

func (*Client) GetOrderCount

func (c *Client) GetOrderCount() OrderCount

func (*Client) GetPrivateKeyHex

func (c *Client) GetPrivateKeyHex() string

func (*Client) GetRecvWindow

func (c *Client) GetRecvWindow() int64

func (*Client) GetSignFn

func (c *Client) GetSignFn() SignFn

func (*Client) GetSignerAddress

func (c *Client) GetSignerAddress() string

func (*Client) GetSignerPrivateKey

func (c *Client) GetSignerPrivateKey() *ecdsa.PrivateKey

func (*Client) GetTimeOffsetMs

func (c *Client) GetTimeOffsetMs() int64

func (*Client) GetUsedWeight

func (c *Client) GetUsedWeight() UsedWeight

func (*Client) GetUserAddress

func (c *Client) GetUserAddress() string

func (*Client) NextNonce

func (c *Client) NextNonce() int64

NextNonce returns a microsecond-precision nonce that is monotonically increasing across concurrent calls. The local clock is adjusted by timeOffsetMs to compensate for client-server time drift.

func (*Client) SetOrderCount

func (c *Client) SetOrderCount(count10s, count1d *int64)

func (*Client) SetTimeOffset

func (c *Client) SetTimeOffset(offsetMs int64)

func (*Client) SetUsedWeight

func (c *Client) SetUsedWeight(used, used1m *int64)

type Option

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

type Options

type Options func(*Option)

func WithAuth

func WithAuth(userAddress, signerPrivateKeyHex string) Options

WithAuth configures the credentials used for V3 signed requests. userAddress is the main wallet address (may be empty when not required by the endpoint). signerPrivateKeyHex is the API wallet private key in hex (with or without the "0x" prefix); the signer address is derived from it.

func WithLogger

func WithLogger(logger log.Logger) Options

func WithNetwork

func WithNetwork(network asterCommon.Network) Options

WithNetwork selects the Aster network. The REST base URL and the EIP-712 chainId are both derived from this value. Defaults to common.Mainnet.

func WithProxy

func WithProxy(proxyURL string) Options

WithProxy routes all REST traffic through the given proxy. Supported schemes: http, https, socks5, socks5h. Pass userinfo in the URL for authenticated proxies, e.g. "http://user:pass@host:8080" or "socks5://user:pass@host:1080". Invalid URLs are logged and skipped.

func WithRecvWindow

func WithRecvWindow(recvWindow int64) Options

func WithSignRequestFn

func WithSignRequestFn(signFn SignFn) Options

WithSignRequestFn replaces the default EIP-712 + ECDSA signer with a custom implementation (e.g. for HSM, TEE, or a remote signing service).

func WithTEEAuth

func WithTEEAuth(userAddress, signerAddress string) Options

WithTEEAuth configures credentials for TEE / HSM / remote-signer mode where the signer's private key never leaves the enclave. Pass the main wallet address and the API-wallet (signer) address; no local private key is required. Must be combined with WithSignRequestFn, which is what actually performs the EIP-712 signing -- typically by shelling out to the TEE binary.

func WithTimeOffset

func WithTimeOffset(timeOffsetMs int64) Options

type OrderCount

type OrderCount struct {
	Count10s int64
	Count1d  int64
}

type Product

type Product int

Product distinguishes the spot and futures REST endpoints. It is supplied by the spot/futures package wrappers; end users do not pass this directly.

const (
	ProductSpot Product = iota
	ProductFutures
)

type SignFn

type SignFn = func(privateKeyHex string, msg string, chainID int64) (signature string, err error)

SignFn signs an EIP-712 typed-data payload using the signer's private key. The msg argument is the URL-encoded query string of the request parameters (placed inside Message.msg). The function returns a hex-encoded signature (with the leading "0x" omitted, matching eth_account.sign_message output).

type UsedWeight

type UsedWeight struct {
	Used   int64
	Used1M int64
}

type WebSocketClient

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

func NewWebSocketClient

func NewWebSocketClient(product Product, options ...WebSocketOptions) *WebSocketClient

func (*WebSocketClient) GetBaseURL

func (c *WebSocketClient) GetBaseURL() string

func (*WebSocketClient) GetDialer

func (c *WebSocketClient) GetDialer() *websocket.Dialer

func (*WebSocketClient) GetHttpClient

func (c *WebSocketClient) GetHttpClient() *resty.Client

func (*WebSocketClient) GetLogger

func (c *WebSocketClient) GetLogger() log.Logger

type WebSocketOption

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

type WebSocketOptions

type WebSocketOptions func(*WebSocketOption)

func WithWebSocketLogger

func WithWebSocketLogger(logger log.Logger) WebSocketOptions

func WithWebSocketNetwork

func WithWebSocketNetwork(network asterCommon.Network) WebSocketOptions

WithWebSocketNetwork selects the Aster network for the WebSocket client. Defaults to common.Mainnet.

func WithWebSocketProxy

func WithWebSocketProxy(proxyURL string) WebSocketOptions

WithWebSocketProxy routes the WebSocket dial through the given proxy. Supported schemes: http, https, socks5, socks5h. Behaves like WithProxy: userinfo in the URL is passed through for auth, invalid URLs are logged and skipped.

Jump to

Keyboard shortcuts

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