From fc47d705ca70bfcb4c5add2964951ae20f8f53dc Mon Sep 17 00:00:00 2001 From: Frederick MARINHO Date: Tue, 24 Apr 2018 02:17:43 +0200 Subject: [PATCH 1/2] I had to modify this shit --- binance/.DS_Store | Bin 0 -> 6148 bytes binance/market.go | 9 +++++++++ 2 files changed, 9 insertions(+) create mode 100644 binance/.DS_Store diff --git a/binance/.DS_Store b/binance/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..671a4153c82e2a7e9d586545e4c1cb4bca0971ce GIT binary patch literal 6148 zcmeHKu};G<5WRyU(!x;60AofbBxaVVDg!eg0Bwm-McM!%5@QDV2Y!L?;{)K`*+85I z!2&|)uCkwF-#gnc%DE;Y9+u|^M13NPPy{A*JFi2ZS-` zun}XsHAX>KSjhrWQkO{@QJxx6dNiRK{KqKMb`C!@I9+&VV5J}VDx8I%8;o`JEot7m zCfV6zO`QndcUaLJd&$r)!ssM>sQY)}IfjCl@b&pKWaxV8jIDt24fXX6)*}pBB7C7e z-#6C1hSj?F-P|D*;V4j~gzpS$6s-zEk-#4lnfQ_A|4; zp|H-5__4YZCl0MP1x$fZfmQd|m-GMV^ZS2DvL{o(6!=#PaA$Nf8e&WSY+c%%oV78^ r8H$+rRSuPc${)wtkfV4PMGa%IG=Pc6${~7S_D4Wvu*wwpRRvxFl^49@ literal 0 HcmV?d00001 diff --git a/binance/market.go b/binance/market.go index 206930f..9a9ca16 100644 --- a/binance/market.go +++ b/binance/market.go @@ -70,6 +70,15 @@ func (b *Binance) Get24Hr(q SymbolQuery) (changeStats ChangeStats, err error) { return } +// 24 hour price for all statistics +func (b *Binance) GetAll24Hr(q SymbolQuery) (changeStats []ChangeStats, err error) { + + reqUrl := fmt.Sprintf("api/v1/ticker/24hr") + _, err = b.client.do("GET", reqUrl, "", false, &changeStats) + + return +} + // Latest price for all symbols. func (b *Binance) GetAllPrices() (prices []TickerPrice, err error) { From 06d566ce860bd93236e1b134e7f2e1e7aae7ec37 Mon Sep 17 00:00:00 2001 From: Frederick MARINHO Date: Thu, 26 Apr 2018 06:29:45 +0200 Subject: [PATCH 2/2] . --- binance/examples/ticker.go | 58 ++++++++++++++++++++++++++++++++++++++ binance/market_response.go | 1 + 2 files changed, 59 insertions(+) create mode 100644 binance/examples/ticker.go diff --git a/binance/examples/ticker.go b/binance/examples/ticker.go new file mode 100644 index 0000000..e751e47 --- /dev/null +++ b/binance/examples/ticker.go @@ -0,0 +1,58 @@ +package main + +import ( + //"sync" + //"strings" + "encoding/json" + "fmt" + "log" + + "github.com/gorilla/websocket" +) + +const ( + MaxQueue = 100 // Size of message queue +) + +type ChangeStats struct { + Symbol string `json:"s"` + PriceChange string `json:"p"` + PriceChangePercent string `json:"P"` + WeightedAvgPrice string `json:"w"` + PrevClosePrice string `json:"x"` + BidPrice string `json:"b"` + AskPrice string `json:"a"` + HighPrice string `json:"h"` + Volume string `json:"v"` +} + +func main() { + + address := fmt.Sprintf("wss://stream.binance.com:9443/ws/!ticker@arr") + + var wsDialer websocket.Dialer + wsConn, _, err := wsDialer.Dial(address, nil) + if err != nil { + panic(err) + } + defer wsConn.Close() + log.Println("Dialed:", address) + + for { + _, message, err := wsConn.ReadMessage() + + if err != nil { + log.Println("[ERROR] ReadMessage:", err) + } + + var msg []ChangeStats + fmt.Println("Received message !") + + err = json.Unmarshal(message, &msg) + if err != nil { + log.Println("[ERROR] Parsing:", err) + continue + } + fmt.Println(msg) + } +} diff --git a/binance/market_response.go b/binance/market_response.go index 4e25c06..c502215 100644 --- a/binance/market_response.go +++ b/binance/market_response.go @@ -48,6 +48,7 @@ func (o *Order) UnmarshalJSON(b []byte) error { // Result from: GET /api/v1/ticker/24hr type ChangeStats struct { + Symbol string `json:"symbol, string"` PriceChange float64 `json:"priceChange,string"` PriceChangePercent float64 `json:"priceChangePercent,string"` WeightedAvgPrice float64 `json:"weightedAvgPrice,string"`