Help us shape the future of Go! Take the 2026 Go Developer Survey

api

package
v1.24.29 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package api provides RPC and REST API handlers for the DEX VM.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotBootstrapped     = errors.New("DEX not bootstrapped")
	ErrInvalidRequest      = errors.New("invalid request")
	ErrOrderNotFound       = errors.New("order not found")
	ErrPoolNotFound        = errors.New("pool not found")
	ErrInsufficientBalance = errors.New("insufficient balance")
)

Functions

This section is empty.

Types

type ADLEngine added in v1.22.76

type ADLEngine interface {
	GetCandidateCount(symbol string) (longs, shorts int)
	Statistics() interface{}
	GetEvents(limit int) []interface{}
	ShouldTriggerADL(currentFund, targetFund *big.Int) bool
}

ADLEngine interface for auto-deleveraging.

type AddLiquidityArgs

type AddLiquidityArgs struct {
	PoolID       string `json:"poolId"`
	Amount0      string `json:"amount0"`
	Amount1      string `json:"amount1"`
	MinLiquidity string `json:"minLiquidity"`
}

AddLiquidityArgs is the argument for the AddLiquidity API.

type AddLiquidityReply

type AddLiquidityReply struct {
	LPTokens string `json:"lpTokens"`
}

AddLiquidityReply is the reply for the AddLiquidity API.

type CancelOrderArgs

type CancelOrderArgs struct {
	OrderID string `json:"orderId"`
	Symbol  string `json:"symbol"`
}

CancelOrderArgs is the argument for the CancelOrder API.

type CancelOrderReply

type CancelOrderReply struct {
	Success bool `json:"success"`
}

CancelOrderReply is the reply for the CancelOrder API.

type CommitmentStore added in v1.22.76

type CommitmentStore interface {
	GetCommitment(hash ids.ID) (interface{}, bool)
	GetSenderCommitments(sender ids.ShortID) []interface{}
	Statistics() interface{}
}

CommitmentStore interface for MEV protection.

type GetADLEventsArgs added in v1.22.76

type GetADLEventsArgs struct {
	Limit int `json:"limit"`
}

GetADLEventsArgs is the argument for the GetADLEvents API.

type GetADLEventsReply added in v1.22.76

type GetADLEventsReply struct {
	Events []interface{} `json:"events"`
}

GetADLEventsReply is the reply for the GetADLEvents API.

type GetADLStatsArgs added in v1.22.76

type GetADLStatsArgs struct{}

GetADLStatsArgs is the argument for the GetADLStats API.

type GetADLStatsReply added in v1.22.76

type GetADLStatsReply struct {
	Stats interface{} `json:"stats"`
}

GetADLStatsReply is the reply for the GetADLStats API.

type GetADLStatusArgs added in v1.22.76

type GetADLStatusArgs struct {
	Symbol string `json:"symbol"`
}

GetADLStatusArgs is the argument for the GetADLStatus API.

type GetADLStatusReply added in v1.22.76

type GetADLStatusReply struct {
	LongCandidates  int  `json:"longCandidates"`
	ShortCandidates int  `json:"shortCandidates"`
	ShouldTrigger   bool `json:"shouldTrigger"`
}

GetADLStatusReply is the reply for the GetADLStatus API.

type GetAccountArgs added in v1.22.76

type GetAccountArgs struct {
	TraderID string `json:"traderId"`
}

GetAccountArgs is the argument for the GetAccount API.

type GetAccountReply added in v1.22.76

type GetAccountReply struct {
	Account     interface{} `json:"account"`
	MarginRatio string      `json:"marginRatio"`
}

GetAccountReply is the reply for the GetAccount API.

type GetCommitmentArgs added in v1.22.76

type GetCommitmentArgs struct {
	CommitmentHash string `json:"commitmentHash"`
}

GetCommitmentArgs is the argument for the GetCommitment API.

type GetCommitmentReply added in v1.22.76

type GetCommitmentReply struct {
	Commitment interface{} `json:"commitment"`
	Found      bool        `json:"found"`
}

GetCommitmentReply is the reply for the GetCommitment API.

type GetCommitmentsArgs added in v1.22.76

type GetCommitmentsArgs struct {
	Sender string `json:"sender"`
}

GetCommitmentsArgs is the argument for the GetCommitments API.

type GetCommitmentsReply added in v1.22.76

type GetCommitmentsReply struct {
	Commitments []interface{} `json:"commitments"`
}

GetCommitmentsReply is the reply for the GetCommitments API.

type GetFundingRateArgs added in v1.22.76

type GetFundingRateArgs struct {
	Symbol string `json:"symbol"`
}

GetFundingRateArgs is the argument for the GetFundingRate API.

type GetFundingRateReply added in v1.22.76

