mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 07:26:44 +00:00
Add currency pair support
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/common"
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/currency/pair"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/stats"
|
||||
@@ -29,7 +30,7 @@ func (h *HUOBI) Run() {
|
||||
|
||||
for h.Enabled {
|
||||
for _, x := range h.EnabledPairs {
|
||||
curr := common.StringToLower(x[0:3])
|
||||
curr := pair.NewCurrencyPair(x[0:3], x[3:])
|
||||
go func() {
|
||||
ticker, err := h.GetTickerPrice(curr)
|
||||
if err != nil {
|
||||
@@ -39,46 +40,45 @@ func (h *HUOBI) Run() {
|
||||
HuobiLastUSD, _ := currency.ConvertCurrency(ticker.Last, "CNY", "USD")
|
||||
HuobiHighUSD, _ := currency.ConvertCurrency(ticker.High, "CNY", "USD")
|
||||
HuobiLowUSD, _ := currency.ConvertCurrency(ticker.Low, "CNY", "USD")
|
||||
log.Printf("Huobi %s: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", curr, HuobiLastUSD, ticker.Last, HuobiHighUSD, ticker.High, HuobiLowUSD, ticker.Low, ticker.Volume)
|
||||
stats.AddExchangeInfo(h.GetName(), common.StringToUpper(curr[0:3]), common.StringToUpper(curr[3:]), ticker.Last, ticker.Volume)
|
||||
stats.AddExchangeInfo(h.GetName(), common.StringToUpper(curr[0:3]), "USD", HuobiLastUSD, ticker.Volume)
|
||||
log.Printf("Huobi %s: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", curr.Pair().String(), HuobiLastUSD, ticker.Last, HuobiHighUSD, ticker.High, HuobiLowUSD, ticker.Low, ticker.Volume)
|
||||
stats.AddExchangeInfo(h.GetName(), curr.GetFirstCurrency().String(), curr.GetSecondCurrency().String(), ticker.Last, ticker.Volume)
|
||||
stats.AddExchangeInfo(h.GetName(), curr.GetFirstCurrency().String(), "USD", HuobiLastUSD, ticker.Volume)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * h.RESTPollingDelay)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *HUOBI) GetTickerPrice(currency string) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(h.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[3:]))
|
||||
func (h *HUOBI) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
|
||||
tickerNew, err := ticker.GetTicker(h.GetName(), p)
|
||||
if err == nil {
|
||||
return tickerNew, nil
|
||||
}
|
||||
|
||||
var tickerPrice ticker.TickerPrice
|
||||
tick, err := h.GetTicker(currency)
|
||||
tick, err := h.GetTicker(p.GetFirstCurrency().Lower().String())
|
||||
if err != nil {
|
||||
return tickerPrice, err
|
||||
}
|
||||
tickerPrice.Pair = p
|
||||
tickerPrice.Ask = tick.Sell
|
||||
tickerPrice.Bid = tick.Buy
|
||||
tickerPrice.FirstCurrency = common.StringToUpper(currency[0:3])
|
||||
tickerPrice.SecondCurrency = common.StringToUpper(currency[3:])
|
||||
tickerPrice.Low = tick.Low
|
||||
tickerPrice.Last = tick.Last
|
||||
tickerPrice.Volume = tick.Vol
|
||||
tickerPrice.High = tick.High
|
||||
ticker.ProcessTicker(h.GetName(), tickerPrice.FirstCurrency, tickerPrice.SecondCurrency, tickerPrice)
|
||||
ticker.ProcessTicker(h.GetName(), p, tickerPrice)
|
||||
return tickerPrice, nil
|
||||
}
|
||||
|
||||
func (h *HUOBI) GetOrderbookEx(currency string) (orderbook.OrderbookBase, error) {
|
||||
ob, err := orderbook.GetOrderbook(h.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[3:]))
|
||||
func (h *HUOBI) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, error) {
|
||||
ob, err := orderbook.GetOrderbook(h.GetName(), p)
|
||||
if err == nil {
|
||||
return ob, nil
|
||||
}
|
||||
|
||||
var orderBook orderbook.OrderbookBase
|
||||
orderbookNew, err := h.GetOrderBook(currency)
|
||||
orderbookNew, err := h.GetOrderBook(p.GetFirstCurrency().Lower().String())
|
||||
if err != nil {
|
||||
return orderBook, err
|
||||
}
|
||||
@@ -92,9 +92,8 @@ func (h *HUOBI) GetOrderbookEx(currency string) (orderbook.OrderbookBase, error)
|
||||
data := orderbookNew.Asks[x]
|
||||
orderBook.Asks = append(orderBook.Asks, orderbook.OrderbookItem{Amount: data[1], Price: data[0]})
|
||||
}
|
||||
orderBook.FirstCurrency = common.StringToUpper(currency[0:3])
|
||||
orderBook.SecondCurrency = common.StringToUpper(currency[3:])
|
||||
orderbook.ProcessOrderbook(h.GetName(), orderBook.FirstCurrency, orderBook.SecondCurrency, orderBook)
|
||||
orderBook.Pair = p
|
||||
orderbook.ProcessOrderbook(h.GetName(), p, orderBook)
|
||||
return orderBook, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user