perp

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssetContext

type AssetContext struct {
	Funding      string   `json:"funding"` // Current funding rate (hourly)
	MarkPx       string   `json:"markPx"`  // Mark price
	OpenInterest string   `json:"openInterest"`
	PrevDayPx    string   `json:"prevDayPx"`
	DayNtlVlm    string   `json:"dayNtlVlm"` // Daily notional volume
	Premium      string   `json:"premium"`
	OraclePx     string   `json:"oraclePx"`
	MidPx        string   `json:"midPx"`
	ImpactPxs    []string `json:"impactPxs,omitempty"`
	DayBaseVlm   string   `json:"dayBaseVlm,omitempty"` // Daily base volume
}

type CancelOrderRequest

type CancelOrderRequest struct {
	AssetID int
	OrderID int64
}

type CancelOrderResponse

type CancelOrderResponse struct {
	Statuses hyperliquid.MixedArray `json:"statuses"`
}

type Candle

type Candle struct {
	T      int64  `json:"t"` // Open time
	TClose int64  `json:"T"` // Close time
	S      string `json:"s"` // Symbol
	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 CandleSnapshotRequest

type CandleSnapshotRequest struct {
	Coin      string `json:"coin"`
	Interval  string `json:"interval"`
	StartTime int64  `json:"startTime"`
	EndTime   int64  `json:"endTime"`
}

type Client

type Client struct {
	*hyperliquid.Client
}

func NewClient

func NewClient(base *hyperliquid.Client) *Client

func (*Client) AllMids

func (c *Client) AllMids(ctx context.Context) (map[string]string, error)

func (*Client) CancelOrder

func (c *Client) CancelOrder(ctx context.Context, req CancelOrderRequest) (*string, error)

func (*Client) CandleSnapshot

func (c *Client) CandleSnapshot(ctx context.Context, coin string, interval string, startTime, endTime int64) ([]Candle, error)

func (*Client) GetAllFundingRates

func (c *Client) GetAllFundingRates(ctx context.Context) (map[string]string, error)

GetAllFundingRates retrieves funding rates for all available coins. Returns a map where keys are coin names (e.g., "BTC", "ETH") and values are funding rates.

func (*Client) GetBalance

func (c *Client) GetBalance(ctx context.Context) (*PerpPosition, error)

GetBalance (Alias for GetPerpPosition)

func (*Client) GetFundingRate

func (c *Client) GetFundingRate(ctx context.Context, coin string) (*FundingRate, error)

GetFundingRate retrieves the current funding rate for a specific coin. It uses the metaAndAssetCtxs endpoint which provides real-time asset contexts including mark price, funding rate, open interest, etc.

func (*Client) GetPerpPosition

func (c *Client) GetPerpPosition(ctx context.Context) (*PerpPosition, error)

func (*Client) GetPrepMeta

func (c *Client) GetPrepMeta(ctx context.Context) (*PrepMeta, error)

func (*Client) L2Book

func (c *Client) L2Book(ctx context.Context, coin string) (*L2BookResponse, error)

func (*Client) ModifyOrder

func (c *Client) ModifyOrder(ctx context.Context, req ModifyOrderRequest) (*OrderStatus, error)

func (*Client) OrderStatus

func (c *Client) OrderStatus(ctx context.Context, user string, oid int64) (*OrderStatusInfo, error)

OrderStatus

func (*Client) PlaceOrder

func (c *Client) PlaceOrder(ctx context.Context, req PlaceOrderRequest) (*OrderStatus, error)

func (*Client) UpdateIsolatedMargin

func (c *Client) UpdateIsolatedMargin(ctx context.Context, req UpdateIsolatedMarginRequest) error

func (*Client) UpdateLeverage

func (c *Client) UpdateLeverage(ctx context.Context, req UpdateLeverageRequest) error

func (*Client) UserFills

func (c *Client) UserFills(ctx context.Context, user string) ([]UserFill, error)

func (*Client) UserOpenOrders

func (c *Client) UserOpenOrders(ctx context.Context, user string) ([]Order, error)

UserOpenOrders

type FundingRate

type FundingRate struct {
	Coin                 string `json:"coin"`
	FundingRate          string `json:"fundingRate"`          // Per-hour funding rate
	FundingIntervalHours int64  `json:"fundingIntervalHours"` // Always 1 for Hyperliquid
	FundingTime          int64  `json:"fundingTime"`          // Current hour start (calculated)
	NextFundingTime      int64  `json:"nextFundingTime"`      // Next hour start (calculated)
}

FundingRate - Simplified funding rate response

type L2BookResponse

type L2BookResponse struct {
	Coin   string      `json:"coin"`
	Levels [][]L2Level `json:"levels"`
	Time   int64       `json:"time"`
}

type L2Level

type L2Level struct {
	Px string `json:"px"`
	Sz string `json:"sz"`
	N  int    `json:"n"`
}

type MetaAndAssetCtxsResponse

type MetaAndAssetCtxsResponse []AssetContext

MetaAndAssetCtxs - Response for metaAndAssetCtxs endpoint

type ModifyOrderRequest

type ModifyOrderRequest struct {
	Oid   *int64
	Cloid *string
	Order PlaceOrderRequest
}

type ModifyOrderResponse

type ModifyOrderResponse struct {
	Statuses []OrderStatus `json:"statuses"`
}

type Order

type Order struct {
	Coin      string `json:"coin"`
	Side      string `json:"side"`
	LimitPx   string `json:"limitPx"`
	Sz        string `json:"sz"`
	Oid       int64  `json:"oid"`
	Timestamp int64  `json:"timestamp"`
	OrigSz    string `json:"origSz"`
}

type OrderFilled

type OrderFilled struct {
	TotalSz string `json:"totalSz"`
	AvgPx   string `json:"avgPx"`
	Oid     int    `json:"oid"`
}

type OrderResting

type OrderResting struct {
	Oid      int64   `json:"oid"`
	ClientID *string `json:"cloid"`
	Status   string  `json:"status"`
}

type OrderStatus

type OrderStatus struct {
	Resting *OrderResting `json:"resting,omitempty"`
	Filled  *OrderFilled  `json:"filled,omitempty"`
	Error   *string       `json:"error,omitempty"`
}

type OrderStatusInfo

type OrderStatusInfo struct {
	Coin         string `json:"coin"`
	Side         string `json:"side"`
	LimitPx      string `json:"limitPx"`
	Sz           string `json:"sz"`
	Oid          int64  `json:"oid"`
	Timestamp    int64  `json:"timestamp"`
	OrigSz       string `json:"origSz"`
	Status       string `json:"status"`
	FilledSz     string `json:"filledSz"`
	AvgPx        string `json:"avgPx"`
	CancelReason string `json:"cancelReason"`
}

type OrderStatusQueryResponse

type OrderStatusQueryResponse struct {
	OrderStatus OrderStatusInfo `json:"order"`
}

OrderStatusQueryResponse

type OrderType

type OrderType struct {
	Limit   *OrderTypeLimit
	Trigger *OrderTypeTrigger
}

type OrderTypeLimit

type OrderTypeLimit struct {
	Tif hyperliquid.Tif
}

type OrderTypeTrigger

type OrderTypeTrigger struct {
	IsMarket  bool
	TriggerPx float64
	Tpsl      hyperliquid.Tpsl
}

type PerpPosition

type PerpPosition struct {
	AssetPositions []struct {
		Position struct {
			Coin       string `json:"coin"`
			CumFunding struct {
				AllTime     string `json:"allTime"`
				SinceOpen   string `json:"sinceOpen"`
				SinceChange string `json:"sinceChange"`
			} `json:"cumFunding"`
			EntryPx  string `json:"entryPx"`
			Leverage struct {
				RawUsd string `json:"rawUsd"`
				Type   string `json:"type"`
				Value  int    `json:"value"`
			} `json:"leverage"`
			LiquidationPx  string `json:"liquidationPx"`
			MarginUsed     string `json:"marginUsed"`
			MaxLeverage    int    `json:"maxLeverage"`
			PositionValue  string `json:"positionValue"`
			ReturnOnEquity string `json:"returnOnEquity"`
			Szi            string `json:"szi"`
			UnrealizedPnl  string `json:"unrealizedPnl"`
		} `json:"position"`
		Type string `json:"type"`
	} `json:"assetPositions"`
	CrossMaintenanceMarginUsed string `json:"crossMaintenanceMarginUsed"`
	CrossMarginSummary         struct {
		AccountValue    string `json:"accountValue"`
		TotalMarginUsed string `json:"totalMarginUsed"`
		TotalNtlPos     string `json:"totalNtlPos"`
		TotalRawUsd     string `json:"totalRawUsd"`
	} `json:"crossMarginSummary"`
	MarginSummary struct {
		AccountValue    string `json:"accountValue"`
		TotalMarginUsed string `json:"totalMarginUsed"`
		TotalNtlPos     string `json:"totalNtlPos"`
		TotalRawUsd     string `json:"totalRawUsd"`
	} `json:"marginSummary"`
	Time         int64  `json:"time"`
	Withdrawable string `json:"withdrawable"`
}

PerpPosition

type PlaceOrderRequest

type PlaceOrderRequest struct {
	AssetID       int
	IsBuy         bool
	Price         float64
	Size          float64
	ReduceOnly    bool
	ClientOrderID *string
	OrderType     OrderType
}

type PlaceOrderResponse

type PlaceOrderResponse struct {
	Statuses []OrderStatus `json:"statuses"`
}

type PrepMeta

type PrepMeta struct {
	Universe []struct {
		Name        string `json:"name"`
		SzDecimals  int    `json:"szDecimals"`
		MaxLeverage int    `json:"maxLeverage"`
	} `json:"universe"`
}

PrepMeta

type UpdateIsolatedMarginRequest

type UpdateIsolatedMarginRequest struct {
	AssetID int
	IsBuy   bool
	Amount  float64
}

UpdateIsolatedMargin

type UpdateIsolatedMarginResponse

type UpdateIsolatedMarginResponse struct {
	Type string `json:"type"`
}

type UpdateLeverageRequest

type UpdateLeverageRequest struct {
	AssetID  int
	IsCross  bool
	Leverage int
}

UpdateLeverage

type UpdateLeverageResponse

type UpdateLeverageResponse struct {
	Type string `json:"type"`
}

type UserFill

type UserFill 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"`
}

