Skip to content

Commit

Permalink
add bch orderbooks
Browse files Browse the repository at this point in the history
  • Loading branch information
lian committed Dec 21, 2017
1 parent d293adb commit 93e82ab
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ cd $GOPATH/src/github.com/lian/gdax-bookmap
## current controls

```
1/2/3/4/5/6 selects BTC-USD, BTC-EUR, LTC--USD, ETH-USD, LTC-BTC and ETH-BTC
1/2/3/4/5/6/7/8/9 selects BTC-USD, BTC-EUR, LTC--USD, ETH-USD, LTC-BTC, ETH-BTC, BCH-USD, BCH-BTC, BCH-EUR
q/esc to quit
c center the graph to last price
p enable auto center
up/down to change the price steps (aka price zoom) (PriceSteps)
w/s to change the graph price position (PriceScrollPosition)
j/k to change the volume chunks brightness (MaxSizeHisto)
w/s to change the graph price position (PriceScrollPosition)
a/d to change how many seconds a chunk contains (aka time zoom) (ViewportStep)
left/right to change the column withd of volume chunks (ColumnWidth)
c to try to center the graph by last price/trade (buggy)
left/right to change the column width of volume chunks (ColumnWidth)
```
26 changes: 25 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ func keyCallback(window *glfw.Window, key glfw.Key, scancode int, action glfw.Ac
orderbooks[ActiveProduct].ID = newID
trades[ActiveProduct].ID = newID
trades[ActiveProduct].Render()
} else if key == glfw.Key7 && action == glfw.Press {
newID := "BCH-USD"
bm := bookmaps[ActiveProduct]
bm.SetBook(gdax.Books[newID])
orderbooks[ActiveProduct].ID = newID
trades[ActiveProduct].ID = newID
trades[ActiveProduct].Render()
} else if key == glfw.Key8 && action == glfw.Press {
newID := "BCH-BTC"
bm := bookmaps[ActiveProduct]
bm.SetBook(gdax.Books[newID])
orderbooks[ActiveProduct].ID = newID
trades[ActiveProduct].ID = newID
trades[ActiveProduct].Render()
} else if key == glfw.Key9 && action == glfw.Press {
newID := "BCH-EUR"
bm := bookmaps[ActiveProduct]
bm.SetBook(gdax.Books[newID])
orderbooks[ActiveProduct].ID = newID
trades[ActiveProduct].ID = newID
trades[ActiveProduct].Render()
} else if key == glfw.KeyS && action == glfw.Press {
bm := bookmaps[ActiveProduct]
bm.PriceScrollPosition += bm.PriceSteps
Expand Down Expand Up @@ -158,6 +179,9 @@ func keyCallback(window *glfw.Window, key glfw.Key, scancode int, action glfw.Ac
bm.PriceScrollPosition = 0.0
bm.InitPriceScrollPosition()
bm.Graph.ClearSlotRows()
} else if key == glfw.KeyP && action == glfw.Press {
bm := bookmaps[ActiveProduct]
bm.AutoScroll = !bm.AutoScroll
} else if key == glfw.KeyR && action == glfw.Press {
bm := bookmaps[ActiveProduct]
bm.MaxSizeHisto = 0.0
Expand Down Expand Up @@ -282,7 +306,7 @@ func main() {
tradesUpdated := make(chan string)
//gdax := websocket.New([]string{ActiveProduct}, bookUpdated, tradesUpdated)
//gdax = websocket.New([]string{"BTC-USD", "BTC-EUR", "LTC-USD", "ETH-USD"}, bookUpdated, tradesUpdated)
gdax = websocket.New([]string{"BTC-USD", "BTC-EUR", "LTC-USD", "ETH-USD", "ETH-BTC", "LTC-BTC"}, bookUpdated, tradesUpdated)
gdax = websocket.New([]string{"BTC-USD", "BTC-EUR", "LTC-USD", "ETH-USD", "ETH-BTC", "LTC-BTC", "BCH-USD", "BCH-BTC", "BCH-EUR"}, bookUpdated, tradesUpdated)
go gdax.Run()

orderbooks = map[string]*opengl_orderbook.Orderbook{}
Expand Down
25 changes: 25 additions & 0 deletions opengl/bookmap/bookmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Bookmap struct {
IgnoreTexture bool
ShowDebug bool
AutoHistoSize bool
AutoScroll bool
}

func New(program *shader.Program, width, height float64, x float64, book *orderbook.Book, gdax *websocket.Client) *Bookmap {
Expand Down Expand Up @@ -94,6 +95,29 @@ func (s *Bookmap) InitPriceScrollPosition() {
}
}

func (s *Bookmap) DoAutoScroll() {
if !s.AutoScroll {
return
}

if s.Graph == nil {
return
}

rowsCount := s.Texture.Height / s.RowHeight

last := s.PriceScrollPosition

//price := s.Graph.Book.Book.LastPrice()
price := s.Graph.Book.Book.CenterPrice()
if price != 0.0 {
s.PriceScrollPosition = (price - math.Mod(price, s.PriceSteps)) + (float64(rowsCount/2) * s.PriceSteps)
if last != s.PriceScrollPosition {
s.Graph.ClearSlotRows()
}
}
}

func (s *Bookmap) WriteTexture() {
if s.IgnoreTexture {
return
Expand Down Expand Up @@ -132,6 +156,7 @@ func (s *Bookmap) Render() {
}

s.InitPriceScrollPosition()
s.DoAutoScroll()
x := s.Texture.Width - 80

if !s.Graph.SetEnd(now) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/cross-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -x
mkdir -p builds/tmp
cd builds/tmp

version=0.0.2
version=0.0.3
githash=$(git rev-parse HEAD)

/opt/bin/xgo -v -x -ldflags "-X main.AppVersion=$version -X main.AppGitHash=$githash" --targets=darwin/amd64,windows/386 ../../../
Expand Down

0 comments on commit 93e82ab

Please sign in to comment.