hyperliquid

package module
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2025 License: MIT Imports: 31 Imported by: 14

README

go-hyperliquid

Go Reference Go Report Card CI Coverage Status Go Version

Unofficial Go client for the Hyperliquid exchange API. This implementation follows the same philosophy and patterns as the official Python SDK.

Installation

go get github.com/sonirico/go-hyperliquid

Features

This Go SDK provides full feature parity with the official Python SDK, including:

Trading Features
  • Order Management: Limit orders, market orders, trigger orders, order modifications
  • Position Management: Leverage updates, isolated margin, position closing
  • Bulk Operations: Bulk orders, bulk cancellations, bulk modifications
  • Advanced Trading: Market open/close with slippage protection, scheduled cancellations
  • Builder Support: Order routing through builders with fee structures
Account Management
  • Referral System: Set referral codes, track referral state
  • Sub-Accounts: Create and manage sub-accounts, transfer funds
  • Multi-Signature: Convert to multi-sig, execute multi-sig actions
  • Vault Operations: Vault deposits, withdrawals, and transfers
Asset Management
  • USD Transfers: Cross-chain USD transfers, spot transfers
  • Class Transfers: USD class transfers (perp ↔ spot), perp dex transfers
  • Bridge Operations: Withdraw from bridge with fee management
  • Token Delegation: Stake tokens with validators
  • Spot Trading: Full spot market support
Advanced Features
  • Agent Approval: Approve trading agents with permissions
  • Builder Fee Management: Approve and manage builder fees
  • Big Blocks: Enable/disable big block usage
Deployment Features (Advanced)
  • Spot Deployment: Token registration, genesis, freeze privileges
  • Perp Deployment: Asset registration, oracle management
  • Hyperliquidity: Register hyperliquidity assets
Consensus Layer (Validators)
  • Validator Operations: Register, unregister, profile management
  • Signer Operations: Jail/unjail self, inner actions
  • Consensus Actions: Full consensus layer interaction
WebSocket Features
  • Market Data: Real-time L2 book, trades, candles, mid prices
  • User Events: Order updates, fills, funding, ledger updates
  • Advanced Streams: BBO, active asset context, web data v2

Usage

package main

import (
    "context"
    "fmt"
    "log"
    
    "github.com/ethereum/go-ethereum/crypto"
    hyperliquid "github.com/sonirico/go-hyperliquid"
)

func main() {
    // Initialize client
    client := hyperliquid.NewClient(hyperliquid.MainnetAPIURL)
    
    // For trading, create an Exchange with your private key
    privateKey, _ := crypto.HexToECDSA("your-private-key")
    exchange := hyperliquid.NewExchange(
        privateKey,
        hyperliquid.MainnetAPIURL,
        nil,    // Meta will be fetched automatically
        "vault-address",
        "account-address",
        nil,    // SpotMeta will be fetched automatically
    )
    
    // Place a limit order
    order := hyperliquid.OrderRequest{
        Coin:    "BTC",
        IsBuy:   true,
        Size:    0.1,
        LimitPx: 40000.0,
        OrderType: hyperliquid.OrderType{
            Limit: &hyperliquid.LimitOrderType{
                Tif: "Gtc",
            },
        },
    }
    
    resp, err := exchange.Order(order, nil)
    if err != nil {
        log.Fatal(err)
    }
    
    // Subscribe to WebSocket updates
    ws := hyperliquid.NewWebsocketClient(hyperliquid.MainnetAPIURL)
    if err := ws.Connect(context.Background()); err != nil {
        log.Fatal(err)
    }
    defer ws.Close()
    
    // Subscribe to BTC trades
    _, err = ws.Subscribe(hyperliquid.Subscription{
        Type: "trades",
        Coin: "BTC",
    }, func(msg hyperliquid.WSMessage) {
        fmt.Printf("Trade: %+v\n", msg)
    })
}

Documentation

For detailed API documentation, please refer to:

Examples

Check the examples/ directory for more usage examples:

  • WebSocket subscriptions
  • Order management
  • Position handling
  • Market data retrieval

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Quick Start for Contributors
# Clone the repository
git clone https://github.com/sonirico/go-hyperliquid.git
cd go-hyperliquid

# Install dependencies and tools
make deps install-tools

# Run all checks
make ci-full

# Run tests (excluding examples)
make ci-test

Roadmap

✅ Completed Features
  • Complete WebSocket API implementation
  • REST API client
  • All trading operations (orders, positions, leverage)
  • Market data (L2 book, trades, candles, all mids)
  • User account management
  • Referral system implementation
  • Sub-account management
  • Vault operations
  • USD and spot transfers
  • Bridge operations
  • Agent approval system
  • Builder fee management
  • Multi-signature support
  • Token delegation/staking
  • Spot deployment features
  • Perp deployment features
  • Consensus layer (validator operations)
  • Full feature parity with Python SDK
🚀 Future Enhancements
  • Enhanced documentation with more examples
  • Performance optimizations
  • Additional testing and edge case coverage
  • Rate limiting and retry mechanisms
  • Monitoring and observability features
  • Order management
  • User account operations
  • Advanced order types
  • Historical data API
  • Rate limiting improvements
  • Connection pooling

License

MIT License

Copyright (c) 2025

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package hyperliquid provides a Go client library for the Hyperliquid exchange API. It includes support for both REST API and WebSocket connections, allowing users to access market data, manage orders, and handle user account operations.

Index

Constants

View Source
const (
	MainnetAPIURL = "https://api.hyperliquid.xyz"
	TestnetAPIURL = "https://api.hyperliquid-testnet.xyz"
	LocalAPIURL   = "http://localhost:3001"
)
View Source
const (
	TifAlo = "Alo" // Add Liquidity Only
	TifIoc = "Ioc" // Immediate or Cancel
	TifGtc = "Gtc" // Good Till Cancel
)

Order Time-in-Force constants

View Source
const (
	DefaultSlippage = 0.05 // 5%
)

Constants for default values

Variables

This section is empty.

Functions

func FloatToUsdInt added in v0.4.0

func FloatToUsdInt(value float64) int

Utility function to convert float to USD integer representation

func GetTimestampMs added in v0.4.0

func GetTimestampMs() int64

GetTimestampMs returns current timestamp in milliseconds

Types

