Documentation
¶
Index ¶
- Constants
- Variables
- func HashCancelAllOrders(lighterChainId uint32, info *CancelAllOrdersInfo) ([]byte, error)
- func HashCancelOrder(lighterChainId uint32, info *CancelOrderInfo) ([]byte, error)
- func HashCreateOrder(lighterChainId uint32, info *CreateOrderInfo) ([]byte, error)
- func HashModifyOrder(lighterChainId uint32, info *ModifyOrderInfo) ([]byte, error)
- func HashUpdateLeverage(lighterChainId uint32, info *UpdateLeverageInfo) ([]byte, error)
- type APIError
- type Account
- type AccountActiveOrdersResponse
- type AccountInactiveOrdersResponse
- type AccountInfo
- type AccountLimitsResponse
- type AccountMetadata
- type AccountMetadataResponse
- type AccountResponse
- type AccountStats
- type AccountTxsResponse
- type AccountsByL1AddressResponse
- type Announcement
- type AnnouncementResponse
- type ApiKey
- type ApiKeysResponse
- type Ask
- type Asset
- type AssetDetailsResponse
- type Bid
- type Callback
- type CancelAllOrdersInfo
- type CancelAllOrdersRequest
- type CancelOrderInfo
- type CancelOrderRequest
- type CancelOrderResponse
- type Candlestick
- type CandlesticksResponse
- type ChangeAccountTierResponse
- type Client
- func (c *Client) CancelOrder(ctx context.Context, req CancelOrderRequest) (*CancelOrderResponse, error)
- func (c *Client) ChangeAccountTier(ctx context.Context, newTier string) (*ChangeAccountTierResponse, error)
- func (c *Client) CreateAuthToken(deadline time.Time) (string, error)
- func (c *Client) CreateToken(ctx context.Context, name, permission string, expiration int64) (string, error)
- func (c *Client) GetAccount(ctx context.Context) (*AccountResponse, error)
- func (c *Client) GetAccountActiveOrders(ctx context.Context, marketId int) (*AccountActiveOrdersResponse, error)
- func (c *Client) GetAccountLimits(ctx context.Context) (*AccountLimitsResponse, error)
- func (c *Client) GetAccountMetadata(ctx context.Context) (*AccountMetadataResponse, error)
- func (c *Client) GetAccountTxs(ctx context.Context, limit int64) (*AccountTxsResponse, error)
- func (c *Client) GetAccountsByL1Address(ctx context.Context, l1Address string) (*AccountsByL1AddressResponse, error)
- func (c *Client) GetAllFundingRates(ctx context.Context) ([]FundingRateData, error)
- func (c *Client) GetAnnouncements(ctx context.Context) (*AnnouncementResponse, error)
- func (c *Client) GetApiKeys(ctx context.Context) (*ApiKeysResponse, error)
- func (c *Client) GetAssetDetails(ctx context.Context, assetIndex *int16) (*AssetDetailsResponse, error)
- func (c *Client) GetBlockHeight(ctx context.Context) (int64, error)
- func (c *Client) GetCandlesticks(ctx context.Context, marketId int, resolution string, ...) (*CandlesticksResponse, error)
- func (c *Client) GetExchangeStats(ctx context.Context) (*ExchangeStatsResponse, error)
- func (c *Client) GetFundingHistory(ctx context.Context, marketId *int, limit int64) (*FundingHistoryResponse, error)
- func (c *Client) GetFundingRate(ctx context.Context, marketId int) (*FundingRateData, error)
- func (c *Client) GetFundingRates(ctx context.Context) (*FundingRatesResponse, error)
- func (c *Client) GetInactiveOrders(ctx context.Context, marketId *int, limit int64) (*AccountInactiveOrdersResponse, error)
- func (c *Client) GetL1Metadata(ctx context.Context) (*L1MetadataResponse, error)
- func (c *Client) GetNextNonce(ctx context.Context) (int64, error)
- func (c *Client) GetOrderBookDetails(ctx context.Context, marketId *int, filter *string) (*OrderBookDetailsResponse, error)
- func (c *Client) GetOrderBookOrders(ctx context.Context, marketId int, limit int64) (*OrderBookOrdersResponse, error)
- func (c *Client) GetOrderBooks(ctx context.Context, marketId *int) (*OrderBooksResponse, error)
- func (c *Client) GetPnL(ctx context.Context, startTimestamp, endTimestamp int64) (*PnlResponse, error)
- func (c *Client) GetPositionFunding(ctx context.Context, marketId *int, limit int64, side *string) (*PositionFundingResponse, error)
- func (c *Client) GetPublicPoolsMetadata(ctx context.Context) (*PublicPoolsMetadataResponse, error)
- func (c *Client) GetRecentTrades(ctx context.Context, marketId int, limit int64) (*RecentTradesResponse, error)
- func (c *Client) GetReferralPoints(ctx context.Context) (*ReferralPointsResponse, error)
- func (c *Client) GetTokens(ctx context.Context) ([]Token, error)
- func (c *Client) GetTransferFeeInfo(ctx context.Context) (*TransferFeeInfoResponse, error)
- func (c *Client) GetWithdrawalDelay(ctx context.Context) (*WithdrawalDelayResponse, error)
- func (c *Client) ModifyOrder(ctx context.Context, req ModifyOrderRequest) (*ModifyOrderResponse, error)
- func (c *Client) PlaceOrder(ctx context.Context, req CreateOrderRequest) (*CreateOrderResponse, error)
- func (c *Client) Post(ctx context.Context, path string, payload any, auth bool) ([]byte, error)
- func (c *Client) PostForm(ctx context.Context, path string, params map[string]string, auth bool) ([]byte, error)
- func (c *Client) RevokeToken(ctx context.Context, tokenId int64) error
- func (c *Client) SendTxBatch(ctx context.Context, txs []map[string]string) (*SendTxBatchResponse, error)
- func (c *Client) UpdateLeverage(ctx context.Context, marketId int, leverage uint16, marginMode uint8) (*UpdateLeverageResponse, error)
- func (c *Client) WithCredentials(privateKey string, accountIndex int64, keyIndex uint8) *Client
- type CreateOrderInfo
- type CreateOrderRequest
- type CreateOrderResponse
- type CreateTokenRequest
- type CreateTokenResponse
- type CrossRiskParameters
- type DailyReturn
- type Deposit
- type DepositHistoryResponse
- type ExchangeStatsResponse
- type FundingHistory
- type FundingHistoryResponse
- type FundingRate
- type FundingRateData
- type FundingRateHistory
- type FundingRatesResponse
- type IsolatedRiskParameters
- type L1Metadata
- type L1MetadataResponse
- type L2CreateGroupedOrdersTxInfo
- type L2UpdateMarginTxInfo
- type LiqInfo
- type LiqTrade
- type Liquidation
- type LiquidationsResponse
- type MarketType
- type ModifyOrderInfo
- type ModifyOrderRequest
- type ModifyOrderResponse
- type MsgDispatcher
- type Notification
- type NotificationContent
- type Order
- type OrderBook
- type OrderBookDetail
- type OrderBookDetailsResponse
- type OrderBookLevel
- type OrderBookOrdersResponse
- type OrderBookStat
- type OrderBooksResponse
- type OrderStatus
- type OrderTypeResp
- type Pnl
- type PnlResponse
- type PoolInfo
- type Position
- type PositionFunding
- type PositionFundingResponse
- type PublicPoolMetadata
- type PublicPoolsMetadataResponse
- type RecentTradesResponse
- type ReferralPoints
- type ReferralPointsResponse
- type RevokeTokenRequest
- type RevokeTokenResponse
- type RiskInfo
- type SendTxBatchResponse
- type Share
- type SharePrice
- type SpotAsset
- type SubscribeRequest
- type Subscriber
- type Token
- type TokenListResponse
- type Trade
- type TradesResponse
- type Transfer
- type TransferFeeInfoResponse
- type TransferHistoryResponse
- type Tx
- type TxError
- type TxResponse
- type UpdateLeverageInfo
- type UpdateLeveragePayload
- type UpdateLeverageRequest
- type UpdateLeverageResponse
- type WebsocketClient
- func (c *WebsocketClient) CancelAllOrders(ctx context.Context, client *Client, req CancelAllOrdersRequest) (string, error)
- func (c *WebsocketClient) CancelOrder(ctx context.Context, client *Client, req CancelOrderRequest) (string, error)
- func (c *WebsocketClient) Close()
- func (c *WebsocketClient) Connect() error
- func (c *WebsocketClient) HandleMessage(message []byte)
- func (c *WebsocketClient) ModifyOrder(ctx context.Context, client *Client, req ModifyOrderRequest) (string, error)
- func (c *WebsocketClient) PlaceOrder(ctx context.Context, client *Client, req CreateOrderRequest) (string, error)
- func (c *WebsocketClient) RegisterPendingRequest(id string) chan *TxResponse
- func (c *WebsocketClient) Send(v any) error
- func (c *WebsocketClient) Subscribe(channel string, authToken *string, handler func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountAll(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountAllOrders(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountAllPositions(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountAllTrades(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountMarket(marketId int, accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountOrders(marketId int, accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAccountTx(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeAllMarketStats(cb func([]byte)) error
- func (c *WebsocketClient) SubscribeHeight(cb func([]byte)) error
- func (c *WebsocketClient) SubscribeMarketStats(marketId int, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeNotification(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeOrderBook(marketId int, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeTrades(marketId int, cb func([]byte)) error
- func (c *WebsocketClient) SubscribeUserStats(accountId int64, authToken string, cb func([]byte)) error
- func (c *WebsocketClient) UnregisterPendingRequest(id string)
- func (c *WebsocketClient) Unsubscribe(channel string) error
- func (c *WebsocketClient) UnsubscribeOrderBook(marketId int) error
- func (c *WebsocketClient) UnsubscribeTrades(marketId int) error
- type Withdraw
- type WithdrawHistoryResponse
- type WithdrawalDelayResponse
- type WsAccountAllEvent
- type WsAccountAllOrdersEvent
- type WsAccountAllPositionsEvent
- type WsAccountAllTradesEvent
- type WsAccountMarketEvent
- type WsAccountOrdersEvent
- type WsAccountTxEvent
- type WsHeightEvent
- type WsMarketStatsEvent
- type WsNotificationEvent
- type WsOrderBookEvent
- type WsTradeEvent
- type WsUserStatsEvent
Constants ¶
const ( TxTypeChangePubKey = 8 TxTypeCreateSubAccount = 9 TxTypeCreatePublicPool = 10 TxTypeUpdatePublicPool = 11 TxTypeTransfer = 12 TxTypeWithdraw = 13 TxTypeCreateOrder = 14 TxTypeCancelOrder = 15 TxTypeCancelAllOrders = 16 TxTypeModifyOrder = 17 TxTypeUpdateLeverage = 20 TxTypeL2CreateGroupedOrders = 28 TxTypeL2UpdateMargin = 29 OrderTypeLimit = 0 OrderTypeMarket = 1 OrderTypeStopLoss = 2 OrderTypeStopLossLimit = 3 OrderTypeTakeProfit = 4 OrderTypeTakeProfitLimit = 5 OrderTypeTwap = 6 OrderTimeInForceImmediateOrCancel = 0 OrderTimeInForceGoodTillTime = 1 OrderTimeInForcePostOnly = 2 CancelAllTifImmediate = 0 CancelAllTifScheduled = 1 CancelAllTifAbort = 2 NilTriggerPrice = 0 Default28DayOrderExpiry = -1 DefaultIocExpiry = 0 Default10MinAuthExpiry = -1 Minute = 60 CrossMarginMode = 0 IsolatedMarginMode = 1 MainnetChainID = 304 )
Constants
const (
MainnetAPIURL = "https://mainnet.zklighter.elliot.ai"
)
const (
MainnetWSURL = "wss://mainnet.zklighter.elliot.ai/stream"
)
Variables ¶
var ( ErrInvalidSignature = fmt.Errorf("invalid signature") ErrOrderNotFound = fmt.Errorf("order not found") )
Common error types
Functions ¶
func HashCancelAllOrders ¶
func HashCancelAllOrders(lighterChainId uint32, info *CancelAllOrdersInfo) ([]byte, error)
HashCancelAllOrders computes the hash for a CancelAllOrders transaction. Based on official SDK hash order: chainId, txType, nonce, expiredAt, accountIndex, apiKeyIndex, timeInForce, time
func HashCancelOrder ¶
func HashCancelOrder(lighterChainId uint32, info *CancelOrderInfo) ([]byte, error)
HashCancelOrder computes the hash for a CancelOrder transaction.
func HashCreateOrder ¶
func HashCreateOrder(lighterChainId uint32, info *CreateOrderInfo) ([]byte, error)
HashCreateOrder computes the hash for a CreateOrder transaction.
func HashModifyOrder ¶
func HashModifyOrder(lighterChainId uint32, info *ModifyOrderInfo) ([]byte, error)
HashModifyOrder computes the hash for a ModifyOrder transaction.
func HashUpdateLeverage ¶
func HashUpdateLeverage(lighterChainId uint32, info *UpdateLeverageInfo) ([]byte, error)
HashUpdateLeverage computes the hash for an UpdateLeverage transaction.
Types ¶
type Account ¶
type Account struct {
Code int32 `json:"code"`
Msg string `json:"message"`
AccountType int8 `json:"account_type"`
Index int64 `json:"index"`
L1Address string `json:"l1_address"`
CancelAllTime int64 `json:"cancel_all_time"`
TotalOrderCount int64 `json:"total_order_count"`
TotalIsolatedOrderCount int64 `json:"total_isolated_order_count"`
PendingOrderCount int64 `json:"pending_order_count"`
AvailableBalance string `json:"available_balance"`
Status uint8 `json:"status"`
Collateral string `json:"collateral"`
AccountIndex int64 `json:"account_index"`
Name string `json:"name"`
Description string `json:"description"`
CanInvite bool `json:"can_invite"`
ReferralPointsPercentage string `json:"referral_points_percentage"`
Positions []*Position `json:"positions"`
Assets []*SpotAsset `json:"assets"`
TotalAssetValue string `json:"total_asset_value"`
CrossAssetValue string `json:"cross_asset_value"`
PoolInfo *PoolInfo `json:"pool_info"`
}
type AccountInfo ¶
type AccountInfo struct {
AccountIndex int64 `json:"account_index"`
L1Address string `json:"l1_address"`
}
AccountInfo represents account information
type AccountLimitsResponse ¶
type AccountLimitsResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
MaxLlpPercentage int32 `json:"max_llp_percentage"`
UserTier string `json:"user_tier"`
CanCreatePublicPool bool `json:"can_create_public_pool"`
CurrentMakerFeeTick int32 `json:"current_maker_fee_tick"`
CurrentTakerFeeTick int32 `json:"current_taker_fee_tick"`
}
type AccountMetadata ¶
type AccountMetadataResponse ¶
type AccountMetadataResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
AccountMetadatas []*AccountMetadata `json:"account_metadatas"`
}
type AccountResponse ¶
type AccountStats ¶
type AccountStats struct {
Collateral string `json:"collateral"`
PortfolioValue string `json:"portfolio_value"`
Leverage string `json:"leverage"`
AvailableBalance string `json:"available_balance"`
MarginUsage string `json:"margin_usage"`
BuyingPower string `json:"buying_power"`
}
AccountStats represents account statistics
type AccountTxsResponse ¶
type Announcement ¶
type AnnouncementResponse ¶
type AnnouncementResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
Announcements []Announcement `json:"announcements"`
}
type ApiKeysResponse ¶
type Ask ¶
type Ask 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 Asset ¶
type Asset struct {
AssetIndex int16 `json:"asset_index"`
Symbol string `json:"symbol"`
L1Decimals uint8 `json:"l1_decimals"`
Decimals uint8 `json:"decimals"`
ExtensionMultiplier int64 `json:"extension_multiplier"`
MinTransferAmount int64 `json:"min_transfer_amount"`
MinWithdrawalAmount int64 `json:"min_withdrawal_amount"`
MarginMode uint8 `json:"margin_mode"`
IndexPrice uint32 `json:"index_price"`
L1Address string `json:"l1_address"`
TickSize string `json:"tick_size"`
}
type AssetDetailsResponse ¶
type Bid ¶
type Bid 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 CancelAllOrdersInfo ¶
type CancelAllOrdersInfo struct {
Nonce int64
ExpiredAt int64
AccountIndex int64
ApiKeyIndex uint32
TimeInForce uint32 // 0=ImmediateCancelAll, 1=ScheduledCancelAll, 2=AbortScheduledCancelAll
Time int64 // 0 for Immediate, scheduled time for Scheduled, 0 for Abort
// For WebSocket operations
Sig []byte `json:"Sig,omitempty"`
SignedHash string `json:"-"`
}
CancelAllOrdersInfo contains information needed to sign a cancel all orders transaction Based on official SDK: https://github.com/elliottech/lighter-go/blob/main/types/txtypes/cancel_all_orders.go
type CancelAllOrdersRequest ¶
type CancelAllOrdersRequest struct {
MarketId int `json:"market_id"`
CancelAllTif uint32 `json:"cancel_all_tif,omitempty"`
}
CancelAllOrdersRequest represents the payload for cancelling all orders
type CancelOrderInfo ¶
type CancelOrderInfo struct {
Nonce int64
ExpiredAt int64
AccountIndex int64
ApiKeyIndex uint32
MarketIndex uint32
Index int64
// For WebSocket operations
Sig []byte `json:"Sig,omitempty"`
SignedHash string `json:"-"`
}
CancelOrderInfo contains information needed to sign a cancel order transaction
type CancelOrderRequest ¶
CancelOrderRequest represents the payload for cancelling an order
type CancelOrderResponse ¶
type CancelOrderResponse struct {
Code int32 `json:"code"`
Message string `json:"message"`
TxHash string `json:"tx_hash"`
PredictedExecutionTimeMs int64 `json:"predicted_execution_time_ms"`
}
CancelOrderResponse represents the response from cancelling an order
type Candlestick ¶
type CandlesticksResponse ¶
type CandlesticksResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
Candlesticks []Candlestick `json:"candlesticks"`
}
type Client ¶
type Client struct {
BaseURL string
HTTPClient *http.Client
Logger *zap.SugaredLogger
PrivateKey string
AccountIndex int64
KeyIndex uint8
ChainId uint32
KeyManager common.KeyManager
// contains filtered or unexported fields
}
func (*Client) CancelOrder ¶
func (c *Client) CancelOrder(ctx context.Context, req CancelOrderRequest) (*CancelOrderResponse, error)
CancelOrder cancels an order
func (*Client) ChangeAccountTier ¶
func (c *Client) ChangeAccountTier(ctx context.Context, newTier string) (*ChangeAccountTierResponse, error)
ChangeAccountTier changes account tier
func (*Client) CreateAuthToken ¶
func (*Client) CreateToken ¶
func (c *Client) CreateToken(ctx context.Context, name, permission string, expiration int64) (string, error)
CreateToken creates a new API token
func (*Client) GetAccount ¶
func (c *Client) GetAccount(ctx context.Context) (*AccountResponse, error)
GetAccount fetches account information
func (*Client) GetAccountActiveOrders ¶
func (c *Client) GetAccountActiveOrders(ctx context.Context, marketId int) (*AccountActiveOrdersResponse, error)
GetAccountActiveOrders fetches active orders for the account
func (*Client) GetAccountLimits ¶
func (c *Client) GetAccountLimits(ctx context.Context) (*AccountLimitsResponse, error)
GetAccountLimits fetches account limits
func (*Client) GetAccountMetadata ¶
func (c *Client) GetAccountMetadata(ctx context.Context) (*AccountMetadataResponse, error)
GetAccountMetadata fetches account metadata
func (*Client) GetAccountTxs ¶
GetAccountTxs fetches account transactions
func (*Client) GetAccountsByL1Address ¶
func (c *Client) GetAccountsByL1Address(ctx context.Context, l1Address string) (*AccountsByL1AddressResponse, error)
GetAccountsByL1Address fetches accounts by L1 address
func (*Client) GetAllFundingRates ¶
func (c *Client) GetAllFundingRates(ctx context.Context) ([]FundingRateData, error)
GetAllFundingRates retrieves funding rates for all symbols Returns per-hour funding rates (Lighter uses 1-hour interval natively)
func (*Client) GetAnnouncements ¶
func (c *Client) GetAnnouncements(ctx context.Context) (*AnnouncementResponse, error)
GetAnnouncements fetches announcements
func (*Client) GetApiKeys ¶
func (c *Client) GetApiKeys(ctx context.Context) (*ApiKeysResponse, error)
GetApiKeys fetches API keys
func (*Client) GetAssetDetails ¶
func (c *Client) GetAssetDetails(ctx context.Context, assetIndex *int16) (*AssetDetailsResponse, error)
GetAssetDetails fetches asset details
func (*Client) GetCandlesticks ¶
func (c *Client) GetCandlesticks(ctx context.Context, marketId int, resolution string, startTimestamp, endTimestamp int64) (*CandlesticksResponse, error)
GetCandlesticks fetches candlesticks
func (*Client) GetExchangeStats ¶
func (c *Client) GetExchangeStats(ctx context.Context) (*ExchangeStatsResponse, error)
GetExchangeStats fetches exchange statistics
func (*Client) GetFundingHistory ¶
func (c *Client) GetFundingHistory(ctx context.Context, marketId *int, limit int64) (*FundingHistoryResponse, error)
GetFundingHistory fetches funding history
func (*Client) GetFundingRate ¶
GetFundingRate retrieves the funding rate for a specific market id Returns per-hour funding rate (Lighter uses 1-hour interval natively)
func (*Client) GetFundingRates ¶
func (c *Client) GetFundingRates(ctx context.Context) (*FundingRatesResponse, error)
GetFundingRates fetches current funding rates
func (*Client) GetInactiveOrders ¶
func (c *Client) GetInactiveOrders(ctx context.Context, marketId *int, limit int64) (*AccountInactiveOrdersResponse, error)
GetInactiveOrders fetches inactive orders
func (*Client) GetL1Metadata ¶
func (c *Client) GetL1Metadata(ctx context.Context) (*L1MetadataResponse, error)
GetL1Metadata fetches L1 metadata
func (*Client) GetNextNonce ¶
GetNextNonce fetches the next nonce for the account, using a local cache to handle high concurrency
func (*Client) GetOrderBookDetails ¶
func (c *Client) GetOrderBookDetails(ctx context.Context, marketId *int, filter *string) (*OrderBookDetailsResponse, error)
GetOrderBookDetails fetches order book details
func (*Client) GetOrderBookOrders ¶
func (c *Client) GetOrderBookOrders(ctx context.Context, marketId int, limit int64) (*OrderBookOrdersResponse, error)
GetOrderBookOrders fetches detailed order book orders
func (*Client) GetOrderBooks ¶
GetOrderBooks fetches order books
func (*Client) GetPnL ¶
func (c *Client) GetPnL(ctx context.Context, startTimestamp, endTimestamp int64) (*PnlResponse, error)
GetPnL fetches account PnL
func (*Client) GetPositionFunding ¶
func (c *Client) GetPositionFunding(ctx context.Context, marketId *int, limit int64, side *string) (*PositionFundingResponse, error)
GetPositionFunding fetches position funding history
func (*Client) GetPublicPoolsMetadata ¶
func (c *Client) GetPublicPoolsMetadata(ctx context.Context) (*PublicPoolsMetadataResponse, error)
GetPublicPoolsMetadata fetches public pools metadata
func (*Client) GetRecentTrades ¶
func (c *Client) GetRecentTrades(ctx context.Context, marketId int, limit int64) (*RecentTradesResponse, error)
GetRecentTrades fetches recent trades
func (*Client) GetReferralPoints ¶
func (c *Client) GetReferralPoints(ctx context.Context) (*ReferralPointsResponse, error)
GetReferralPoints fetches referral points
func (*Client) GetTokens ¶
GetTokens lists all active tokens for the account Notice: This api not return api_token filed, what a shit......
func (*Client) GetTransferFeeInfo ¶
func (c *Client) GetTransferFeeInfo(ctx context.Context) (*TransferFeeInfoResponse, error)
GetTransferFeeInfo fetches transfer fee info
func (*Client) GetWithdrawalDelay ¶
func (c *Client) GetWithdrawalDelay(ctx context.Context) (*WithdrawalDelayResponse, error)
GetWithdrawalDelay fetches withdrawal delay
func (*Client) ModifyOrder ¶
func (c *Client) ModifyOrder(ctx context.Context, req ModifyOrderRequest) (*ModifyOrderResponse, error)
ModifyOrder modifies an existing order
func (*Client) PlaceOrder ¶
func (c *Client) PlaceOrder(ctx context.Context, req CreateOrderRequest) (*CreateOrderResponse, error)
PlaceOrder places a new order
func (*Client) PostForm ¶
func (c *Client) PostForm(ctx context.Context, path string, params map[string]string, auth bool) ([]byte, error)
PostForm sends a multipart/form-data request
func (*Client) RevokeToken ¶
RevokeToken revokes an API token
func (*Client) SendTxBatch ¶
func (c *Client) SendTxBatch(ctx context.Context, txs []map[string]string) (*SendTxBatchResponse, error)
SendTxBatch sends a batch of transactions
func (*Client) UpdateLeverage ¶
func (c *Client) UpdateLeverage(ctx context.Context, marketId int, leverage uint16, marginMode uint8) (*UpdateLeverageResponse, error)
UpdateLeverage updates leverage
type CreateOrderInfo ¶
type CreateOrderInfo struct {
Nonce int64
ExpiredAt int64
AccountIndex int64
ApiKeyIndex uint32
MarketIndex uint32
ClientOrderIndex int64
BaseAmount int64
Price uint32
IsAsk uint32
Type uint32
TimeInForce uint32
ReduceOnly uint32
TriggerPrice uint32
OrderExpiry int64
// For WebSocket operations
Sig []byte `json:"Sig,omitempty"`
SignedHash string `json:"-"`
}
CreateOrderInfo contains information needed to sign a create order transaction
type CreateOrderRequest ¶
type CreateOrderRequest struct {
MarketId int `json:"market_id"`
Price uint32 `json:"price"`
BaseAmount int64 `json:"base_amount"`
IsAsk uint32 `json:"is_ask"`
OrderType uint32 `json:"order_type"`
ClientOrderId int64 `json:"client_order_id,omitempty"`
TimeInForce uint32 `json:"time_in_force,omitempty"`
ReduceOnly uint32 `json:"reduce_only"`
TriggerPrice uint32 `json:"trigger_price"`
OrderExpiry int64 `json:"order_expiry"`
}
CreateOrderRequest represents the payload for creating an order
type CreateOrderResponse ¶
type CreateOrderResponse struct {
Code int32 `json:"code"`
Message string `json:"message"`
TxHash string `json:"tx_hash"`
PredictedExecutionTimeMs int64 `json:"predicted_execution_time_ms"`
}
CreateOrderResponse represents the response from creating an order
type CreateTokenRequest ¶
type CreateTokenResponse ¶
type CreateTokenResponse struct {
Code int `json:"code"`
Msg string `json:"message"`
TokenId int64 `json:"token_id"`
ApiToken string `json:"api_token"`
Name string `json:"name"`
AccountIndex int64 `json:"account_index"`
Expiry int64 `json:"expiry"`
SubAccountAccess bool `json:"sub_account_access"`
Scopes string `json:"scopes"`
}
type CrossRiskParameters ¶
type CrossRiskParameters struct {
MarketId int `json:"market_id"`
Collateral string `json:"collateral"`
TotalAccountValue string `json:"total_account_value"`
InitialMarginReq string `json:"initial_margin_req"`
MaintenanceMarginReq string `json:"maintenance_margin_req"`
CloseOutMarginReq string `json:"close_out_margin_req"`
}
type DailyReturn ¶
type DepositHistoryResponse ¶
type ExchangeStatsResponse ¶
type FundingHistory ¶
type FundingHistory struct {
Timestamp int64 `json:"timestamp"`
MarketId uint8 `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 a funding payment
type FundingHistoryResponse ¶
type FundingHistoryResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
Fundings []FundingRateHistory `json:"fundings"`
}
type FundingRate ¶
type FundingRateData ¶
type FundingRateData struct {
Symbol string `json:"symbol"`
MarketId int `json:"market_id"`
Exchange string `json:"exchange"` // Exchange name (lighter, binance, bybit, hyperliquid)
FundingRate string `json:"rate"` // Changed from fundingRate to rate to match API
FundingIntervalHours int64 `json:"fundingIntervalHours"` // Always 1 for Lighter
FundingTime int64 `json:"fundingTime"` // Current hour start (calculated)
NextFundingTime int64 `json:"nextFundingTime"` // Next hour start (calculated)
}
FundingRateData contains standardized funding rate information
type FundingRateHistory ¶
type FundingRatesResponse ¶
type FundingRatesResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
FundingRate []*FundingRate `json:"funding_rates"`
}
type IsolatedRiskParameters ¶
type IsolatedRiskParameters struct {
MarketId int `json:"market_id"`
Collateral string `json:"collateral"`
TotalAccountValue string `json:"total_account_value"`
InitialMarginReq string `json:"initial_margin_req"`
MaintenanceMarginReq string `json:"maintenance_margin_req"`
CloseOutMarginReq string `json:"close_out_margin_req"`
}
type L1Metadata ¶
type L1MetadataResponse ¶
type L1MetadataResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
L1Metadata L1Metadata `json:"l1_metadata"`
}
type L2CreateGroupedOrdersTxInfo ¶
type L2UpdateMarginTxInfo ¶
type Liquidation ¶
type LiquidationsResponse ¶
type LiquidationsResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
Liquidations []Liquidation `json:"liquidations"`
}
type MarketType ¶
type MarketType string
const ( MarketTypePerp MarketType = "perp" MarketTypeSpot MarketType = "spot" )
type ModifyOrderInfo ¶
type ModifyOrderInfo struct {
Nonce int64
ExpiredAt int64
AccountIndex int64
ApiKeyIndex uint32
MarketIndex uint32
Index int64
BaseAmount int64
Price uint32
TriggerPrice uint32
// For WebSocket operations
Sig []byte `json:"Sig,omitempty"`
SignedHash string `json:"-"`
}
ModifyOrderInfo contains information needed to sign a modify order transaction
type ModifyOrderRequest ¶
type ModifyOrderRequest struct {
MarketId int
OrderIndex int64
BaseAmount int64
Price uint32
TriggerPrice uint32
}
ModifyOrderRequest represents a modify order request
type ModifyOrderResponse ¶
type MsgDispatcher ¶
type MsgDispatcher interface {
Dispatch(subscribers map[string]*Subscriber, msg []byte) error
}
MsgDispatcher interface for handling different message types
type Notification ¶
type Notification struct {
Id string `json:"id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Kind string `json:"kind"` // "liquidation", "deleverage", "announcement"
AccountIndex int64 `json:"account_index"`
Content NotificationContent `json:"content"`
Ack bool `json:"ack"`
AckedAt *string `json:"acked_at"`
}
Notification represents a notification
type NotificationContent ¶
type NotificationContent map[string]interface{}
NotificationContent can be different types based on notification kind
type Order ¶
type Order struct {
OrderIndex int64 `json:"order_index"`
ClientOrderIndex int64 `json:"client_order_index"`
OrderId string `json:"order_id"`
ClientOrderId string `json:"client_order_id"`
MarketIndex int `json:"market_index"`
OwnerAccountIndex int `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"`
OrderType OrderTypeResp `json:"type"`
TimeInForce string `json:"time_in_force"`
ReduceOnly bool `json:"reduce_only"`
TriggerPrice string `json:"trigger_price"`
OrderExpiry int64 `json:"order_expiry"`
Status OrderStatus `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"`
ToTriggerOrderId2 string `json:"to_trigger_order_id_2"`
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"`
}
Order represents an order in the system
type OrderBook ¶
type OrderBook struct {
Symbol string `json:"symbol"`
MarketId int `json:"market_id"`
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 uint8 `json:"supported_size_decimals"`
SupportedPriceDecimals uint8 `json:"supported_price_decimals"`
SupportedQuoteDecimals uint8 `json:"supported_quote_decimals"`
MarketType MarketType `json:"market_type"`
BaseAssetId int16 `json:"base_asset_id"`
QuoteAssetId int16 `json:"quote_asset_id"`
OrderQuoteLimit string `json:"order_quote_limit"`
}
type OrderBookDetail ¶
type OrderBookDetail struct {
Symbol string `json:"symbol"`
MarketId int `json:"market_id"`
MarketType string `json:"market_type"`
BaseAssetId int `json:"base_asset_id"`
QuoteAssetId int `json:"quote_asset_id"`
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 uint8 `json:"supported_size_decimals"`
SupportedPriceDecimals uint8 `json:"supported_price_decimals"`
SupportedQuoteDecimals uint8 `json:"supported_quote_decimals"`
SizeDecimals uint8 `json:"size_decimals"`
PriceDecimals uint8 `json:"price_decimals"`
QuoteMultiplier int64 `json:"quote_multiplier"`
DefaultInitialMarginFraction int `json:"default_initial_margin_fraction"`
MinInitialMarginFraction int `json:"min_initial_margin_fraction"`
MaintenanceMarginFraction int `json:"maintenance_margin_fraction"`
CloseoutMarginFraction int `json:"closeout_margin_fraction"`
LastTradePrice float64 `json:"last_trade_price"`
DailyTradesCount int64 `json:"daily_trades_count"`
DailyBaseTokenVolume float64 `json:"daily_base_token_volume"`
DailyQuoteTokenVolume float64 `json:"daily_quote_token_volume"`
DailyPriceLow float64 `json:"daily_price_low"`
DailyPriceHigh float64 `json:"daily_price_high"`
DailyPriceChange float64 `json:"daily_price_change"`
OpenInterest float64 `json:"open_interest"`
}
type OrderBookDetailsResponse ¶
type OrderBookDetailsResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
OrderBookDetails []*OrderBookDetail `json:"order_book_details"`
SpotOrderBookDetails []*OrderBookDetail `json:"spot_order_book_details"`
}
type OrderBookLevel ¶
type OrderBookOrdersResponse ¶
type OrderBookOrdersResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
TotalAsks int64 `json:"total_asks"`
Asks []Ask `json:"asks"`
TotalBids int64 `json:"total_bids"`
Bids []Bid `json:"bids"`
}
Market Data types
type OrderBookStat ¶
type OrderBookStat struct {
Symbol string `json:"symbol"`
LastTradePrice float64 `json:"last_trade_price"`
DailyTradesCount int64 `json:"daily_trades_count"`
DailyBaseTokenVolume float64 `json:"daily_base_token_volume"`
DailyQuoteTokenVolume float64 `json:"daily_quote_token_volume"`
DailyPriceChange float64 `json:"daily_price_change"`
}
type OrderBooksResponse ¶
type OrderStatus ¶
type OrderStatus string
const ( // OrderStatus OrderStatusInProgress OrderStatus = "in-progress" OrderStatusPending OrderStatus = "pending" OrderStatusOpen OrderStatus = "open" OrderStatusFilled OrderStatus = "filled" OrderStatusCanceled OrderStatus = "canceled" OrderStatusCanceledPostOnly OrderStatus = "canceled-post-only" OrderStatusCanceledReduceOnly OrderStatus = "canceled-reduce-only" OrderStatusCanceledPositionNotAllowed OrderStatus = "canceled-position-not-allowed" OrderStatusCanceledMarginNotAllowed OrderStatus = "canceled-margin-not-allowed" OrderStatusCanceledTooMuchSlippage OrderStatus = "canceled-too-much-slippage" OrderStatusCanceledNotEnoughLiquidity OrderStatus = "canceled-not-enough-liquidity" OrderStatusCanceledSelfTrade OrderStatus = "canceled-self-trade" OrderStatusCanceledExpired OrderStatus = "canceled-expired" OrderStatusCanceledOco OrderStatus = "canceled-oco" OrderStatusCanceledChild OrderStatus = "canceled-child" OrderStatusCanceledLiquidation OrderStatus = "canceled-liquidation" // lighter not provided OrderStatusRejected OrderStatus = "rejected" OrderStatusPartiallyFilled OrderStatus = "partially-filled" )
type OrderTypeResp ¶
type OrderTypeResp string
const ( OrderTypeRespLimit OrderTypeResp = "limit" OrderTypeRespMarket OrderTypeResp = "market" OrderTypeRespStopLoss OrderTypeResp = "stop-loss" OrderTypeRespStopLossLimit OrderTypeResp = "stop-loss-limit" OrderTypeRespTakeProfit OrderTypeResp = "take-profit" OrderTypeRespTakeProfitLimit OrderTypeResp = "take-profit-limit" OrderTypeRespTwap OrderTypeResp = "twap" OrderTypeRespTwapSub OrderTypeResp = "twap-sub" OrderTypeRespLiquidation OrderTypeResp = "liquidation" )
type PnlResponse ¶
type PoolInfo ¶
type PoolInfo struct {
Status uint8 `json:"status"`
OperatorFee string `json:"operator_fee"`
AnnualPercentageYield float64 `json:"annual_percentage_yield"`
DailyReturn *DailyReturn `json:"daily_return"`
}
type Position ¶
type Position struct {
MarketId int `json:"market_id"`
Symbol string `json:"symbol"`
InitialMarginFraction string `json:"initial_margin_fraction"`
OpenOrderCount int64 `json:"open_order_count"`
PendingOrderCount int64 `json:"pending_order_count"`
PositionTiedOrderCount int64 `json:"position_tied_order_count"`
Sign int32 `json:"sign"`
Position string `json:"position"`
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 int32 `json:"margin_mode"`
AllocatedMargin string `json:"allocated_margin"`
}
type PositionFunding ¶
type PositionFundingResponse ¶
type PositionFundingResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
PositionFundings []*PositionFunding `json:"position_fundings"`
}
type PublicPoolMetadata ¶
type PublicPoolsMetadataResponse ¶
type PublicPoolsMetadataResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
PublicPoolsMetadata []PublicPoolMetadata `json:"public_pools_metadata"`
}
type RecentTradesResponse ¶
type ReferralPoints ¶
type ReferralPointsResponse ¶
type ReferralPointsResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
ReferralPoints ReferralPoints `json:"referral_points"`
}
type RevokeTokenRequest ¶
type RevokeTokenResponse ¶
type RiskInfo ¶
type RiskInfo struct {
CrossRiskParameters CrossRiskParameters `json:"cross_risk_parameters"`
IsolatedRiskParameters IsolatedRiskParameters `json:"isolated_risk_parameters"`
}
type SendTxBatchResponse ¶
type SharePrice ¶
type SharePrice struct {
}
type SubscribeRequest ¶
type SubscribeRequest struct {
Type string `json:"type"`
Channel string `json:"channel"`
Auth *string `json:"auth,omitempty"`
}
SubscribeRequest represents a WebSocket subscription request
type Subscriber ¶
Subscriber manages subscriptions for a channel
func (*Subscriber) Dispatch ¶
func (s *Subscriber) Dispatch(data []byte)
type Token ¶
type Token struct {
TokenID int64 `json:"token_id"`
ApiToken string `json:"api_token"`
Name string `json:"name"`
Expiry int64 `json:"expiry"`
AccountIndex int64 `json:"account_index"`
SubAccountAccess bool `json:"sub_account_access"`
Scopes string `json:"scopes"`
Revoked bool `json:"revoked"`
}
Token structs for API Management
type TokenListResponse ¶
type Trade ¶
type Trade struct {
TradeId int64 `json:"trade_id"`
TxHash string `json:"tx_hash"`
TradeType string `json:"type"`
MarketId int `json:"market_id"`
Size string `json:"size"`
Price string `json:"price"`
UsdAmount string `json:"usd_amount"`
AskId int64 `json:"ask_id"`
BidId int64 `json:"bid_id"`
AskAccountId int64 `json:"ask_account_id"`
BidAccountId int64 `json:"bid_account_id"`
IsMakerAsk bool `json:"is_maker_ask"`
BlockHeight int64 `json:"block_height"`
Timestamp int64 `json:"timestamp"`
TakerFee int32 `json:"taker_fee"`
TakerPositionSizeBefore string `json:"taker_position_size_before"`
TakerEntryQuoteBefore string `json:"taker_entry_quote_before"`
TakerInitialMarginFractionBefore int `json:"taker_initial_margin_fraction_before"`
TakerPositionSignChanged bool `json:"taker_position_sign_changed"`
MakerFee int32 `json:"maker_fee"`
MakerPositionSizeBefore string `json:"maker_position_size_before"`
MakerEntryQuoteBefore string `json:"maker_entry_quote_before"`
MakerInitialMarginFractionBefore int `json:"maker_initial_margin_fraction_before"`
MakerPositionSignChanged bool `json:"maker_position_sign_changed"`
}
type TradesResponse ¶
type TransferFeeInfoResponse ¶
type TransferHistoryResponse ¶
type Tx ¶
type Tx struct {
Hash string `json:"hash"`
TxType uint8 `json:"tx_type"`
Info string `json:"info"`
EventInfo string `json:"event_info"`
Status int64 `json:"status"`
TransactionIndex int64 `json:"transaction_index"`
L1Address string `json:"l1_address"`
AccountIndex int64 `json:"account_index"`
Nonce int64 `json:"nonce"`
ExpireAt int64 `json:"expire_at"`
BlockHeight int64 `json:"block_height"`
QueuedAt int64 `json:"queued_at"`
SequenceIndex int64 `json:"sequence_index"`
ParentHash string `json:"parent_hash"`
}
type TxResponse ¶
type TxResponse struct {
ID string `json:"id"`
Type string `json:"type"`
Code int `json:"code"` // 200 = success, others = error
Message string `json:"message,omitempty"` // Error message if code != 200
TxHash string `json:"tx_hash,omitempty"`
PredictedExecutionTimeMs int64 `json:"predicted_execution_time_ms,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
TxError *TxError `json:"error,omitempty"`
}
TxResponse represents a WebSocket transaction response from Lighter
func (*TxResponse) Error ¶
func (r *TxResponse) Error() string
Error returns the error message if the response is not successful
func (*TxResponse) IsSuccess ¶
func (r *TxResponse) IsSuccess() bool
IsSuccess returns true if the response indicates success
type UpdateLeverageInfo ¶
type UpdateLeverageInfo struct {
Nonce int64
ExpiredAt int64
AccountIndex int64
ApiKeyIndex uint32
MarketIndex uint32
InitialMarginFraction uint16
MarginMode uint8
// For WebSocket operations
Sig []byte `json:"Sig,omitempty"`
SignedHash string `json:"-"`
}
UpdateLeverageInfo contains information needed to sign an update leverage transaction
type UpdateLeveragePayload ¶
type UpdateLeveragePayload struct {
*UpdateLeverageInfo
Sig []byte `json:"Sig"`
SignedHash string `json:"-"`
}
type UpdateLeverageRequest ¶
type UpdateLeverageRequest struct {
MarketId int `json:"market_id"`
InitialMarginFraction uint16 `json:"initial_margin_fraction"`
MarginMode uint8 `json:"margin_mode"` // 0: Cross, 1: Isolated
}
UpdateLeverageRequest represents the payload for updating leverage
type UpdateLeverageResponse ¶
type UpdateLeverageResponse struct {
Code int32 `json:"code"`
Msg string `json:"message"`
TxHash string `json:"tx_hash"`
PredictedExecutionTimeMs int64 `json:"predicted_execution_time_ms"`
}
UpdateLeverageResponse represents the response from updating leverage
type WebsocketClient ¶
type WebsocketClient struct {
URL string
Conn *websocket.Conn
Mu sync.RWMutex
WriteMu sync.Mutex
// Subscriptions maps channel name -> subscription (auth + handler)
Subscriptions map[string]*subscription
// PendingRequests maps request ID -> response channel for transaction tracking
PendingRequests map[string]chan *TxResponse
Logger *zap.SugaredLogger
// Reconnect logic
ReconnectWait time.Duration
// Error handling
OnError func(error)
// contains filtered or unexported fields
}
func NewWebsocketClient ¶
func NewWebsocketClient(ctx context.Context) *WebsocketClient
func (*WebsocketClient) CancelAllOrders ¶
func (c *WebsocketClient) CancelAllOrders(ctx context.Context, client *Client, req CancelAllOrdersRequest) (string, error)
CancelAllOrders cancels all orders via WebSocket
func (*WebsocketClient) CancelOrder ¶
func (c *WebsocketClient) CancelOrder(ctx context.Context, client *Client, req CancelOrderRequest) (string, error)
CancelOrder cancels an order via WebSocket
func (*WebsocketClient) Close ¶
func (c *WebsocketClient) Close()
func (*WebsocketClient) Connect ¶
func (c *WebsocketClient) Connect() error
func (*WebsocketClient) HandleMessage ¶
func (c *WebsocketClient) HandleMessage(message []byte)
func (*WebsocketClient) ModifyOrder ¶
func (c *WebsocketClient) ModifyOrder(ctx context.Context, client *Client, req ModifyOrderRequest) (string, error)
ModifyOrder modifies an order via WebSocket
func (*WebsocketClient) PlaceOrder ¶
func (c *WebsocketClient) PlaceOrder(ctx context.Context, client *Client, req CreateOrderRequest) (string, error)
PlaceOrder places a new order via WebSocket
func (*WebsocketClient) RegisterPendingRequest ¶
func (c *WebsocketClient) RegisterPendingRequest(id string) chan *TxResponse
RegisterPendingRequest creates a response channel for a request ID with timeout
func (*WebsocketClient) Send ¶
func (c *WebsocketClient) Send(v any) error
func (*WebsocketClient) Subscribe ¶
func (c *WebsocketClient) Subscribe(channel string, authToken *string, handler func([]byte)) error
Subscribe registers a handler for a channel.
func (*WebsocketClient) SubscribeAccountAll ¶
func (c *WebsocketClient) SubscribeAccountAll(accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountAll subscribes to all account data
func (*WebsocketClient) SubscribeAccountAllOrders ¶
func (c *WebsocketClient) SubscribeAccountAllOrders(accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountAllOrders subscribes to all account orders
func (*WebsocketClient) SubscribeAccountAllPositions ¶
func (c *WebsocketClient) SubscribeAccountAllPositions(accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountAllPositions subscribes to all account positions
func (*WebsocketClient) SubscribeAccountAllTrades ¶
func (c *WebsocketClient) SubscribeAccountAllTrades(accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountAllTrades subscribes to all account trades
func (*WebsocketClient) SubscribeAccountMarket ¶
func (c *WebsocketClient) SubscribeAccountMarket(marketId int, accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountMarket subscribes to account data for a specific market
func (*WebsocketClient) SubscribeAccountOrders ¶
func (c *WebsocketClient) SubscribeAccountOrders(marketId int, accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountOrders subscribes to account orders for a specific market
func (*WebsocketClient) SubscribeAccountTx ¶
func (c *WebsocketClient) SubscribeAccountTx(accountId int64, authToken string, cb func([]byte)) error
SubscribeAccountTx subscribes to account transactions
func (*WebsocketClient) SubscribeAllMarketStats ¶
func (c *WebsocketClient) SubscribeAllMarketStats(cb func([]byte)) error
SubscribeAllMarketStats subscribes to market stats for all markets
func (*WebsocketClient) SubscribeHeight ¶
func (c *WebsocketClient) SubscribeHeight(cb func([]byte)) error
SubscribeHeight subscribes to blockchain height updates
func (*WebsocketClient) SubscribeMarketStats ¶
func (c *WebsocketClient) SubscribeMarketStats(marketId int, cb func([]byte)) error
SubscribeMarketStats subscribes to market stats for a specific market
func (*WebsocketClient) SubscribeNotification ¶
func (c *WebsocketClient) SubscribeNotification(accountId int64, authToken string, cb func([]byte)) error
SubscribeNotification subscribes to account notifications
func (*WebsocketClient) SubscribeOrderBook ¶
func (c *WebsocketClient) SubscribeOrderBook(marketId int, cb func([]byte)) error
SubscribeOrderBook subscribes to the order book channel for a specific market
func (*WebsocketClient) SubscribeTrades ¶
func (c *WebsocketClient) SubscribeTrades(marketId int, cb func([]byte)) error
SubscribeTrades subscribes to the trades channel for a specific market
func (*WebsocketClient) SubscribeUserStats ¶
func (c *WebsocketClient) SubscribeUserStats(accountId int64, authToken string, cb func([]byte)) error
SubscribeUserStats subscribes to user statistics
func (*WebsocketClient) UnregisterPendingRequest ¶
func (c *WebsocketClient) UnregisterPendingRequest(id string)
UnregisterPendingRequest removes a pending request
func (*WebsocketClient) Unsubscribe ¶
func (c *WebsocketClient) Unsubscribe(channel string) error
func (*WebsocketClient) UnsubscribeOrderBook ¶
func (c *WebsocketClient) UnsubscribeOrderBook(marketId int) error
func (*WebsocketClient) UnsubscribeTrades ¶
func (c *WebsocketClient) UnsubscribeTrades(marketId int) error
type WithdrawHistoryResponse ¶
type WithdrawalDelayResponse ¶
type WsAccountAllEvent ¶
type WsAccountAllEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Account int64 `json:"account"`
DailyTradesCount int64 `json:"daily_trades_count"`
DailyVolume float64 `json:"daily_volume"`
WeeklyTradesCount int64 `json:"weekly_trades_count"`
WeeklyVolume float64 `json:"weekly_volume"`
MonthlyTradesCount int64 `json:"monthly_trades_count"`
MonthlyVolume float64 `json:"monthly_volume"`
TotalTradesCount int64 `json:"total_trades_count"`
TotalVolume float64 `json:"total_volume"`
FundingHistories map[string][]FundingHistory `json:"funding_histories"`
Positions map[string]*Position `json:"positions"`
Trades map[string][]Trade `json:"trades"`
}
WsAccountAllEvent represents all account data
type WsAccountAllOrdersEvent ¶
type WsAccountAllOrdersEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Orders map[string][]*Order `json:"orders"`
}
WsAccountAllOrdersEvent represents all account orders
type WsAccountAllPositionsEvent ¶
type WsAccountAllPositionsEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Positions map[string]*Position `json:"positions"`
}
WsAccountAllPositionsEvent represents all account positions
type WsAccountAllTradesEvent ¶
type WsAccountAllTradesEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Trades map[string][]Trade `json:"trades"`
}
WsAccountAllTradesEvent represents all account trades
type WsAccountMarketEvent ¶
type WsAccountMarketEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Account int64 `json:"account"`
Position *Position `json:"position"`
Orders []*Order `json:"orders"`
Trades []Trade `json:"trades"`
}
WsAccountMarketEvent represents account data for a specific market
type WsAccountOrdersEvent ¶
type WsAccountOrdersEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Account int64 `json:"account"`
Nonce int64 `json:"nonce"`
Orders map[string][]*Order `json:"orders"`
}
WsAccountOrdersEvent represents account orders for a specific market
type WsAccountTxEvent ¶
type WsAccountTxEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Txs []Tx `json:"txs"`
}
WsAccountTxEvent represents account transaction updates
type WsHeightEvent ¶
type WsHeightEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Height int64 `json:"height"`
}
WsHeightEvent represents blockchain height updates
type WsMarketStatsEvent ¶
type WsMarketStatsEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
MarketStats struct {
MarketId uint8 `json:"market_id"`
IndexPrice string `json:"index_price"`
MarkPrice string `json:"mark_price"`
OpenInterest string `json:"open_interest"`
LastTradePrice string `json:"last_trade_price"`
CurrentFundingRate string `json:"current_funding_rate"`
FundingRate string `json:"funding_rate"`
FundingTimestamp int64 `json:"funding_timestamp"`
DailyBaseTokenVolume float64 `json:"daily_base_token_volume"`
DailyQuoteTokenVolume float64 `json:"daily_quote_token_volume"`
DailyPriceLow float64 `json:"daily_price_low"`
DailyPriceHigh float64 `json:"daily_price_high"`
DailyPriceChange float64 `json:"daily_price_change"`
} `json:"market_stats"`
}
WsMarketStatsEvent represents market statistics update
type WsNotificationEvent ¶
type WsNotificationEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Notifs []Notification `json:"notifs"`
}
WsNotificationEvent represents notification updates
type WsOrderBookEvent ¶
type WsOrderBookEvent struct {
Channel string `json:"channel"`
Offset int64 `json:"offset"`
Type string `json:"type"`
OrderBook struct {
Code int64 `json:"code"`
Asks []OrderBookLevel `json:"asks"`
Bids []OrderBookLevel `json:"bids"`
Offset int64 `json:"offset"`
Nonce int64 `json:"nonce"`
BeginNonce int64 `json:"begin_nonce"`
Timestamp int64 `json:"timestamp"`
} `json:"order_book"`
}
WsOrderBookEvent represents an order book update
type WsTradeEvent ¶
type WsTradeEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Trades []Trade `json:"trades"`
}
WsTradeEvent represents trade updates
type WsUserStatsEvent ¶
type WsUserStatsEvent struct {
Channel string `json:"channel"`
Type string `json:"type"`
Stats struct {
Collateral string `json:"collateral"`
PortfolioValue string `json:"portfolio_value"`
Leverage string `json:"leverage"`
AvailableBalance string `json:"available_balance"`
MarginUsage string `json:"margin_usage"`
BuyingPower string `json:"buying_power"`
CrossStats AccountStats `json:"cross_stats"`
TotalStats AccountStats `json:"total_stats"`
} `json:"stats"`
}
WsUserStatsEvent represents user statistics update