engine

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Add opType = iota + 1
	Delete
)

Variables

This section is empty.

Functions

func DepthComparator

func DepthComparator(a, b interface{}) int

DepthComparator 存储为从大到小

Types

type CancelResp

type CancelResp struct {
	//取消订单的id,如果不为空则表示取消订单。
	CancelId int64
	//币种id 取消买单则为计价币id,取消卖单则为基础币id
	CoinId int32
	//数量 取消买单则为计价币数量,取消卖单则为基础币数量
	Qty string
	//用户id
	Uid int64
}

type DepthData

type DepthData struct {
	Asks           []*Position
	Bids           []*Position
	LastVersion    int64
	CurrentVersion int64
}

type DepthHandler

type DepthHandler struct {
	ChangedPosition chan DepthData
	// contains filtered or unexported fields
}

func NewDepthHandler

func NewDepthHandler(version int64, c *config.Config, proxyClient ws.ProxyClient) *DepthHandler

type DepthPosition

type DepthPosition struct {
	Price string `json:"Price"`
	Qty   string `json:"qty"`
}

type Key

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

type MatchEngine

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

MatchEngine 撮合引擎

func NewMatchEngine

func NewMatchEngine(c *config.Config, producer pulsar.Producer, proxyClient ws.ProxyClient) *MatchEngine

func (*MatchEngine) GetDepth

func (m *MatchEngine) GetDepth(level int32) DepthData

func (*MatchEngine) HandleOrder

func (m *MatchEngine) HandleOrder(order *Order)

func (*MatchEngine) SendMatchResult

func (m *MatchEngine) SendMatchResult(matchResult *MatchResult)

SendMatchResult 发送撮合结果,这个操作不异步。

type MatchResult

type MatchResult struct {
	//每一次匹配的结构
	MatchedRecords []*MatchedRecord
	//本次撮合的id
	MatchID    string
	CancelResp *CancelResp
	//撮合时间
	MatchTime int64
	//taker为买单
	TakerIsBuy bool
}

type MatchedRecord

type MatchedRecord struct {
	Price           decimal.Decimal
	Qty             decimal.Decimal
	Amount          decimal.Decimal
	MatchedRecordID string
	//最新的taker订单的状态
	Taker Order
	//最新的maker订单的状态
	Maker Order
}

MatchedRecord 一次撮合匹配的结果,一次撮合会多次匹配

type Order

type Order struct {
	OrderID        string
	SequenceId     int64
	CreateTime     int64
	IsCancel       bool
	Uid            int64            //用户id
	Price          decimal.Decimal  //价格
	Qty            decimal.Decimal  //数量 市价单位零
	OrderType      enum.OrderType   //订单类型 市价单 限价单
	Amount         decimal.Decimal  //金额
	Side           enum.Side        //方向
	OrderStatus    enum.OrderStatus //订单状态
	UnfilledQty    decimal.Decimal  //未成交数量
	FilledQty      decimal.Decimal  //已成交数量
	UnfilledAmount decimal.Decimal  //未成交金额
	FilledAmount   decimal.Decimal  //成交金额
}

Order 订单

type OrderBook

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

OrderBook 订单簿

func NewOrderBook

func NewOrderBook(side enum.Side) *OrderBook

func (*OrderBook) PriceComparator

func (ob *OrderBook) PriceComparator(a, b interface{}) int

func (*OrderBook) String

func (ob *OrderBook) String() string

type Position

type Position struct {
	Qty    string
	Price  string
	Amount string
}

Jump to

Keyboard shortcuts

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