Documentation ¶
Index ¶
- Constants
- func Get(m []byte, i int64) bool
- func GetBit(b byte, i int64) bool
- func Len(m []byte) int
- func NewOrderBook(product *models.Product) *orderBook
- func NewSlice(l int64) []byte
- func Set(m []byte, i int64, v bool)
- func SetBit(b byte, i int64, v bool) byte
- func SetBitRef(b *byte, i int64, v bool)
- func StartEngine()
- type Base
- type Bitmap
- type BookOrder
- type DoneLog
- type Engine
- type KafkaLogReader
- type KafkaLogStore
- type KafkaOrderReader
- type Log
- type LogObserver
- type LogReader
- type LogStore
- type LogType
- type MatchLog
- type OpenLog
- type OrderReader
- type ReceivedLog
- type RedisSnapshotStore
- type Snapshot
- type SnapshotStore
- type Window
Constants ¶
View Source
const ( LogTypeMatch = LogType("match") LogTypeOpen = LogType("open") LogTypeDone = LogType("done") )
View Source
const (
TopicOrderPrefix = "matching_order_"
)
Variables ¶
This section is empty.
Functions ¶
func NewOrderBook ¶
func StartEngine ¶
func StartEngine()
Types ¶
type DoneLog ¶
type Engine ¶
type Engine struct { // engine持有的orderBook,和product对应,需要快照,并从快照中恢复 OrderBook *orderBook // contains filtered or unexported fields }
func NewEngine ¶
func NewEngine(product *models.Product, orderReader OrderReader, logStore LogStore, snapshotStore SnapshotStore) *Engine
type KafkaLogReader ¶
type KafkaLogReader struct {
// contains filtered or unexported fields
}
func (*KafkaLogReader) GetProductId ¶
func (r *KafkaLogReader) GetProductId() string
func (*KafkaLogReader) RegisterObserver ¶
func (r *KafkaLogReader) RegisterObserver(observer LogObserver)
func (*KafkaLogReader) Run ¶
func (r *KafkaLogReader) Run(seq, offset int64)
type KafkaLogStore ¶
type KafkaLogStore struct {
// contains filtered or unexported fields
}
func NewKafkaLogStore ¶
func NewKafkaLogStore(productId string, brokers []string) *KafkaLogStore
func (*KafkaLogStore) Store ¶
func (s *KafkaLogStore) Store(logs []interface{}) error
type KafkaOrderReader ¶
type KafkaOrderReader struct {
// contains filtered or unexported fields
}
func NewKafkaOrderReader ¶
func NewKafkaOrderReader(productId string, brokers []string) *KafkaOrderReader
func (*KafkaOrderReader) FetchOrder ¶
func (s *KafkaOrderReader) FetchOrder() (offset int64, order *models.Order, err error)
func (*KafkaOrderReader) SetOffset ¶
func (s *KafkaOrderReader) SetOffset(offset int64) error
type LogObserver ¶
type LogObserver interface { // 当读到OpenLog时回调 OnOpenLog(log *OpenLog, offset int64) // 当读到MatchLog时回调 OnMatchLog(log *MatchLog, offset int64) // 当读到DoneLog是回调 OnDoneLog(log *DoneLog, offset int64) }
撮合日志reader观察者
type LogReader ¶
type LogReader interface { // 获取当前的productId GetProductId() string // 注册一个日志观察者 RegisterObserver(observer LogObserver) // 开始执行读取log,读取到的log将会回调给观察者 Run(seq, offset int64) }
以观察者模式读取撮合日志
func NewKafkaLogReader ¶
type MatchLog ¶
type OpenLog ¶
type OrderReader ¶
type OrderReader interface { // 设置读取的起始offset SetOffset(offset int64) error // 拉取order FetchOrder() (offset int64, order *models.Order, err error) }
用于撮合引擎读取order,需要支持设置offset,从指定的offset开始读取
type ReceivedLog ¶
type ReceivedLog struct { Base OrderId int64 Size decimal.Decimal Price decimal.Decimal Side models.Side OrderType models.OrderType }
func (*ReceivedLog) GetSeq ¶
func (l *ReceivedLog) GetSeq() int64
type RedisSnapshotStore ¶
type RedisSnapshotStore struct {
// contains filtered or unexported fields
}
func (*RedisSnapshotStore) GetLatest ¶
func (s *RedisSnapshotStore) GetLatest() (*Snapshot, error)
func (*RedisSnapshotStore) Store ¶
func (s *RedisSnapshotStore) Store(snapshot *Snapshot) error
type Snapshot ¶
type Snapshot struct { OrderBookSnapshot orderBookSnapshot OrderOffset int64 }
快照是engine在某一时候的一致性内存状态
type SnapshotStore ¶
type SnapshotStore interface { // 保存快照 Store(snapshot *Snapshot) error // 获取最后一次快照 GetLatest() (*Snapshot, error) }
用于保存撮合引擎的快照
func NewRedisSnapshotStore ¶
func NewRedisSnapshotStore(productId string) SnapshotStore
Click to show internal directories.
Click to hide internal directories.