type APIError

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"msg"`
	Data    any    `json:"data,omitempty"`
}

func (APIError) Error

func (e APIError) Error() string

type APIResponse added in v0.4.2

type APIResponse[T any] struct {
	Status string
	Data   T
	Type   string
	Err    string
	Ok     bool
}

func (*APIResponse[T]) UnmarshalJSON added in v0.4.2

func (r *APIResponse[T]) UnmarshalJSON(data []byte) error

type AgentApprovalResponse added in v0.4.1

type AgentApprovalResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type ApprovalResponse added in v0.4.1

type ApprovalResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type ApproveAgentAction added in v0.4.5

type ApproveAgentAction struct {
	Type         string  `json:"type"                msgpack:"type"`
	AgentAddress string  `json:"agentAddress"        msgpack:"agentAddress"`
	AgentName    *string `json:"agentName,omitempty" msgpack:"agentName,omitempty"`
	Nonce        int64   `json:"nonce"               msgpack:"nonce"`
}

ApproveAgentAction represents approve agent action

type ApproveBuilderFeeAction added in v0.4.5

type ApproveBuilderFeeAction struct {
	Type       string `json:"type"       msgpack:"type"`
	Builder    string `json:"builder"    msgpack:"builder"`
	MaxFeeRate string `json:"maxFeeRate" msgpack:"maxFeeRate"`
	Nonce      int64  `json:"nonce"      msgpack:"nonce"`
}

ApproveBuilderFeeAction represents approve builder fee action

type AssetInfo

type AssetInfo struct {
	Name       string `json:"name"`
	SzDecimals int    `json:"szDecimals"`
}

type AssetPosition

type AssetPosition struct {
	Position Position `json:"position"`
	Type     string   `json:"type"`
}

type BatchModifyAction added in v0.4.5

type BatchModifyAction struct {
	Type     string         `json:"type"     msgpack:"type"`
	Modifies []ModifyAction `json:"modifies" msgpack:"modifies"`
}

BatchModifyAction represents multiple order modifications

type BuilderInfo

type BuilderInfo struct {
	Builder string `json:"b"`
	Fee     int    `json:"f"`
}

type BulkCancelResponse added in v0.4.1

type BulkCancelResponse struct {
	Status string      `json:"status"`
	Data   []OpenOrder `json:"data,omitempty"`
	Error  string      `json:"error,omitempty"`
}

type BulkOrderResponse added in v0.4.1

type BulkOrderResponse struct {
	Status string        `json:"status"`
	Data   []OrderStatus `json:"data,omitempty"`
	Error  string        `json:"error,omitempty"`
}

type CancelAction added in v0.4.5

type CancelAction struct {
	Type    string            `json:"type"    msgpack:"type"`
	Cancels []CancelOrderWire `json:"cancels" msgpack:"cancels"`
}

CancelAction represents the cancel action

type CancelByCloidAction added in v0.4.5

type CancelByCloidAction struct {
	Type    string              `json:"type"    msgpack:"type"`
	Cancels []CancelByCloidWire `json:"cancels" msgpack:"cancels"`
}

CancelByCloidAction represents the cancel by cloid action

type CancelByCloidRequest added in v0.4.0

type CancelByCloidRequest struct {
	Coin  string `json:"coin"`
	Cloid string `json:"cloid"`
}

type CancelByCloidWire added in v0.4.5

type CancelByCloidWire struct {
	Asset   int    `json:"a"     msgpack:"a"`
	OrderID string `json:"cloid" msgpack:"cloid"`
}

CancelByCloidWire represents cancel by cloid item wire format

type CancelOrderRequest added in v0.4.3

type CancelOrderRequest struct {
	Coin    string
	OrderID int64
}

type CancelOrderRequestByCloid added in v0.4.3

type CancelOrderRequestByCloid struct {
	Coin  string
	Cloid string
}

type CancelOrderResponse added in v0.4.2

type CancelOrderResponse struct {
	Statuses MixedArray
}

type CancelOrderWire added in v0.4.5

type CancelOrderWire struct {
	Asset   int    `json:"a" msgpack:"a"`
	OrderID string `json:"o" msgpack:"o"`
}

CancelOrderWire represents cancel order item wire format

type CancelRequest added in v0.4.0

type CancelRequest struct {
	Coin string `json:"coin"`
	Oid  int64  `json:"oid"`
}

type CancelResponse added in v0.4.1

type CancelResponse struct {
	Status string     `json:"status"`
	Data   *OpenOrder `json:"data,omitempty"`
	Error  string     `json:"error,omitempty"`
}

type Candle

type Candle struct {
	Timestamp int64  `json:"T"`
	Close     string `json:"c"`
	High      string `json:"h"`
	Interval  string `json:"i"`
	Low       string `json:"l"`
	Number    int    `json:"n"`
	Open      string `json:"o"`
	Symbol    string `json:"s"`
	Time      int64  `json:"t"`
	Volume    string `json:"v"`
}

type Client

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

func NewClient

func NewClient(baseURL string) *Client

type Cloid added in v0.4.0

type Cloid struct {
	Value string
}

func (Cloid) ToRaw added in v0.4.0

func (c Cloid) ToRaw() string

type ConvertToMultiSigUserAction added in v0.4.5

type ConvertToMultiSigUserAction struct {
	Type    string `json:"type"    msgpack:"type"`
	Signers string `json:"signers" msgpack:"signers"`
	Nonce   int64  `json:"nonce"   msgpack:"nonce"`
}

ConvertToMultiSigUserAction represents convert to multi-sig user action

type CreateOrderRequest added in v0.4.2

type CreateOrderRequest struct {
	Coin          string
	IsBuy         bool
	Price         float64
	Size          float64
	ReduceOnly    bool
	OrderType     OrderType
	ClientOrderID *string
}

type CreateSubAccountAction added in v0.4.5

type CreateSubAccountAction struct {
	Type string `json:"type" msgpack:"type"`
	Name string `json:"name" msgpack:"name"`
}

CreateSubAccountAction represents create sub-account action

type CreateSubAccountResponse added in v0.4.1

type CreateSubAccountResponse struct {
	Status string      `json:"status"`
	Data   *SubAccount `json:"data,omitempty"`
	Error  string      `json:"error,omitempty"`
}

type EvmContract added in v0.2.0

type EvmContract struct {
	Address             string `json:"address"`
	EvmExtraWeiDecimals int    `json:"evm_extra_wei_decimals"`
}

type Exchange

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

func NewExchange

func NewExchange(
	privateKey *ecdsa.PrivateKey,
	baseURL string,
	meta *Meta,
	vaultAddr, accountAddr string,
	spotMeta *SpotMeta,
) *Exchange

func (*Exchange) ApproveAgent added in v0.4.0

func (e *Exchange) ApproveAgent(name *string) (*AgentApprovalResponse, string, error)

ApproveAgent approves an agent to trade on behalf of the user Returns the result and the generated agent private key

func (*Exchange) ApproveBuilderFee added in v0.4.0

func (e *Exchange) ApproveBuilderFee(builder string, maxFeeRate string) (*ApprovalResponse, error)

ApproveBuilderFee approves builder fee payment

func (*Exchange) BulkCancel added in v0.4.0

func (e *Exchange) BulkCancel(
	requests []CancelOrderRequest,
) (res *APIResponse[CancelOrderResponse], err error)

func (*Exchange) BulkCancelByCloids added in v0.4.3

func (e *Exchange) BulkCancelByCloids(
	requests []CancelOrderRequestByCloid,
) (res *APIResponse[CancelOrderResponse], err error)

func (*Exchange) BulkModifyOrders added in v0.4.0

func (e *Exchange) BulkModifyOrders(
	modifyRequests []ModifyOrderRequest,
) ([]OrderStatus, error)

BulkModifyOrders modifies multiple orders

func (*Exchange) BulkOrders

func (e *Exchange) BulkOrders(
	orders []CreateOrderRequest,
	builder *BuilderInfo,
) (result *APIResponse[OrderResponse], err error)

func (*Exchange) CSignerInner added in v0.4.0

func (e *Exchange) CSignerInner(innerAction map[string]any) (*ValidatorResponse, error)

CSignerInner executes inner consensus signer action

func (*Exchange) CSignerJailSelf added in v0.4.0

func (e *Exchange) CSignerJailSelf() (*ValidatorResponse, error)

CSignerJailSelf jails self as consensus signer

func (*Exchange) CSignerUnjailSelf added in v0.4.0

func (e *Exchange) CSignerUnjailSelf() (*ValidatorResponse, error)

CSignerUnjailSelf unjails self as consensus signer

func (*Exchange) CValidatorChangeProfile added in v0.4.0

func (e *Exchange) CValidatorChangeProfile(newProfile map[string]any) (*ValidatorResponse, error)

CValidatorChangeProfile changes validator profile

func (*Exchange) CValidatorRegister added in v0.4.0

func (e *Exchange) CValidatorRegister(validatorProfile map[string]any) (*ValidatorResponse, error)

CValidatorRegister registers as consensus validator

func (*Exchange) CValidatorUnregister added in v0.4.0

func (e *Exchange) CValidatorUnregister() (*ValidatorResponse, error)

CValidatorUnregister unregisters as consensus validator

func (*Exchange) Cancel

func (e *Exchange) Cancel(
	coin string,
	oid int64,
) (res *APIResponse[CancelOrderResponse], err error)

func (*Exchange) CancelByCloid

func (e *Exchange) CancelByCloid(
	coin, cloid string,
) (res *APIResponse[CancelOrderResponse], err error)

func (*Exchange) ConvertToMultiSigUser added in v0.4.0

func (e *Exchange) ConvertToMultiSigUser(
	authorizedUsers []string,
	threshold int,
) (*MultiSigConversionResponse, error)

ConvertToMultiSigUser converts account to multi-signature user

func (*Exchange) CreateSubAccount added in v0.4.0

func (e *Exchange) CreateSubAccount(name string) (*CreateSubAccountResponse, error)

CreateSubAccount creates a new sub-account

func (*Exchange) MarketClose added in v0.4.0

func (e *Exchange) MarketClose(
	coin string,
	sz *float64,
	px *float64,
	slippage float64,
	cloid *string,
	builder *BuilderInfo,
) (OrderStatus, error)

MarketClose closes a position

func (*Exchange) MarketOpen added in v0.4.0

func (e *Exchange) MarketOpen(
	name string,
	isBuy bool,
	sz float64,
	px *float64,
	slippage float64,
	cloid *string,
	builder *BuilderInfo,
) (res OrderStatus, err error)

MarketOpen opens a market position

func (*Exchange) ModifyOrder added in v0.4.0

func (e *Exchange) ModifyOrder(
	req ModifyOrderRequest,
) (result OrderStatus, err error)

ModifyOrder modifies an existing order

func (*Exchange) MultiSig added in v0.4.0

func (e *Exchange) MultiSig(
	action map[string]any,
	signers []string,
	signatures []string,
) (*MultiSigResponse, error)

func (*Exchange) Order

func (e *Exchange) Order(
	req CreateOrderRequest,
	builder *BuilderInfo,
) (result OrderStatus, err error)

func (*Exchange) PerpDeployRegisterAsset added in v0.4.0

func (e *Exchange) PerpDeployRegisterAsset(
	asset string,
	perpDexInput PerpDexSchemaInput,
) (*PerpDeployResponse, error)

PerpDeployRegisterAsset registers a new perpetual asset

func (*Exchange) PerpDeploySetOracle added in v0.4.0

func (e *Exchange) PerpDeploySetOracle(
	asset string,
	oracleAddress string,
) (*SpotDeployResponse, error)

PerpDeploySetOracle sets oracle for perpetual asset

func (*Exchange) PerpDexClassTransfer added in v0.4.0

func (e *Exchange) PerpDexClassTransfer(
	dex, token string,
	amount float64,
	toPerp bool,
) (*TransferResponse, error)

PerpDexClassTransfer transfers tokens between perp dex classes

func (*Exchange) ScheduleCancel added in v0.4.0

func (e *Exchange) ScheduleCancel(scheduleTime *int64) (*ScheduleCancelResponse, error)

ScheduleCancel schedules cancellation of all open orders

func (*Exchange) SetExpiresAfter added in v0.4.0

func (e *Exchange) SetExpiresAfter(expiresAfter *int64)

SetExpiresAfter sets the expiration time for actions If expiresAfter is nil, actions will not have an expiration time If expiresAfter is set, actions will include this expiration timestamp

func (*Exchange) SetReferrer added in v0.4.0

func (e *Exchange) SetReferrer(code string) (*SetReferrerResponse, error)

SetReferrer sets a referral code

func (*Exchange) SlippagePrice added in v0.4.0

func (e *Exchange) SlippagePrice(
	name string,
	isBuy bool,
	slippage float64,
	px *float64,
) (float64, error)

SlippagePrice calculates the slippage price for market orders

func (*Exchange) SpotDeployEnableFreezePrivilege added in v0.4.0

func (e *Exchange) SpotDeployEnableFreezePrivilege() (*SpotDeployResponse, error)

SpotDeployEnableFreezePrivilege enables freeze privilege for spot deployer

func (*Exchange) SpotDeployFreezeUser added in v0.4.0

func (e *Exchange) SpotDeployFreezeUser(userAddress string) (*SpotDeployResponse, error)

SpotDeployFreezeUser freezes a user in spot trading

func (*Exchange) SpotDeployGenesis added in v0.4.0

func (e *Exchange) SpotDeployGenesis(deployer string, dexName string) (*SpotDeployResponse, error)

SpotDeployGenesis initializes spot genesis

func (*Exchange) SpotDeployRegisterHyperliquidity added in v0.4.0

func (e *Exchange) SpotDeployRegisterHyperliquidity(
	name string,
	tokens []string,
) (*SpotDeployResponse, error)

SpotDeployRegisterHyperliquidity registers hyperliquidity spot

func (*Exchange) SpotDeployRegisterSpot added in v0.4.0

func (e *Exchange) SpotDeployRegisterSpot(
	baseToken string,
	quoteToken string,
) (*SpotDeployResponse, error)

SpotDeployRegisterSpot registers spot market

func (*Exchange) SpotDeployRegisterToken added in v0.4.0

func (e *Exchange) SpotDeployRegisterToken(
	tokenName string,
	szDecimals int,
	weiDecimals int,
	maxGas int,
	fullName string,
) (*SpotDeployResponse, error)

SpotDeployRegisterToken registers a new spot token

func (*Exchange) SpotDeployRevokeFreezePrivilege added in v0.4.0

func (e *Exchange) SpotDeployRevokeFreezePrivilege() (*SpotDeployResponse, error)

SpotDeployRevokeFreezePrivilege revokes freeze privilege for spot deployer

func (*Exchange) SpotDeploySetDeployerTradingFeeShare added in v0.4.0

func (e *Exchange) SpotDeploySetDeployerTradingFeeShare(
	feeShare float64,
) (*SpotDeployResponse, error)

SpotDeploySetDeployerTradingFeeShare sets deployer trading fee share

func (*Exchange) SpotDeployUserGenesis added in v0.4.0

func (e *Exchange) SpotDeployUserGenesis(balances map[string]float64) (*SpotDeployResponse, error)

SpotDeployUserGenesis initializes user genesis for spot trading

func (*Exchange) SpotTransfer added in v0.4.0

func (e *Exchange) SpotTransfer(
	amount float64,
	destination, token string,
) (*TransferResponse, error)

SpotTransfer transfers spot tokens to another address

func (*Exchange) SubAccountSpotTransfer added in v0.4.0

func (e *Exchange) SubAccountSpotTransfer(
	subAccountUser string,
	isDeposit bool,
	token string,
	amount float64,
) (*TransferResponse, error)

SubAccountSpotTransfer transfers spot tokens to/from sub-account

func (*Exchange) SubAccountTransfer added in v0.4.0

func (e *Exchange) SubAccountTransfer(
	subAccountUser string,
	isDeposit bool,
	usd int,
) (*TransferResponse, error)

SubAccountTransfer transfers funds to/from sub-account

func (*Exchange) TokenDelegate added in v0.4.0

func (e *Exchange) TokenDelegate(
	validator string,
	wei int,
	isUndelegate bool,
) (*TransferResponse, error)

TokenDelegate delegates tokens for staking

func (*Exchange) UpdateIsolatedMargin

func (e *Exchange) UpdateIsolatedMargin(amount float64, name string) (*UserState, error)

func (*Exchange) UpdateLeverage

func (e *Exchange) UpdateLeverage(leverage int, name string, isCross bool) (*UserState, error)

func (*Exchange) UsdClassTransfer added in v0.4.0

func (e *Exchange) UsdClassTransfer(amount float64, toPerp bool) (*TransferResponse, error)

UsdClassTransfer transfers between USD classes

func (*Exchange) UsdTransfer added in v0.4.0

func (e *Exchange) UsdTransfer(amount float64, destination string) (*TransferResponse, error)

UsdTransfer transfers USD to another address

func (*Exchange) UseBigBlocks added in v0.4.0

func (e *Exchange) UseBigBlocks(enable bool) (*ApprovalResponse, error)

UseBigBlocks enables or disables big blocks

func (*Exchange) VaultUsdTransfer added in v0.4.0

func (e *Exchange) VaultUsdTransfer(
	vaultAddress string,
	isDeposit bool,
	usd int,
) (*TransferResponse, error)

VaultUsdTransfer transfers to/from vault

func (*Exchange) WithdrawFromBridge added in v0.4.0

func (e *Exchange) WithdrawFromBridge(
	amount float64,
	destination string,
) (*TransferResponse, error)

WithdrawFromBridge withdraws tokens from bridge

type FeeSchedule

type FeeSchedule struct {
	Add              string `json:"add"`
	Cross            string `json:"cross"`
	ReferralDiscount string `json:"referralDiscount"`
	Tiers            Tiers  `json:"tiers"`
}

type Fill

type Fill struct {
	ClosedPnl     string `json:"closedPnl"`
	Coin          string `json:"coin"`
	Crossed       bool   `json:"crossed"`
	Dir           string `json:"dir"`
	Hash          string `json:"hash"`
	Oid           int64  `json:"oid"`
	Price         string `json:"px"`
	Side          string `json:"side"`
	StartPosition string `json:"startPosition"`
	Size          string `json:"sz"`
	Time          int64  `json:"time"`
}

type FundingHistory

type FundingHistory struct {
	Coin        string `json:"coin"`
	FundingRate string `json:"fundingRate"`
	Premium     string `json:"premium"`
	Time        int64  `json:"time"`
}

type Grouping added in v0.4.2

type Grouping string
const (
	GroupingNA           Grouping = "na"
	GroupingNormalTpsl   Grouping = "normalTpsl"
	GroupingPositionTpls Grouping = "positionTpsl"
)

type Info

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

func NewInfo

func NewInfo(baseURL string, skipWS bool, meta *Meta, spotMeta *SpotMeta) *Info

func (*Info) AllMids

func (i *Info) AllMids() (map[string]string, error)

func (*Info) CandlesSnapshot

func (i *Info) CandlesSnapshot(name, interval string, startTime, endTime int64) ([]Candle, error)

func (*Info) FrontendOpenOrders

func (i *Info) FrontendOpenOrders(address string) ([]OpenOrder, error)

func (*Info) FundingHistory

func (i *Info) FundingHistory(
	name string,
	startTime int64,
	endTime *int64,
) ([]FundingHistory, error)

func (*Info) L2Snapshot

func (i *Info) L2Snapshot(name string) (*L2Book, error)

func (*Info) Meta

func (i *Info) Meta() (*Meta, error)

func (*Info) MetaAndAssetCtxs

func (i *Info) MetaAndAssetCtxs() (map[string]any, error)

func (*Info) NameToAsset

func (i *Info) NameToAsset(name string) int

func (*Info) OpenOrders

func (i *Info) OpenOrders(address string) ([]OpenOrder, error)

func (*Info) PerpDexs added in v0.4.0

func (i *Info) PerpDexs() ([]string, error)

PerpDexs returns the list of available perpetual dexes

func (*Info) QueryOrderByCloid

func (i *Info) QueryOrderByCloid(user, cloid string) (*OpenOrder, error)

func (*Info) QueryOrderByOid

func (i *Info) QueryOrderByOid(user string, oid int64) (*OpenOrder, error)

func (*Info) QueryReferralState

func (i *Info) QueryReferralState(user string) (*ReferralState, error)

func (*Info) QuerySubAccounts

func (i *Info) QuerySubAccounts(user string) ([]SubAccount, error)

func (*Info) QueryUserToMultiSigSigners

func (i *Info) QueryUserToMultiSigSigners(multiSigUser string) ([]MultiSigSigner, error)

func (*Info) SpotMeta

func (i *Info) SpotMeta() (*SpotMeta, error)

func (*Info) SpotMetaAndAssetCtxs

func (i *Info) SpotMetaAndAssetCtxs() (map[string]any, error)

func (*Info) SpotUserState

func (i *Info) SpotUserState(address string) (*UserState, error)

func (*Info) UserFees

func (i *Info) UserFees(address string) (*UserFees, error)

func (*Info) UserFills

func (i *Info) UserFills(address string) ([]Fill, error)

func (*Info) UserFillsByTime

func (i *Info) UserFillsByTime(address string, startTime int64, endTime *int64) ([]Fill, error)

func (*Info) UserFundingHistory

func (i *Info) UserFundingHistory(
	user string,
	startTime int64,
	endTime *int64,
) ([]UserFundingHistory, error)

func (*Info) UserStakingDelegations

func (i *Info) UserStakingDelegations(address string) ([]StakingDelegation, error)

func (*Info) UserStakingRewards

func (i *Info) UserStakingRewards(address string) ([]StakingReward, error)

func (*Info) UserStakingSummary

func (i *Info) UserStakingSummary(address string) (*StakingSummary, error)

func (*Info) UserState

func (i *Info) UserState(address string) (*UserState, error)

type L2Book

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

type Level

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

type Leverage

type Leverage struct {
	Type   string  `json:"type"`
	Value  int     `json:"value"`
	RawUsd *string `json:"rawUsd,omitempty"`
}

type LimitOrderType

type LimitOrderType struct {
	Tif string `json:"tif"` // TifAlo, TifIoc, TifGtc
}

type MMTier

type MMTier struct {
	Add                 string `json:"add"`
	MakerFractionCutoff string `json:"makerFractionCutoff"`
}

type MarginSummary

type MarginSummary struct {
	AccountValue    string `json:"accountValue"`
	TotalMarginUsed string `json:"totalMarginUsed"`
	TotalNtlPos     string `json:"totalNtlPos"`
	TotalRawUsd     string `json:"totalRawUsd"`
}

type Meta

type Meta struct {
	Universe []AssetInfo `json:"universe"`
}

type MixedArray added in v0.4.2

type MixedArray []MixedValue

func (*MixedArray) UnmarshalJSON added in v0.4.2

func (ma *MixedArray) UnmarshalJSON(data []byte) error

type MixedValue added in v0.4.2

type MixedValue json.RawMessage

func (*MixedValue) Array added in v0.4.2

func (mv *MixedValue) Array() ([]json.RawMessage, bool)

func (MixedValue) MarshalJSON added in v0.4.2

func (mv MixedValue) MarshalJSON() ([]byte, error)

func (*MixedValue) Object added in v0.4.2

func (mv *MixedValue) Object() (map[string]any, bool)

func (*MixedValue) Parse added in v0.4.2

func (mv *MixedValue) Parse(v any) error

func (*MixedValue) String added in v0.4.2

func (mv *MixedValue) String() (string, bool)

func (*MixedValue) Type added in v0.4.2

func (mv *MixedValue) Type() string

func (*MixedValue) UnmarshalJSON added in v0.4.2

func (mv *MixedValue) UnmarshalJSON(data []byte) error

type ModifyAction added in v0.4.5

type ModifyAction struct {
	Type  string    `json:"type"  msgpack:"type"`
	Oid   any       `json:"oid"   msgpack:"oid"`
	Order OrderWire `json:"order" msgpack:"order"`
}

ModifyAction represents a single order modification

type ModifyOrderRequest added in v0.4.2

type ModifyOrderRequest struct {
	Oid   any // can be int64 or Cloid
	Order CreateOrderRequest
}

type ModifyResponse added in v0.4.1

type ModifyResponse struct {
	Status string        `json:"status"`
	Data   []OrderStatus `json:"data,omitempty"`
	Error  string        `json:"error,omitempty"`
}

type MultiSigAction added in v0.4.5

type MultiSigAction struct {
	Type       string         `json:"type"       msgpack:"type"`
	Action     map[string]any `json:"action"     msgpack:"action"`
	Signers    []string       `json:"signers"    msgpack:"signers"`
	Signatures []string       `json:"signatures" msgpack:"signatures"`
}

MultiSigAction represents multi-signature action

type MultiSigConversionResponse added in v0.4.1

type MultiSigConversionResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type MultiSigResponse added in v0.4.1

type MultiSigResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type MultiSigSigner

type MultiSigSigner struct {
	User      string `json:"user"`
	Threshold int    `json:"threshold"`
}

type OpenOrder

type OpenOrder struct {
	Coin      string  `json:"coin"`
	LimitPx   float64 `json:"limitPx,string"`
	Oid       int64   `json:"oid"`
	Side      string  `json:"side"`
	Size      float64 `json:"sz,string"`
	Timestamp int64   `json:"timestamp"`
}

type OrderAction added in v0.4.5

type OrderAction struct {
	Type     string       `json:"type"              msgpack:"type"`
	Orders   []OrderWire  `json:"orders"            msgpack:"orders"`
	Grouping string       `json:"grouping"          msgpack:"grouping"`
	Builder  *BuilderInfo `json:"builder,omitempty" msgpack:"builder,omitempty"`
}

OrderAction represents the order action with deterministic field ordering

type OrderResponse added in v0.4.1

type OrderResponse struct {
	Statuses []OrderStatus
}

type OrderStatus added in v0.4.0

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

func (*OrderStatus) String added in v0.4.7

func (s *OrderStatus) String() string

type OrderStatusFilled added in v0.4.2

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

type OrderStatusResting added in v0.4.2

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

type OrderType

type OrderType struct {
	Limit   *LimitOrderType   `json:"limit,omitempty"`
	Trigger *TriggerOrderType `json:"trigger,omitempty"`
}

type OrderWire

type OrderWire struct {
	Asset      int            `json:"a"           msgpack:"a"`
	IsBuy      bool           `json:"b"           msgpack:"b"`
	LimitPx    string         `json:"p"           msgpack:"p"`
	Size       string         `json:"s"           msgpack:"s"`
	ReduceOnly bool           `json:"r"           msgpack:"r"`
	OrderType  map[string]any `json:"t"           msgpack:"t"`
	Cloid      *string        `json:"c,omitempty" msgpack:"c,omitempty"`
}

OrderWire represents the wire format for orders with deterministic field ordering

type PerpDeployResponse added in v0.4.1

type PerpDeployResponse struct {
	Status string `json:"status"`
	Data   struct {
		Statuses []TxStatus `json:"statuses"`
	} `json:"data"`
}

type PerpDexClassTransferAction added in v0.4.5

type PerpDexClassTransferAction struct {
	Type   string  `json:"type"   msgpack:"type"`
	Dex    string  `json:"dex"    msgpack:"dex"`
	Token  string  `json:"token"  msgpack:"token"`
	Amount float64 `json:"amount" msgpack:"amount"`
	ToPerp bool    `json:"toPerp" msgpack:"toPerp"`
}

PerpDexClassTransferAction represents perp dex class transfer

type PerpDexSchemaInput added in v0.4.0

type PerpDexSchemaInput struct {
	FullName        string  `json:"fullName"`
	CollateralToken int     `json:"collateralToken"`
	OracleUpdater   *string `json:"oracleUpdater"`
}

type Position

type Position struct {
	Coin           string   `json:"coin"`
	EntryPx        *string  `json:"entryPx"`
	Leverage       Leverage `json:"leverage"`
	LiquidationPx  *string  `json:"liquidationPx"`
	MarginUsed     string   `json:"marginUsed"`
	PositionValue  string   `json:"positionValue"`
	ReturnOnEquity string   `json:"returnOnEquity"`
	Szi            string   `json:"szi"`
	UnrealizedPnl  string   `json:"unrealizedPnl"`
}

type ReferralState

type ReferralState struct {
	ReferralCode string   `json:"referralCode"`
	Referrer     string   `json:"referrer"`
	Referred     []string `json:"referred"`
}

type ScheduleCancelAction added in v0.4.0

type ScheduleCancelAction struct {
	Type string `json:"type"           msgpack:"type"`
	Time *int64 `json:"time,omitempty" msgpack:"time,omitempty"`
}

ScheduleCancelAction represents schedule cancel action

type ScheduleCancelResponse added in v0.4.1

type ScheduleCancelResponse struct {
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

type SetReferrerAction added in v0.4.5

type SetReferrerAction struct {
	Type string `json:"type" msgpack:"type"`
	Code string `json:"code" msgpack:"code"`
}

SetReferrerAction represents set referrer action

type SetReferrerResponse added in v0.4.1

type SetReferrerResponse struct {
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
}

type Side

type Side string
const (
	SideAsk Side = "A"
	SideBid Side = "B"
)

type SignatureResult added in v0.4.2

type SignatureResult struct {
	R string `json:"r"`
	S string `json:"s"`
	V int    `json:"v"`
}

SignatureResult represents the structured signature result

func SignAgent added in v0.4.0

func SignAgent(
	privateKey *ecdsa.PrivateKey,
	agentAddress, agentName string,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignAgent signs agent approval action

func SignApproveBuilderFee added in v0.4.0

func SignApproveBuilderFee(
	privateKey *ecdsa.PrivateKey,
	builderAddress string,
	maxFeeRate float64,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignApproveBuilderFee signs approve builder fee action

func SignConvertToMultiSigUserAction added in v0.4.0

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)

SignL1Action implements the same logic as Python's sign_l1_action

func SignMultiSigAction added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

func SignSpotTransferAction(
	privateKey *ecdsa.PrivateKey,
	amount float64,
	destination, token string,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignSpotTransferAction signs spot transfer action

func SignTokenDelegateAction added in v0.4.0

func SignTokenDelegateAction(
	privateKey *ecdsa.PrivateKey,
	token string,
	amount float64,
	validatorAddress string,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignTokenDelegateAction signs token delegate action

func SignUsdClassTransferAction added in v0.4.0

func SignUsdClassTransferAction(
	privateKey *ecdsa.PrivateKey,
	amount float64,
	toPerp bool,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignUsdClassTransferAction signs USD class transfer action

func SignUsdTransferAction added in v0.4.0

func SignUsdTransferAction(
	privateKey *ecdsa.PrivateKey,
	amount float64,
	destination string,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignUsdTransferAction signs USD transfer action

func SignWithdrawFromBridgeAction added in v0.4.0

func SignWithdrawFromBridgeAction(
	privateKey *ecdsa.PrivateKey,
	destination string,
	amount, fee float64,
	timestamp int64,
	isMainnet bool,
) (SignatureResult, error)

SignWithdrawFromBridgeAction signs withdraw from bridge action

type SpotAssetCtx

type SpotAssetCtx struct {
	DayNtlVlm         string  `json:"dayNtlVlm"`
	MarkPx            string  `json:"markPx"`
	MidPx             *string `json:"midPx"`
	PrevDayPx         string  `json:"prevDayPx"`
	CirculatingSupply string  `json:"circulatingSupply"`
	Coin              string  `json:"coin"`
}

type SpotAssetInfo

type SpotAssetInfo struct {
	Name        string `json:"name"`
	Tokens      []int  `json:"tokens"`
	Index       int    `json:"index"`
	IsCanonical bool   `json:"isCanonical"`
}

type SpotDeployResponse added in v0.4.1

type SpotDeployResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type SpotMeta

type SpotMeta struct {
	Universe []SpotAssetInfo `json:"universe"`
	Tokens   []SpotTokenInfo `json:"tokens"`
}

type SpotTokenInfo

type SpotTokenInfo 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 *EvmContract `json:"evmContract"`
	FullName    *string      `json:"fullName"`
}

type SpotTransferAction added in v0.4.5

type SpotTransferAction struct {
	Type        string `json:"type"        msgpack:"type"`
	Destination string `json:"destination" msgpack:"destination"`
	Amount      string `json:"amount"      msgpack:"amount"`
	Token       string `json:"token"       msgpack:"token"`
	Time        int64  `json:"time"        msgpack:"time"`
}

SpotTransferAction represents spot transfer

type StakingDelegation

type StakingDelegation struct {
	Validator            string `json:"validator"`
	Amount               string `json:"amount"`
	LockedUntilTimestamp int64  `json:"lockedUntilTimestamp"`
}

type StakingReward

type StakingReward struct {
	Time        int64  `json:"time"`
	Source      string `json:"source"`
	TotalAmount string `json:"totalAmount"`
}

type StakingSummary

type StakingSummary struct {
	Delegated              string `json:"delegated"`
	Undelegated            string `json:"undelegated"`
	TotalPendingWithdrawal string `json:"totalPendingWithdrawal"`
	NPendingWithdrawals    int    `json:"nPendingWithdrawals"`
}

type SubAccount

type SubAccount struct {
	Name        string   `json:"name"`
	User        string   `json:"user"`
	Permissions []string `json:"permissions"`
}

type SubAccountSpotTransferAction added in v0.4.5

type SubAccountSpotTransferAction struct {
	Type           string  `json:"type"           msgpack:"type"`
	SubAccountUser string  `json:"subAccountUser" msgpack:"subAccountUser"`
	IsDeposit      bool    `json:"isDeposit"      msgpack:"isDeposit"`
	Token          string  `json:"token"          msgpack:"token"`
	Amount         float64 `json:"amount"         msgpack:"amount"`
}

SubAccountSpotTransferAction represents sub-account spot transfer

type SubAccountTransferAction added in v0.4.5

type SubAccountTransferAction struct {
	Type           string `json:"type"           msgpack:"type"`
	SubAccountUser string `json:"subAccountUser" msgpack:"subAccountUser"`
	IsDeposit      bool   `json:"isDeposit"      msgpack:"isDeposit"`
	Usd            int    `json:"usd"            msgpack:"usd"`
}

SubAccountTransferAction represents sub-account transfer

type Subscription

type Subscription struct {
	Type     string `json:"type"`
	Coin     string `json:"coin,omitempty"`
	User     string `json:"user,omitempty"`
	Interval string `json:"interval,omitempty"`
}

func (Subscription) MarshalEasyJSON added in v0.2.0

func (v Subscription) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Subscription) MarshalJSON added in v0.2.0

func (v Subscription) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Subscription) UnmarshalEasyJSON added in v0.2.0

func (v *Subscription) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Subscription) UnmarshalJSON added in v0.2.0

func (v *Subscription) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type Tiers

type Tiers struct {
	MM  []MMTier  `json:"mm"`
	VIP []VIPTier `json:"vip"`
}

type TokenDelegateAction added in v0.4.5

type TokenDelegateAction struct {
	Type         string `json:"type"         msgpack:"type"`
	Validator    string `json:"validator"    msgpack:"validator"`
	Wei          int    `json:"wei"          msgpack:"wei"`
	IsUndelegate bool   `json:"isUndelegate" msgpack:"isUndelegate"`
	Nonce        int64  `json:"nonce"        msgpack:"nonce"`
}

TokenDelegateAction represents token delegate action

type Trade

type Trade struct {
	Coin  string   `json:"coin"`
	Side  string   `json:"side"`
	Px    string   `json:"px"`
	Sz    string   `json:"sz"`
	Time  int64    `json:"time"`
	Hash  string   `json:"hash"`
	Tid   int64    `json:"tid"`
	Users []string `json:"users"`
}

type TransferResponse added in v0.4.1

type TransferResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type TriggerOrderType

type TriggerOrderType struct {
	TriggerPx float64 `json:"triggerPx"`
	IsMarket  bool    `json:"isMarket"`
	Tpsl      string  `json:"tpsl"` // "tp" or "sl"
}

type TxStatus added in v0.4.1

type TxStatus struct {
	Coin   string `json:"coin"`
	Status string `json:"status"`
}

type UpdateIsolatedMarginAction added in v0.4.5

type UpdateIsolatedMarginAction struct {
	Type  string  `json:"type"  msgpack:"type"`
	Asset int     `json:"asset" msgpack:"asset"`
	IsBuy bool    `json:"isBuy" msgpack:"isBuy"`
	Ntli  float64 `json:"ntli"  msgpack:"ntli"`
}

UpdateIsolatedMarginAction represents isolated margin update

type UpdateLeverageAction added in v0.4.5

type UpdateLeverageAction struct {
	Type     string         `json:"type"     msgpack:"type"`
	Asset    int            `json:"asset"    msgpack:"asset"`
	Leverage map[string]any `json:"leverage" msgpack:"leverage"`
}

UpdateLeverageAction represents leverage update

type UsdClassTransferAction added in v0.4.5

type UsdClassTransferAction struct {
	Type   string `json:"type"   msgpack:"type"`
	Amount string `json:"amount" msgpack:"amount"`
	ToPerp bool   `json:"toPerp" msgpack:"toPerp"`
	Nonce  int64  `json:"nonce"  msgpack:"nonce"`
}

UsdClassTransferAction represents USD class transfer

type UsdTransferAction added in v0.4.5

type UsdTransferAction struct {
	Type        string `json:"type"        msgpack:"type"`
	Destination string `json:"destination" msgpack:"destination"`
	Amount      string `json:"amount"      msgpack:"amount"`
	Time        int64  `json:"time"        msgpack:"time"`
}

UsdTransferAction represents USD transfer

type UseBigBlocksAction added in v0.4.5

type UseBigBlocksAction struct {
	Type           string `json:"type"           msgpack:"type"`
	UsingBigBlocks bool   `json:"usingBigBlocks" msgpack:"usingBigBlocks"`
}

UseBigBlocksAction represents use big blocks action

type UserFees

type UserFees struct {
	ActiveReferralDiscount string       `json:"activeReferralDiscount"`
	DailyUserVolume        []UserVolume `json:"dailyUserVlm"`
	FeeSchedule            FeeSchedule  `json:"feeSchedule"`
	UserAddRate            string       `json:"userAddRate"`
	UserCrossRate          string       `json:"userCrossRate"`
}

type UserFundingHistory

type UserFundingHistory struct {
	User      string `json:"user"`
	Type      string `json:"type"`
	StartTime int64  `json:"startTime"`
	EndTime   int64  `json:"endTime"`
}

type UserState

type UserState struct {
	AssetPositions     []AssetPosition `json:"assetPositions"`
	CrossMarginSummary MarginSummary   `json:"crossMarginSummary"`
	MarginSummary      MarginSummary   `json:"marginSummary"`
	Withdrawable       string          `json:"withdrawable"`
}

type UserVolume

type UserVolume struct {
	Date      string `json:"date"`
	Exchange  string `json:"exchange"`
	UserAdd   string `json:"userAdd"`
	UserCross string `json:"userCross"`
}

type VIPTier

type VIPTier struct {
	Add       string `json:"add"`
	Cross     string `json:"cross"`
	NtlCutoff string `json:"ntlCutoff"`
}

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidatorResponse added in v0.4.1

type ValidatorResponse struct {
	Status string `json:"status"`
	TxHash string `json:"txHash,omitempty"`
	Error  string `json:"error,omitempty"`
}

type VaultUsdTransferAction added in v0.4.5

type VaultUsdTransferAction struct {
	Type         string `json:"type"         msgpack:"type"`
	VaultAddress string `json:"vaultAddress" msgpack:"vaultAddress"`
	IsDeposit    bool   `json:"isDeposit"    msgpack:"isDeposit"`
	Usd          int    `json:"usd"          msgpack:"usd"`
}

VaultUsdTransferAction represents vault USD transfer

type WSMessage

type WSMessage struct {
	Channel string          `json:"channel"`
	Data    json.RawMessage `json:"data"`
}

func (WSMessage) MarshalEasyJSON added in v0.2.0

func (v WSMessage) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (WSMessage) MarshalJSON added in v0.2.0

func (v WSMessage) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*WSMessage) UnmarshalEasyJSON added in v0.2.0

func (v *WSMessage) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*WSMessage) UnmarshalJSON added in v0.2.0

func (v *WSMessage) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type WebsocketClient

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

func NewWebsocketClient

func NewWebsocketClient(baseURL string) *WebsocketClient

func (*WebsocketClient) Close

func (w *WebsocketClient) Close() error

func (*WebsocketClient) Connect

func (w *WebsocketClient) Connect(ctx context.Context) error

func (*WebsocketClient) Subscribe

func (w *WebsocketClient) Subscribe(sub Subscription, callback func(WSMessage)) (int, error)

func (*WebsocketClient) SubscribeToActiveAssetCtx added in v0.4.0

func (w *WebsocketClient) SubscribeToActiveAssetCtx(
	coin string,
	callback func(WSMessage),
) (int, error)

SubscribeToActiveAssetCtx subscribes to active asset context

func (*WebsocketClient) SubscribeToAllMids added in v0.4.0

func (w *WebsocketClient) SubscribeToAllMids(callback func(WSMessage)) (int, error)

SubscribeToAllMids subscribes to all mid prices

func (*WebsocketClient) SubscribeToBBO added in v0.4.0

func (w *WebsocketClient) SubscribeToBBO(coin string, callback func(WSMessage)) (int, error)

SubscribeToBBO subscribes to best bid/offer data

func (*WebsocketClient) SubscribeToCandles added in v0.4.0

func (w *WebsocketClient) SubscribeToCandles(
	coin, interval string,
	callback func(WSMessage),
) (int, error)

SubscribeToCandles subscribes to candle data

func (*WebsocketClient) SubscribeToOrderUpdates added in v0.4.0

func (w *WebsocketClient) SubscribeToOrderUpdates(callback func(WSMessage)) (int, error)

SubscribeToOrderUpdates subscribes to order updates

func (*WebsocketClient) SubscribeToOrderbook

func (w *WebsocketClient) SubscribeToOrderbook(coin string, callback func(WSMessage)) (int, error)

func (*WebsocketClient) SubscribeToTrades

func (w *WebsocketClient) SubscribeToTrades(coin string, callback func(WSMessage)) (int, error)

func (*WebsocketClient) SubscribeToUserEvents added in v0.4.0

func (w *WebsocketClient) SubscribeToUserEvents(
	user string,
	callback func(WSMessage),
) (int, error)

SubscribeToUserEvents subscribes to user events

func (*WebsocketClient) SubscribeToUserFills added in v0.4.0

func (w *WebsocketClient) SubscribeToUserFills(user string, callback func(WSMessage)) (int, error)

SubscribeToUserFills subscribes to user fills

func (*WebsocketClient) SubscribeToUserFundings added in v0.4.0

func (w *WebsocketClient) SubscribeToUserFundings(
	user string,
	callback func(WSMessage),
) (int, error)

SubscribeToUserFundings subscribes to user funding updates

func (*WebsocketClient) SubscribeToUserNonFundingLedgerUpdates added in v0.4.0

func (w *WebsocketClient) SubscribeToUserNonFundingLedgerUpdates(
	user string,
	callback func(WSMessage),
) (int, error)

SubscribeToUserNonFundingLedgerUpdates subscribes to user non-funding ledger updates

func (*WebsocketClient) SubscribeToWebData2 added in v0.4.0

func (w *WebsocketClient) SubscribeToWebData2(user string, callback func(WSMessage)) (int, error)

SubscribeToWebData2 subscribes to web data v2

func (*WebsocketClient) Unsubscribe

func (w *WebsocketClient) Unsubscribe(sub Subscription, id int) error

type WithdrawFromBridgeAction added in v0.4.5

type WithdrawFromBridgeAction struct {
	Type        string `json:"type"        msgpack:"type"`
	Destination string `json:"destination" msgpack:"destination"`
	Amount      string `json:"amount"      msgpack:"amount"`
	Time        int64  `json:"time"        msgpack:"time"`
}

WithdrawFromBridgeAction represents withdraw from bridge action

type WsCommand added in v0.1.2

type WsCommand struct {
	Method       string        `json:"method"`
	Subscription *Subscription `json:"subscription,omitempty"`
}

func (WsCommand) MarshalEasyJSON added in v0.2.0

func (v WsCommand) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (WsCommand) MarshalJSON added in v0.2.0

func (v WsCommand) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*WsCommand) UnmarshalEasyJSON added in v0.2.0

func (v *WsCommand) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*WsCommand) UnmarshalJSON added in v0.2.0

func (v *WsCommand) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

type WsMsg

type WsMsg struct {
	Channel string         `json:"channel"`
	Data    map[string]any `json:"data"`
}

WsMsg represents a WebSocket message with a channel and data payload.

Jump to

Keyboard shortcuts

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