Add currency pair support

This commit is contained in:
Adrian Gallagher
2017-04-18 23:16:18 +10:00
parent 7457a7a209
commit d526e9f2a9
23 changed files with 484 additions and 320 deletions

View File

@@ -6,6 +6,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
"github.com/thrasher-/gocryptotrader/exchanges/stats"
@@ -39,51 +40,50 @@ func (b *Bitfinex) Run() {
for b.Enabled {
for _, x := range b.EnabledPairs {
currency := x
currency := pair.NewCurrencyPair(x[0:3], x[3:])
go func() {
ticker, err := b.GetTickerPrice(currency)
if err != nil {
return
}
log.Printf("Bitfinex %s Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
stats.AddExchangeInfo(b.GetName(), currency[0:3], currency[3:], ticker.Last, ticker.Volume)
log.Printf("Bitfinex %s Last %f High %f Low %f Volume %f\n", currency.Pair().String(), ticker.Last, ticker.High, ticker.Low, ticker.Volume)
stats.AddExchangeInfo(b.GetName(), currency.GetFirstCurrency().String(), currency.GetSecondCurrency().String(), ticker.Last, ticker.Volume)
}()
}
time.Sleep(time.Second * b.RESTPollingDelay)
}
}
func (b *Bitfinex) GetTickerPrice(currency string) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(b.GetName(), currency[0:3], currency[3:])
func (b *Bitfinex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
tick, err := ticker.GetTicker(b.GetName(), p)
if err == nil {
return tick, nil
}
var tickerPrice ticker.TickerPrice
tickerNew, err := b.GetTicker(currency, nil)
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
tickerPrice.FirstCurrency = currency[0:3]
tickerPrice.SecondCurrency = currency[3:]
tickerPrice.Low = tickerNew.Low
tickerPrice.Last = tickerNew.Last
tickerPrice.Volume = tickerNew.Volume
tickerPrice.High = tickerNew.High
ticker.ProcessTicker(b.GetName(), tickerPrice.FirstCurrency, tickerPrice.SecondCurrency, tickerPrice)
ticker.ProcessTicker(b.GetName(), p, tickerPrice)
return tickerPrice, nil
}
func (b *Bitfinex) GetOrderbookEx(currency string) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), currency[0:3], currency[3:])
func (b *Bitfinex) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
ob, err := orderbook.GetOrderbook(b.GetName(), p)
if err == nil {
return ob, nil
}
var orderBook orderbook.OrderbookBase
orderbookNew, err := b.GetOrderbook(currency, nil)
orderbookNew, err := b.GetOrderbook(p.Pair().String(), nil)
if err != nil {
return orderBook, err
}
@@ -100,9 +100,8 @@ func (b *Bitfinex) GetOrderbookEx(currency string) (orderbook.OrderbookBase, err
orderBook.Bids = append(orderBook.Bids, orderbook.OrderbookItem{Price: price, Amount: amount})
}
orderBook.FirstCurrency = currency[0:3]
orderBook.SecondCurrency = currency[3:]
orderbook.ProcessOrderbook(b.GetName(), orderBook.FirstCurrency, orderBook.SecondCurrency, orderBook)
orderBook.Pair = p
orderbook.ProcessOrderbook(b.GetName(), p, orderBook)
return orderBook, nil
}