type WebsocketClient

type WebsocketClient struct {
	*hyperliquid.WebsocketClient
}

func NewWebsocketClient

func NewWebsocketClient(base *hyperliquid.WebsocketClient) *WebsocketClient

func (*WebsocketClient) CancelOrder

func (c *WebsocketClient) CancelOrder(ctx context.Context, req CancelOrderRequest) (chan hyperliquid.PostResult, error)

CancelOrder via WS

func (*WebsocketClient) ModifyOrder

func (c *WebsocketClient) ModifyOrder(ctx context.Context, req ModifyOrderRequest) (chan hyperliquid.PostResult, error)

ModifyOrder via WS

func (*WebsocketClient) PlaceOrder

func (c *WebsocketClient) PlaceOrder(ctx context.Context, req PlaceOrderRequest) (chan hyperliquid.PostResult, error)

PlaceOrder via WS

func (*WebsocketClient) SubscribeBbo

func (c *WebsocketClient) SubscribeBbo(coin string, handler func(hyperliquid.WsBbo)) error

func (*WebsocketClient) SubscribeL2Book

func (c *WebsocketClient) SubscribeL2Book(coin string, handler func(hyperliquid.WsL2Book)) error

Helper to subscribe to L2Book Notice: Snapshot update

func (*WebsocketClient) SubscribeOrderUpdates

