Skip to content

Commit

Permalink
add ShowDebug and AutoHistoSize flag to Bookmap
Browse files Browse the repository at this point in the history
  • Loading branch information
lian committed May 5, 2017
1 parent baff588 commit fc3a962
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
14 changes: 11 additions & 3 deletions opengl/bookmap/bookmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Bookmap struct {
Graph *Graph
Image *image.RGBA
IgnoreTexture bool
ShowDebug bool
AutoHistoSize bool
}

func New(program *shader.Program, width, height float64, x float64, book *orderbook.Book, gdax *websocket.Client) *Bookmap {
Expand All @@ -40,6 +42,7 @@ func New(program *shader.Program, width, height float64, x float64, book *orderb
RowHeight: 14,
ColumnWidth: 4,
ViewportStep: 1,
ShowDebug: true,
Texture: &texture.Texture{
X: x,
Y: height + 10,
Expand Down Expand Up @@ -139,7 +142,7 @@ func (s *Bookmap) Render() {
statsSlot := NewTimeSlot(s, now, now)
stats := s.Graph.Book.Book.StateAsStats()
statsSlot.Fill(stats)
if s.MaxSizeHisto == 0 {
if s.MaxSizeHisto == 0 || s.AutoHistoSize {
s.MaxSizeHisto = round(statsSlot.MaxSize/2, 0)
}

Expand Down Expand Up @@ -205,14 +208,19 @@ func (s *Bookmap) Render() {
}

s.RenderDebug(now)
s.DrawString(10, 5, fmt.Sprintf("%s %s", s.Book.ID, s.Book.ProductInfo.FormatFloat(s.Graph.Book.Book.LastPrice())), fg1)

s.WriteTexture()
}

func (s *Bookmap) RenderDebug(now time.Time) {
if !s.ShowDebug {
return
}

fg1 := color.RGBA{0xdd, 0xdf, 0xe1, 0xff}

s.DrawString(10, 5, fmt.Sprintf(
s.DrawString(10, 25, fmt.Sprintf(
"%s PriceScrollPos %s PriceSteps %s MaxSizeHisto %.2f ColumnWidth %.0f ViewportStep %d",
s.Book.ID,
s.Book.ProductInfo.FormatFloat(s.PriceScrollPosition),
Expand All @@ -222,5 +230,5 @@ func (s *Bookmap) RenderDebug(now time.Time) {
s.ViewportStep,
), fg1)

s.DrawString(10, 25, fmt.Sprintf("graph-time-diff: %s", now.Sub(s.Graph.CurrentTime)), fg1)
s.DrawString(10, 40, fmt.Sprintf("graph-time-diff: %s", now.Sub(s.Graph.CurrentTime)), fg1)
}
11 changes: 11 additions & 0 deletions orderbook/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,17 @@ func (b *Book) Match(data map[string]interface{}, change bool) {
}
}

func (b *Book) LastPrice() float64 {
var lastPrice float64
i := len(b.Trades)
if i > 0 {
lastPrice = b.Trades[i-1].Price
} else {
lastPrice = b.CenterPrice()
}
return lastPrice
}

func (b *Book) AddTrade(match *Order) {
//fmt.Println("trade", match)
if len(b.Trades) >= 50 {
Expand Down

0 comments on commit fc3a962

Please sign in to comment.