Skip to content

Commit

Permalink
Start websocket implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Sep 11, 2017
1 parent 89848eb commit a1040c8
Show file tree
Hide file tree
Showing 25 changed files with 738 additions and 125 deletions.
25 changes: 17 additions & 8 deletions exchanges/alphapoint/alphapoint_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package alphapoint

import (
"log"

"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
Expand Down Expand Up @@ -30,21 +28,32 @@ func (a *Alphapoint) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
return response, nil
}

// GetTickerPrice returns the current ticker price by currency pair
func (a *Alphapoint) GetTickerPrice(p pair.CurrencyPair) ticker.TickerPrice {
func (a *Alphapoint) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := a.GetTicker(p.Pair().String())
if err != nil {
log.Println(err)
return ticker.TickerPrice{}
return tickerPrice, err
}

tickerPrice.Pair = p
tickerPrice.Ask = tick.Ask
tickerPrice.Bid = tick.Bid
return tickerPrice
tickerPrice.Low = tick.Low
tickerPrice.High = tick.High
tickerPrice.Volume = tick.Volume
tickerPrice.Last = tick.Last
ticker.ProcessTicker(a.GetName(), p, tickerPrice)
return tickerPrice, nil
}

func (a *Alphapoint) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(a.GetName(), p)
if err != nil {
return a.UpdateTicker(p)
}
return tick, nil
}

// GetOrderbookEx returns an orderbookbase by currency pair
func (a *Alphapoint) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(a.GetName(), p)
if err == nil {
Expand Down
17 changes: 10 additions & 7 deletions exchanges/anx/anx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (a *ANX) Run() {
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := a.GetTickerPrice(currency)
ticker, err := a.UpdateTicker(currency)
if err != nil {
log.Println(err)
return
Expand All @@ -40,12 +40,7 @@ func (a *ANX) Run() {
}
}

func (a *ANX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(a.GetName(), p)
if err == nil {
return tickerNew, nil
}

func (a *ANX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := a.GetTicker(p.Pair().String())
if err != nil {
Expand Down Expand Up @@ -111,6 +106,14 @@ func (a *ANX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
return tickerPrice, nil
}

func (a *ANX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(a.GetName(), p)
if err != nil {
return a.UpdateTicker(p)
}
return tickerNew, nil
}

func (e *ANX) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
return orderbook.OrderbookBase{}, nil
}
Expand Down
20 changes: 11 additions & 9 deletions exchanges/bitfinex/bitfinex_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (b *Bitfinex) Run() {
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
ticker, err := b.UpdateTicker(currency)
if err != nil {
return
}
Expand All @@ -56,18 +56,13 @@ func (b *Bitfinex) Run() {
}
}

// GetTickerPrice returns ticker information
func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(b.GetName(), p)
if err == nil {
return tick, nil
}

func (b *Bitfinex) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tickerNew, err := b.GetTicker(p.Pair().String(), nil)
if err != nil {
return tickerPrice, err
}

tickerPrice.Pair = p
tickerPrice.Ask = tickerNew.Ask
tickerPrice.Bid = tickerNew.Bid
Expand All @@ -79,7 +74,14 @@ func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, erro
return tickerPrice, nil
}

// GetOrderbookEx returns orderbook information based on currency pair
func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(b.GetName(), p)
if err != nil {
return b.UpdateTicker(p)
}
return tick, nil
}

func (b *Bitfinex) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), p)
if err == nil {
Expand Down
19 changes: 10 additions & 9 deletions exchanges/bitstamp/bitstamp_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (b *Bitstamp) Run() {
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
ticker, err := b.UpdateTicker(currency)
if err != nil {
log.Println(err)
return
Expand All @@ -47,13 +47,7 @@ func (b *Bitstamp) Run() {
}
}

// GetTickerPrice returns ticker price information
func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p)
if err == nil {
return tickerNew, nil
}

func (b *Bitstamp) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := b.GetTicker(p.Pair().String(), false)
if err != nil {
Expand All @@ -71,7 +65,14 @@ func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, erro
return tickerPrice, nil
}

// GetOrderbookEx returns base orderbook information
func (b *Bitstamp) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(b.GetName(), p)
if err != nil {
return b.UpdateTicker(p)
}
return tick, nil
}

