mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
Added fiat support to stats handler.
This commit is contained in:
@@ -149,7 +149,7 @@ func (a *ANX) Run() {
|
||||
go func() {
|
||||
ticker := a.GetTicker(currency)
|
||||
log.Printf("ANX %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Data.Last.Value, ticker.Data.High.Value, ticker.Data.Low.Value, ticker.Data.Vol.Value)
|
||||
AddExchangeInfo(a.GetName(), currency, ticker.Data.Last.Value, ticker.Data.Vol.Value)
|
||||
AddExchangeInfo(a.GetName(), currency[0:3], currency[3:], ticker.Data.Last.Value, ticker.Data.Vol.Value)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * a.RESTPollingDelay)
|
||||
|
||||
@@ -216,7 +216,7 @@ func (b *Bitfinex) Run() {
|
||||
go func() {
|
||||
ticker := b.GetTicker(currency)
|
||||
log.Printf("Bitfinex %s Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
|
||||
AddExchangeInfo(b.GetName(), currency, ticker.Last, ticker.Volume)
|
||||
AddExchangeInfo(b.GetName(), currency[0:3], currency[3:], ticker.Last, ticker.Volume)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * b.RESTPollingDelay)
|
||||
|
||||
@@ -132,7 +132,7 @@ func (b *Bitstamp) Run() {
|
||||
go func() {
|
||||
ticker := b.GetTicker()
|
||||
log.Printf("Bitstamp %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
|
||||
AddExchangeInfo(b.GetName(), currency, ticker.Last, ticker.Volume)
|
||||
AddExchangeInfo(b.GetName(), currency[0:3], currency[3:], ticker.Last, ticker.Volume)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * b.RESTPollingDelay)
|
||||
|
||||
@@ -223,10 +223,11 @@ func (b *BTCChina) Run() {
|
||||
tickerHighUSD, _ := ConvertCurrency(ticker.High, "CNY", "USD")
|
||||
tickerLowUSD, _ := ConvertCurrency(ticker.Low, "CNY", "USD")
|
||||
log.Printf("BTCChina %s: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", currency, tickerLastUSD, ticker.Last, tickerHighUSD, ticker.High, tickerLowUSD, ticker.Low, ticker.Vol)
|
||||
AddExchangeInfo(b.GetName(), currency, tickerLastUSD, ticker.Vol)
|
||||
AddExchangeInfo(b.GetName(), StringToUpper(currency[0:3]), StringToUpper(currency[3:]), ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(b.GetName(), StringToUpper(currency[0:3]), "USD", tickerLastUSD, ticker.Vol)
|
||||
} else {
|
||||
log.Printf("BTCChina %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Vol)
|
||||
AddExchangeInfo(b.GetName(), currency, ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(b.GetName(), StringToUpper(currency[0:3]), StringToUpper(currency[3:]), ticker.Last, ticker.Vol)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ func (b *BTCE) Run() {
|
||||
x = StringToUpper(x[0:3] + x[4:])
|
||||
log.Printf("BTC-e %s: Last %f High %f Low %f Volume %f\n", x, y.Last, y.High, y.Low, y.Vol_cur)
|
||||
b.Ticker[x] = y
|
||||
AddExchangeInfo(b.GetName(), x, y.Last, y.Vol_cur)
|
||||
AddExchangeInfo(b.GetName(), StringToUpper(x[0:3]), StringToUpper(x[4:]), y.Last, y.Vol_cur)
|
||||
}
|
||||
}()
|
||||
time.Sleep(time.Second * b.RESTPollingDelay)
|
||||
|
||||
@@ -146,7 +146,8 @@ func (b *BTCMarkets) Run() {
|
||||
BTCMarketsBestBidUSD, _ := ConvertCurrency(ticker.BestBID, "AUD", "USD")
|
||||
BTCMarketsBestAskUSD, _ := ConvertCurrency(ticker.BestAsk, "AUD", "USD")
|
||||
log.Printf("BTC Markets %s: Last %f (%f) Bid %f (%f) Ask %f (%f)\n", currency, BTCMarketsLastUSD, ticker.LastPrice, BTCMarketsBestBidUSD, ticker.BestBID, BTCMarketsBestAskUSD, ticker.BestAsk)
|
||||
AddExchangeInfo(b.GetName(), currency, BTCMarketsLastUSD, 0)
|
||||
AddExchangeInfo(b.GetName(), currency[0:3], currency[3:], ticker.LastPrice, 0)
|
||||
AddExchangeInfo(b.GetName(), currency[0:3], "USD", BTCMarketsLastUSD, 0)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * b.RESTPollingDelay)
|
||||
|
||||
@@ -154,7 +154,7 @@ func (c *Coinbase) Run() {
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Printf("%s Updating available pairs. Changed %s.\n", c.Name, diff)
|
||||
log.Printf("%s Updating available pairs. Difference: %s.\n", c.Name, diff)
|
||||
exch.AvailablePairs = JoinStrings(currencies, ",")
|
||||
UpdateExchangeConfig(exch)
|
||||
}
|
||||
@@ -168,7 +168,7 @@ func (c *Coinbase) Run() {
|
||||
stats := c.GetStats(currency)
|
||||
ticker := c.GetTicker(currency)
|
||||
log.Printf("Coinbase %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Price, stats.High, stats.Low, stats.Volume)
|
||||
AddExchangeInfo(c.GetName(), currency, ticker.Price, stats.Volume)
|
||||
AddExchangeInfo(c.GetName(), currency[0:3], currency[4:], ticker.Price, stats.Volume)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * c.RESTPollingDelay)
|
||||
|
||||
@@ -208,7 +208,7 @@ func (c *Cryptsy) Run() {
|
||||
market := c.Market[x]
|
||||
if market.ID != "" {
|
||||
log.Printf("Cryptsy %s: Last %f High %f Low %f Volume %f\n", x, market.LastTrade.Price, market.DayStats.PriceHigh, market.DayStats.PriceLow, market.DayStats.Volume)
|
||||
AddExchangeInfo(c.GetName(), x, market.LastTrade.Price, market.DayStats.Volume)
|
||||
AddExchangeInfo(c.GetName(), x[0:3], x[3:], market.LastTrade.Price, market.DayStats.Volume)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,8 @@ func (h *HUOBI) Run() {
|
||||
HuobiHighUSD, _ := ConvertCurrency(ticker.High, "CNY", "USD")
|
||||
HuobiLowUSD, _ := ConvertCurrency(ticker.Low, "CNY", "USD")
|
||||
log.Printf("Huobi %s: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", currency, HuobiLastUSD, ticker.Last, HuobiHighUSD, ticker.High, HuobiLowUSD, ticker.Low, ticker.Vol)
|
||||
AddExchangeInfo(h.GetName(), StringToUpper(currency), HuobiLastUSD, ticker.Vol)
|
||||
AddExchangeInfo(h.GetName(), StringToUpper(currency[0:3]), StringToUpper(currency[3:]), ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(h.GetName(), StringToUpper(currency[0:3]), "USD", HuobiLastUSD, ticker.Vol)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * h.RESTPollingDelay)
|
||||
|
||||
@@ -96,7 +96,7 @@ func (i *ItBit) Run() {
|
||||
go func() {
|
||||
ticker := i.GetTicker(currency)
|
||||
log.Printf("ItBit %s: Last %f High %f Low %f Volume %f\n", currency, ticker.LastPrice, ticker.High24h, ticker.Low24h, ticker.Volume24h)
|
||||
AddExchangeInfo(i.GetName(), currency, ticker.LastPrice, ticker.Volume24h)
|
||||
AddExchangeInfo(i.GetName(), currency[0:3], currency[3:], ticker.LastPrice, ticker.Volume24h)
|
||||
}()
|
||||
}
|
||||
time.Sleep(time.Second * i.RESTPollingDelay)
|
||||
|
||||
@@ -101,7 +101,7 @@ func (k *Kraken) Run() {
|
||||
for _, x := range k.EnabledPairs {
|
||||
ticker := k.Ticker[x]
|
||||
log.Printf("Kraken %s Last %f High %f Low %f Volume %f\n", x, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
|
||||
AddExchangeInfo(k.GetName(), x, ticker.Last, ticker.Volume)
|
||||
AddExchangeInfo(k.GetName(), x[0:3], x[3:], ticker.Last, ticker.Volume)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * k.RESTPollingDelay)
|
||||
|
||||
@@ -108,10 +108,10 @@ func (l *LakeBTC) Run() {
|
||||
for _, x := range l.EnabledPairs {
|
||||
if x == "BTCUSD" {
|
||||
log.Printf("LakeBTC BTC USD: Last %f High %f Low %f Volume %f\n", ticker.USD.Last, ticker.USD.High, ticker.USD.Low, ticker.USD.Volume)
|
||||
AddExchangeInfo(l.GetName(), "BTCUSD", ticker.USD.Last, ticker.USD.Volume)
|
||||
AddExchangeInfo(l.GetName(), x[0:3], x[3:], ticker.USD.Last, ticker.USD.Volume)
|
||||
} else if x == "BTCCNY" {
|
||||
log.Printf("LakeBTC BTC CNY: Last %f High %f Low %f Volume %f\n", ticker.CNY.Last, ticker.CNY.High, ticker.CNY.Low, ticker.CNY.Volume)
|
||||
AddExchangeInfo(l.GetName(), "BTCCNY", ticker.CNY.Last, ticker.CNY.Volume)
|
||||
AddExchangeInfo(l.GetName(), x[0:3], x[3:], ticker.CNY.Last, ticker.CNY.Volume)
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Second * l.RESTPollingDelay)
|
||||
|
||||
@@ -217,13 +217,13 @@ func (o *OKCoin) Run() {
|
||||
go func() {
|
||||
ticker := o.GetFuturesTicker(currency, futuresValue)
|
||||
log.Printf("OKCoin Intl Futures %s (%s): Last %f High %f Low %f Volume %f\n", currency, futuresValue, ticker.Last, ticker.High, ticker.Low, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), currency, ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), StringToUpper(currency[0:3]), StringToUpper(currency[4:]), ticker.Last, ticker.Vol)
|
||||
}()
|
||||
}
|
||||
go func() {
|
||||
ticker := o.GetTicker(currency)
|
||||
log.Printf("OKCoin Intl Spot %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), currency, ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), StringToUpper(currency[0:3]), StringToUpper(currency[4:]), ticker.Last, ticker.Vol)
|
||||
}()
|
||||
} else {
|
||||
go func() {
|
||||
@@ -232,7 +232,8 @@ func (o *OKCoin) Run() {
|
||||
tickerHighUSD, _ := ConvertCurrency(ticker.High, "CNY", "USD")
|
||||
tickerLowUSD, _ := ConvertCurrency(ticker.Low, "CNY", "USD")
|
||||
log.Printf("OKCoin China %s: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", currency, tickerLastUSD, ticker.Last, tickerHighUSD, ticker.High, tickerLowUSD, ticker.Low, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), currency, ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), StringToUpper(currency[0:3]), StringToUpper(currency[4:]), ticker.Last, ticker.Vol)
|
||||
AddExchangeInfo(o.GetName(), StringToUpper(currency[0:3]), "USD", tickerLastUSD, ticker.Vol)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
37
stats.go
37
stats.go
@@ -5,10 +5,11 @@ import (
|
||||
)
|
||||
|
||||
type ExchangeInfo struct {
|
||||
Exchange string
|
||||
Currency string
|
||||
Price float64
|
||||
Volume float64
|
||||
Exchange string
|
||||
CryptoCurrency string
|
||||
FiatCurrency string
|
||||
Price float64
|
||||
Volume float64
|
||||
}
|
||||
|
||||
var ExchInfo []ExchangeInfo
|
||||
@@ -41,30 +42,34 @@ func (this ByVolume) Swap(i, j int) {
|
||||
this[i], this[j] = this[j], this[i]
|
||||
}
|
||||
|
||||
func AddExchangeInfo(exchange, currency string, price, volume float64) {
|
||||
func AddExchangeInfo(exchange, crypto, fiat string, price, volume float64) {
|
||||
if !IsFiatCurrency(fiat) {
|
||||
return
|
||||
}
|
||||
if len(ExchInfo) == 0 {
|
||||
AppendExchangeInfo(exchange, currency, price, volume)
|
||||
AppendExchangeInfo(exchange, crypto, fiat, price, volume)
|
||||
} else {
|
||||
if ExchangeInfoAlreadyExists(exchange, currency, price, volume) {
|
||||
if ExchangeInfoAlreadyExists(exchange, crypto, fiat, price, volume) {
|
||||
return
|
||||
} else {
|
||||
AppendExchangeInfo(exchange, currency, price, volume)
|
||||
AppendExchangeInfo(exchange, crypto, fiat, price, volume)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func AppendExchangeInfo(exchange, currency string, price, volume float64) {
|
||||
func AppendExchangeInfo(exchange, crypto, fiat string, price, volume float64) {
|
||||
exch := ExchangeInfo{}
|
||||
exch.Exchange = exchange
|
||||
exch.Currency = currency
|
||||
exch.CryptoCurrency = crypto
|
||||
exch.FiatCurrency = fiat
|
||||
exch.Price = price
|
||||
exch.Volume = volume
|
||||
ExchInfo = append(ExchInfo, exch)
|
||||
}
|
||||
|
||||
func ExchangeInfoAlreadyExists(exchange, currency string, price, volume float64) (bool) {
|
||||
func ExchangeInfoAlreadyExists(exchange, crypto, fiat string, price, volume float64) bool {
|
||||
for i, _ := range ExchInfo {
|
||||
if ExchInfo[i].Exchange == exchange && ExchInfo[i].Currency == currency {
|
||||
if ExchInfo[i].Exchange == exchange && ExchInfo[i].CryptoCurrency == crypto && ExchInfo[i].FiatCurrency == fiat {
|
||||
ExchInfo[i].Price, ExchInfo[i].Volume = price, volume
|
||||
return true
|
||||
}
|
||||
@@ -72,11 +77,11 @@ func ExchangeInfoAlreadyExists(exchange, currency string, price, volume float64)
|
||||
return false
|
||||
}
|
||||
|
||||
func SortExchangesByVolume(currency string, reverse bool) []ExchangeInfo {
|
||||
func SortExchangesByVolume(crypto, fiat string, reverse bool) []ExchangeInfo {
|
||||
info := []ExchangeInfo{}
|
||||
|
||||
for _, x := range ExchInfo {
|
||||
if x.Currency == currency {
|
||||
if x.CryptoCurrency == crypto && x.FiatCurrency == fiat {
|
||||
info = append(info, x)
|
||||
}
|
||||
}
|
||||
@@ -89,11 +94,11 @@ func SortExchangesByVolume(currency string, reverse bool) []ExchangeInfo {
|
||||
return info
|
||||
}
|
||||
|
||||
func SortExchangesByPrice(currency string, reverse bool) []ExchangeInfo {
|
||||
func SortExchangesByPrice(crypto, fiat string, reverse bool) []ExchangeInfo {
|
||||
info := []ExchangeInfo{}
|
||||
|
||||
for _, x := range ExchInfo {
|
||||
if x.Currency == currency {
|
||||
if x.CryptoCurrency == crypto && x.FiatCurrency == fiat {
|
||||
info = append(info, x)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user