func (c *WebsocketClient) SubscribeOrderUpdates(user string, handler func([]hyperliquid.WsOrderUpdate)) error

SubscribeOrderUpdates

func (*WebsocketClient) SubscribeTrades

func (c *WebsocketClient) SubscribeTrades(coin string, handler func([]hyperliquid.WsTrade)) error

SubscribeTrades

func (*WebsocketClient) SubscribeUserEvents

func (c *WebsocketClient) SubscribeUserEvents(user string, handler func(hyperliquid.WsUserEvent)) error

SubscribeUserEvents

func (*WebsocketClient) SubscribeUserFills

func (c *WebsocketClient) SubscribeUserFills(user string, handler func(hyperliquid.WsUserFills)) error

SubscribeUserFills

func (*WebsocketClient) SubscribeWebData2

func (c *WebsocketClient) SubscribeWebData2(user string, handler func(PerpPosition)) error

SubscribeWebData2

func (*WebsocketClient) UnsubscribeBbo

func (c *WebsocketClient) UnsubscribeBbo(coin string) error

func (*WebsocketClient) UnsubscribeL2Book

func (c *WebsocketClient) UnsubscribeL2Book(coin string) error

func (*WebsocketClient) UnsubscribeTrades

func (c *WebsocketClient) UnsubscribeTrades(coin string) error

func (*WebsocketClient) WithCredentials

func (c *WebsocketClient) WithCredentials(privateKey, accountAddr string) *WebsocketClient

Jump to

Keyboard shortcuts

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