Skip to content

Commit

Permalink
remove BCH-BTC and BCH-EUR
Browse files Browse the repository at this point in the history
  • Loading branch information
lian committed Jan 17, 2018
1 parent 93e82ab commit 4d9c4f8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cd $GOPATH/src/github.com/lian/gdax-bookmap
## current controls

```
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
1/2/3/4/5/6/7 selects BTC-USD, BTC-EUR, LTC--USD, ETH-USD, LTC-BTC, ETH-BTC, BCH-USD
q/esc to quit
c center the graph to last price
p enable auto center
Expand Down
18 changes: 1 addition & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,6 @@ 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.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 @@ -304,9 +290,7 @@ func main() {

bookUpdated := make(chan string, 1024)
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", "BCH-USD", "BCH-BTC", "BCH-EUR"}, bookUpdated, tradesUpdated)
gdax = websocket.New([]string{"BTC-USD", "BTC-EUR", "LTC-USD", "ETH-USD", "ETH-BTC", "LTC-BTC", "BCH-USD"}, bookUpdated, tradesUpdated)
go gdax.Run()

orderbooks = map[string]*opengl_orderbook.Orderbook{}
Expand Down
4 changes: 2 additions & 2 deletions opengl/bookmap/bookmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func New(program *shader.Program, width, height float64, x float64, book *orderb
Height: height,
},
}
s.PriceSteps = float64(s.Book.ProductInfo.QuoteIncrement) * 10
s.PriceSteps = float64(s.Book.ProductInfo.QuoteIncrement) * 50
if program != nil {
s.Texture.Setup(program)
}
Expand All @@ -61,7 +61,7 @@ func New(program *shader.Program, width, height float64, x float64, book *orderb

func (s *Bookmap) SetBook(book *orderbook.Book) {
s.Book = book
s.PriceSteps = float64(s.Book.ProductInfo.QuoteIncrement) * 10
s.PriceSteps = float64(s.Book.ProductInfo.QuoteIncrement) * 50
s.PriceScrollPosition = 0
s.MaxSizeHisto = 0
s.Graph.ProductID = book.ID
Expand Down
18 changes: 8 additions & 10 deletions opengl/trades/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,23 @@ func (s *Trades) Render() {
timePadding := pricePadding + (font.Width * 12)
lineHeight := font.Height + 2

var latestPrice float64
i := len(book.Trades)
if i > 0 {
latestPrice = book.Trades[i-1].Price
font.DrawString(data, 10, 5, fmt.Sprintf("%s %.2f", book.ID, latestPrice), fg1)
} else {
font.DrawString(data, 10, 5, book.ID, fg1)
}
font.DrawString(data, 10, 5, fmt.Sprintf("%s %.2f", book.ID, book.LastPrice()), fg1)

limit := (int(s.Texture.Height) / lineHeight) - 3
tradesCount := len(book.Trades)

book.MuTrades.Lock()
trades := book.Trades
book.MuTrades.Unlock()

tradesCount := len(trades)
if tradesCount < limit {
limit = tradesCount
}

x := 0
y := lineHeight * 2
for i := tradesCount - 1; i >= (tradesCount - limit); i-- {
trade := book.Trades[i]
trade := trades[i]

var fg color.Color
if trade.Side == orderbook.BidSide {
Expand Down
6 changes: 6 additions & 0 deletions orderbook/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package orderbook
import (
"fmt"
"sort"
"sync"
"time"
)

Expand Down Expand Up @@ -99,6 +100,7 @@ type Book struct {
SkipStatsUpdate bool
AlwaysSort bool
ProductInfo ProductInfo
MuTrades sync.Mutex
}

func New(id string) *Book {
Expand Down Expand Up @@ -463,6 +465,8 @@ func (b *Book) Match(data map[string]interface{}, change bool) {
}

func (b *Book) LastPrice() float64 {
b.MuTrades.Lock()
defer b.MuTrades.Unlock()
var lastPrice float64
i := len(b.Trades)
if i > 0 {
Expand All @@ -474,6 +478,7 @@ func (b *Book) LastPrice() float64 {
}

func (b *Book) AddTrade(match *Order) {
b.MuTrades.Lock()
//fmt.Println("trade", match)
if len(b.Trades) >= 50 {
// remove and free first item
Expand All @@ -482,6 +487,7 @@ func (b *Book) AddTrade(match *Order) {
b.Trades = b.Trades[:len(b.Trades)-1]
}
b.Trades = append(b.Trades, match)
b.MuTrades.Unlock()

if b.TradesUpdated != nil {
b.TradesUpdated <- b.ID
Expand Down

0 comments on commit 4d9c4f8

Please sign in to comment.