type GetFundingRateReply struct {
	FundingRate     string `json:"fundingRate"`
	NextFundingTime int64  `json:"nextFundingTime"`
}

GetFundingRateReply is the reply for the GetFundingRate API.

type GetInsuranceFundArgs added in v1.22.76

type GetInsuranceFundArgs struct{}

GetInsuranceFundArgs is the argument for the GetInsuranceFund API.

type GetInsuranceFundReply added in v1.22.76

type GetInsuranceFundReply struct {
	Balance string `json:"balance"`
}

GetInsuranceFundReply is the reply for the GetInsuranceFund API.

type GetMEVStatsArgs added in v1.22.76

type GetMEVStatsArgs struct{}

GetMEVStatsArgs is the argument for the GetMEVStats API.

type GetMEVStatsReply added in v1.22.76

type GetMEVStatsReply struct {
	Stats interface{} `json:"stats"`
}

GetMEVStatsReply is the reply for the GetMEVStats API.

type GetMarketArgs added in v1.22.76

type GetMarketArgs struct {
	Symbol string `json:"symbol"`
}

GetMarketArgs is the argument for the GetMarket API.

type GetMarketReply added in v1.22.76

type GetMarketReply struct {
	Market interface{} `json:"market"`
}

GetMarketReply is the reply for the GetMarket API.

type GetMarketsArgs added in v1.22.76

type GetMarketsArgs struct{}

GetMarketsArgs is the argument for the GetMarkets API.

type GetMarketsReply added in v1.22.76

type GetMarketsReply struct {
	Markets []interface{} `json:"markets"`
}

GetMarketsReply is the reply for the GetMarkets API.

type GetOrderArgs

type GetOrderArgs struct {
	OrderID string `json:"orderId"`
	Symbol  string `json:"symbol"`
}

GetOrderArgs is the argument for the GetOrder API.

type GetOrderReply

type GetOrderReply struct {
	Order *orderbook.Order `json:"order"`
}

GetOrderReply is the reply for the GetOrder API.

type GetOrderbookArgs

type GetOrderbookArgs struct {
	Symbol string `json:"symbol"`
	Depth  int    `json:"depth"`
}

GetOrderbookArgs is the argument for the GetOrderbook API.

type GetOrderbookReply

type GetOrderbookReply struct {
	Symbol    string                  `json:"symbol"`
	Bids      []*orderbook.PriceLevel `json:"bids"`
	Asks      []*orderbook.PriceLevel `json:"asks"`
	BestBid   uint64                  `json:"bestBid"`
	BestAsk   uint64                  `json:"bestAsk"`
	Spread    uint64                  `json:"spread"`
	MidPrice  uint64                  `json:"midPrice"`
	Timestamp int64                   `json:"timestamp"`
}

GetOrderbookReply is the reply for the GetOrderbook API.

type GetPoolArgs

type GetPoolArgs struct {
	PoolID string `json:"poolId"`
}

GetPoolArgs is the argument for the GetPool API.

type GetPoolReply

type GetPoolReply struct {
	Pool *liquidity.Pool `json:"pool"`
}

GetPoolReply is the reply for the GetPool API.

type GetPoolsArgs

type GetPoolsArgs struct{}

GetPoolsArgs is the argument for the GetPools API.

type GetPoolsReply

type GetPoolsReply struct {
	Pools []*liquidity.Pool `json:"pools"`
}

GetPoolsReply is the reply for the GetPools API.

type GetPositionArgs added in v1.22.76

type GetPositionArgs struct {
	TraderID string `json:"traderId"`
	Symbol   string `json:"symbol"`
}

GetPositionArgs is the argument for the GetPosition API.

type GetPositionReply added in v1.22.76

type GetPositionReply struct {
	Position interface{} `json:"position"`
}

GetPositionReply is the reply for the GetPosition API.

type GetPositionsArgs added in v1.22.76

type GetPositionsArgs struct {
	TraderID string `json:"traderId"`
}

GetPositionsArgs is the argument for the GetPositions API.

type GetPositionsReply added in v1.22.76

type GetPositionsReply struct {
	Positions []interface{} `json:"positions"`
}

GetPositionsReply is the reply for the GetPositions API.

type GetQuoteArgs

type GetQuoteArgs struct {
	PoolID   string `json:"poolId"`
	TokenIn  string `json:"tokenIn"`
	AmountIn string `json:"amountIn"` // String for big.Int
}

GetQuoteArgs is the argument for the GetQuote API.

type GetQuoteReply

type GetQuoteReply struct {
	AmountOut     string `json:"amountOut"`
	EffectiveRate string `json:"effectiveRate"`
}

GetQuoteReply is the reply for the GetQuote API.

type GetStatsArgs

type GetStatsArgs struct {
	Symbol string `json:"symbol"`
}

