Documentation
¶
Index ¶
- Constants
- Variables
- func ArrayAppend(data []byte, toAppend []byte) []byte
- func CalculateSlippage(isBuy bool, px float64, slippage float64) float64
- func CompatibleMarshal(v interface{}) ([]byte, error)
- func CompatibleUnmarshal(data []byte, v interface{}) error
- func FastMarshal(v interface{}) ([]byte, error)
- func FastMarshalToString(v interface{}) (string, error)
- func FastUnmarshal(data []byte, v interface{}) error
- func FastUnmarshalFromString(str string, v interface{}) error
- func FloatToWire(x float64, maxDecimals int, szDecimals int) string
- func GetDefaultTimeRange() (int64, int64)
- func GetNonce() uint64
- func GetRandomCloid() string
- func GetSlippage(sl *float64) float64
- func HexToBytes(addr string) []byte
- func IsBuy(szi float64) bool
- func MakeUniversalRequest[T any](api IAPIService, request any) (*T, error)
- func PooledMarshal(v interface{}) ([]byte, error)
- func PooledUnmarshal(data []byte, v interface{}) error
- func PriceToWire(x float64, maxDecimals, szDecimals int) string
- func SignRequestToEIP712TypedData(request *SignRequest) apitypes.TypedData
- func SignatureToVRS(sig []byte) (byte, [32]byte, [32]byte, error)
- func SizeToWire(x float64, szDecimals int) string
- func StructToMap(strct any) (res map[string]interface{}, err error)
- type APIError
- type Asset
- type AssetInfo
- type AssetPosition
- type CancelCloidOrderAction
- type CancelCloidWire
- type CancelOidOrderAction
- type CancelOidWire
- type CancelRequest
- type CandleSnapshot
- type CandleSnapshotRequest
- type CandleSnapshotSubRequest
- type Client
- func (client *Client) AccountAddress() string
- func (client *Client) IsMainnet() bool
- func (client *Client) KeyManager() *PKeyManager
- func (client *Client) Request(endpoint string, payload any) ([]byte, error)
- func (client *Client) SetAccountAddress(address string)
- func (client *Client) SetDebug(status bool)
- func (client *Client) SetPrivateKey(privateKey string) error
- func (client *Client) SetWebSocketAPI(wsAPI *WebSocketAPI)
- type CloseRequest
- type Context
- type DataResponse
- type DefaultExchangeResponse
- type Deposit
- type ExchangeAPI
- func (api *ExchangeAPI) BuildBulkOrdersEIP712(requests []OrderRequest, grouping Grouping) (apitypes.TypedData, error)
- func (api *ExchangeAPI) BuildEIP712Message(action any, timestamp uint64) (*SignRequest, error)
- func (api *ExchangeAPI) BuildOrderEIP712(request OrderRequest, grouping Grouping) (apitypes.TypedData, error)
- func (api *ExchangeAPI) BulkCancelOrders(cancels []CancelOidWire) (*OrderResponse, error)
- func (api *ExchangeAPI) BulkModifyOrders(modifyRequests []ModifyOrderRequest, isSpot bool) (*OrderResponse, error)
- func (api *ExchangeAPI) BulkOrders(requests []OrderRequest, grouping Grouping, isSpot bool) (*OrderResponse, error)
- func (api *ExchangeAPI) CancelAllOrders() (*OrderResponse, error)
- func (api *ExchangeAPI) CancelAllOrdersByCoin(coin string) (*OrderResponse, error)
- func (api *ExchangeAPI) CancelOrderByCloid(coin string, clientOID string) (*OrderResponse, error)
- func (api *ExchangeAPI) CancelOrderByOID(coin string, orderID int64) (*OrderResponse, error)
- func (api *ExchangeAPI) ClosePosition(coin string) (*OrderResponse, error)
- func (api *ExchangeAPI) Endpoint() string
- func (api *ExchangeAPI) LimitOrder(orderType string, coin string, size float64, px float64, reduceOnly bool, ...) (*OrderResponse, error)
- func (api *ExchangeAPI) MarketOrder(coin string, size float64, slippage *float64, clientOID ...string) (*OrderResponse, error)
- func (api *ExchangeAPI) MarketOrderSpot(coin string, size float64, slippage *float64) (*OrderResponse, error)
- func (api *ExchangeAPI) Order(request OrderRequest, grouping Grouping) (*OrderResponse, error)
- func (api *ExchangeAPI) OrderSpot(request OrderRequest, grouping Grouping) (*OrderResponse, error)
- func (api *ExchangeAPI) SetWebSocketAPI(wsAPI *WebSocketAPI)
- func (api *ExchangeAPI) Sign(request *SignRequest) (byte, [32]byte, [32]byte, error)
- func (api *ExchangeAPI) SignL1Action(action any, timestamp uint64) (byte, [32]byte, [32]byte, error)
- func (api *ExchangeAPI) SignUserSignableAction(action any, payloadTypes []apitypes.Type, primaryType string) (byte, [32]byte, [32]byte, error)
- func (api *ExchangeAPI) SignWithdrawAction(action WithdrawAction) (byte, [32]byte, [32]byte, error)
- func (api *ExchangeAPI) SlippagePrice(coin string, isBuy bool, slippage float64) float64
- func (api *ExchangeAPI) SlippagePriceSpot(coin string, isBuy bool, slippage float64) float64
- func (api *ExchangeAPI) UpdateLeverage(coin string, isCross bool, leverage int) (*DefaultExchangeResponse, error)
- func (api *ExchangeAPI) Withdraw(destination string, amount float64) (*WithdrawResponse, error)
- type ExchangeRequest
- type FilledStatus
- type FundingDelta
- type FundingUpdate
- type Grouping
- type HistoricalFundingRate
- type Hyperliquid
- type HyperliquidClientConfig
- type IAPIService
- type IClient
- type IExchangeAPI
- type IHyperliquid
- type IInfoAPI
- type IWebSocketAPI
- type InfoAPI
- func (api *InfoAPI) BuildMetaMap() (map[string]AssetInfo, error)
- func (api *InfoAPI) BuildSpotMetaMap() (map[string]AssetInfo, error)
- func (api *InfoAPI) Endpoint() string
- func (api *InfoAPI) GetAccountDeposits() (*[]Deposit, error)
- func (api *InfoAPI) GetAccountFills() (*[]OrderFill, error)
- func (api *InfoAPI) GetAccountFundingUpdates(startTime int64, endTime int64) (*[]FundingUpdate, error)
- func (api *InfoAPI) GetAccountNonFundingUpdates(startTime int64, endTime int64) (*[]NonFundingUpdate, error)
- func (api *InfoAPI) GetAccountOpenOrders() (*[]Order, error)
- func (api *InfoAPI) GetAccountRateLimits() (*RatesLimits, error)
- func (api *InfoAPI) GetAccountState() (*UserState, error)
- func (api *InfoAPI) GetAccountStateSpot() (*UserStateSpot, error)
- func (api *InfoAPI) GetAccountWithdrawals() (*[]Withdrawal, error)
- func (api *InfoAPI) GetAllMids() (*map[string]string, error)
- func (api *InfoAPI) GetAllSpotPrices() (*map[string]string, error)
- func (api *InfoAPI) GetCandleSnapshot(coin string, interval string, startTime int64, endTime int64) (*[]CandleSnapshot, error)
- func (api *InfoAPI) GetDeposits(address string) (*[]Deposit, error)
- func (api *InfoAPI) GetFundingUpdates(address string, startTime int64, endTime int64) (*[]FundingUpdate, error)
- func (api *InfoAPI) GetHistoricalFundingRates(coin string, startTime int64, endTime int64) (*[]HistoricalFundingRate, error)
- func (api *InfoAPI) GetL2BookSnapshot(coin string) (*L2BookSnapshot, error)
- func (api *InfoAPI) GetMartketPx(coin string) (float64, error)
- func (api *InfoAPI) GetMeta() (*Meta, error)
- func (api *InfoAPI) GetNonFundingUpdates(address string, startTime int64, endTime int64) (*[]NonFundingUpdate, error)
- func (api *InfoAPI) GetOpenOrders(address string) (*[]Order, error)
- func (api *InfoAPI) GetSpotMarketPx(coin string) (float64, error)
- func (api *InfoAPI) GetSpotMeta() (*SpotMeta, error)
- func (api *InfoAPI) GetUserFills(address string) (*[]OrderFill, error)
- func (api *InfoAPI) GetUserRateLimits(address string) (*RatesLimits, error)
- func (api *InfoAPI) GetUserState(address string) (*UserState, error)
- func (api *InfoAPI) GetUserStateSpot(address string) (*UserStateSpot, error)
- func (api *InfoAPI) GetWithdrawals(address string) (*[]Withdrawal, error)
- func (api *InfoAPI) SetWebSocketAPI(wsAPI *WebSocketAPI)
- type InfoRequest
- type L2BookSnapshot
- type Leverage
- type LimitOrderType
- type Liquidation
- type MarginSummary
- type Market
- type Message
- type Meta
- type ModifyOrderAction
- type ModifyOrderRequest
- type ModifyOrderWire
- type ModifyResponse
- type NonFundingDelta
- type NonFundingUpdate
- type Order
- type OrderFill
- type OrderInnerResponse
- type OrderRequest
- type OrderResponse
- type OrderType
- type OrderTypeWire
- type OrderWire
- type PKeyManager
- type PlaceOrderAction
- type Position
- type PostResponseHandler
- type PreMarshaledMessage
- type RatesLimits
- type RestingStatus
- type RsvSignature
- type SignRequest
- type Signer
- type SpotAssetPosition
- type SpotMeta
- type SpotMetaAndAssetCtxsResponse
- type StatusResponse
- type Subscription
- type SubscriptionHandler
- type SubscriptionType
- type TpSl
- type TriggerOrderType
- type UpdateLeverageAction
- type UserState
- type UserStateRequest
- type UserStateSpot
- type WSPostData
- type WSPostRequest
- type WSPostResponse
- type WSPostResponseBody
- type WSPostResponseData
- type WSResponse
- type WSSubscription
- type WebSocketAPI
- func (ws *WebSocketAPI) Connect() error
- func (ws *WebSocketAPI) Disconnect() error
- func (ws *WebSocketAPI) DisconnectForTesting() error
- func (ws *WebSocketAPI) IsConnected() bool
- func (ws *WebSocketAPI) PostActionRequest(payload interface{}) (*WSPostResponseData, error)
- func (ws *WebSocketAPI) PostInfoRequest(payload interface{}) (*WSPostResponseData, error)
- func (ws *WebSocketAPI) PostOrderRequest(action interface{}, nonce uint64, signature RsvSignature, vaultAddress *string) (*WSPostResponseData, error)
- func (ws *WebSocketAPI) PostRequest(requestType string, payload interface{}) (*WSPostResponseData, error)
- func (ws *WebSocketAPI) SetDebug(status bool)
- func (ws *WebSocketAPI) SubscribeActiveAssetCtx(coin string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeActiveAssetData(user string, coin string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeAllMids(handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeBbo(coin string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeCandle(coin string, interval string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeNotification(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeOrderUpdates(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeOrderbook(coin string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeTrades(coin string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeUserEvents(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeUserFills(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeUserFundings(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeUserNonFundingLedgerUpdates(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeUserTwapHistory(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeUserTwapSliceFills(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) SubscribeWebData2(user string, handler SubscriptionHandler) error
- func (ws *WebSocketAPI) UnsubscribeActiveAssetCtx(coin string) error
- func (ws *WebSocketAPI) UnsubscribeActiveAssetData(user string, coin string) error
- func (ws *WebSocketAPI) UnsubscribeAllMids() error
- func (ws *WebSocketAPI) UnsubscribeBbo(coin string) error
- func (ws *WebSocketAPI) UnsubscribeCandle(coin string, interval string) error
- func (ws *WebSocketAPI) UnsubscribeNotification(user string) error
- func (ws *WebSocketAPI) UnsubscribeOrderUpdates(user string) error
- func (ws *WebSocketAPI) UnsubscribeOrderbook(coin string) error
- func (ws *WebSocketAPI) UnsubscribeTrades(coin string) error
- func (ws *WebSocketAPI) UnsubscribeUserEvents(user string) error
- func (ws *WebSocketAPI) UnsubscribeUserFills(user string) error
- func (ws *WebSocketAPI) UnsubscribeUserFundings(user string) error
- func (ws *WebSocketAPI) UnsubscribeUserNonFundingLedgerUpdates(user string) error
- func (ws *WebSocketAPI) UnsubscribeUserTwapHistory(user string) error
- func (ws *WebSocketAPI) UnsubscribeUserTwapSliceFills(user string) error
- func (ws *WebSocketAPI) UnsubscribeWebData2(user string) error
- type WithdrawAction
- type WithdrawResponse
- type Withdrawal
Constants ¶
const ( MAINNET_API_URL = "https://api.hyperliquid.xyz" TESTNET_API_URL = "https://api.hyperliquid-testnet.xyz" // WebSocket URLs MainnetWSURL = "wss://api.hyperliquid.xyz/ws" TestnetWSURL = "wss://api.hyperliquid-testnet.xyz/ws" )
API constants
const ( TifGtc string = "Gtc" TifIoc string = "Ioc" TifAlo string = "Alo" )
const ARBITRUM_CHAIN_ID = 42161
const ARBITRUM_TESTNET_CHAIN_ID = 421614
const DEFAULT_SLIPPAGE = 0.005 // 0.5% default slippage
Execution constants
const HYPERLIQUID_CHAIN_ID = 1337
Signing constants
const PERP_MAX_DECIMALS = 6 // Default decimals for perp
const SPOT_MAX_DECIMALS = 8 // Default decimals for spot
const VERIFYING_CONTRACT = "0x0000000000000000000000000000000000000000"
Variables ¶
var USDC_SZ_DECIMALS = 2 // Default decimals for usdc that is used for withdraw
Functions ¶
func ArrayAppend ¶
func CalculateSlippage ¶
Calculate the slippage of a trade
func CompatibleMarshal ¶
CompatibleMarshal uses standard library compatible marshaling Use this when you need exact compatibility with standard library
func CompatibleUnmarshal ¶
CompatibleUnmarshal uses standard library compatible unmarshaling
func FastMarshal ¶
FastMarshal marshals an object to JSON using the fastest configuration This is optimized for high-frequency trading scenarios
func FastMarshalToString ¶
FastMarshalToString marshals to string (useful for logging)
func FastUnmarshal ¶
FastUnmarshal unmarshals JSON to an object using the fastest configuration
func FastUnmarshalFromString ¶
FastUnmarshalFromString unmarshals from string
func FloatToWire ¶
Format the float with custom decimal places, default is 6 (perp), 8 (spot). https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/tick-and-lot-size
func GetDefaultTimeRange ¶
Returns default time range of 90 days Returns the start time and end time in milliseconds
func GetNonce ¶
func GetNonce() uint64
Hyperliquid uses timestamps in milliseconds for nonce GetNonce returns a unique nonce that is always at least the current time in milliseconds. It ensures thread-safe updates using atomic operations.
func GetSlippage ¶
Get the slippage of a trade Returns the default slippage if the slippage is nil
func HexToBytes ¶
func MakeUniversalRequest ¶
func MakeUniversalRequest[T any](api IAPIService, request any) (*T, error)
MakeUniversalRequest is a generic function that takes an IAPIService and a request and returns a pointer to the result and an error. It makes a request to the API Service and unmarshals the result into the result type T
func PooledMarshal ¶
PooledMarshal marshals using a pooled buffer and encoder for maximum efficiency This is the fastest method for repeated marshaling of similar objects
func PooledUnmarshal ¶
PooledUnmarshal unmarshals using a pooled decoder
func PriceToWire ¶
PriceToWire converts a price value to its string representation per Hyperliquid rules. It enforces:
- At most 5 significant figures,
- And no more than (maxDecimals - szDecimals) decimal places.
Integer prices are returned as is.
func SignRequestToEIP712TypedData ¶
func SignRequestToEIP712TypedData(request *SignRequest) apitypes.TypedData
func SizeToWire ¶
SizeToWire converts a size value to its string representation, rounding it to exactly szDecimals decimals. Integer sizes are returned without decimals.
func StructToMap ¶
To sign raw messages via EIP-712
Types ¶
type AssetPosition ¶
type CancelCloidOrderAction ¶
type CancelCloidOrderAction struct {
Type string `msgpack:"type" json:"type"`
Cancels []CancelCloidWire `msgpack:"cancels" json:"cancels"`
}
type CancelCloidWire ¶
type CancelOidOrderAction ¶
type CancelOidOrderAction struct {
Type string `msgpack:"type" json:"type"`
Cancels []CancelOidWire `msgpack:"cancels" json:"cancels"`
}
type CancelOidWire ¶
type CancelRequest ¶
type CandleSnapshot ¶
type CandleSnapshot struct {
CloseTime int64 `json:"t"`
OpenTime int64 `json:"T"`
Symbol string `json:"s"`
Interval string `json:"i"`
Open float64 `json:"o,string"`
Close float64 `json:"c,string"`
High float64 `json:"h,string"`
Low float64 `json:"l,string"`
Volume float64 `json:"v,string"`
N int `json:"n"`
}
type CandleSnapshotRequest ¶
type CandleSnapshotRequest struct {
Typez string `json:"type"`
Req CandleSnapshotSubRequest `json:"req"`
}
type Client ¶
type Client struct {
Debug bool // Debug mode
Logger *log.Logger // Logger for debug messages
// contains filtered or unexported fields
}
Client is the default implementation of the Client interface.
It contains the base URL of the HyperLiquid API, the HTTP client, the debug mode, the network type, the private key, and the logger. The debug method prints the debug messages.
func (*Client) AccountAddress ¶
Returns the public address connected to the API.
func (*Client) KeyManager ¶
func (client *Client) KeyManager() *PKeyManager
Returns the private key manager connected to the API.
func (*Client) Request ¶
Request sends a POST request to the HyperLiquid API. If WebSocket is connected, it will use WebSocket instead of HTTP.
func (*Client) SetAccountAddress ¶
Some methods need public address to gather info (from infoAPI). In case you use PKeyManager from API section https://app.hyperliquid.xyz/API Then you can use this method to set the address.
func (*Client) SetPrivateKey ¶
SetPrivateKey sets the private key for the client.
func (*Client) SetWebSocketAPI ¶
func (client *Client) SetWebSocketAPI(wsAPI *WebSocketAPI)
SetWebSocketAPI sets the WebSocket API reference for automatic fallback
type CloseRequest ¶
type Context ¶
type Context struct {
DayBaseVlm float64 `json:"dayBaseVlm,string"`
DayNtlVlm float64 `json:"dayNtlVlm,string"`
Funding float64 `json:"funding,string"`
ImpactPxs []string `json:"impactPxs"`
MarkPx float64 `json:"markPx,string"`
MidPx float64 `json:"midPx,string"`
OpenInterest float64 `json:"openInterest,string"`
OraclePx float64 `json:"oraclePx,string"`
Premium float64 `json:"premium,string"`
PrevDayPx float64 `json:"prevDayPx,string"`
}
type DataResponse ¶
type DataResponse struct {
Statuses []StatusResponse `json:"statuses"`
}
type DefaultExchangeResponse ¶
type ExchangeAPI ¶
type ExchangeAPI struct {
Client
// contains filtered or unexported fields
}
Implement the IExchangeAPI interface.
func NewExchangeAPI ¶
func NewExchangeAPI(isMainnet bool, accountAddress string, privateKey string) *ExchangeAPI
NewExchangeAPI creates a new default ExchangeAPI. The API automatically handles private key and account address setup.
func (*ExchangeAPI) BuildBulkOrdersEIP712 ¶
func (api *ExchangeAPI) BuildBulkOrdersEIP712(requests []OrderRequest, grouping Grouping) (apitypes.TypedData, error)
Build bulk orders EIP712 message
func (*ExchangeAPI) BuildEIP712Message ¶
func (api *ExchangeAPI) BuildEIP712Message(action any, timestamp uint64) (*SignRequest, error)
func (*ExchangeAPI) BuildOrderEIP712 ¶
func (api *ExchangeAPI) BuildOrderEIP712(request OrderRequest, grouping Grouping) (apitypes.TypedData, error)
Build order EIP712 message
func (*ExchangeAPI) BulkCancelOrders ¶
func (api *ExchangeAPI) BulkCancelOrders(cancels []CancelOidWire) (*OrderResponse, error)
Cancel order(s) https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s
func (*ExchangeAPI) BulkModifyOrders ¶
func (api *ExchangeAPI) BulkModifyOrders(modifyRequests []ModifyOrderRequest, isSpot bool) (*OrderResponse, error)
Bulk modify orders https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#modify-multiple-orders
func (*ExchangeAPI) BulkOrders ¶
func (api *ExchangeAPI) BulkOrders(requests []OrderRequest, grouping Grouping, isSpot bool) (*OrderResponse, error)
Place orders in bulk https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#place-an-order
func (*ExchangeAPI) CancelAllOrders ¶
func (api *ExchangeAPI) CancelAllOrders() (*OrderResponse, error)
Cancel all open orders
func (*ExchangeAPI) CancelAllOrdersByCoin ¶
func (api *ExchangeAPI) CancelAllOrdersByCoin(coin string) (*OrderResponse, error)
Cancel all orders for a given coin
func (*ExchangeAPI) CancelOrderByCloid ¶
func (api *ExchangeAPI) CancelOrderByCloid(coin string, clientOID string) (*OrderResponse, error)
Cancel exact order by Client Order Id https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#cancel-order-s-by-cloid
func (*ExchangeAPI) CancelOrderByOID ¶
func (api *ExchangeAPI) CancelOrderByOID(coin string, orderID int64) (*OrderResponse, error)
Cancel exact order by OID
func (*ExchangeAPI) ClosePosition ¶
func (api *ExchangeAPI) ClosePosition(coin string) (*OrderResponse, error)
Close all positions for a given coin. They are closing with a market order.
func (*ExchangeAPI) Endpoint ¶
func (api *ExchangeAPI) Endpoint() string
func (*ExchangeAPI) LimitOrder ¶
func (api *ExchangeAPI) LimitOrder(orderType string, coin string, size float64, px float64, reduceOnly bool, clientOID ...string) (*OrderResponse, error)
Open a limit order. Order type can be Gtc, Ioc, Alo. Size determines the amount of the coin to buy/sell. See the constants TifGtc, TifIoc, TifAlo.
func (*ExchangeAPI) MarketOrder ¶
func (api *ExchangeAPI) MarketOrder(coin string, size float64, slippage *float64, clientOID ...string) (*OrderResponse, error)
Open a market order. Limit order with TIF=IOC and px=market price * (1 +- slippage). Size determines the amount of the coin to buy/sell.
MarketOrder("BTC", 0.1, nil) // Buy 0.1 BTC
MarketOrder("BTC", -0.1, nil) // Sell 0.1 BTC
MarketOrder("BTC", 0.1, &slippage) // Buy 0.1 BTC with slippage
func (*ExchangeAPI) MarketOrderSpot ¶
func (api *ExchangeAPI) MarketOrderSpot(coin string, size float64, slippage *float64) (*OrderResponse, error)
MarketOrderSpot is a market order for a spot coin. It is used to buy/sell a spot coin. Limit order with TIF=IOC and px=market price * (1 +- slippage). Size determines the amount of the coin to buy/sell.
MarketOrderSpot("HYPE", 0.1, nil) // Buy 0.1 HYPE
MarketOrderSpot("HYPE", -0.1, nil) // Sell 0.1 HYPE
MarketOrderSpot("HYPE", 0.1, &slippage) // Buy 0.1 HYPE with slippage
func (*ExchangeAPI) Order ¶
func (api *ExchangeAPI) Order(request OrderRequest, grouping Grouping) (*OrderResponse, error)
Place single order
func (*ExchangeAPI) OrderSpot ¶
func (api *ExchangeAPI) OrderSpot(request OrderRequest, grouping Grouping) (*OrderResponse, error)
OrderSpot places a spot order
func (*ExchangeAPI) SetWebSocketAPI ¶
func (api *ExchangeAPI) SetWebSocketAPI(wsAPI *WebSocketAPI)
SetWebSocketAPI sets the WebSocket API reference for automatic fallback
func (*ExchangeAPI) Sign ¶
func (api *ExchangeAPI) Sign(request *SignRequest) (byte, [32]byte, [32]byte, error)
func (*ExchangeAPI) SignL1Action ¶
func (*ExchangeAPI) SignUserSignableAction ¶
func (*ExchangeAPI) SignWithdrawAction ¶
func (api *ExchangeAPI) SignWithdrawAction(action WithdrawAction) (byte, [32]byte, [32]byte, error)
func (*ExchangeAPI) SlippagePrice ¶
func (api *ExchangeAPI) SlippagePrice(coin string, isBuy bool, slippage float64) float64
Helper function to calculate the slippage price based on the market price.
func (*ExchangeAPI) SlippagePriceSpot ¶
func (api *ExchangeAPI) SlippagePriceSpot(coin string, isBuy bool, slippage float64) float64
SlippagePriceSpot is a helper function to calculate the slippage price for a spot coin.
func (*ExchangeAPI) UpdateLeverage ¶
func (api *ExchangeAPI) UpdateLeverage(coin string, isCross bool, leverage int) (*DefaultExchangeResponse, error)
Update leverage for a coin https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#update-leverage
func (*ExchangeAPI) Withdraw ¶
func (api *ExchangeAPI) Withdraw(destination string, amount float64) (*WithdrawResponse, error)
Initiate a withdraw request https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/exchange-endpoint#initiate-a-withdrawal-request
type ExchangeRequest ¶
type ExchangeRequest struct {
Action any `json:"action"`
Nonce uint64 `json:"nonce"`
Signature RsvSignature `json:"signature"`
VaultAddress *string `json:"vaultAddress,omitempty" msgpack:",omitempty"`
}
Base request for /exchange endpoint
type FilledStatus ¶
type FundingDelta ¶
type FundingUpdate ¶
type FundingUpdate struct {
Hash string `json:"hash"`
Time int64 `json:"time"`
Delta FundingDelta `json:"delta"`
}
type Grouping ¶
type Grouping string
const GroupingNa Grouping = "na"
const GroupingTpSl Grouping = "positionTpsl"
type HistoricalFundingRate ¶
type Hyperliquid ¶
type Hyperliquid struct {
*ExchangeAPI
*InfoAPI
*WebSocketAPI
}
Hyperliquid is the main struct that contains all APIs
func NewHyperliquid ¶
func NewHyperliquid(config *HyperliquidClientConfig) *Hyperliquid
func (*Hyperliquid) AccountAddress ¶
func (h *Hyperliquid) AccountAddress() string
AccountAddress returns the account address
func (*Hyperliquid) IsMainnet ¶
func (h *Hyperliquid) IsMainnet() bool
IsMainnet returns true if the client is connected to mainnet
type HyperliquidClientConfig ¶
HyperliquidClientConfig is a configuration struct for Hyperliquid API. PrivateKey can be empty if you only need to use the public endpoints. AccountAddress is the default account address for the API that can be changed with SetAccountAddress(). AccountAddress may be different from the address build from the private key due to Hyperliquid's account system.
type IAPIService ¶
type IAPIService interface {
Request(path string, payload any) ([]byte, error)
Endpoint() string
KeyManager() *PKeyManager
// contains filtered or unexported methods
}
IAPIService is an interface for making requests to the API Service.
It has a Request method that takes a path and a payload and returns a byte array and an error. It has a debug method that takes a format string and args and returns nothing. It has an Endpoint method that returns a string.
type IClient ¶
type IClient interface {
IAPIService
// SetPrivateKey(privateKey string) error
// SetAccountAddress(address string)
// AccountAddress() string
Debug(status bool)
IsMainnet() bool
}
IClient is the interface that wraps the basic Requst method.
Request method sends a POST request to the HyperLiquid API. IsMainnet method returns true if the client is connected to the mainnet. debug method enables debug mode. SetPrivateKey method sets the private key for the client.
type IExchangeAPI ¶
type IExchangeAPI interface {
// Open orders
BulkOrders(requests []OrderRequest, grouping Grouping) (*OrderResponse, error)
Order(request OrderRequest, grouping Grouping) (*OrderResponse, error)
MarketOrder(coin string, size float64, slippage *float64, clientOID ...string) (*OrderResponse, error)
LimitOrder(orderType string, coin string, size float64, px float64, isBuy bool, reduceOnly bool, clientOID ...string) (*OrderResponse, error)
// Order management
CancelOrderByOID(coin string, orderID int) (any, error)
CancelOrderByCloid(coin string, clientOID string) (any, error)
BulkCancelOrders(cancels []CancelOidWire) (any, error)
CancelAllOrdersByCoin(coin string) (any, error)
CancelAllOrders() (any, error)
ClosePosition(coin string) (*OrderResponse, error)
// Account management
Withdraw(destination string, amount float64) (*WithdrawResponse, error)
UpdateLeverage(coin string, isCross bool, leverage int) (any, error)
}
IExchangeAPI is an interface for the /exchange service.
type IHyperliquid ¶
type IHyperliquid interface {
IExchangeAPI
IInfoAPI
IWebSocketAPI
}
IHyperliquid is the main interface that embeds all other APIs
type IInfoAPI ¶
type IInfoAPI interface {
// INFO API ENDPOINTS
GetAllMids() (*map[string]string, error)
GetOpenOrders(address string) (*[]Order, error)
GetAccountOpenOrders() (*[]Order, error)
GetUserFills(address string) (*[]OrderFill, error)
GetAccountFills() (*[]OrderFill, error)
GetUserRateLimits(address string) (*float64, error)
GetL2BookSnapshot(coin string) (*L2BookSnapshot, error)
GetCandleSnapshot(coin string, interval string, startTime int64, endTime int64) (*CandleSnapshot, error)
// PERPETUALS INFO API ENDPOINTS
GetMeta() (*Meta, error)
GetUserState(address string) (*UserState, error)
GetAccountState() (*UserState, error)
GetFundingUpdates(address string, startTime int64, endTime int64) (*[]FundingUpdate, error)
GetAccountFundingUpdates(startTime int64, endTime int64) (*[]FundingUpdate, error)
GetNonFundingUpdates(address string, startTime int64, endTime int64) (*[]NonFundingUpdate, error)
GetAccountNonFundingUpdates(startTime int64, endTime int64) (*[]NonFundingUpdate, error)
GetHistoricalFundingRates() (*[]HistoricalFundingRate, error)
// Additional helper functions
GetMartketPx(coin string) (float64, error)
BuildMetaMap() (map[string]AssetInfo, error)
GetWithdrawals(address string) (*[]Withdrawal, error)
GetAccountWithdrawals() (*[]Withdrawal, error)
}
IInfoAPI is an interface for the /info service.
type IWebSocketAPI ¶
type IWebSocketAPI interface {
Connect() error
Disconnect() error
DisconnectForTesting() error // For testing reconnection
IsConnected() bool
SetDebug(status bool)
// Subscription methods
SubscribeOrderbook(coin string, handler SubscriptionHandler) error
SubscribeTrades(coin string, handler SubscriptionHandler) error
SubscribeUserFills(user string, handler SubscriptionHandler) error
SubscribeAllMids(handler SubscriptionHandler) error
SubscribeUserEvents(user string, handler SubscriptionHandler) error
SubscribeUserFundings(user string, handler SubscriptionHandler) error
SubscribeUserNonFundingLedgerUpdates(user string, handler SubscriptionHandler) error
SubscribeUserTwapSliceFills(user string, handler SubscriptionHandler) error
SubscribeUserTwapHistory(user string, handler SubscriptionHandler) error
SubscribeActiveAssetCtx(coin string, handler SubscriptionHandler) error
SubscribeActiveAssetData(user string, coin string, handler SubscriptionHandler) error
SubscribeBbo(coin string, handler SubscriptionHandler) error
SubscribeCandle(coin string, interval string, handler SubscriptionHandler) error
SubscribeOrderUpdates(user string, handler SubscriptionHandler) error
SubscribeNotification(user string, handler SubscriptionHandler) error
SubscribeWebData2(user string, handler SubscriptionHandler) error
// Unsubscribe methods
UnsubscribeOrderbook(coin string) error
UnsubscribeTrades(coin string) error
UnsubscribeUserFills(user string) error
UnsubscribeAllMids() error
UnsubscribeUserEvents(user string) error
UnsubscribeUserFundings(user string) error
UnsubscribeUserNonFundingLedgerUpdates(user string) error
UnsubscribeUserTwapSliceFills(user string) error
UnsubscribeUserTwapHistory(user string) error
UnsubscribeActiveAssetCtx(coin string) error
UnsubscribeActiveAssetData(user string, coin string) error
UnsubscribeBbo(coin string) error
UnsubscribeCandle(coin string, interval string) error
UnsubscribeOrderUpdates(user string) error
UnsubscribeNotification(user string) error
UnsubscribeWebData2(user string) error
// Post request methods
PostRequest(requestType string, payload interface{}) (*WSPostResponseData, error)
PostInfoRequest(payload interface{}) (*WSPostResponseData, error)
PostActionRequest(payload interface{}) (*WSPostResponseData, error)
PostOrderRequest(action interface{}, nonce uint64, signature RsvSignature, vaultAddress *string) (*WSPostResponseData, error)
}
IWebSocketAPI is the interface for WebSocket operations
type InfoAPI ¶
type InfoAPI struct {
Client
// contains filtered or unexported fields
}
func NewInfoAPI ¶
NewInfoAPI returns a new instance of the InfoAPI struct. It sets the base endpoint to "/info" and the client to the NewClient function. The isMainnet parameter is used to set the network type. The API automatically handles private key and account address setup.
func (*InfoAPI) BuildMetaMap ¶
Helper function to build a map of asset names to asset info It is used to get the assetId for a given asset name
func (*InfoAPI) BuildSpotMetaMap ¶
Helper function to build a map of asset names to asset info It is used to get the assetId for a given asset name
func (*InfoAPI) GetAccountDeposits ¶
Helper function to get the deposits of the account address The same as GetDeposits but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountFills ¶
Retrieve a account's fill history The same as GetUserFills but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountFundingUpdates ¶
func (api *InfoAPI) GetAccountFundingUpdates(startTime int64, endTime int64) (*[]FundingUpdate, error)
Retrieve account's funding history The same as GetFundingUpdates but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountNonFundingUpdates ¶
func (api *InfoAPI) GetAccountNonFundingUpdates(startTime int64, endTime int64) (*[]NonFundingUpdate, error)
Retrieve account's funding history or non-funding ledger updates The same as GetNonFundingUpdates but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountOpenOrders ¶
Retrieve a account's order history The same as GetOpenOrders but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountRateLimits ¶
func (api *InfoAPI) GetAccountRateLimits() (*RatesLimits, error)
Query account rate limits The same as GetUserRateLimits but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountState ¶
Retrieve account's perpetuals account summary The same as GetUserState but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountStateSpot ¶
func (api *InfoAPI) GetAccountStateSpot() (*UserStateSpot, error)
Retrieve account's spot account summary The same as GetUserStateSpot but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAccountWithdrawals ¶
func (api *InfoAPI) GetAccountWithdrawals() (*[]Withdrawal, error)
Helper function to get the withdrawals of the account address The same as GetWithdrawals but user is set to the account address Check AccountAddress() or SetAccountAddress() if there is a need to set the account address
func (*InfoAPI) GetAllMids ¶
Retrieve mids for all actively traded coins https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-mids-for-all-actively-traded-coins
func (*InfoAPI) GetAllSpotPrices ¶
Retrieve spot meta and asset contexts https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-spot-asset-contexts
func (*InfoAPI) GetCandleSnapshot ¶
func (api *InfoAPI) GetCandleSnapshot(coin string, interval string, startTime int64, endTime int64) (*[]CandleSnapshot, error)
Candle snapshot (Only the most recent 5000 candles are available) https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#candle-snapshot
func (*InfoAPI) GetDeposits ¶
Helper function to get the deposits of the given address By default returns last 90 days
func (*InfoAPI) GetFundingUpdates ¶
func (api *InfoAPI) GetFundingUpdates(address string, startTime int64, endTime int64) (*[]FundingUpdate, error)
Retrieve a user's funding history https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-a-users-funding-history-or-non-funding-ledger-updates
func (*InfoAPI) GetHistoricalFundingRates ¶
func (api *InfoAPI) GetHistoricalFundingRates(coin string, startTime int64, endTime int64) (*[]HistoricalFundingRate, error)
Retrieve historical funding rates https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-historical-funding-rates
func (*InfoAPI) GetL2BookSnapshot ¶
func (api *InfoAPI) GetL2BookSnapshot(coin string) (*L2BookSnapshot, error)
L2 Book snapshot https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#l2-book-snapshot
func (*InfoAPI) GetMartketPx ¶
Helper function to get the market price of a given coin The coin parameter is the name of the coin
Example:
api.GetMartketPx("BTC")
func (*InfoAPI) GetMeta ¶
Retrieve perpetuals metadata https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-perpetuals-metadata
func (*InfoAPI) GetNonFundingUpdates ¶
func (api *InfoAPI) GetNonFundingUpdates(address string, startTime int64, endTime int64) (*[]NonFundingUpdate, error)
Retrieve a user's funding history or non-funding ledger updates https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-a-users-funding-history-or-non-funding-ledger-updates
func (*InfoAPI) GetOpenOrders ¶
Retrieve a user's open orders https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-open-orders
func (*InfoAPI) GetSpotMarketPx ¶
GetSpotMarketPx returns the market price of a given spot coin The coin parameter is the name of the coin
Example:
api.GetSpotMarketPx("HYPE")
func (*InfoAPI) GetSpotMeta ¶
Retrieve spot metadata
func (*InfoAPI) GetUserFills ¶
Retrieve a user's fills https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#retrieve-a-users-fills
func (*InfoAPI) GetUserRateLimits ¶
func (api *InfoAPI) GetUserRateLimits(address string) (*RatesLimits, error)
Query user rate limits https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint#query-user-rate-limits
func (*InfoAPI) GetUserState ¶
Retrieve user's perpetuals account summary https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/perpetuals#retrieve-users-perpetuals-account-summary
func (*InfoAPI) GetUserStateSpot ¶
func (api *InfoAPI) GetUserStateSpot(address string) (*UserStateSpot, error)
Retrieve user's spot account summary https://hyperliquid.gitbook.io/hyperliquid-docs/for-developers/api/info-endpoint/spot#retrieve-a-users-token-balances
func (*InfoAPI) GetWithdrawals ¶
func (api *InfoAPI) GetWithdrawals(address string) (*[]Withdrawal, error)
Helper function to get the withdrawals of a given address By default returns last 90 days
func (*InfoAPI) SetWebSocketAPI ¶
func (api *InfoAPI) SetWebSocketAPI(wsAPI *WebSocketAPI)
SetWebSocketAPI sets the WebSocket API reference for automatic fallback
type InfoRequest ¶
type InfoRequest struct {
User string `json:"user,omitempty"`
Typez string `json:"type"`
Oid string `json:"oid,omitempty"`
Coin string `json:"coin,omitempty"`
StartTime int64 `json:"startTime,omitempty"`
EndTime int64 `json:"endTime,omitempty"`
}
Base request for /info
type L2BookSnapshot ¶
type LimitOrderType ¶
type LimitOrderType struct {
Tif string `json:"tif" msgpack:"tif"`
}
type Liquidation ¶
type MarginSummary ¶
type Market ¶
type Market struct {
PrevDayPx string `json:"prevDayPx,omitempty"`
DayNtlVlm string `json:"dayNtlVlm,omitempty"`
MarkPx string `json:"markPx,omitempty"`
MidPx string `json:"midPx,omitempty"`
CirculatingSupply string `json:"circulatingSupply,omitempty"`
Coin string `json:"coin,omitempty"`
TotalSupply string `json:"totalSupply,omitempty"`
DayBaseVlm string `json:"dayBaseVlm,omitempty"`
}
type ModifyOrderAction ¶
type ModifyOrderAction struct {
Type string `msgpack:"type" json:"type"`
Modifies []ModifyOrderWire `msgpack:"modifies" json:"modifies"`
}
type ModifyOrderRequest ¶
type ModifyOrderWire ¶
type ModifyOrderWire struct {
OrderId int `msgpack:"oid" json:"oid"`
Order OrderWire `msgpack:"order" json:"order"`
}
func ModifyOrderRequestToWire ¶
func ModifyOrderRequestToWire(req ModifyOrderRequest, meta map[string]AssetInfo, isSpot bool) ModifyOrderWire
type ModifyResponse ¶
type ModifyResponse struct {
Status string `json:"status"`
Response OrderInnerResponse `json:"response"`
}
type NonFundingDelta ¶
type NonFundingDelta struct {
Type string `json:"type"`
Usdc float64 `json:"usdc,string,omitempty"`
Amount float64 `json:"amount,string,omitempty"`
ToPerp bool `json:"toPerp,omitempty"`
Token string `json:"token,omitempty"`
Fee float64 `json:"fee,string,omitempty"`
Nonce int64 `json:"nonce"`
}
Depending on Type this struct can has different non-nil fields
type NonFundingUpdate ¶
type NonFundingUpdate struct {
Hash string `json:"hash"`
Time int64 `json:"time"`
Delta NonFundingDelta `json:"delta"`
}
type Order ¶
type Order struct {
Children []any `json:"children,omitempty"`
Cloid string `json:"cloid,omitempty"`
Coin string `json:"coin"`
IsPositionTpsl bool `json:"isPositionTpsl,omitempty"`
IsTrigger bool `json:"isTrigger,omitempty"`
LimitPx float64 `json:"limitPx,string,omitempty"`
Oid int64 `json:"oid"`
OrderType string `json:"orderType,omitempty"`
OrigSz float64 `json:"origSz,string,omitempty"`
ReduceOnly bool `json:"reduceOnly,omitempty"`
Side string `json:"side"`
Sz float64 `json:"sz,string,omitempty"`
Tif string `json:"tif,omitempty"`
Timestamp int64 `json:"timestamp"`
TriggerCondition string `json:"triggerCondition,omitempty"`
TriggerPx float64 `json:"triggerPx,string,omitempty"`
}
type OrderFill ¶
type OrderFill struct {
Cloid string `json:"cloid"`
ClosedPnl float64 `json:"closedPnl,string"`
Coin string `json:"coin"`
Crossed bool `json:"crossed"`
Dir string `json:"dir"`
Fee float64 `json:"fee,string"`
FeeToken string `json:"feeToken"`
Hash string `json:"hash"`
Oid int `json:"oid"`
Px float64 `json:"px,string"`
Side string `json:"side"`
StartPosition string `json:"startPosition"`
Sz float64 `json:"sz,string"`
Tid int64 `json:"tid"`
Time int64 `json:"time"`
Liquidation *Liquidation `json:"liquidation"`
}
type OrderInnerResponse ¶
type OrderInnerResponse struct {
Type string `json:"type"`
Data DataResponse `json:"data"`
}
type OrderRequest ¶
type OrderResponse ¶
type OrderResponse struct {
Status string `json:"status"`
Response OrderInnerResponse `json:"response"`
}
type OrderType ¶
type OrderType struct {
Limit *LimitOrderType `json:"limit,omitempty" msgpack:"limit,omitempty"`
Trigger *TriggerOrderType `json:"trigger,omitempty" msgpack:"trigger,omitempty"`
}
type OrderTypeWire ¶
type OrderTypeWire struct {
Limit *LimitOrderType `json:"limit,omitempty" msgpack:"limit,omitempty"`
Trigger *TriggerOrderType `json:"trigger,omitempty" msgpack:"trigger,omitempty"`
}
func OrderTypeToWire ¶
func OrderTypeToWire(orderType OrderType) OrderTypeWire
type OrderWire ¶
type OrderWire struct {
Asset int `msgpack:"a" json:"a"`
IsBuy bool `msgpack:"b" json:"b"`
LimitPx string `msgpack:"p" json:"p"`
SizePx string `msgpack:"s" json:"s"`
ReduceOnly bool `msgpack:"r" json:"r"`
OrderType OrderTypeWire `msgpack:"t" json:"t"`
Cloid string `msgpack:"c,omitempty" json:"c,omitempty"`
}
func OrderRequestToWire ¶
func OrderRequestToWire(req OrderRequest, meta map[string]AssetInfo, isSpot bool) OrderWire
type PKeyManager ¶
type PKeyManager struct {
PrivateKeyStr string
// contains filtered or unexported fields
}
func NewPKeyManager ¶
func NewPKeyManager(privateKey string) (*PKeyManager, error)
NewPKeyManager creates a new PKeyManager instance from a private key string
func (*PKeyManager) PrivateECDSA ¶
func (km *PKeyManager) PrivateECDSA() *ecdsa.PrivateKey
func (*PKeyManager) PublicAddress ¶
func (km *PKeyManager) PublicAddress() common.Address
func (*PKeyManager) PublicAddressHex ¶
func (km *PKeyManager) PublicAddressHex() string
func (*PKeyManager) PublicECDSA ¶
func (km *PKeyManager) PublicECDSA() *ecdsa.PublicKey
type PlaceOrderAction ¶
type PlaceOrderAction struct {
Type string `msgpack:"type" json:"type"`
Orders []OrderWire `msgpack:"orders" json:"orders"`
Grouping Grouping `msgpack:"grouping" json:"grouping"`
}
func OrderWiresToOrderAction ¶
func OrderWiresToOrderAction(orders []OrderWire, grouping Grouping) PlaceOrderAction
type Position ¶
type Position struct {
Coin string `json:"coin"`
EntryPx float64 `json:"entryPx,string"`
Leverage Leverage `json:"leverage"`
LiquidationPx float64 `json:"liquidationPx,string"`
MarginUsed float64 `json:"marginUsed,string"`
PositionValue float64 `json:"positionValue,string"`
ReturnOnEquity float64 `json:"returnOnEquity,string"`
Szi float64 `json:"szi,string"`
UnrealizedPnl float64 `json:"unrealizedPnl,string"`
MaxLeverage int `json:"maxLeverage"`
CumFunding struct {
AllTime float64 `json:"allTime,string"`
SinceOpne float64 `json:"sinceOpen,string"`
SinceChan float64 `json:"sinceChange,string"`
} `json:"cumFunding"`
}
type PostResponseHandler ¶
type PostResponseHandler func(response WSPostResponseData)
PostResponseHandler is a function type for handling post response data
type PreMarshaledMessage ¶
type PreMarshaledMessage struct {
// contains filtered or unexported fields
}
PreMarshaledMessage represents a pre-marshaled JSON message This is the fastest approach for static messages
func NewPreMarshaledMessage ¶
func NewPreMarshaledMessage(v interface{}) (*PreMarshaledMessage, error)
NewPreMarshaledMessage creates a pre-marshaled message
func (*PreMarshaledMessage) Bytes ¶
func (p *PreMarshaledMessage) Bytes() []byte
Bytes returns the marshaled bytes
func (*PreMarshaledMessage) String ¶
func (p *PreMarshaledMessage) String() string
String returns the marshaled string
type RatesLimits ¶
type RestingStatus ¶
type RsvSignature ¶
func ToTypedSig ¶
func ToTypedSig(r [32]byte, s [32]byte, v byte) RsvSignature
type SignRequest ¶
type SignRequest struct {
PrimaryType string
DType []apitypes.Type
DTypeMsg map[string]interface{}
IsMainNet bool
DomainName string
}
SignRequest is the implementation of EIP-712 typed data
func (*SignRequest) GetDomain ¶
func (request *SignRequest) GetDomain() apitypes.TypedDataDomain
func (*SignRequest) GetTypes ¶
func (request *SignRequest) GetTypes() apitypes.Types
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
func NewSigner ¶
func NewSigner(manager *PKeyManager) Signer
type SpotAssetPosition ¶
type SpotMeta ¶
type SpotMeta struct {
Universe []struct {
Tokens []int `json:"tokens"`
Name string `json:"name"`
Index int `json:"index"`
IsCanonical bool `json:"isCanonical"`
} `json:"universe"`
Tokens []struct {
Name string `json:"name"`
SzDecimals int `json:"szDecimals"`
WeiDecimals int `json:"weiDecimals"`
Index int `json:"index"`
TokenID string `json:"tokenId"`
IsCanonical bool `json:"isCanonical"`
EvmContract any `json:"evmContract"`
FullName any `json:"fullName"`
} `json:"tokens"`
}
type SpotMetaAndAssetCtxsResponse ¶
type SpotMetaAndAssetCtxsResponse [2]interface{} // Array of exactly 2 elements
type StatusResponse ¶
type StatusResponse struct {
Resting RestingStatus `json:"resting,omitempty"`
Filled FilledStatus `json:"filled,omitempty"`
Error string `json:"error,omitempty"`
Status string `json:"status,omitempty"`
}
func (*StatusResponse) UnmarshalJSON ¶
func (sr *StatusResponse) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling for StatusResponse. It first checks if the incoming JSON is a simple string. If so, it assigns the value to the Status field. Otherwise, it unmarshals the JSON into the struct normally.
type Subscription ¶
type Subscription struct {
Type SubscriptionType
Channel chan interface{}
Params map[string]string // Pre-split parameters
Handler SubscriptionHandler
User string // For user-specific subscriptions
Coin string // For coin-specific subscriptions
Interval string // For candle subscriptions
}
Subscription represents a subscription with optimized matching
type SubscriptionHandler ¶
type SubscriptionHandler func(data interface{})
SubscriptionHandler is a function type for handling subscription data
type SubscriptionType ¶
type SubscriptionType int
SubscriptionType represents the type of subscription
const ( SubTypeUserFills SubscriptionType = iota SubTypeL2Book SubTypeTrades SubTypeOrderUpdates SubTypeUserEvents SubTypeUserFundings SubTypeUserNonFundingLedgerUpdates SubTypeUserTwapSliceFills SubTypeUserTwapHistory SubTypeActiveAssetCtx SubTypeActiveAssetData SubTypeBbo SubTypeCandle SubTypeNotification SubTypeWebData2 SubTypeAllMids )
type TriggerOrderType ¶
type UpdateLeverageAction ¶
type UserState ¶
type UserState struct {
Withdrawable float64 `json:"withdrawable,string"`
CrossMaintenanceMarginUsed float64 `json:"crossMaintenanceMarginUsed,string"`
AssetPositions []AssetPosition `json:"assetPositions"`
CrossMarginSummary MarginSummary `json:"crossMarginSummary"`
MarginSummary MarginSummary `json:"marginSummary"`
Time int64 `json:"time"`
}
type UserStateRequest ¶
type UserStateSpot ¶
type UserStateSpot struct {
Balances []SpotAssetPosition `json:"balances"`
}
type WSPostData ¶
type WSPostData struct {
Type string `json:"type"`
Payload interface{} `json:"payload"`
}
WSPostData represents the data part of a post request
type WSPostRequest ¶
type WSPostRequest struct {
Method string `json:"method"`
ID int `json:"id"`
Request WSPostData `json:"request"`
}
WSPostRequest represents a WebSocket post request
type WSPostResponse ¶
type WSPostResponse struct {
Channel string `json:"channel"`
Data WSPostResponseData `json:"data"`
}
WSPostResponse represents a WebSocket post response
type WSPostResponseBody ¶
type WSPostResponseBody struct {
Type string `json:"type"`
Payload interface{} `json:"payload"`
}
WSPostResponseBody represents the response body of a post response
type WSPostResponseData ¶
type WSPostResponseData struct {
ID int `json:"id"`
Response WSPostResponseBody `json:"response"`
}
WSPostResponseData represents the data part of a post response
type WSResponse ¶
type WSResponse struct {
Channel string `json:"channel"`
Data interface{} `json:"data"`
}
WSResponse represents a WebSocket response
type WSSubscription ¶
type WSSubscription struct {
Method string `json:"method"`
Params interface{} `json:"params"`
}
WSSubscription represents a WebSocket subscription request
type WebSocketAPI ¶
type WebSocketAPI struct {
Debug bool
// contains filtered or unexported fields
}
func NewWebSocketAPI ¶
func NewWebSocketAPI(isMainnet bool) *WebSocketAPI
func (*WebSocketAPI) Connect ¶
func (ws *WebSocketAPI) Connect() error
Connect establishes a WebSocket connection
func (*WebSocketAPI) Disconnect ¶
func (ws *WebSocketAPI) Disconnect() error
Disconnect closes the WebSocket connection and prevents auto-reconnect
func (*WebSocketAPI) DisconnectForTesting ¶
func (ws *WebSocketAPI) DisconnectForTesting() error
DisconnectForTesting closes the connection without setting manualDisconnect flag This allows the automatic reconnection logic to work for testing purposes
func (*WebSocketAPI) IsConnected ¶
func (ws *WebSocketAPI) IsConnected() bool
IsConnected returns the connection status
func (*WebSocketAPI) PostActionRequest ¶
func (ws *WebSocketAPI) PostActionRequest(payload interface{}) (*WSPostResponseData, error)
PostActionRequest sends an action request through WebSocket
func (*WebSocketAPI) PostInfoRequest ¶
func (ws *WebSocketAPI) PostInfoRequest(payload interface{}) (*WSPostResponseData, error)
PostInfoRequest sends an info request through WebSocket
func (*WebSocketAPI) PostOrderRequest ¶
func (ws *WebSocketAPI) PostOrderRequest(action interface{}, nonce uint64, signature RsvSignature, vaultAddress *string) (*WSPostResponseData, error)
PostOrderRequest sends an order request through WebSocket
func (*WebSocketAPI) PostRequest ¶
func (ws *WebSocketAPI) PostRequest(requestType string, payload interface{}) (*WSPostResponseData, error)
PostRequest sends a post request through WebSocket and returns the response
func (*WebSocketAPI) SetDebug ¶
func (ws *WebSocketAPI) SetDebug(status bool)
SetDebugActive enables debug mode
func (*WebSocketAPI) SubscribeActiveAssetCtx ¶
func (ws *WebSocketAPI) SubscribeActiveAssetCtx(coin string, handler SubscriptionHandler) error
SubscribeActiveAssetCtx subscribes to active asset context for a specific coin
func (*WebSocketAPI) SubscribeActiveAssetData ¶
func (ws *WebSocketAPI) SubscribeActiveAssetData(user string, coin string, handler SubscriptionHandler) error
SubscribeActiveAssetData subscribes to active asset data for a specific user and coin
func (*WebSocketAPI) SubscribeAllMids ¶
func (ws *WebSocketAPI) SubscribeAllMids(handler SubscriptionHandler) error
SubscribeAllMids subscribes to all mid price updates
func (*WebSocketAPI) SubscribeBbo ¶
func (ws *WebSocketAPI) SubscribeBbo(coin string, handler SubscriptionHandler) error
SubscribeBbo subscribes to best bid/offer updates for a specific coin
func (*WebSocketAPI) SubscribeCandle ¶
func (ws *WebSocketAPI) SubscribeCandle(coin string, interval string, handler SubscriptionHandler) error
SubscribeCandle subscribes to candle updates for a specific coin and interval
func (*WebSocketAPI) SubscribeNotification ¶
func (ws *WebSocketAPI) SubscribeNotification(user string, handler SubscriptionHandler) error
SubscribeNotification subscribes to notifications for a specific user
func (*WebSocketAPI) SubscribeOrderUpdates ¶
func (ws *WebSocketAPI) SubscribeOrderUpdates(user string, handler SubscriptionHandler) error
SubscribeOrderUpdates subscribes to order updates for a specific user
func (*WebSocketAPI) SubscribeOrderbook ¶
func (ws *WebSocketAPI) SubscribeOrderbook(coin string, handler SubscriptionHandler) error
SubscribeOrderbook subscribes to orderbook updates for a specific coin
func (*WebSocketAPI) SubscribeTrades ¶
func (ws *WebSocketAPI) SubscribeTrades(coin string, handler SubscriptionHandler) error
SubscribeTrades subscribes to trade updates for a specific coin
func (*WebSocketAPI) SubscribeUserEvents ¶
func (ws *WebSocketAPI) SubscribeUserEvents(user string, handler SubscriptionHandler) error
SubscribeUserEvents subscribes to user events for a specific user
func (*WebSocketAPI) SubscribeUserFills ¶
func (ws *WebSocketAPI) SubscribeUserFills(user string, handler SubscriptionHandler) error
SubscribeUserFills subscribes to user fill updates
func (*WebSocketAPI) SubscribeUserFundings ¶
func (ws *WebSocketAPI) SubscribeUserFundings(user string, handler SubscriptionHandler) error
SubscribeUserFundings subscribes to user fundings for a specific user
func (*WebSocketAPI) SubscribeUserNonFundingLedgerUpdates ¶
func (ws *WebSocketAPI) SubscribeUserNonFundingLedgerUpdates(user string, handler SubscriptionHandler) error
SubscribeUserNonFundingLedgerUpdates subscribes to user non-funding ledger updates for a specific user
func (*WebSocketAPI) SubscribeUserTwapHistory ¶
func (ws *WebSocketAPI) SubscribeUserTwapHistory(user string, handler SubscriptionHandler) error
SubscribeUserTwapHistory subscribes to user TWAP history for a specific user
func (*WebSocketAPI) SubscribeUserTwapSliceFills ¶
func (ws *WebSocketAPI) SubscribeUserTwapSliceFills(user string, handler SubscriptionHandler) error
SubscribeUserTwapSliceFills subscribes to user TWAP slice fills for a specific user
func (*WebSocketAPI) SubscribeWebData2 ¶
func (ws *WebSocketAPI) SubscribeWebData2(user string, handler SubscriptionHandler) error
SubscribeWebData2 subscribes to web data for a specific user
func (*WebSocketAPI) UnsubscribeActiveAssetCtx ¶
func (ws *WebSocketAPI) UnsubscribeActiveAssetCtx(coin string) error
UnsubscribeActiveAssetCtx unsubscribes from active asset context
func (*WebSocketAPI) UnsubscribeActiveAssetData ¶
func (ws *WebSocketAPI) UnsubscribeActiveAssetData(user string, coin string) error
UnsubscribeActiveAssetData unsubscribes from active asset data
func (*WebSocketAPI) UnsubscribeAllMids ¶
func (ws *WebSocketAPI) UnsubscribeAllMids() error
UnsubscribeAllMids unsubscribes from all mids updates
func (*WebSocketAPI) UnsubscribeBbo ¶
func (ws *WebSocketAPI) UnsubscribeBbo(coin string) error
UnsubscribeBbo unsubscribes from best bid/offer updates
func (*WebSocketAPI) UnsubscribeCandle ¶
func (ws *WebSocketAPI) UnsubscribeCandle(coin string, interval string) error
UnsubscribeCandle unsubscribes from candle updates
func (*WebSocketAPI) UnsubscribeNotification ¶
func (ws *WebSocketAPI) UnsubscribeNotification(user string) error
UnsubscribeNotification unsubscribes from notifications
func (*WebSocketAPI) UnsubscribeOrderUpdates ¶
func (ws *WebSocketAPI) UnsubscribeOrderUpdates(user string) error
UnsubscribeOrderUpdates unsubscribes from order updates
func (*WebSocketAPI) UnsubscribeOrderbook ¶
func (ws *WebSocketAPI) UnsubscribeOrderbook(coin string) error
UnsubscribeOrderbook unsubscribes from orderbook updates for a specific coin
func (*WebSocketAPI) UnsubscribeTrades ¶
func (ws *WebSocketAPI) UnsubscribeTrades(coin string) error
UnsubscribeTrades unsubscribes from trade updates for a specific coin
func (*WebSocketAPI) UnsubscribeUserEvents ¶
func (ws *WebSocketAPI) UnsubscribeUserEvents(user string) error
UnsubscribeUserEvents unsubscribes from user events
func (*WebSocketAPI) UnsubscribeUserFills ¶
func (ws *WebSocketAPI) UnsubscribeUserFills(user string) error
UnsubscribeUserFills unsubscribes from user fill updates
func (*WebSocketAPI) UnsubscribeUserFundings ¶
func (ws *WebSocketAPI) UnsubscribeUserFundings(user string) error
UnsubscribeUserFundings unsubscribes from user fundings
func (*WebSocketAPI) UnsubscribeUserNonFundingLedgerUpdates ¶
func (ws *WebSocketAPI) UnsubscribeUserNonFundingLedgerUpdates(user string) error
UnsubscribeUserNonFundingLedgerUpdates unsubscribes from user non-funding ledger updates
func (*WebSocketAPI) UnsubscribeUserTwapHistory ¶
func (ws *WebSocketAPI) UnsubscribeUserTwapHistory(user string) error
UnsubscribeUserTwapHistory unsubscribes from user TWAP history
func (*WebSocketAPI) UnsubscribeUserTwapSliceFills ¶
func (ws *WebSocketAPI) UnsubscribeUserTwapSliceFills(user string) error
UnsubscribeUserTwapSliceFills unsubscribes from user TWAP slice fills
func (*WebSocketAPI) UnsubscribeWebData2 ¶
func (ws *WebSocketAPI) UnsubscribeWebData2(user string) error
UnsubscribeWebData2 unsubscribes from web data 2
type WithdrawAction ¶
type WithdrawAction struct {
Type string `msgpack:"type" json:"type"`
Destination string `msgpack:"destination" json:"destination"`
Amount string `msgpack:"amount" json:"amount"`
Time uint64 `msgpack:"time" json:"time"`
HyperliquidChain string `msgpack:"hyperliquidChain" json:"hyperliquidChain"`
SignatureChainID string `msgpack:"signatureChainId" json:"signatureChainId"`
}