client

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeOK = 200
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountApiKeys

type AccountApiKeys struct {
	ResultCode
	ApiKeys []*ApiKey `json:"api_keys"`
}

type AccountAssetUpdateHandler added in v0.0.29

type AccountAssetUpdateHandler func(account int64, assets []Asset)

AccountAssetUpdateHandler handles asset updates specifically

type AccountData

type AccountData struct {
	AccountIndex     int64      `json:"account_id"`
	Balance          string     `json:"balance"`
	AvailableBalance string     `json:"available_balance"`
	MarginBalance    string     `json:"margin_balance"`
	UnrealizedPnL    string     `json:"unrealized_pnl"`
	RealizedPnL      string     `json:"realized_pnl"`
	MarginRatio      string     `json:"margin_ratio"`
	Positions        []Position `json:"positions"`
	Orders           []Order    `json:"orders"`
}

AccountData contains account information

type AccountInfo

type AccountInfo struct {
	Code                    int            `json:"code"`
	AccountType             int            `json:"account_type"`
	L1Address               string         `json:"l1_address"`
	CancelAllTime           int64          `json:"cancel_all_time"`
	TotalOrderCount         int            `json:"total_order_count"`
	TotalIsolatedOrderCount int            `json:"total_isolated_order_count"`
	PendingOrderCount       int            `json:"pending_order_count"`
	AvailableBalance        string         `json:"available_balance"`
	Status                  int            `json:"status"`
	Collateral              string         `json:"collateral"`
	AccountIndex            int64          `json:"account_index"`
	CanInvite               bool           `json:"can_invite"`
	TotalAssetValue         string         `json:"total_asset_value"`
	CrossAssetValue         string         `json:"cross_asset_value"`
	Positions               []PositionInfo `json:"positions"`
	Orders                  []OrderInfo    `json:"orders"`
	Assets                  []AssetInfo    `json:"assets"`
}

type AccountMarketData

type AccountMarketData struct {
	AccountIndex     int64                  `json:"account_id"`
	MarketID         uint16                 `json:"market_id"`
	Balance          string                 `json:"balance"`
	AvailableBalance string                 `json:"available_balance"`
	MarginBalance    string                 `json:"margin_balance"`
	Position         *AccountMarketPosition `json:"position,omitempty"`
	Orders           []AccountMarketOrder   `json:"orders"`
	MarginRatio      string                 `json:"margin_ratio"`
}

Legacy AccountMarketData - kept for backward compatibility

type AccountMarketFundingUpdateHandler

type AccountMarketFundingUpdateHandler func(account int64, funding []FundingHistory)

AccountMarketFundingUpdateHandler handles funding updates specifically

type AccountMarketOrder

type AccountMarketOrder struct {
	OrderID          string `json:"order_id"`
	ClientOrderID    string `json:"client_order_id"`
	ClientOrderIndex int64  `json:"client_order_index"`
	MarketID         uint16 `json:"market_index"`
	OrderType        string `json:"type"`
	Price            string `json:"price"`
	Quantity         string `json:"initial_base_amount"`
	FilledQuantity   string `json:"filled_base_amount"`
	Status           string `json:"status"`
	CreatedAt        int64  `json:"created_at"`
	UpdatedAt        int64  `json:"updated_at"`
	IsAsk            bool   `json:"is_ask"`
}

AccountMarketOrder represents an order for a specific market

type AccountMarketOrderUpdateHandler

type AccountMarketOrderUpdateHandler func(account int64, orders []AccountMarketOrder)

AccountMarketOrderUpdateHandler handles order updates specifically

type AccountMarketPosition

type AccountMarketPosition struct {
	MarketID               uint16 `json:"market_id"`
	Symbol                 string `json:"symbol"`
	InitialMarginFraction  string `json:"initial_margin_fraction"`
	OpenOrderCount         int    `json:"open_order_count"`
	PendingOrderCount      int    `json:"pending_order_count"`
	PositionTiedOrderCount int    `json:"position_tied_order_count"`
	Sign                   int    `json:"sign"`     // 1 for long, -1 for short
	Position               string `json:"position"` // position size
	AvgEntryPrice          string `json:"avg_entry_price"`
	PositionValue          string `json:"position_value"`
	UnrealizedPnL          string `json:"unrealized_pnl"`
	RealizedPnL            string `json:"realized_pnl"`
	LiquidationPrice       string `json:"liquidation_price"`
	TotalFundingPaidOut    string `json:"total_funding_paid_out"`
	MarginMode             int    `json:"margin_mode"` // 1 for cross, 2 for isolated
	AllocatedMargin        string `json:"allocated_margin"`
}

AccountMarketPosition represents position data for a specific market

type AccountMarketPositionUpdateHandler

type AccountMarketPositionUpdateHandler func(account int64, position *AccountMarketPosition)

AccountMarketPositionUpdateHandler handles position updates specifically

type AccountMarketSnapshot

type AccountMarketSnapshot struct {
	Account        int64                  `json:"account"`
	Channel        string                 `json:"channel"`
	Type           string                 `json:"type"`
	FundingHistory *[]FundingHistory      `json:"funding_history,omitempty"`
	Orders         []AccountMarketOrder   `json:"orders"`
	Position       *AccountMarketPosition `json:"position,omitempty"`
	Trades         []Trade                `json:"trades"`
}