func (b *Bitstamp) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), p)
if err == nil {
Expand Down
18 changes: 10 additions & 8 deletions exchanges/btcc/btcc_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (b *BTCC) Run() {
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
ticker, err := b.UpdateTicker(currency)
if err != nil {
log.Println(err)
return
Expand All @@ -45,18 +45,12 @@ func (b *BTCC) Run() {
}
}

func (b *BTCC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p)
if err == nil {
return tickerNew, nil
}

func (b *BTCC) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := b.GetTicker(exchange.FormatExchangeCurrency(b.GetName(), p).String())
if err != nil {
return tickerPrice, err
}

tickerPrice.Pair = p
tickerPrice.Ask = tick.Sell
tickerPrice.Bid = tick.Buy
Expand All @@ -68,6 +62,14 @@ func (b *BTCC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
return tickerPrice, nil
}

func (b *BTCC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p)
if err != nil {
return b.UpdateTicker(p)
}
return tickerNew, nil
}

func (b *BTCC) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), p)
if err == nil {
Expand Down
17 changes: 15 additions & 2 deletions exchanges/btce/btce_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ func (b *BTCE) Run() {
}
}

func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
func (b *BTCE) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, ok := b.Ticker[exchange.FormatExchangeCurrency(b.Name, p).String()]
result, err := b.GetTicker(p.Pair().String())
if err != nil {
return tickerPrice, err
}

tick, ok := result[p.Pair().Lower().String()]
if !ok {
return tickerPrice, errors.New("unable to get currency")
}
Expand All @@ -67,6 +72,14 @@ func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
return tickerPrice, nil
}

func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(b.GetName(), p)
if err != nil {
return b.UpdateTicker(p)
}
return tick, nil
}

func (b *BTCE) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), p)
if err == nil {
Expand Down
17 changes: 9 additions & 8 deletions exchanges/btcmarkets/btcmarkets_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (b *BTCMarkets) Run() {
for x := range pairs {
curr := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(curr)
ticker, err := b.UpdateTicker(curr)
if err != nil {
return
}
Expand All @@ -73,13 +73,7 @@ func (b *BTCMarkets) Run() {
}
}

// GetTickerPrice returns ticker information
func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p)
if err == nil {
return tickerNew, nil
}

func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := b.GetTicker(p.GetFirstCurrency().String())
if err != nil {
Expand All @@ -92,6 +86,13 @@ func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, er
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
return tickerPrice, nil
}
func (b *BTCMarkets) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(b.GetName(), p)
if err != nil {
return b.UpdateTicker(p)
}
return tickerNew, nil
}

// GetOrderbookEx returns orderbook base on the currency pair
func (b *BTCMarkets) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
Expand Down
18 changes: 11 additions & 7 deletions exchanges/coinut/coinut_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *COINUT) Run() {
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := c.GetTickerPrice(currency)
ticker, err := c.UpdateTicker(currency)
if err != nil {
log.Println(err)
return
Expand Down Expand Up @@ -84,12 +84,7 @@ func (c *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
return response, nil
}

func (c *COINUT) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(c.GetName(), p)
if err == nil {
return tickerNew, nil
}

func (c *COINUT) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := c.GetInstrumentTicker(c.InstrumentMap[p.Pair().String()])
if err != nil {
Expand All @@ -103,6 +98,15 @@ func (c *COINUT) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error)
tickerPrice.Low = tick.LowestSell
ticker.ProcessTicker(c.GetName(), p, tickerPrice)
return tickerPrice, nil

}

func (c *COINUT) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(c.GetName(), p)
if err != nil {
return c.UpdateTicker(p)
}
return tickerNew, nil
}

func (c *COINUT) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
Expand Down
1 change: 1 addition & 0 deletions exchanges/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type IBotExchange interface {
GetName() string
IsEnabled() bool
GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error)
UpdateTicker(currency pair.CurrencyPair) (ticker.TickerPrice, error)
GetOrderbookEx(currency pair.CurrencyPair) (orderbook.OrderbookBase, error)
GetEnabledCurrencies() []pair.CurrencyPair
GetExchangeAccountInfo() (AccountInfo, error)
Expand Down
17 changes: 10 additions & 7 deletions exchanges/gdax/gdax_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (g *GDAX) Run() {
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := g.GetTickerPrice(currency)
ticker, err := g.UpdateTicker(currency)

if err != nil {
log.Println(err)
Expand Down Expand Up @@ -81,12 +81,7 @@ func (g *GDAX) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
return response, nil
}

func (g *GDAX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(g.GetName(), p)
if err == nil {
return tickerNew, nil
}

func (g *GDAX) UpdateTicker(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, err := g.GetTicker(exchange.FormatExchangeCurrency(g.Name, p).String())
if err != nil {
Expand All @@ -108,6 +103,14 @@ func (g *GDAX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
return tickerPrice, nil
}

func (g *GDAX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tickerNew, err := ticker.GetTicker(g.GetName(), p)
if err != nil {
return g.UpdateTicker(p)
}
return tickerNew, nil
}

func (g *GDAX) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(g.GetName(), p)
if err == nil {
Expand Down
Loading

0 comments on commit a1040c8

Please sign in to comment.