Documentation
¶
Index ¶
- Constants
- Variables
- func FloatToString(x float64) (string, error)
- func FloatToUsdInt(value float64) int
- func GetTimestampMs() int64
- func IsWalletDoesNotExistError(err error) bool
- type APIError
- type APIResponse
- type ActiveStakingDiscount
- type BatchModifyAction
- type Builder
- type CancelOrderAction
- type CancelOrderWire
- type Client
- func (c *Client) GetNextNonce() int64
- func (c *Client) GetUserFees(ctx context.Context) (*UserFees, error)
- func (c *Client) Post(ctx context.Context, path string, payload any) ([]byte, error)
- func (c *Client) PostAction(ctx context.Context, action any, sig SignatureResult, nonce int64) ([]byte, error)
- func (c *Client) WithAccount(accountAddr string) *Client
- func (c *Client) WithCredentials(privateKey string, vault *string) *Client
- type CreateOrderAction
- type DailyUserVlm
- type FeeSchedule
- type Grouping
- type MM
- type MixedArray
- type MixedValue
- func (mv *MixedValue) Array() ([]json.RawMessage, bool)
- func (mv MixedValue) MarshalJSON() ([]byte, error)
- func (mv *MixedValue) Object() (map[string]any, bool)
- func (mv *MixedValue) Parse(v any) error
- func (mv *MixedValue) String() (string, bool)
- func (mv *MixedValue) Type() string
- func (mv *MixedValue) UnmarshalJSON(data []byte) error
- type ModifyOrderAction
- type OrderStatusValue
- type OrderTypeWire
- type OrderTypeWireLimit
- type OrderTypeWireTrigger
- type OrderWire
- type PostResult
- type Side
- type SignatureResult
- func SignAgent(privateKey *ecdsa.PrivateKey, agentAddress, agentName string, nonce int64, ...) (SignatureResult, error)
- func SignApproveBuilderFee(privateKey *ecdsa.PrivateKey, builderAddress string, maxFeeRate float64, ...) (SignatureResult, error)
- func SignConvertToMultiSigUserAction(privateKey *ecdsa.PrivateKey, signers []string, threshold int, timestamp int64, ...) (SignatureResult, error)
- func SignL1Action(privateKey *ecdsa.PrivateKey, action any, vaultAddress string, timestamp int64, ...) (SignatureResult, error)
- func SignMultiSigAction(privateKey *ecdsa.PrivateKey, innerAction map[string]any, signers []string, ...) (SignatureResult, error)
- func SignPerpDexClassTransferAction(privateKey *ecdsa.PrivateKey, dex, token string, amount float64, toPerp bool, ...) (SignatureResult, error)
- func SignSpotTransferAction(privateKey *ecdsa.PrivateKey, amount float64, destination, token string, ...) (SignatureResult, error)
- func SignTokenDelegateAction(privateKey *ecdsa.PrivateKey, token string, amount float64, ...) (SignatureResult, error)
- func SignUsdClassTransferAction(privateKey *ecdsa.PrivateKey, amount float64, toPerp bool, timestamp int64, ...) (SignatureResult, error)
- func SignUsdTransferAction(privateKey *ecdsa.PrivateKey, amount float64, destination string, ...) (SignatureResult, error)
- func SignUserSignedAction(privateKey *ecdsa.PrivateKey, action map[string]any, ...) (SignatureResult, error)
- func SignWithdrawFromBridgeAction(privateKey *ecdsa.PrivateKey, destination string, amount, fee float64, ...) (SignatureResult, error)
- type StakingDiscountTier
- type StakingLink
- type Tiers
- type Tif
- type Tpsl
- type UpdateIsolatedMarginAction
- type UpdateLeverageAction
- type UsdClassTransferAction
- type UserFees
- type ValidationError
- type Vip
- type WebsocketClient
- func (c *WebsocketClient) Close()
- func (c *WebsocketClient) Connect() error
- func (c *WebsocketClient) GetNextNonce() int64
- func (c *WebsocketClient) PostAction(action any, sig SignatureResult, nonce int64) (chan PostResult, error)
- func (c *WebsocketClient) PostRequest(payload WsPostRequestPayload) (chan PostResult, error)
- func (c *WebsocketClient) SendCommand(cmd any) error
- func (c *WebsocketClient) Subscribe(channel string, subscription any, handler func(WsMessage)) error
- func (c *WebsocketClient) Unsubscribe(channel string, subscription any) error
- func (c *WebsocketClient) WithCredentials(privateKey string, vault *string) *WebsocketClient
- func (c *WebsocketClient) WithURL(u string) *WebsocketClient
- type WsAllMids
- type WsBbo
- type WsCandle
- type WsL2Book
- type WsLevel
- type WsLiquidation
- type WsMessage
- type WsNonUserCancel
- type WsOrder
- type WsOrderUpdate
- type WsPostRequest
- type WsPostRequestPayload
- type WsPostResponse
- type WsPostResponsePayload
- type WsSubscribeRequest
- type WsSubscriptionResponse
- type WsTrade
- type WsUserEvent
- type WsUserFill
- type WsUserFills
- type WsUserFunding
- type WsUserLiquidations
- type WsUserNonFundingLedgerUpdates
Constants ¶
const (
MainnetAPIURL = "https://api.hyperliquid.xyz"
)
Variables ¶
var ErrCredentialsRequired = fmt.Errorf("credentials required")
Functions ¶
func FloatToString ¶
func FloatToUsdInt ¶
FloatToUsdInt converts float to USD integer representation
func GetTimestampMs ¶
func GetTimestampMs() int64
GetTimestampMs returns current timestamp in milliseconds
func IsWalletDoesNotExistError ¶
IsWalletDoesNotExistError checks if the error is a "wallet does not exist" error from the API
Types ¶
type APIError ¶
type APIResponse ¶
type ActiveStakingDiscount ¶
type BatchModifyAction ¶
type BatchModifyAction struct {
Type string `json:"type" msgpack:"type"`
Modifies []ModifyOrderAction `json:"modifies" msgpack:"modifies"`
}
type CancelOrderAction ¶
type CancelOrderAction struct {
Type string `json:"type" msgpack:"type"`
Cancels []CancelOrderWire `json:"cancels" msgpack:"cancels"`
}
cancel order
type CancelOrderWire ¶
type Client ¶
type Client struct {
Logger *zap.SugaredLogger
Debug bool
BaseURL string
Http *http.Client
PrivateKey *ecdsa.PrivateKey
Vault string
AccountAddr string
LastNonce atomic.Int64
ExpiresAfter *int64
}
func (*Client) GetNextNonce ¶
func (*Client) PostAction ¶
func (*Client) WithAccount ¶
type CreateOrderAction ¶
type DailyUserVlm ¶
type FeeSchedule ¶
type FeeSchedule struct {
Cross string `json:"cross"`
Add string `json:"add"`
SpotCross string `json:"spotCross"`
SpotAdd string `json:"spotAdd"`
Tiers Tiers `json:"tiers"`
ReferralDiscount string `json:"referralDiscount"`
StakingDiscountTiers []StakingDiscountTier `json:"stakingDiscountTiers"`
UserCrossRate string `json:"userCrossRate"`
UserAddRate string `json:"userAddRate"`
UserSpotCrossRate string `json:"userSpotCrossRate"`
UserSpotAddRate string `json:"userSpotAddRate"`
ActiveReferralDiscount string `json:"activeReferralDiscount"`
FeeTrialReward string `json:"feeTrialReward"`
StakingLink StakingLink `json:"stakingLink"`
ActiveStakingDiscount ActiveStakingDiscount `json:"activeStakingDiscount"`
}
type MixedArray ¶
type MixedArray []MixedValue
func (MixedArray) FirstError ¶
func (ma MixedArray) FirstError() error
func (*MixedArray) UnmarshalJSON ¶
func (ma *MixedArray) UnmarshalJSON(data []byte) error
type MixedValue ¶
type MixedValue json.RawMessage
func (*MixedValue) Array ¶
func (mv *MixedValue) Array() ([]json.RawMessage, bool)
func (MixedValue) MarshalJSON ¶
func (mv MixedValue) MarshalJSON() ([]byte, error)
func (*MixedValue) Parse ¶
func (mv *MixedValue) Parse(v any) error
func (*MixedValue) String ¶
func (mv *MixedValue) String() (string, bool)
func (*MixedValue) Type ¶
func (mv *MixedValue) Type() string
func (*MixedValue) UnmarshalJSON ¶
func (mv *MixedValue) UnmarshalJSON(data []byte) error
type ModifyOrderAction ¶
type ModifyOrderAction struct {
Type string `json:"type,omitempty" msgpack:"type,omitempty"`
Oid any `json:"oid" msgpack:"oid"`
Order OrderWire `json:"order" msgpack:"order"`
}
modify order
type OrderStatusValue ¶ added in v0.1.4
type OrderStatusValue string
OrderStatusValue represents the status string returned by the Hyperliquid API. Used in both REST and WS order responses for perp and spot markets. See: https://hyperliquid.gitbook.io/hyperliquid-docs
const ( StatusOpen OrderStatusValue = "open" StatusFilled OrderStatusValue = "filled" StatusCanceled OrderStatusValue = "canceled" StatusTriggered OrderStatusValue = "triggered" StatusRejected OrderStatusValue = "rejected" StatusMarginCanceled OrderStatusValue = "marginCanceled" StatusVaultWithdrawalCanceled OrderStatusValue = "vaultWithdrawalCanceled" StatusOpenInterestCapCanceled OrderStatusValue = "openInterestCapCanceled" StatusSelfTradeCanceled OrderStatusValue = "selfTradeCanceled" StatusReduceOnlyCanceled OrderStatusValue = "reduceOnlyCanceled" StatusSiblingFilledCanceled OrderStatusValue = "siblingFilledCanceled" StatusDelistedCanceled OrderStatusValue = "delistedCanceled" StatusLiquidatedCanceled OrderStatusValue = "liquidatedCanceled" StatusScheduledCancel OrderStatusValue = "scheduledCancel" StatusTickRejected OrderStatusValue = "tickRejected" StatusMinTradeNtlRejected OrderStatusValue = "minTradeNtlRejected" )
type OrderTypeWire ¶
type OrderTypeWire struct {
Limit *OrderTypeWireLimit `json:"limit,omitempty" msgpack:"limit,omitempty"`
Trigger *OrderTypeWireTrigger `json:"trigger,omitempty" msgpack:"trigger,omitempty"`
}
type OrderTypeWireLimit ¶
type OrderTypeWireLimit struct {
Tif Tif `json:"tif" msgpack:"tif"`
}
type OrderTypeWireTrigger ¶
type OrderWire ¶
type OrderWire struct {
Asset int `json:"a" msgpack:"a"` // 1st
IsBuy bool `json:"b" msgpack:"b"` // 2nd
LimitPx string `json:"p" msgpack:"p"` // 3rd
Size string `json:"s" msgpack:"s"` // 4th
ReduceOnly bool `json:"r" msgpack:"r"` // 5th
OrderType OrderTypeWire `json:"t" msgpack:"t"` // 6th
Cloid *string `json:"c,omitempty" msgpack:"c,omitempty"` // 7th (optional)
}
create order
type PostResult ¶
type PostResult struct {
Response WsPostResponsePayload
Error error
}
type SignatureResult ¶
SignatureResult represents the structured signature result
func SignAgent ¶
func SignAgent( privateKey *ecdsa.PrivateKey, agentAddress, agentName string, nonce int64, isMainnet bool, ) (SignatureResult, error)
SignAgent signs agent approval action using EIP-712 direct signing
func SignApproveBuilderFee ¶
func SignApproveBuilderFee( privateKey *ecdsa.PrivateKey, builderAddress string, maxFeeRate float64, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignApproveBuilderFee signs approve builder fee action
func SignConvertToMultiSigUserAction ¶
func SignConvertToMultiSigUserAction( privateKey *ecdsa.PrivateKey, signers []string, threshold int, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignConvertToMultiSigUserAction signs convert to multi-sig user action
func SignL1Action ¶
func SignL1Action( privateKey *ecdsa.PrivateKey, action any, vaultAddress string, timestamp int64, expiresAfter *int64, isMainnet bool, ) (SignatureResult, error)
func SignMultiSigAction ¶
func SignMultiSigAction( privateKey *ecdsa.PrivateKey, innerAction map[string]any, signers []string, signatures []string, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignMultiSigAction signs multi-signature action
func SignPerpDexClassTransferAction ¶
func SignPerpDexClassTransferAction( privateKey *ecdsa.PrivateKey, dex, token string, amount float64, toPerp bool, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignPerpDexClassTransferAction signs perp dex class transfer action
func SignSpotTransferAction ¶
func SignSpotTransferAction( privateKey *ecdsa.PrivateKey, amount float64, destination, token string, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignSpotTransferAction signs spot transfer action
func SignTokenDelegateAction ¶
func SignTokenDelegateAction( privateKey *ecdsa.PrivateKey, token string, amount float64, validatorAddress string, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignTokenDelegateAction signs token delegate action
func SignUsdClassTransferAction ¶
func SignUsdClassTransferAction( privateKey *ecdsa.PrivateKey, amount float64, toPerp bool, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignUsdClassTransferAction signs USD class transfer action
func SignUsdTransferAction ¶
func SignUsdTransferAction( privateKey *ecdsa.PrivateKey, amount float64, destination string, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignUsdTransferAction signs USD transfer action
func SignUserSignedAction ¶
func SignUserSignedAction( privateKey *ecdsa.PrivateKey, action map[string]any, payloadTypes []apitypes.Type, primaryType string, isMainnet bool, ) (SignatureResult, error)
SignUserSignedAction signs actions that require direct EIP-712 signing (e.g., approveAgent, approveBuilderFee, convertToMultiSigUser)
IMPORTANT: The message will contain MORE fields than declared in payloadTypes to avoid the error "422 Failed to deserialize the JSON body" and "User or API Wallet 0x123... does not exist". This matches Python SDK behavior where the field order doesn't matter and extra fields (type, signatureChainId) are present in the message but ignored during EIP-712 hashing via hashStructLenient.
func SignWithdrawFromBridgeAction ¶
func SignWithdrawFromBridgeAction( privateKey *ecdsa.PrivateKey, destination string, amount, fee float64, timestamp int64, isMainnet bool, ) (SignatureResult, error)
SignWithdrawFromBridgeAction signs withdraw from bridge action
type StakingDiscountTier ¶
type StakingLink ¶
type UpdateIsolatedMarginAction ¶
type UpdateIsolatedMarginAction struct {
Type string `json:"type" msgpack:"type"`
Asset int `json:"asset" msgpack:"asset"`
IsBuy bool `json:"isBuy" msgpack:"isBuy"`
Ntli int `json:"ntli" msgpack:"ntli"`
}
update isolated margin
type UpdateLeverageAction ¶
type UpdateLeverageAction struct {
Type string `json:"type" msgpack:"type"`
Asset int `json:"asset" msgpack:"asset"`
IsCross bool `json:"isCross" msgpack:"isCross"`
Leverage int `json:"leverage" msgpack:"leverage"`
}
update leverage
type UsdClassTransferAction ¶
type UserFees ¶
type UserFees struct {
DailyUserVlm []DailyUserVlm `json:"dailyUserVlm"`
FeeSchedule FeeSchedule `json:"feeSchedule"`
}
type ValidationError ¶
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type WebsocketClient ¶
type WebsocketClient struct {
URL string
Conn *websocket.Conn
Mu sync.RWMutex
WriteMu sync.Mutex
ReconnectWait time.Duration
Debug bool
Logger *zap.SugaredLogger
PrivateKey *ecdsa.PrivateKey
Vault string
AccountAddr string
LastNonce atomic.Int64
NextPostID atomic.Int64
PostChannels map[int64]chan PostResult
PingInterval time.Duration
// contains filtered or unexported fields
}
func NewWebsocketClient ¶
func NewWebsocketClient(ctx context.Context) *WebsocketClient
func (*WebsocketClient) Close ¶
func (c *WebsocketClient) Close()
func (*WebsocketClient) Connect ¶
func (c *WebsocketClient) Connect() error
func (*WebsocketClient) GetNextNonce ¶
func (c *WebsocketClient) GetNextNonce() int64
func (*WebsocketClient) PostAction ¶
func (c *WebsocketClient) PostAction(action any, sig SignatureResult, nonce int64) (chan PostResult, error)
func (*WebsocketClient) PostRequest ¶
func (c *WebsocketClient) PostRequest(payload WsPostRequestPayload) (chan PostResult, error)
func (*WebsocketClient) SendCommand ¶
func (c *WebsocketClient) SendCommand(cmd any) error
SendCommand sends a raw JSON command
func (*WebsocketClient) Subscribe ¶
func (c *WebsocketClient) Subscribe(channel string, subscription any, handler func(WsMessage)) error
Subscribe registers a handler for a specific channel name and optionally sends a subscription request.
func (*WebsocketClient) Unsubscribe ¶
func (c *WebsocketClient) Unsubscribe(channel string, subscription any) error
Unsubscribe removes a handler and optionally sends unsubscribe command
func (*WebsocketClient) WithCredentials ¶
func (c *WebsocketClient) WithCredentials(privateKey string, vault *string) *WebsocketClient
func (*WebsocketClient) WithURL ¶
func (c *WebsocketClient) WithURL(u string) *WebsocketClient
type WsCandle ¶
type WsCandle struct {
T int64 `json:"t"` // Open time
TClose int64 `json:"T"` // Close time
S string `json:"s"` // Symbol/Coin
I string `json:"i"` // Interval
O string `json:"o"` // Open
C string `json:"c"` // Close
H string `json:"h"` // High
L string `json:"l"` // Low
V string `json:"v"` // Volume
N int64 `json:"n"` // Number of trades
}
type WsLiquidation ¶
type WsMessage ¶
type WsMessage struct {
Channel string `json:"channel"`
Data json.RawMessage `json:"data"`
}
type WsNonUserCancel ¶
type WsOrderUpdate ¶
type WsOrderUpdate struct {
Order WsOrder `json:"order"`
Status OrderStatusValue `json:"status"`
StatusTimestamp int64 `json:"statusTimestamp"`
}
type WsPostRequest ¶
type WsPostRequest struct {
Method string `json:"method"`
ID int64 `json:"id"`
Request WsPostRequestPayload `json:"request"`
}
type WsPostRequestPayload ¶
type WsPostResponse ¶
type WsPostResponse struct {
ID int64 `json:"id"`
Response WsPostResponsePayload `json:"response"`
}
type WsPostResponsePayload ¶
type WsPostResponsePayload struct {
Type string `json:"type"` // "info", "action", "error"
Payload json.RawMessage `json:"payload"`
}
type WsSubscribeRequest ¶
type WsSubscriptionResponse ¶
type WsSubscriptionResponse struct {
Method string `json:"method"`
Subscription json.RawMessage `json:"subscription"`
}
type WsUserEvent ¶
type WsUserEvent struct {
Fills []WsUserFill `json:"fills,omitempty"`
Funding *WsUserFunding `json:"funding,omitempty"`
Liquidation *WsLiquidation `json:"liquidation,omitempty"`
NonUserCancel []WsNonUserCancel `json:"nonUserCancel,omitempty"`
}
type WsUserFill ¶
type WsUserFill struct {
Coin string `json:"coin"`
Px string `json:"px"`
Sz string `json:"sz"`
Side string `json:"side"`
Time int64 `json:"time"`
StartPosition string `json:"startPosition"`
Dir string `json:"dir"`
ClosedPnl string `json:"closedPnl"`
Hash string `json:"hash"`
Oid int64 `json:"oid"`
Crossed bool `json:"crossed"`
Fee string `json:"fee"`
FeeToken string `json:"feeToken"`
Tid int64 `json:"tid"`
BuilderFee string `json:"builderFee,omitempty"`
Liquidation *WsLiquidation `json:"liquidation,omitempty"`
}
type WsUserFills ¶
type WsUserFills struct {
IsSnapshot bool `json:"isSnapshot,omitempty"`
User string `json:"user"`
Fills []WsUserFill `json:"fills"`
}