AccountMarketSnapshot represents the initial account market subscription response Note: API docs don't mention snapshot, but keeping for backward compatibility

type AccountMarketSnapshotHandler

type AccountMarketSnapshotHandler func(snapshot *AccountMarketSnapshot)

AccountMarketSnapshotHandler handles account market snapshots

type AccountMarketSub

type AccountMarketSub struct {
	AccountIndex int64
	MarketID     uint16
	AuthToken    string    // Optional auth token for authentication (deprecated - use TxClient instead)
	TxClient     *TxClient // Optional TxClient for generating auth tokens
}

AccountMarketSub represents an account-market pair to subscribe to

type AccountMarketSubscription

type AccountMarketSubscription struct {
	Type    string `json:"type"`
	Channel string `json:"channel"`
	Auth    string `json:"auth,omitempty"` // Optional auth token for private subscriptions
}

AccountMarketSubscription represents a market-specific account subscription

func NewAccountMarketSubscription

func NewAccountMarketSubscription(accountIndex int64, marketID uint16, authToken string) AccountMarketSubscription

NewAccountMarketSubscription creates a subscription message for an account on a specific market

func (AccountMarketSubscription) GetType

func (m AccountMarketSubscription) GetType() string

type AccountMarketTradeUpdateHandler

type AccountMarketTradeUpdateHandler func(account int64, trades []Trade)

AccountMarketTradeUpdateHandler handles trade updates specifically

type AccountMarketUpdate

type AccountMarketUpdate struct {
	Account        int64                  `json:"account"`
	Channel        string                 `json:"channel"`
	Type           string                 `json:"type"`
	FundingHistory []FundingHistory       `json:"funding_history,omitempty"`
	Orders         []AccountMarketOrder   `json:"orders"`
	Position       *AccountMarketPosition `json:"position,omitempty"`
	Assets         map[string]Asset       `json:"assets,omitempty"`
	Trades         []Trade                `json:"trades"`
}

AccountMarketUpdate represents an account market update message (matches API docs)

type AccountMarketUpdateHandler

type AccountMarketUpdateHandler func(update *AccountMarketUpdate)

AccountMarketUpdateHandler handles account market updates

type AccountResponse

type AccountResponse struct {
	Code     int           `json:"code"`
	Total    int           `json:"total"`
	Accounts []AccountInfo `json:"accounts"`
}

AccountInfo represents account information AccountResponse represents the full API response for account queries

type ApiKey

type ApiKey struct {
	AccountIndex int64  `json:"account_index,example=3"`
	ApiKeyIndex  uint8  `json:"api_key_index,example=0"`
	Nonce        int64  `json:"nonce,example=722"`
	PublicKey    string `json:"public_key"`
}

type Asset added in v0.0.27

type Asset struct {
	Symbol        string `json:"symbol"`
	AssetId       int    `json:"asset_id"`
	Balance       string `json:"balance"`
	LockedBalance string `json:"locked_balance"`
}

type AssetInfo added in v0.0.24

type AssetInfo struct {
	Symbol        string `json:"symbol"`
	AssetId       int    `json:"asset_id"`
	Balance       string `json:"balance"`
	LockedBalance string `json:"locked_balance"`
}

type BatchTxResponse

type BatchTxResponse struct {
	ID       string                   `json:"id"`
	Status   string                   `json:"status"`
	TxHashes []string                 `json:"tx_hashes,omitempty"`
	Results  []map[string]interface{} `json:"results,omitempty"`
	Failures []map[string]interface{} `json:"failures,omitempty"`
	Error    string                   `json:"error,omitempty"`
}

BatchTxResponse represents a batch transaction response

type BatchTxResponseHandler

type BatchTxResponseHandler func(requestID string, response *BatchTxResponse)

BatchTxResponseHandler handles batch transaction response callbacks

type ConnectedMessage

