mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
types: add lastUpdateTime field
This commit is contained in:
parent
915f2c7476
commit
2aeb9e870c
|
@ -4,6 +4,7 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/c9s/bbgo/pkg/sigchan"
|
||||
|
@ -13,6 +14,7 @@ type OrderBook interface {
|
|||
Spread() (fixedpoint.Value, bool)
|
||||
BestAsk() (PriceVolume, bool)
|
||||
BestBid() (PriceVolume, bool)
|
||||
LastUpdateTime() time.Time
|
||||
Reset()
|
||||
Load(book SliceOrderBook)
|
||||
Update(book SliceOrderBook)
|
||||
|
|
|
@ -14,7 +14,8 @@ type RBTOrderBook struct {
|
|||
Symbol string
|
||||
Bids *RBTree
|
||||
Asks *RBTree
|
||||
LastUpdateTime time.Time
|
||||
|
||||
lastUpdateTime time.Time
|
||||
|
||||
loadCallbacks []func(book *RBTOrderBook)
|
||||
updateCallbacks []func(book *RBTOrderBook)
|
||||
|
@ -28,6 +29,10 @@ func NewRBOrderBook(symbol string) *RBTOrderBook {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *RBTOrderBook) LastUpdateTime() time.Time {
|
||||
return b.lastUpdateTime
|
||||
}
|
||||
|
||||
func (b *RBTOrderBook) BestBid() (PriceVolume, bool) {
|
||||
right := b.Bids.Rightmost()
|
||||
if right != nil {
|
||||
|
@ -118,14 +123,14 @@ func (b *RBTOrderBook) updateBids(pvs PriceVolumeSlice) {
|
|||
func (b *RBTOrderBook) update(book SliceOrderBook) {
|
||||
b.updateBids(book.Bids)
|
||||
b.updateAsks(book.Asks)
|
||||
b.LastUpdateTime = time.Now()
|
||||
b.lastUpdateTime = time.Now()
|
||||
}
|
||||
|
||||
func (b *RBTOrderBook) load(book SliceOrderBook) {
|
||||
b.Reset()
|
||||
b.updateBids(book.Bids)
|
||||
b.updateAsks(book.Asks)
|
||||
b.LastUpdateTime = time.Now()
|
||||
b.lastUpdateTime = time.Now()
|
||||
}
|
||||
|
||||
func (b *RBTOrderBook) Copy() OrderBook {
|
||||
|
|
|
@ -3,9 +3,11 @@ package types
|
|||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SliceOrderBook is a general order book structure which could be used
|
||||
|
@ -16,6 +18,8 @@ type SliceOrderBook struct {
|
|||
Bids PriceVolumeSlice
|
||||
Asks PriceVolumeSlice
|
||||
|
||||
lastUpdateTime time.Time
|
||||
|
||||
loadCallbacks []func(book *SliceOrderBook)
|
||||
updateCallbacks []func(book *SliceOrderBook)
|
||||
}
|
||||
|
@ -26,6 +30,10 @@ func NewSliceOrderBook(symbol string) *SliceOrderBook {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *SliceOrderBook) LastUpdateTime() time.Time {
|
||||
return b.lastUpdateTime
|
||||
}
|
||||
|
||||
func (b *SliceOrderBook) Spread() (fixedpoint.Value, bool) {
|
||||
bestBid, ok := b.BestBid()
|
||||
if !ok {
|
||||
|
@ -125,6 +133,7 @@ func (b *SliceOrderBook) updateBids(pvs PriceVolumeSlice) {
|
|||
func (b *SliceOrderBook) update(book SliceOrderBook) {
|
||||
b.updateBids(book.Bids)
|
||||
b.updateAsks(book.Asks)
|
||||
b.lastUpdateTime = time.Now()
|
||||
}
|
||||
|
||||
func (b *SliceOrderBook) Reset() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user