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

api

package
v1.22.10 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 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 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 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 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 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) 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) 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
}

VM interface for the API service.

Jump to

Keyboard shortcuts

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