Package currency

This commit is contained in:
Adrian Gallagher
2017-03-28 15:52:16 +11:00
parent aeb327c80c
commit a9d9ee54f7
8 changed files with 105 additions and 80 deletions

View File

@@ -4,6 +4,7 @@ import (
"log"
"time"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
@@ -20,17 +21,16 @@ func (b *BTCMarkets) Run() {
for b.Enabled {
for _, x := range b.EnabledPairs {
currency := x
curr := x
go func() {
ticker, err := b.GetTickerPrice(currency)
ticker, err := b.GetTickerPrice(curr)
if err != nil {
return
}
//BTCMarketsLastUSD, _ := ConvertCurrency(ticker.Last, "AUD", "USD")
//BTCMarketsBestBidUSD, _ := ConvertCurrency(ticker.Bid, "AUD", "USD")
//BTCMarketsBestAskUSD, _ := ConvertCurrency(ticker.Ask, "AUD", "USD")
//log.Printf("BTC Markets %s: Last %f (%f) Bid %f (%f) Ask %f (%f)\n", currency, BTCMarketsLastUSD, ticker.Last, BTCMarketsBestBidUSD, ticker.Bid, BTCMarketsBestAskUSD, ticker.Ask)
log.Printf("BTC Markets %s: Last %f Bid %f Ask %f \n", currency, ticker.Last, ticker.Bid, ticker.Ask)
BTCMarketsLastUSD, _ := currency.ConvertCurrency(ticker.Last, "AUD", "USD")
BTCMarketsBestBidUSD, _ := currency.ConvertCurrency(ticker.Bid, "AUD", "USD")
BTCMarketsBestAskUSD, _ := currency.ConvertCurrency(ticker.Ask, "AUD", "USD")
log.Printf("BTC Markets %s: Last %f (%f) Bid %f (%f) Ask %f (%f)\n", curr, BTCMarketsLastUSD, ticker.Last, BTCMarketsBestBidUSD, ticker.Bid, BTCMarketsBestAskUSD, ticker.Ask)
//AddExchangeInfo(b.GetName(), currency[0:3], currency[3:], ticker.Last, 0)
//AddExchangeInfo(b.GetName(), currency[0:3], "USD", BTCMarketsLastUSD, 0)
}()

View File

@@ -5,6 +5,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
@@ -26,22 +27,19 @@ func (h *HUOBI) Run() {
for h.Enabled {
for _, x := range h.EnabledPairs {
currency := common.StringToLower(x[0:3])
curr := common.StringToLower(x[0:3])
go func() {
ticker, err := h.GetTickerPrice(currency)
ticker, err := h.GetTickerPrice(curr)
if err != nil {
log.Println(err)
return
}
/*
HuobiLastUSD, _ := ConvertCurrency(ticker.Last, "CNY", "USD")
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.Volume)
AddExchangeInfo(h.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[3:]), ticker.Last, ticker.Volume)
AddExchangeInfo(h.GetName(), common.StringToUpper(currency[0:3]), "USD", HuobiLastUSD, ticker.Volume)
*/
log.Printf("Huobi %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
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)
// AddExchangeInfo(h.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[3:]), ticker.Last, ticker.Volume)
// AddExchangeInfo(h.GetName(), common.StringToUpper(currency[0:3]), "USD", HuobiLastUSD, ticker.Volume)
}()
}
time.Sleep(time.Second * h.RESTPollingDelay)

View File

@@ -5,6 +5,7 @@ import (
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
@@ -26,41 +27,40 @@ func (o *OKCoin) Run() {
for o.Enabled {
for _, x := range o.EnabledPairs {
currency := common.StringToLower(x[0:3] + "_" + x[3:])
curr := common.StringToLower(x[0:3] + "_" + x[3:])
if o.APIUrl == OKCOIN_API_URL {
for _, y := range o.FuturesValues {
futuresValue := y
go func() {
ticker, err := o.GetFuturesTicker(currency, futuresValue)
ticker, err := o.GetFuturesTicker(curr, futuresValue)
if err != nil {
log.Println(err)
return
}
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)
log.Printf("OKCoin Intl Futures %s (%s): Last %f High %f Low %f Volume %f\n", curr, futuresValue, ticker.Last, ticker.High, ticker.Low, ticker.Vol)
//AddExchangeInfo(o.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[4:]), ticker.Last, ticker.Vol)
}()
}
go func() {
ticker, err := o.GetTickerPrice(currency)
ticker, err := o.GetTickerPrice(curr)
if err != nil {
log.Println(err)
return
}
log.Printf("OKCoin Intl Spot %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
log.Printf("OKCoin Intl Spot %s: Last %f High %f Low %f Volume %f\n", curr, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
//AddExchangeInfo(o.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[4:]), ticker.Last, ticker.Volume)
}()
} else {
go func() {
ticker, err := o.GetTickerPrice(currency)
ticker, err := o.GetTickerPrice(curr)
if err != nil {
log.Println(err)
return
}
//tickerLastUSD, _ := ConvertCurrency(ticker.Last, "CNY", "USD")
//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.Volume)
log.Printf("OKCoin China %s: Last %f High %f Low %f Volume %f\n", currency, ticker.Last, ticker.High, ticker.Low, ticker.Volume)
tickerLastUSD, _ := currency.ConvertCurrency(ticker.Last, "CNY", "USD")
tickerHighUSD, _ := currency.ConvertCurrency(ticker.High, "CNY", "USD")
tickerLowUSD, _ := currency.ConvertCurrency(ticker.Low, "CNY", "USD")
log.Printf("OKCoin China %s: Last %f (%f) High %f (%f) Low %f (%f) Volume %f\n", curr, tickerLastUSD, ticker.Last, tickerHighUSD, ticker.High, tickerLowUSD, ticker.Low, ticker.Volume)
//AddExchangeInfo(o.GetName(), common.StringToUpper(currency[0:3]), common.StringToUpper(currency[4:]), ticker.Last, ticker.Volume)
//AddExchangeInfo(o.GetName(), common.StringToUpper(currency[0:3]), "USD", tickerLastUSD, ticker.Volume)
}()