GetStatsArgs is the argument for the GetStats API.

type GetStatsReply

type GetStatsReply struct {
	TotalVolume   uint64 `json:"totalVolume"`
	TradeCount    uint64 `json:"tradeCount"`
	LastTradeTime int64  `json:"lastTradeTime"`
}

GetStatsReply is the reply for the GetStats API.

type PerpetualsEngine added in v1.22.76

type PerpetualsEngine interface {
	GetMarket(symbol string) (interface{}, error)
	GetAllMarkets() []interface{}
	GetAccount(traderID ids.ID) (interface{}, error)
	GetPosition(traderID ids.ID, market string) (interface{}, error)
	GetAllPositions(traderID ids.ID) ([]interface{}, error)
	GetInsuranceFund() *big.Int
	GetMarginRatio(traderID ids.ID) (*big.Int, error)
}

PerpetualsEngine interface for perpetuals trading.

type PingArgs

type PingArgs struct{}

PingArgs is the argument for the Ping API.

type PingReply

type PingReply struct {
	Success bool `json:"success"`
}

PingReply is the reply for the Ping API.

type PlaceOrderArgs

type PlaceOrderArgs struct {
	Owner       string `json:"owner"` // hex-encoded address
	Symbol      string `json:"symbol"`
	Side        string `json:"side"` // "buy" or "sell"
	Type        string `json:"type"` // "limit", "market", etc.
	Price       uint64 `json:"price"`
	Quantity    uint64 `json:"quantity"`
	TimeInForce string `json:"timeInForce"` // "GTC", "IOC", "FOK"
	PostOnly    bool   `json:"postOnly"`
	ReduceOnly  bool   `json:"reduceOnly"`
}

PlaceOrderArgs is the argument for the PlaceOrder API.

type PlaceOrderReply

type PlaceOrderReply struct {
	OrderID   string             `json:"orderId"`
	Status    string             `json:"status"`
	FilledQty uint64             `json:"filledQty"`
	Trades    []*orderbook.Trade `json:"trades"`
}

PlaceOrderReply is the reply for the PlaceOrder API.

type RemoveLiquidityArgs

type RemoveLiquidityArgs struct {
	PoolID     string `json:"poolId"`
	Liquidity  string `json:"liquidity"`
	MinAmount0 string `json:"minAmount0"`
	MinAmount1 string `json:"minAmount1"`
}

RemoveLiquidityArgs is the argument for the RemoveLiquidity API.

type RemoveLiquidityReply

type RemoveLiquidityReply struct {
	Amount0 string `json:"amount0"`
	Amount1 string `json:"amount1"`
}

RemoveLiquidityReply is the reply for the RemoveLiquidity API.

type Service

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

Service provides the RPC API for the DEX VM.

func NewService

func NewService(vm VM) *Service

NewService creates a new API service.

func (*Service) AddLiquidity

func (s *Service) AddLiquidity(_ *http.Request, args *AddLiquidityArgs, reply *AddLiquidityReply) error

AddLiquidity adds liquidity to a pool.

func (*Service) CancelOrder

func (s *Service) CancelOrder(_ *http.Request, args *CancelOrderArgs, reply *CancelOrderReply) error

CancelOrder cancels an existing order.

func (*Service) GetADLEvents added in v1.22.76

func (s *Service) GetADLEvents(_ *http.Request, args *GetADLEventsArgs, reply *GetADLEventsReply) error

GetADLEvents returns recent ADL events.

func (*Service) GetADLStats added in v1.22.76

func (s *Service) GetADLStats(_ *http.Request, _ *GetADLStatsArgs, reply *GetADLStatsReply) error

GetADLStats returns ADL engine statistics.

func (*Service) GetADLStatus added in v1.22.76

func (s *Service) GetADLStatus(_ *http.Request, args *GetADLStatusArgs, reply *GetADLStatusReply) error

GetADLStatus returns ADL status for a symbol.

func (*Service) GetAccount added in v1.22.76

func (s *Service) GetAccount(_ *http.Request, args *GetAccountArgs, reply *GetAccountReply) error

GetAccount returns a trader's margin account.

func (*Service) GetCommitment added in v1.22.76

func (s *Service) GetCommitment(_ *http.Request, args *GetCommitmentArgs, reply *GetCommitmentReply) error

GetCommitment returns a commitment by hash.

func (*Service) GetCommitments added in v1.22.76

func (s *Service) GetCommitments(_ *http.Request, args *GetCommitmentsArgs, reply *GetCommitmentsReply) error

GetCommitments returns all pending commitments for a sender.

func (*Service) GetFundingRate added in v1.22.76

func (s *Service) GetFundingRate(_ *http.Request, args *GetFundingRateArgs, reply *GetFundingRateReply) error

