From e5b3ce8de879b4313b7cf72cdeefe6b0aaa6113a Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Fri, 13 Jul 2018 11:20:29 +1000 Subject: [PATCH] Use WebsocketEvent in ws client and add timestamp to Tickers Fixes https://github.com/thrasher-/gocryptotrader/issues/137 --- exchanges/orderbook/orderbook.go | 4 ++++ exchanges/ticker/ticker.go | 8 ++++++++ tools/websocket_client/main.go | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/exchanges/orderbook/orderbook.go b/exchanges/orderbook/orderbook.go index bad3b49d..67033ff8 100644 --- a/exchanges/orderbook/orderbook.go +++ b/exchanges/orderbook/orderbook.go @@ -157,6 +157,10 @@ func CreateNewOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew B // ProcessOrderbook processes incoming orderbooks, creating or updating the // Orderbook list func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew Base, orderbookType string) { + if orderbookNew.Pair.Pair() == "" { + // set Pair if not set + orderbookNew.Pair = p + } orderbookNew.CurrencyPair = p.Pair().String() orderbookNew.LastUpdated = time.Now() diff --git a/exchanges/ticker/ticker.go b/exchanges/ticker/ticker.go index 3d5e012d..695374ce 100644 --- a/exchanges/ticker/ticker.go +++ b/exchanges/ticker/ticker.go @@ -4,6 +4,7 @@ import ( "errors" "strconv" "sync" + "time" "github.com/thrasher-/gocryptotrader/common" "github.com/thrasher-/gocryptotrader/currency/pair" @@ -27,6 +28,7 @@ var ( // Price struct stores the currency pair and pricing information type Price struct { Pair pair.CurrencyPair `json:"Pair"` + LastUpdated time.Time `json:"LastUpdated"` CurrencyPair string `json:"CurrencyPair"` Last float64 `json:"Last"` High float64 `json:"High"` @@ -148,7 +150,13 @@ func CreateNewTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, // ProcessTicker processes incoming tickers, creating or updating the Tickers // list func ProcessTicker(exchangeName string, p pair.CurrencyPair, tickerNew Price, tickerType string) { + if tickerNew.Pair.Pair() == "" { + // set Pair if not set + tickerNew.Pair = p + } + tickerNew.CurrencyPair = p.Pair().String() + tickerNew.LastUpdated = time.Now() if len(Tickers) == 0 { CreateNewTicker(exchangeName, p, tickerNew, tickerType) return diff --git a/tools/websocket_client/main.go b/tools/websocket_client/main.go index 4cb31fe1..70c980c3 100644 --- a/tools/websocket_client/main.go +++ b/tools/websocket_client/main.go @@ -179,7 +179,7 @@ func main() { log.Println("Got orderbook!") for { - var wsEvent WebsocketEventResponse + var wsEvent WebsocketEvent err = WSConn.ReadJSON(&wsEvent) if err != nil { break