type ConnectedMessage struct {
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

ConnectedMessage represents the initial connection message

type ErrorHandler

type ErrorHandler func(error *ErrorMessage)

ErrorHandler handles error messages

type ErrorMessage

type ErrorMessage struct {
	Type    string `json:"type"`
	Code    int    `json:"code"`
	Message string `json:"message"`
	Channel string `json:"channel,omitempty"`
}

ErrorMessage represents a WebSocket error message

type FundingHistory

type FundingHistory struct {
	Timestamp    int64  `json:"timestamp"`
	MarketID     uint16 `json:"market_id"`
	FundingID    int64  `json:"funding_id"`
	Change       string `json:"change"`
	Rate         string `json:"rate"`
	PositionSize string `json:"position_size"`
	PositionSide string `json:"position_side"`
}

FundingHistory represents funding fee history data

type GetAccountParams

type GetAccountParams struct {
	By    string `json:"by"`
	Value string `json:"value"`
	Auth  string `json:"auth,omitempty"`
}

GetAccountParams represents parameters for GetAccount request

func (GetAccountParams) ToMap

func (p GetAccountParams) ToMap() map[string]string

type GetOrdersParams

type GetOrdersParams struct {
	AccountIndex int64   `json:"account_index"`
	MarketID     *uint16 `json:"market_id,omitempty"`
	Status       string  `json:"status,omitempty"`
	Limit        int     `json:"limit,omitempty"`
	Offset       int     `json:"offset,omitempty"`
	Auth         string  `json:"auth,omitempty"`
}

GetOrdersParams represents parameters for GetOrders request

func (GetOrdersParams) ToMap

func (p GetOrdersParams) ToMap() map[string]string

type GetTradesParams

type GetTradesParams struct {
	AccountIndex int64   `json:"account_index"`
	MarketID     *uint16 `json:"market_id,omitempty"`
	StartTime    *int64  `json:"start_time,omitempty"`
	EndTime      *int64  `json:"end_time,omitempty"`
	Limit        int     `json:"limit,omitempty"`
	Offset       int     `json:"offset,omitempty"`
	Auth         string  `json:"auth,omitempty"`
}

GetTradesParams represents parameters for GetTrades request

func (GetTradesParams) ToMap

func (p GetTradesParams) ToMap() map[string]string

type HTTPClient

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

func NewHTTPClient

func NewHTTPClient(baseUrl string, opts ...HTTPClientOption) *HTTPClient

func (*HTTPClient) CheckPublicIP added in v0.0.18

func (c *HTTPClient) CheckPublicIP() (string, error)

CheckPublicIP 使用当前 HTTPClient 的本地出口 IP 访问 https://api.ipify.org 并打印返回的公网 IP 地址(确认 localAddr 是否生效)

func (*HTTPClient) GetAccountInfo

func (c *HTTPClient) GetAccountInfo(accountIndex int64) (*AccountInfo, error)

GetAccountInfo fetches account information

func (*HTTPClient) GetAccountInfoWithAuth

func (c *HTTPClient) GetAccountInfoWithAuth(accountIndex int64, authToken string) (*AccountInfo, error)

GetAccountInfoWithAuth fetches account information with authentication

func (*HTTPClient) GetActiveMarkets

func (c *HTTPClient) GetActiveMarkets() ([]OrderBook, error)

GetActiveMarkets returns only active markets

func (*HTTPClient) GetApiKey

func (c *HTTPClient) GetApiKey(accountIndex int64, apiKeyIndex uint8) (*AccountApiKeys, error)

GetApiKey fetches API key information using legacy parameters

func (*HTTPClient) GetApiKeyV2

func (c *HTTPClient) GetApiKeyV2(params GetAccountParams) (*AccountApiKeys, error)

GetApiKeyV2 fetches API key information with typed parameters

func (*HTTPClient) GetMarketByID

func (c *HTTPClient) GetMarketByID(marketID uint16) (*OrderBook, error)

GetMarketByID fetches information for a specific market

func (*HTTPClient) GetMarketBySymbol

func (c *HTTPClient) GetMarketBySymbol(symbol string) (*OrderBook, error)

GetMarketBySymbol fetches market information by trading pair symbol

func (*HTTPClient) GetNextNonce

func (c *HTTPClient) GetNextNonce(accountIndex int64, apiKeyIndex uint8) (int64, error)

GetNextNonce fetches the next nonce using legacy parameters

func (*HTTPClient) GetNextNonceV2

func (c *HTTPClient) GetNextNonceV2(params NextNonceParams) (*NextNonce, error)

GetNextNonceV2 fetches the next nonce with typed parameters

func (*HTTPClient) GetOrderBookOrders added in v0.0.5

func (c *HTTPClient) GetOrderBookOrders(marketIndex uint16, limit int64) (*OrderBookResponse, error)

func (*HTTPClient) GetOrderBooks

func (c *HTTPClient) GetOrderBooks() (*OrderBooksResponse, error)

GetOrderBooks fetches all available markets from Lighter exchange

func (*HTTPClient) GetOrders

func (c *HTTPClient) GetOrders(params GetOrdersParams) (*OrdersResponse, error)

GetOrders fetches orders with typed parameters

func (*HTTPClient) GetTrades

func (c *HTTPClient) GetTrades(params GetTradesParams) (*TradesResponse, error)

GetTrades fetches trades with typed parameters

func (*HTTPClient) GetTransferFeeInfo

func (c *HTTPClient) GetTransferFeeInfo(accountIndex, toAccountIndex int64, auth string) (*TransferFeeInfo, error)

GetTransferFeeInfo fetches transfer fee information

func (*HTTPClient) PrintMarkets

func (c *HTTPClient) PrintMarkets() error

PrintMarkets prints all markets in a formatted way (for debugging)

func (*HTTPClient) SendRawTx

func (c *HTTPClient) SendRawTx(tx txtypes.TxInfo) (string, error)

SendRawTx sends a raw transaction to the exchange

func (*HTTPClient) SetFatFingerProtection

func (c *HTTPClient) SetFatFingerProtection(enabled bool)

type HTTPClientOption

type HTTPClientOption func(*HTTPClient)

HTTPClientOption 定义 HTTP 客户端配置选项

func WithLocalAddress

func WithLocalAddress(localAddr string) HTTPClientOption

WithLocalAddress 设置本地地址

func WithLocalIP

func WithLocalIP(localIP string) HTTPClientOption

WithLocalIP 设置本地IP地址(端口由系统自动分配)

type HTTPParams

type HTTPParams interface {
	ToMap() map[string]string
}

HTTPParams is the interface for HTTP request parameters

type MessageHandler

type MessageHandler func(messageType string, rawData []byte)

MessageHandler is a callback function for handling raw WebSocket messages

type NextNonce

type NextNonce struct {
	ResultCode
	Nonce int64 `json:"nonce,example=722"`
}

type NextNonceParams

type NextNonceParams struct {
	AccountIndex int64 `json:"account_index"`
	APIKeyIndex  uint8 `json:"api_key_index"`
}

NextNonceParams represents parameters for GetNextNonce request

func (NextNonceParams) ToMap

func (p NextNonceParams) ToMap() map[string]string

type Order

type Order struct {
	OrderID        string    `json:"order_id"`
	ClientOrderID  string    `json:"client_order_id"`
	Symbol         string    `json:"symbol"`
	MarketID       uint16    `json:"market_id"`
	Side           string    `json:"side"`
	OrderType      string    `json:"order_type"`
	Price          string    `json:"price"`
	Quantity       string    `json:"quantity"`
	FilledQuantity string    `json:"filled_quantity"`
	Status         string    `json:"status"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
}

Order represents an order

type OrderBook

type OrderBook struct {
	MarketID               uint16 `json:"market_id"`
	Symbol                 string `json:"symbol"`
	Status                 string `json:"status"`
	TakerFee               string `json:"taker_fee"`
	MakerFee               string `json:"maker_fee"`
	LiquidationFee         string `json:"liquidation_fee"`
	MinBaseAmount          string `json:"min_base_amount"`
	MinQuoteAmount         string `json:"min_quote_amount"`
	SupportedSizeDecimals  int    `json:"supported_size_decimals"`
	SupportedPriceDecimals int    `json:"supported_price_decimals"`
	SupportedQuoteDecimals int    `json:"supported_quote_decimals"`
}

OrderBook represents a market on Lighter exchange

type OrderBookData

type OrderBookData struct {
	Code   int              `json:"code"`
	Asks   []OrderBookLevel `json:"asks"`
	Bids   []OrderBookLevel `json:"bids"`
	Offset int              `json:"offset"`
}

OrderBookData contains the order book data

type OrderBookLevel

type OrderBookLevel struct {
	Price string `json:"price"`
	Size  string `json:"size"`
}

OrderBookLevel represents a single price level in the order book

type OrderBookResponse added in v0.0.5

type OrderBookResponse struct {
	Code      int          `json:"code"`
	TotalAsks int          `json:"total_asks"`
	Asks      []OrderLevel `json:"asks"`
	TotalBids int          `json:"total_bids"`
	Bids      []OrderLevel `json:"bids"`
}

type OrderBookSnapshot

type OrderBookSnapshot struct {
	Channel   string        `json:"channel"`
	Type      string        `json:"type"`
	OrderBook OrderBookData `json:"order_book"`
}

OrderBookSnapshot represents the initial order book snapshot

type OrderBookSnapshotHandler

type OrderBookSnapshotHandler func(marketID uint16, snapshot *OrderBookSnapshot)

OrderBookSnapshotHandler handles order book snapshots

type OrderBookUpdate

type OrderBookUpdate struct {
	Channel   string        `json:"channel"`
	Type      string        `json:"type"`
	Offset    int           `json:"offset"`
	OrderBook OrderBookData `json:"order_book"`
}

OrderBookUpdate represents an order book update message

type OrderBookUpdateHandler

type OrderBookUpdateHandler func(marketID uint16, update *OrderBookUpdate)

OrderBookUpdateHandler handles order book updates

type OrderBooksResponse

type OrderBooksResponse struct {
	Code       int         `json:"code"`
	Message    string      `json:"message"`
	OrderBooks []OrderBook `json:"order_books"`
}

OrderBooksResponse represents the response from order_books API

type OrderInfo

type OrderInfo struct {
	OrderIndex          int64  `json:"order_index"`
	ClientOrderIndex    int64  `json:"client_order_index"`
	OrderID             string `json:"order_id"`
	ClientOrderID       string `json:"client_order_id"`
	MarketIndex         uint16 `json:"market_index"`
	OwnerAccountIndex   int64  `json:"owner_account_index"`
	InitialBaseAmount   string `json:"initial_base_amount"`
	Price               string `json:"price"`
	Nonce               int64  `json:"nonce"`
	RemainingBaseAmount string `json:"remaining_base_amount"`
	IsAsk               bool   `json:"is_ask"`
	BaseSize            int64  `json:"base_size"`
	BasePrice           int64  `json:"base_price"`
	FilledBaseAmount    string `json:"filled_base_amount"`
	FilledQuoteAmount   string `json:"filled_quote_amount"`
	Side                string `json:"side"`
	Type                string `json:"type"`
	TimeInForce         string `json:"time_in_force"`
	ReduceOnly          bool   `json:"reduce_only"`
	TriggerPrice        string `json:"trigger_price"`
	OrderExpiry         int64  `json:"order_expiry"`
	Status              string `json:"status"`
	TriggerStatus       string `json:"trigger_status"`
	TriggerTime         int64  `json:"trigger_time"`
	ParentOrderIndex    int64  `json:"parent_order_index"`
	ParentOrderID       string `json:"parent_order_id"`
	ToTriggerOrderID0   string `json:"to_trigger_order_id_0"`
	ToTriggerOrderID1   string `json:"to_trigger_order_id_1"`
	ToCancelOrderID0    string `json:"to_cancel_order_id_0"`
	BlockHeight         int64  `json:"block_height"`
	Timestamp           int64  `json:"timestamp"`
	CreatedAt           int64  `json:"created_at"`
	UpdatedAt           int64  `json:"updated_at"`
}

OrderInfo represents order information from REST API

type OrderLevel added in v0.0.5

type OrderLevel struct {
	OrderIndex          int64  `json:"order_index"`
	OrderID             string `json:"order_id"`
	OwnerAccountIndex   int64  `json:"owner_account_index"`
	InitialBaseAmount   string `json:"initial_base_amount"`
	RemainingBaseAmount string `json:"remaining_base_amount"`
	Price               string `json:"price"`
	OrderExpiry         int64  `json:"order_expiry"`
}

type OrdersResponse

type OrdersResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Orders  []OrderInfo `json:"orders"`
	Total   int         `json:"total"`
}

OrdersResponse represents the response for orders query

type PingMessage

type PingMessage struct {
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

PingMessage represents a ping message

func (PingMessage) GetType

func (m PingMessage) GetType() string

type PongMessage

type PongMessage struct {
	Type      string `json:"type"`
	Timestamp int64  `json:"timestamp"`
}

PongMessage represents a pong message response

func (PongMessage) GetType

func (m PongMessage) GetType() string

type Position

type Position struct {
	Symbol        string `json:"symbol"`
	MarketID      uint16 `json:"market_id"`
	Side          string `json:"side"`
	Quantity      string `json:"quantity"`
	EntryPrice    string `json:"entry_price"`
	MarkPrice     string `json:"mark_price"`
	UnrealizedPnL string `json:"unrealized_pnl"`
	RealizedPnL   string `json:"realized_pnl"`
}

Position represents a websocket's position

type PositionInfo

type PositionInfo struct {
	MarketID               uint16 `json:"market_id"`
	Symbol                 string `json:"symbol"`
	InitialMarginFraction  string `json:"initial_margin_fraction"`
	OpenOrderCount         int    `json:"open_order_count"`
	PendingOrderCount      int    `json:"pending_order_count"`
	PositionTiedOrderCount int    `json:"position_tied_order_count"`
	Sign                   int    `json:"sign"`     // 1 for long, -1 for short
	Position               string `json:"position"` // position size
	AvgEntryPrice          string `json:"avg_entry_price"`
	PositionValue          string `json:"position_value"`
	UnrealizedPnL          string `json:"unrealized_pnl"`
	RealizedPnL            string `json:"realized_pnl"`
	LiquidationPrice       string `json:"liquidation_price"`
	TotalFundingPaidOut    string `json:"total_funding_paid_out"`
	MarginMode             int    `json:"margin_mode"` // 1 for cross, 2 for isolated
	AllocatedMargin        string `json:"allocated_margin"`
}

PositionInfo represents position information

type ResultCode

type ResultCode struct {
	Code    int32  `json:"code,example=200"`
	Message string `json:"message,omitempty"`
}

type SubscribeMessage

type SubscribeMessage struct {
	Type    string `json:"type"`
	Channel string `json:"channel"`
}

SubscribeMessage represents a subscription request

func NewOrderBookSubscription

func NewOrderBookSubscription(marketID uint16) SubscribeMessage

NewOrderBookSubscription creates a subscription message for an order book

func (SubscribeMessage) GetType

func (m SubscribeMessage) GetType() string

type SubscriptionMessage

type SubscriptionMessage struct {
	Type    string `json:"type"`
	Channel string `json:"channel"`
	Success bool   `json:"success"`
}

SubscriptionMessage represents a subscription confirmation

type Trade

type Trade struct {
	AskAccountID                     int64       `json:"ask_account_id"`
	AskID                            json.Number `json:"ask_id"`
	BidAccountID                     int64       `json:"bid_account_id"`
	BidID                            json.Number `json:"bid_id"`
	BlockHeight                      json.Number `json:"block_height"`
	IsMakerAsk                       bool        `json:"is_maker_ask"`
	MakerEntryQuoteBefore            json.Number `json:"maker_entry_quote_before"`
	MakerInitialMarginFractionBefore json.Number `json:"maker_initial_margin_fraction_before"`
	MakerPositionSizeBefore          json.Number `json:"maker_position_size_before"`
	MarketID                         uint16      `json:"market_id"`
	Price                            json.Number `json:"price"`
	Size                             json.Number `json:"size"`
	TakerEntryQuoteBefore            json.Number `json:"taker_entry_quote_before"`
	TakerInitialMarginFractionBefore json.Number `json:"taker_initial_margin_fraction_before"`
	TakerPositionSizeBefore          json.Number `json:"taker_position_size_before"`
	Timestamp                        json.Number `json:"timestamp"`
	TradeID                          json.Number `json:"trade_id"`
	TxHash                           string      `json:"tx_hash"`
	Type                             string      `json:"type"`
	UsdAmount                        json.Number `json:"usd_amount"`
}

type TradeInfo

type TradeInfo struct {
	TradeID    string `json:"trade_id"`
	OrderID    string `json:"order_id"`
	MarketID   uint16 `json:"market_id"`
	Symbol     string `json:"symbol"`
	Side       string `json:"side"`
	Price      string `json:"price"`
	Quantity   string `json:"quantity"`
	Fee        string `json:"fee"`
	FeeAsset   string `json:"fee_asset"`
	IsMaker    bool   `json:"is_maker"`
	ExecutedAt int64  `json:"executed_at"`
}

TradeInfo represents trade information

type TradesResponse

type TradesResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Trades  []TradeInfo `json:"trades"`
	Total   int         `json:"total"`
}

TradesResponse represents the response for trades query

type TransferFeeInfo

type TransferFeeInfo struct {
	ResultCode
	TransferFee int64 `json:"transfer_fee_usdc"`
}

type TxClient

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

func NewTxClient

func NewTxClient(apiClient *HTTPClient, apiKeyPrivateKey string, accountIndex int64, apiKeyIndex uint8, chainId uint32) (*TxClient, error)

NewTxClient is linked to a specific (account, apiKey) pair apiKeyPrivateKey should be hex-encoded bytes generated using `hexutil.Encode(TxClient.GetKeyManager().PrvKeyBytes())`

func (*TxClient) FullFillDefaultOps

func (c *TxClient) FullFillDefaultOps(ops *types.TransactOpts) (*types.TransactOpts, error)

func (*TxClient) GetAccountIndex

func (c *TxClient) GetAccountIndex() int64

func (*TxClient) GetApiKeyIndex

func (c *TxClient) GetApiKeyIndex() uint8

func (*TxClient) GetAuthToken

func (c *TxClient) GetAuthToken(deadline time.Time) (string, error)

func (*TxClient) GetBurnSharesTransaction

func (c *TxClient) GetBurnSharesTransaction(tx *types.BurnSharesTxReq, ops *types.TransactOpts) (*txtypes.L2BurnSharesTxInfo, error)

func (*TxClient) GetCancelAllOrdersTransaction

func (c *TxClient) GetCancelAllOrdersTransaction(tx *types.CancelAllOrdersTxReq, ops *types.TransactOpts) (*txtypes.L2CancelAllOrdersTxInfo, error)

func (*TxClient) GetCancelOrderTransaction

func (c *TxClient) GetCancelOrderTransaction(tx *types.CancelOrderTxReq, ops *types.TransactOpts) (*txtypes.L2CancelOrderTxInfo, error)

func (*TxClient) GetChangePubKeyTransaction

func (c *TxClient) GetChangePubKeyTransaction(tx *types.ChangePubKeyReq, ops *types.TransactOpts) (*txtypes.L2ChangePubKeyTxInfo, error)

func (*TxClient) GetCreateOrderTransaction

func (c *TxClient) GetCreateOrderTransaction(tx *types.CreateOrderTxReq, ops *types.TransactOpts) (*txtypes.L2CreateOrderTxInfo, error)

func (*TxClient) GetCreatePublicPoolTransaction

func (c *TxClient) GetCreatePublicPoolTransaction(tx *types.CreatePublicPoolTxReq, ops *types.TransactOpts) (*txtypes.L2CreatePublicPoolTxInfo, error)

func (*TxClient) GetCreateSubAccountTransaction

func (c *TxClient) GetCreateSubAccountTransaction(ops *types.TransactOpts) (*txtypes.L2CreateSubAccountTxInfo, error)

func (*TxClient) GetKeyManager

func (c *TxClient) GetKeyManager() signer.KeyManager

func (*TxClient) GetMintSharesTransaction

func (c *TxClient) GetMintSharesTransaction(tx *types.MintSharesTxReq, ops *types.TransactOpts) (*txtypes.L2MintSharesTxInfo, error)

func (*TxClient) GetModifyOrderTransaction

func (c *TxClient) GetModifyOrderTransaction(tx *types.ModifyOrderTxReq, ops *types.TransactOpts) (*txtypes.L2ModifyOrderTxInfo, error)

func (*TxClient) GetTransferTransaction

func (c *TxClient) GetTransferTransaction(tx *types.TransferTxReq, ops *types.TransactOpts) (*txtypes.L2TransferTxInfo, error)

func (*TxClient) GetUpdateLeverageTransaction

func (c *TxClient) GetUpdateLeverageTransaction(tx *types.UpdateLeverageTxReq, ops *types.TransactOpts) (*txtypes.L2UpdateLeverageTxInfo, error)

func (*TxClient) GetUpdateMarginTransaction

func (c *TxClient) GetUpdateMarginTransaction(tx *types.UpdateMarginTxReq, ops *types.TransactOpts) (*txtypes.L2UpdateMarginTxInfo, error)

func (*TxClient) GetUpdatePublicPoolTransaction

func (c *TxClient) GetUpdatePublicPoolTransaction(tx *types.UpdatePublicPoolTxReq, ops *types.TransactOpts) (*txtypes.L2UpdatePublicPoolTxInfo, error)

func (*TxClient) GetWithdrawTransaction

func (c *TxClient) GetWithdrawTransaction(tx *types.WithdrawTxReq, ops *types.TransactOpts) (*txtypes.L2WithdrawTxInfo, error)

func (*TxClient) HTTP

func (c *TxClient) HTTP() *HTTPClient

func (*TxClient) SwitchAPIKey

func (c *TxClient) SwitchAPIKey(apiKey uint8)

type TxHash

type TxHash struct {
	ResultCode
	TxHash string `json:"tx_hash,example=0x70997970C51812dc3A010C7d01b50e0d17dc79C8"`
}

type TxResponse

type TxResponse struct {
	ID     string                 `json:"id"`
	Status string                 `json:"status"`
	TxHash string                 `json:"tx_hash,omitempty"`
	Error  string                 `json:"error,omitempty"`
	Data   map[string]interface{} `json:"data,omitempty"`
}

TxResponse represents a transaction response

type TxResponseHandler

type TxResponseHandler func(requestID string, response *TxResponse)

TxResponseHandler handles transaction response callbacks

type UnsubscribeMessage

type UnsubscribeMessage struct {
	Type    string `json:"type"`
	Channel string `json:"channel"`
}

UnsubscribeMessage represents an unsubscription request

func NewAccountMarketUnsubscription

func NewAccountMarketUnsubscription(accountID int, marketID uint16) UnsubscribeMessage

NewAccountMarketUnsubscription creates an unsubscription message for an account market

func NewOrderBookUnsubscription

func NewOrderBookUnsubscription(marketID uint16) UnsubscribeMessage

NewOrderBookUnsubscription creates an unsubscription message for an order book

func (UnsubscribeMessage) GetType

func (m UnsubscribeMessage) GetType() string

type WSMessage

type WSMessage interface {
	GetType() string
}

WSMessage is the interface for all WebSocket messages

type WsAccountMarketClient

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

WsAccountMarketClient is a WebSocket client dedicated to account market subscriptions

func NewWsAccountMarketClient

func NewWsAccountMarketClient(accountMarketSubs []AccountMarketSub, options ...WsAccountMarketClientOption) (*WsAccountMarketClient, error)

NewWsAccountMarketClient creates a new dedicated account market WebSocket client

func (*WsAccountMarketClient) IsConnected

func (c *WsAccountMarketClient) IsConnected() bool

IsConnected returns whether the client is connected

func (*WsAccountMarketClient) Run

func (c *WsAccountMarketClient) Run() error

Run starts the account market WebSocket client

func (*WsAccountMarketClient) Stop

func (c *WsAccountMarketClient) Stop()

Stop stops the account market client

type WsAccountMarketClientOption

type WsAccountMarketClientOption func(*WsAccountMarketClient)

WsAccountMarketClientOption configures the WsAccountMarketClient

func WithAccountAssetUpdateHandler added in v0.0.30

func WithAccountAssetUpdateHandler(handler AccountAssetUpdateHandler) WsAccountMarketClientOption

WithAccountAssetUpdateHandler sets the asset update handler

func WithAccountMarketErrorHandler

func WithAccountMarketErrorHandler(handler ErrorHandler) WsAccountMarketClientOption

WithAccountMarketErrorHandler sets the error handler

func WithAccountMarketFundingUpdateHandler

func WithAccountMarketFundingUpdateHandler(handler AccountMarketFundingUpdateHandler) WsAccountMarketClientOption

WithAccountMarketFundingUpdateHandler sets the funding update handler

func WithAccountMarketHost

func WithAccountMarketHost(host string) WsAccountMarketClientOption

WithAccountMarketHost sets the WebSocket host

func WithAccountMarketLocalAddress added in v0.0.12

func WithAccountMarketLocalAddress(localAddr string) WsAccountMarketClientOption

WithAccountMarketLocalAddress sets the local address for outgoing connections

func WithAccountMarketLocalIP added in v0.0.12

func WithAccountMarketLocalIP(localIP string) WsAccountMarketClientOption

WithAccountMarketLocalIP sets the local IP address for outgoing connections

func WithAccountMarketMessageHandler

func WithAccountMarketMessageHandler(handler MessageHandler) WsAccountMarketClientOption

WithAccountMarketMessageHandler sets the raw message handler

func WithAccountMarketOrderUpdateHandler

func WithAccountMarketOrderUpdateHandler(handler AccountMarketOrderUpdateHandler) WsAccountMarketClientOption

WithAccountMarketOrderUpdateHandler sets the order update handler

func WithAccountMarketPositionUpdateHandler

func WithAccountMarketPositionUpdateHandler(handler AccountMarketPositionUpdateHandler) WsAccountMarketClientOption

WithAccountMarketPositionUpdateHandler sets the position update handler

func WithAccountMarketReconnectInterval

func WithAccountMarketReconnectInterval(interval time.Duration) WsAccountMarketClientOption

WithAccountMarketReconnectInterval sets the reconnect interval

func WithAccountMarketSnapshotHandler

func WithAccountMarketSnapshotHandler(handler AccountMarketSnapshotHandler) WsAccountMarketClientOption

WithAccountMarketSnapshotHandler sets the account market snapshot handler

func WithAccountMarketTradeUpdateHandler

func WithAccountMarketTradeUpdateHandler(handler AccountMarketTradeUpdateHandler) WsAccountMarketClientOption

WithAccountMarketTradeUpdateHandler sets the trade update handler

func WithAccountMarketTxClient

func WithAccountMarketTxClient(txClient *TxClient) WsAccountMarketClientOption

WithAccountMarketTxClient sets the TxClient for generating auth tokens

func WithAccountMarketUpdateHandler

func WithAccountMarketUpdateHandler(handler AccountMarketUpdateHandler) WsAccountMarketClientOption

WithAccountMarketUpdateHandler sets the account market update handler

type WsOrderBookClient

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

WsOrderBookClient is a WebSocket client dedicated to order book subscriptions

func NewWsOrderBookClient

func NewWsOrderBookClient(marketIDs []uint16, options ...WsOrderBookClientOption) (*WsOrderBookClient, error)

NewWsOrderBookClient creates a new dedicated order book WebSocket client

func (*WsOrderBookClient) IsConnected

func (c *WsOrderBookClient) IsConnected() bool

IsConnected returns whether the client is connected

func (*WsOrderBookClient) Run

func (c *WsOrderBookClient) Run() error

Run starts the order book WebSocket client

func (*WsOrderBookClient) Stop

func (c *WsOrderBookClient) Stop()

Stop stops the order book client

type WsOrderBookClientOption

type WsOrderBookClientOption func(*WsOrderBookClient)

WsOrderBookClientOption configures the WsOrderBookClient

func WithOrderBookErrorHandler

func WithOrderBookErrorHandler(handler ErrorHandler) WsOrderBookClientOption

WithOrderBookErrorHandler sets the error handler

func WithOrderBookHost

func WithOrderBookHost(host string) WsOrderBookClientOption

WithOrderBookHost sets the WebSocket host

func WithOrderBookLocalAddress added in v0.0.12

func WithOrderBookLocalAddress(localAddr string) WsOrderBookClientOption

WithOrderBookLocalAddress sets the local address for outgoing connections

func WithOrderBookLocalIP added in v0.0.12

func WithOrderBookLocalIP(localIP string) WsOrderBookClientOption

WithOrderBookLocalIP sets the local IP address for outgoing connections

func WithOrderBookMaxReconnectAttempts added in v0.0.13

func WithOrderBookMaxReconnectAttempts(maxAttempts int) WsOrderBookClientOption

WithOrderBookMaxReconnectAttempts sets the maxReconnectAttempts

func WithOrderBookMessageHandler

func WithOrderBookMessageHandler(handler MessageHandler) WsOrderBookClientOption

WithOrderBookMessageHandler sets the raw message handler

func WithOrderBookReconnectInterval

func WithOrderBookReconnectInterval(interval time.Duration) WsOrderBookClientOption

WithOrderBookReconnectInterval sets the reconnect interval

func WithOrderBookSnapshotHandler

func WithOrderBookSnapshotHandler(handler OrderBookSnapshotHandler) WsOrderBookClientOption

WithOrderBookSnapshotHandler sets the order book snapshot handler

func WithOrderBookUpdateHandler

func WithOrderBookUpdateHandler(handler OrderBookUpdateHandler) WsOrderBookClientOption

WithOrderBookUpdateHandler sets the order book update handler

type WsTxClient

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

WsTxClient is a WebSocket client dedicated to sending transactions

func NewWsTxClient

func NewWsTxClient(options ...WsTxClientOption) (*WsTxClient, error)

NewWsTxClient creates a new dedicated transaction WebSocket client

func (*WsTxClient) IsConnected

func (c *WsTxClient) IsConnected() bool

IsConnected returns whether the client is connected

func (*WsTxClient) Run

func (c *WsTxClient) Run() error

Run starts the transaction WebSocket client

func (*WsTxClient) SendBatchTransactions

func (c *WsTxClient) SendBatchTransactions(signedTxs []string) (string, error)

SendBatchTransactions sends multiple transactions via WebSocket

func (*WsTxClient) SendTransaction

func (c *WsTxClient) SendTransaction(signedTx string) (string, error)

SendTransaction sends a single transaction via WebSocket

func (*WsTxClient) Stop

func (c *WsTxClient) Stop()

Stop stops the transaction client

type WsTxClientOption

type WsTxClientOption func(*WsTxClient)

WsTxClientOption configures the WsTxClient

func WithBatchTxResponseHandler

func WithBatchTxResponseHandler(handler BatchTxResponseHandler) WsTxClientOption

WithBatchTxResponseHandler sets the batch transaction response handler

func WithTxResponseHandler

func WithTxResponseHandler(handler TxResponseHandler) WsTxClientOption

WithTxResponseHandler sets the transaction response handler

func WithTxWsErrorHandler

func WithTxWsErrorHandler(handler ErrorHandler) WsTxClientOption

WithTxWsErrorHandler sets the error handler

func WithTxWsHost

func WithTxWsHost(host string) WsTxClientOption

WithTxWsHost sets the WebSocket host

func WithTxWsLocalAddress added in v0.0.12

func WithTxWsLocalAddress(localAddr string) WsTxClientOption

WithTxWsLocalAddress sets the local address for outgoing connections

func WithTxWsLocalIP added in v0.0.12

func WithTxWsLocalIP(localIP string) WsTxClientOption

WithTxWsLocalIP sets the local IP address for outgoing connections

func WithTxWsMessageHandler

func WithTxWsMessageHandler(handler MessageHandler) WsTxClientOption

WithTxWsMessageHandler sets the raw message handler

func WithTxWsReconnectInterval

func WithTxWsReconnectInterval(interval time.Duration) WsTxClientOption

WithTxWsReconnectInterval sets the reconnect interval

Jump to

Keyboard shortcuts

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