GetFundingRate returns the funding rate for a perpetual market.

func (*Service) GetInsuranceFund added in v1.22.76

func (s *Service) GetInsuranceFund(_ *http.Request, _ *GetInsuranceFundArgs, reply *GetInsuranceFundReply) error

GetInsuranceFund returns the insurance fund balance.

func (*Service) GetMEVStats added in v1.22.76

func (s *Service) GetMEVStats(_ *http.Request, _ *GetMEVStatsArgs, reply *GetMEVStatsReply) error

GetMEVStats returns MEV protection statistics.

func (*Service) GetMarket added in v1.22.76

func (s *Service) GetMarket(_ *http.Request, args *GetMarketArgs, reply *GetMarketReply) error

GetMarket returns a specific perpetual market.

func (*Service) GetMarkets added in v1.22.76

func (s *Service) GetMarkets(_ *http.Request, _ *GetMarketsArgs, reply *GetMarketsReply) error

GetMarkets returns all perpetual markets.

func (*Service) GetOrder

func (s *Service) GetOrder(_ *http.Request, args *GetOrderArgs, reply *GetOrderReply) error

GetOrder returns an order by ID.

func (*Service) GetOrderbook

func (s *Service) GetOrderbook(_ *http.Request, args *GetOrderbookArgs, reply *GetOrderbookReply) error

GetOrderbook returns the current orderbook for a symbol.

func (*Service) GetPool

func (s *Service) GetPool(_ *http.Request, args *GetPoolArgs, reply *GetPoolReply) error

GetPool returns a specific liquidity pool.

func (*Service) GetPools

func (s *Service) GetPools(_ *http.Request, _ *GetPoolsArgs, reply *GetPoolsReply) error

GetPools returns all liquidity pools.

func (*Service) GetPosition added in v1.22.76

func (s *Service) GetPosition(_ *http.Request, args *GetPositionArgs, reply *GetPositionReply) error

GetPosition returns a trader's position for a market.

func (*Service) GetPositions added in v1.22.76

func (s *Service) GetPositions(_ *http.Request, args *GetPositionsArgs, reply *GetPositionsReply) error

GetPositions returns all positions for a trader.

func (*Service) GetQuote

func (s *Service) GetQuote(_ *http.Request, args *GetQuoteArgs, reply *GetQuoteReply) error

GetQuote returns a swap quote.

func (*Service) GetStats

func (s *Service) GetStats(_ *http.Request, args *GetStatsArgs, reply *GetStatsReply) error

GetStats returns trading statistics for a symbol.

func (*Service) Ping

func (s *Service) Ping(_ *http.Request, _ *PingArgs, reply *PingReply) error

Ping returns a simple health check response.

func (*Service) PlaceOrder

func (s *Service) PlaceOrder(_ *http.Request, args *PlaceOrderArgs, reply *PlaceOrderReply) error

PlaceOrder places a new order on the orderbook.

func (*Service) RemoveLiquidity

func (s *Service) RemoveLiquidity(_ *http.Request, args *RemoveLiquidityArgs, reply *RemoveLiquidityReply) error

RemoveLiquidity removes liquidity from a pool.

func (*Service) Status

func (s *Service) Status(_ *http.Request, _ *StatusArgs, reply *StatusReply) error

Status returns the DEX status.

func (*Service) Swap

func (s *Service) Swap(_ *http.Request, args *SwapArgs, reply *SwapReply) error

Swap executes a swap on a liquidity pool.

type StatusArgs

type StatusArgs struct{}

StatusArgs is the argument for the Status API.

type StatusReply

type StatusReply struct {
	Bootstrapped bool   `json:"bootstrapped"`
	Version      string `json:"version"`
	Uptime       int64  `json:"uptime"`
}

StatusReply is the reply for the Status API.

type SwapArgs

type SwapArgs struct {
	PoolID       string `json:"poolId"`
	TokenIn      string `json:"tokenIn"`
	AmountIn     string `json:"amountIn"`
	MinAmountOut string `json:"minAmountOut"`
}

SwapArgs is the argument for the Swap API.

type SwapReply

type SwapReply struct {
	AmountOut string `json:"amountOut"`
	Fee       string `json:"fee"`
}

SwapReply is the reply for the Swap API.

type VM

type VM interface {
	IsBootstrapped() bool
	GetOrderbook(symbol string) (*orderbook.Orderbook, error)
	GetOrCreateOrderbook(symbol string) *orderbook.Orderbook
	GetLiquidityManager() *liquidity.Manager
	GetPerpetualsEngine() PerpetualsEngine
	GetCommitmentStore() CommitmentStore
	GetADLEngine() ADLEngine
}

VM interface for the API service.

Jump to

Keyboard shortcuts

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