dex

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Overview

Package dex provides GPU-accelerated DEX operations.

Uses dex_swap.* kernels from backend plugins for order matching and atomic swap execution.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidOrder = errors.New("dex: invalid order")
	ErrNoMatch      = errors.New("dex: no matching orders")
	ErrBookEmpty    = errors.New("dex: order book empty")
)

Functions

func BatchMatch

func BatchMatch(orderBooks [][]Order, incomingBatches [][]Order) ([][]Trade, error)

BatchMatch matches multiple order batches in parallel. Useful for high-frequency trading scenarios.

func MatchOrders

func MatchOrders(bids, asks []Order, incoming []Order) ([]Trade, []Order, error)

MatchOrders matches incoming orders against an order book. Uses GPU acceleration for parallel price-time priority matching. Returns executed trades and updated orders.

func Swap

func Swap(
	makerAsset, takerAsset []byte,
	makerAmount, takerAmount uint64,
	makerSig, takerSig []byte,
) ([]byte, error)

Swap executes an atomic swap between two parties. Uses dex_swap kernel for GPU-accelerated execution.

Types

type Level

type Level struct {
	Price      uint64
	Quantity   uint64
	OrderCount uint32
}

Level represents an aggregated order book level.

func AggregateBook

func AggregateBook(orders []Order, numLevels int) (bids, asks []Level, err error)

AggregateBook aggregates orders into price levels. GPU-accelerated for large order books.

type Order

type Order struct {
	ID        uint64
	UserID    uint64
	Price     uint64 // Fixed-point Q32.32 or similar
	Quantity  uint64
	Remaining uint64
	Timestamp uint64
	Side      Side
	Type      OrderType
}

Order represents a trading order.

type OrderType

type OrderType uint8

OrderType represents the order type.

const (
	Limit  OrderType = 0
	Market OrderType = 1
	IOC    OrderType = 2 // Immediate-or-Cancel
	FOK    OrderType = 3 // Fill-or-Kill
)

type Side

type Side uint8

Side represents order side (bid/ask).

const (
	Bid Side = 0
	Ask Side = 1
)

type Trade

type Trade struct {
	ID          uint64
	MakerID     uint64
	TakerID     uint64
	MakerUserID uint64
	TakerUserID uint64
	Price       uint64
	Quantity    uint64
	Timestamp   uint64
	TakerSide   Side
}

Trade represents an executed trade.

Jump to

Keyboard shortcuts

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