Add generalised functions for handling exchange enabled and available currencies

This commit is contained in:
Adrian Gallagher
2017-08-25 15:54:45 +10:00
parent 9bdc316ae8
commit 55ea1fe434
45 changed files with 1032 additions and 208 deletions

View File

@@ -39,6 +39,12 @@ func (a *ANX) SetDefaults() {
a.Verbose = false
a.Websocket = false
a.RESTPollingDelay = 10
a.RequestCurrencyPairFormat.Delimiter = ""
a.RequestCurrencyPairFormat.Uppercase = true
a.RequestCurrencyPairFormat.Index = "BTC"
a.ConfigCurrencyPairFormat.Delimiter = ""
a.ConfigCurrencyPairFormat.Uppercase = true
a.ConfigCurrencyPairFormat.Index = "BTC"
}
//Setup is run on startup to setup exchange with config values
@@ -55,6 +61,10 @@ func (a *ANX) Setup(exch config.ExchangeConfig) {
a.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
a.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
a.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := a.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -30,11 +30,10 @@ type ANXOrderResponse struct {
}
type ANXTickerComponent struct {
Currency string `json:"currency"`
Display string `json:"display"`
DisplayShort string `json:"display_short"`
Value float64 `json:"value,string"`
ValueInt int64 `json:"value_int,string"`
Currency string `json:"currency"`
Display string `json:"display"`
DisplayShort string `json:"display_short"`
Value string `json:"value"`
}
type ANXTicker struct {

View File

@@ -2,6 +2,7 @@ package anx
import (
"log"
"strconv"
"time"
"github.com/thrasher-/gocryptotrader/currency/pair"
@@ -22,8 +23,9 @@ func (a *ANX) Run() {
}
for a.Enabled {
for _, x := range a.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := a.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := a.GetTickerPrice(currency)
if err != nil {
@@ -51,12 +53,60 @@ func (a *ANX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Data.Buy.Value
tickerPrice.Bid = tick.Data.Sell.Value
tickerPrice.Low = tick.Data.Low.Value
tickerPrice.Last = tick.Data.Last.Value
tickerPrice.Volume = tick.Data.Vol.Value
tickerPrice.High = tick.Data.High.Value
if tick.Data.Sell.Value != "" {
tickerPrice.Ask, err = strconv.ParseFloat(tick.Data.Sell.Value, 64)
if err != nil {
return tickerPrice, err
}
} else {
tickerPrice.Ask = 0
}
if tick.Data.Buy.Value != "" {
tickerPrice.Bid, err = strconv.ParseFloat(tick.Data.Buy.Value, 64)
if err != nil {
return tickerPrice, err
}
} else {
tickerPrice.Bid = 0
}
if tick.Data.Low.Value != "" {
tickerPrice.Low, err = strconv.ParseFloat(tick.Data.Low.Value, 64)
if err != nil {
return tickerPrice, err
}
} else {
tickerPrice.Low = 0
}
if tick.Data.Last.Value != "" {
tickerPrice.Last, err = strconv.ParseFloat(tick.Data.Last.Value, 64)
if err != nil {
return tickerPrice, err
}
} else {
tickerPrice.Last = 0
}
if tick.Data.Vol.Value != "" {
tickerPrice.Volume, err = strconv.ParseFloat(tick.Data.Vol.Value, 64)
if err != nil {
return tickerPrice, err
}
} else {
tickerPrice.Volume = 0
}
if tick.Data.High.Value != "" {
tickerPrice.High, err = strconv.ParseFloat(tick.Data.High.Value, 64)
if err != nil {
return tickerPrice, err
}
} else {
tickerPrice.High = 0
}
ticker.ProcessTicker(a.GetName(), p, tickerPrice)
return tickerPrice, nil
}

View File

@@ -81,6 +81,10 @@ func (b *Bitfinex) SetDefaults() {
b.Websocket = false
b.RESTPollingDelay = 10
b.WebsocketSubdChannels = make(map[int]WebsocketChanInfo)
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = ""
b.ConfigCurrencyPairFormat.Uppercase = true
}
// Setup takes in the supplied exchange configuration details and sets params
@@ -97,6 +101,10 @@ func (b *Bitfinex) Setup(exch config.ExchangeConfig) {
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -33,15 +33,16 @@ func (b *Bitfinex) Run() {
if err != nil {
log.Printf("%s Failed to get available symbols.\n", b.GetName())
} else {
err = b.UpdateAvailableCurrencies(exchangeProducts)
err = b.UpdateAvailableCurrencies(exchangeProducts, false)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
}
}
for b.Enabled {
for _, x := range b.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := b.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
if err != nil {

View File

@@ -55,6 +55,10 @@ func (b *Bitstamp) SetDefaults() {
b.Verbose = false
b.Websocket = false
b.RESTPollingDelay = 10
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = ""
b.ConfigCurrencyPairFormat.Uppercase = true
}
func (b *Bitstamp) Setup(exch config.ExchangeConfig) {
@@ -70,6 +74,10 @@ func (b *Bitstamp) Setup(exch config.ExchangeConfig) {
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -28,8 +28,9 @@ func (b *Bitstamp) Run() {
}
for b.Enabled {
for _, x := range b.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := b.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
if err != nil {

View File

@@ -66,6 +66,10 @@ func (b *Bittrex) SetDefaults() {
b.Verbose = false
b.Websocket = false
b.RESTPollingDelay = 10
b.RequestCurrencyPairFormat.Delimiter = "-"
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = "-"
b.ConfigCurrencyPairFormat.Uppercase = true
}
// Setup method sets current configuration details if enabled
@@ -82,6 +86,10 @@ func (b *Bittrex) Setup(exch config.ExchangeConfig) {
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -28,24 +28,37 @@ func (b *Bittrex) Run() {
if err != nil {
log.Printf("%s Failed to get available symbols.\n", b.GetName())
} else {
forceUpgrade := false
if !common.DataContains(b.EnabledPairs, "-") || !common.DataContains(b.AvailablePairs, "-") {
forceUpgrade = true
}
var currencies []string
for x := range exchangeProducts {
if !exchangeProducts[x].IsActive {
continue
}
currencies = append(currencies,
common.ReplaceString(exchangeProducts[x].MarketName, "-", "", -1))
currencies = append(currencies, exchangeProducts[x].MarketName)
}
err = b.UpdateAvailableCurrencies(currencies)
if forceUpgrade {
enabledPairs := []string{"USDT-BTC"}
log.Println("WARNING: Available pairs for Bittrex reset due to config upgrade, please enable the ones you would like again")
err = b.UpdateEnabledCurrencies(enabledPairs, true)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
}
}
err = b.UpdateAvailableCurrencies(currencies, forceUpgrade)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
}
}
for b.Enabled {
for _, x := range b.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
currency.Delimiter = "-"
pairs := b.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
if err != nil {
@@ -87,7 +100,7 @@ func (b *Bittrex) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error
}
var tickerPrice ticker.TickerPrice
tick, err := b.GetMarketSummary(p.Pair().Lower().String())
tick, err := b.GetMarketSummary(exchange.FormatExchangeCurrency(b.GetName(), p).String())
if err != nil {
return tickerPrice, err
}
@@ -108,7 +121,7 @@ func (b *Bittrex) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase,
}
var orderBook orderbook.OrderbookBase
orderbookNew, err := b.GetOrderbook(p.Pair().Lower().String())
orderbookNew, err := b.GetOrderbook(exchange.FormatExchangeCurrency(b.GetName(), p).String())
if err != nil {
return orderBook, err
}

View File

@@ -53,6 +53,10 @@ func (b *BTCC) SetDefaults() {
b.Verbose = false
b.Websocket = false
b.RESTPollingDelay = 10
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = false
b.ConfigCurrencyPairFormat.Delimiter = ""
b.ConfigCurrencyPairFormat.Uppercase = true
}
//Setup is run on startup to setup exchange with config values
@@ -69,6 +73,10 @@ func (b *BTCC) Setup(exch config.ExchangeConfig) {
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -28,8 +28,9 @@ func (b *BTCC) Run() {
}
for b.Enabled {
for _, x := range b.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := b.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(currency)
if err != nil {
@@ -51,7 +52,7 @@ func (b *BTCC) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
}
var tickerPrice ticker.TickerPrice
tick, err := b.GetTicker(p.Pair().Lower().String())
tick, err := b.GetTicker(exchange.FormatExchangeCurrency(b.GetName(), p).String())
if err != nil {
return tickerPrice, err
}
@@ -74,7 +75,7 @@ func (b *BTCC) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err
}
var orderBook orderbook.OrderbookBase
orderbookNew, err := b.GetOrderBook(p.Pair().Lower().String(), 100)
orderbookNew, err := b.GetOrderBook(exchange.FormatExchangeCurrency(b.GetName(), p).String(), 100)
if err != nil {
return orderBook, err
}

View File

@@ -48,6 +48,11 @@ func (b *BTCE) SetDefaults() {
b.Websocket = false
b.RESTPollingDelay = 10
b.Ticker = make(map[string]BTCeTicker)
b.RequestCurrencyPairFormat.Delimiter = "_"
b.RequestCurrencyPairFormat.Uppercase = false
b.RequestCurrencyPairFormat.Separator = "-"
b.ConfigCurrencyPairFormat.Delimiter = ""
b.ConfigCurrencyPairFormat.Uppercase = true
}
func (b *BTCE) Setup(exch config.ExchangeConfig) {
@@ -63,7 +68,10 @@ func (b *BTCE) Setup(exch config.ExchangeConfig) {
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -24,16 +24,17 @@ func (b *BTCE) Run() {
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
}
pairs := []string{}
for _, x := range b.EnabledPairs {
x = common.StringToLower(x[0:3] + "_" + x[3:6])
pairs = append(pairs, x)
pairs := b.GetEnabledCurrencies()
pairsCollated, err := exchange.GetAndFormatExchangeCurrencies(b.Name, pairs)
if err != nil {
log.Println(err)
b.Enabled = false
return
}
pairsString := common.JoinStrings(pairs, "-")
for b.Enabled {
go func() {
ticker, err := b.GetTicker(pairsString)
ticker, err := b.GetTicker(pairsCollated.String())
if err != nil {
log.Println(err)
return
@@ -51,9 +52,9 @@ func (b *BTCE) Run() {
func (b *BTCE) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, ok := b.Ticker[p.Pair().Lower().String()]
tick, ok := b.Ticker[exchange.FormatExchangeCurrency(b.Name, p).String()]
if !ok {
return tickerPrice, errors.New("Unable to get currency.")
return tickerPrice, errors.New("unable to get currency")
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Buy
@@ -73,7 +74,7 @@ func (b *BTCE) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err
}
var orderBook orderbook.OrderbookBase
orderbookNew, err := b.GetDepth(p.Pair().Lower().String())
orderbookNew, err := b.GetDepth(exchange.FormatExchangeCurrency(b.Name, p).String())
if err != nil {
return orderBook, err
}

View File

@@ -38,6 +38,10 @@ func (b *BTCMarkets) SetDefaults() {
b.Websocket = false
b.RESTPollingDelay = 10
b.Ticker = make(map[string]BTCMarketsTicker)
b.RequestCurrencyPairFormat.Delimiter = ""
b.RequestCurrencyPairFormat.Uppercase = true
b.ConfigCurrencyPairFormat.Delimiter = ""
b.ConfigCurrencyPairFormat.Uppercase = true
}
func (b *BTCMarkets) Setup(exch config.ExchangeConfig) {
@@ -53,7 +57,10 @@ func (b *BTCMarkets) Setup(exch config.ExchangeConfig) {
b.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
b.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
b.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := b.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -4,6 +4,8 @@ import (
"log"
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/exchanges"
@@ -22,9 +24,36 @@ func (b *BTCMarkets) Run() {
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
}
if !common.DataContains(b.EnabledPairs, "AUD") || !common.DataContains(b.EnabledPairs, "AUD") {
enabledPairs := []string{}
for x := range b.EnabledPairs {
enabledPairs = append(enabledPairs, b.EnabledPairs[x]+"AUD")
}
availablePairs := []string{}
for x := range b.AvailablePairs {
availablePairs = append(availablePairs, b.AvailablePairs[x]+"AUD")
}
log.Println("BTCMarkets: Upgrading available and enabled pairs")
err := b.UpdateEnabledCurrencies(enabledPairs, true)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
return
}
err = b.UpdateAvailableCurrencies(availablePairs, true)
if err != nil {
log.Printf("%s Failed to get config.\n", b.GetName())
return
}
}
for b.Enabled {
for _, x := range b.EnabledPairs {
curr := pair.NewCurrencyPair(x, "AUD")
pairs := b.GetEnabledCurrencies()
for x := range pairs {
curr := pairs[x]
go func() {
ticker, err := b.GetTickerPrice(curr)
if err != nil {

View File

@@ -48,6 +48,10 @@ func (c *COINUT) SetDefaults() {
c.Verbose = false
c.Websocket = false
c.RESTPollingDelay = 10
c.RequestCurrencyPairFormat.Delimiter = ""
c.RequestCurrencyPairFormat.Uppercase = true
c.ConfigCurrencyPairFormat.Delimiter = ""
c.ConfigCurrencyPairFormat.Uppercase = true
}
func (c *COINUT) Setup(exch config.ExchangeConfig) {
@@ -63,6 +67,10 @@ func (c *COINUT) Setup(exch config.ExchangeConfig) {
c.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
c.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
c.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := c.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -40,14 +40,15 @@ func (c *COINUT) Run() {
currencies = append(currencies, x)
}
err = c.UpdateAvailableCurrencies(currencies)
err = c.UpdateAvailableCurrencies(currencies, false)
if err != nil {
log.Printf("%s Failed to get config.\n", c.GetName())
}
for c.Enabled {
for _, x := range c.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := c.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := c.GetTickerPrice(currency)
if err != nil {
@@ -62,8 +63,8 @@ func (c *COINUT) Run() {
}
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the COINUT exchange
func (e *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
// GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the COINUT exchange
func (c *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
/*
response.ExchangeName = e.GetName()

View File

@@ -51,6 +51,8 @@ type Base struct {
EnabledPairs []string
WebsocketURL string
APIUrl string
RequestCurrencyPairFormat config.CurrencyPairFormatConfig
ConfigCurrencyPairFormat config.CurrencyPairFormatConfig
}
// IBotExchange enforces standard functions for all exchanges supported in
@@ -63,11 +65,51 @@ type IBotExchange interface {
IsEnabled() bool
GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error)
GetOrderbookEx(currency pair.CurrencyPair) (orderbook.OrderbookBase, error)
GetEnabledCurrencies() []string
GetEnabledCurrencies() []pair.CurrencyPair
GetExchangeAccountInfo() (AccountInfo, error)
GetAuthenticatedAPISupport() bool
}
// SetCurrencyPairFormat checks the exchange request and config currency pair
// formats and sets it to a default setting if it doesn't exist
func (e *Base) SetCurrencyPairFormat() error {
cfg := config.GetConfig()
exch, err := cfg.GetExchangeConfig(e.Name)
if err != nil {
return err
}
update := false
if exch.RequestCurrencyPairFormat == nil {
exch.RequestCurrencyPairFormat = &config.CurrencyPairFormatConfig{
Delimiter: e.RequestCurrencyPairFormat.Delimiter,
Uppercase: e.RequestCurrencyPairFormat.Uppercase,
Separator: e.RequestCurrencyPairFormat.Separator,
Index: e.RequestCurrencyPairFormat.Index,
}
update = true
} else {
e.RequestCurrencyPairFormat = *exch.RequestCurrencyPairFormat
}
if exch.ConfigCurrencyPairFormat == nil {
exch.ConfigCurrencyPairFormat = &config.CurrencyPairFormatConfig{
Delimiter: e.ConfigCurrencyPairFormat.Delimiter,
Uppercase: e.ConfigCurrencyPairFormat.Uppercase,
Separator: e.ConfigCurrencyPairFormat.Separator,
Index: e.ConfigCurrencyPairFormat.Index,
}
update = true
} else {
e.ConfigCurrencyPairFormat = *exch.ConfigCurrencyPairFormat
}
if update {
return cfg.UpdateExchangeConfig(exch)
}
return nil
}
// GetAuthenticatedAPISupport returns whether the exchange supports
// authenticated API requests
func (e *Base) GetAuthenticatedAPISupport() bool {
@@ -81,14 +123,135 @@ func (e *Base) GetName() string {
// GetEnabledCurrencies is a method that returns the enabled currency pairs of
// the exchange base
func (e *Base) GetEnabledCurrencies() []string {
return e.EnabledPairs
func (e *Base) GetEnabledCurrencies() []pair.CurrencyPair {
var pairs []pair.CurrencyPair
for x := range e.EnabledPairs {
var currencyPair pair.CurrencyPair
if e.RequestCurrencyPairFormat.Delimiter != "" {
if e.ConfigCurrencyPairFormat.Delimiter != "" {
if e.ConfigCurrencyPairFormat.Delimiter == e.RequestCurrencyPairFormat.Delimiter {
currencyPair = pair.NewCurrencyPairDelimiter(e.EnabledPairs[x],
e.RequestCurrencyPairFormat.Delimiter)
} else {
currencyPair = pair.NewCurrencyPairDelimiter(e.EnabledPairs[x],
e.ConfigCurrencyPairFormat.Delimiter)
currencyPair.Delimiter = "-"
}
} else {
if e.ConfigCurrencyPairFormat.Index != "" {
currencyPair = pair.NewCurrencyPairFromIndex(e.EnabledPairs[x],
e.ConfigCurrencyPairFormat.Index)
} else {
currencyPair = pair.NewCurrencyPair(e.EnabledPairs[x][0:3],
e.EnabledPairs[x][3:])
}
}
} else {
if e.ConfigCurrencyPairFormat.Delimiter != "" {
currencyPair = pair.NewCurrencyPairDelimiter(e.EnabledPairs[x],
e.ConfigCurrencyPairFormat.Delimiter)
} else {
if e.ConfigCurrencyPairFormat.Index != "" {
currencyPair = pair.NewCurrencyPairFromIndex(e.EnabledPairs[x],
e.ConfigCurrencyPairFormat.Index)
} else {
currencyPair = pair.NewCurrencyPair(e.EnabledPairs[x][0:3],
e.EnabledPairs[x][3:])
}
}
}
pairs = append(pairs, currencyPair)
}
return pairs
}
// GetAvailableCurrencies is a method that returns the available currency pairs
// of the exchange base
func (e *Base) GetAvailableCurrencies() []string {
return e.AvailablePairs
func (e *Base) GetAvailableCurrencies() []pair.CurrencyPair {
var pairs []pair.CurrencyPair
for x := range e.AvailablePairs {
var currencyPair pair.CurrencyPair
if e.RequestCurrencyPairFormat.Delimiter != "" {
if e.ConfigCurrencyPairFormat.Delimiter != "" {
if e.ConfigCurrencyPairFormat.Delimiter == e.RequestCurrencyPairFormat.Delimiter {
currencyPair = pair.NewCurrencyPairDelimiter(e.AvailablePairs[x],
e.RequestCurrencyPairFormat.Delimiter)
} else {
currencyPair = pair.NewCurrencyPairDelimiter(e.AvailablePairs[x],
e.ConfigCurrencyPairFormat.Delimiter)
currencyPair.Delimiter = "-"
}
} else {
if e.ConfigCurrencyPairFormat.Index != "" {
currencyPair = pair.NewCurrencyPairFromIndex(e.AvailablePairs[x],
e.ConfigCurrencyPairFormat.Index)
} else {
currencyPair = pair.NewCurrencyPair(e.AvailablePairs[x][0:3],
e.AvailablePairs[x][3:])
}
}
} else {
if e.ConfigCurrencyPairFormat.Delimiter != "" {
currencyPair = pair.NewCurrencyPairDelimiter(e.AvailablePairs[x],
e.ConfigCurrencyPairFormat.Delimiter)
} else {
if e.ConfigCurrencyPairFormat.Index != "" {
currencyPair = pair.NewCurrencyPairFromIndex(e.AvailablePairs[x],
e.ConfigCurrencyPairFormat.Index)
} else {
currencyPair = pair.NewCurrencyPair(e.AvailablePairs[x][0:3],
e.AvailablePairs[x][3:])
}
}
}
pairs = append(pairs, currencyPair)
}
return pairs
}
// GetExchangeFormatCurrencySeperator returns whether or not a specific
// exchange contains a separator used for API requests
func GetExchangeFormatCurrencySeperator(exchName string) bool {
cfg := config.GetConfig()
exch, err := cfg.GetExchangeConfig(exchName)
if err != nil {
return false
}
if exch.RequestCurrencyPairFormat.Separator != "" {
return true
}
return false
}
// GetAndFormatExchangeCurrencies returns a pair.CurrencyItem string containing
// the exchanges formatted currency pairs
func GetAndFormatExchangeCurrencies(exchName string, pairs []pair.CurrencyPair) (pair.CurrencyItem, error) {
var currencyItems pair.CurrencyItem
cfg := config.GetConfig()
exch, err := cfg.GetExchangeConfig(exchName)
if err != nil {
return currencyItems, err
}
for x := range pairs {
currencyItems += FormatExchangeCurrency(exchName, pairs[x])
if x == len(pairs)-1 {
continue
}
currencyItems += pair.CurrencyItem(exch.RequestCurrencyPairFormat.Separator)
}
return currencyItems, nil
}
// FormatExchangeCurrency is a method that formats and returns a currency pair
// based on the user currency display preferences
func FormatExchangeCurrency(exchName string, p pair.CurrencyPair) pair.CurrencyItem {
cfg := config.GetConfig()
exch, _ := cfg.GetExchangeConfig(exchName)
return p.Display(exch.RequestCurrencyPairFormat.Delimiter,
exch.RequestCurrencyPairFormat.Uppercase)
}
// FormatCurrency is a method that formats and returns a currency pair
@@ -126,20 +289,50 @@ func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) {
}
}
// UpdateAvailableCurrencies is a method that sets new pairs to the current
// exchange
func (e *Base) UpdateAvailableCurrencies(exchangeProducts []string) error {
// UpdateEnabledCurrencies is a method that sets new pairs to the current
// exchange. Setting force to true upgrades the enabled currencies
func (e *Base) UpdateEnabledCurrencies(exchangeProducts []string, force bool) error {
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
diff := common.StringSliceDifference(e.AvailablePairs, exchangeProducts)
if len(diff) > 0 {
diff := common.StringSliceDifference(e.EnabledPairs, exchangeProducts)
if force || len(diff) > 0 {
cfg := config.GetConfig()
exch, err := cfg.GetExchangeConfig(e.Name)
if err != nil {
return err
}
log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff)
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
cfg.UpdateExchangeConfig(exch)
if force {
log.Printf("%s forced update of enabled pairs.", e.Name)
} else {
log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff)
}
exch.EnabledPairs = common.JoinStrings(exchangeProducts, ",")
e.EnabledPairs = exchangeProducts
return cfg.UpdateExchangeConfig(exch)
}
return nil
}
// UpdateAvailableCurrencies is a method that sets new pairs to the current
// exchange. Setting force to true upgrades the available currencies
func (e *Base) UpdateAvailableCurrencies(exchangeProducts []string, force bool) error {
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
diff := common.StringSliceDifference(e.AvailablePairs, exchangeProducts)
if force || len(diff) > 0 {
cfg := config.GetConfig()
exch, err := cfg.GetExchangeConfig(e.Name)
if err != nil {
return err
}
if force {
log.Printf("%s forced update of available pairs.", e.Name)
} else {
log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff)
}
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
e.AvailablePairs = exchangeProducts
return cfg.UpdateExchangeConfig(exch)
}
return nil
}

View File

@@ -3,9 +3,8 @@ package exchange
import (
"testing"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/currency/pair"
)
func TestGetName(t *testing.T) {
@@ -19,6 +18,29 @@ func TestGetName(t *testing.T) {
}
}
func TestSetCurrencyPairFormat(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
if err != nil {
t.Fatalf("Failed to load config file. Error: %s", err)
}
exch, err := cfg.GetExchangeConfig("GDAX")
if err != nil {
t.Fatalf("Failed to load GDAX exchange config. Error: %s", err)
}
exch.RequestCurrencyPairFormat = nil
exch.ConfigCurrencyPairFormat = nil
err = cfg.UpdateExchangeConfig(exch)
if err != nil {
t.Fatalf("Failed to update GDAX config. Error: %s", err)
}
// to-do
}
func TestGetEnabledCurrencies(t *testing.T) {
enabledPairs := []string{"BTCUSD", "BTCAUD", "LTCUSD", "LTCAUD"}
GetEnabledCurrencies := Base{
@@ -27,7 +49,7 @@ func TestGetEnabledCurrencies(t *testing.T) {
}
enCurr := GetEnabledCurrencies.GetEnabledCurrencies()
if enCurr[0] != "BTCUSD" {
if enCurr[0].Pair().String() != "BTCUSD" {
t.Error("Test Failed - Exchange GetEnabledCurrencies() incorrect string")
}
}
@@ -40,11 +62,75 @@ func TestGetAvailableCurrencies(t *testing.T) {
}
enCurr := GetEnabledCurrencies.GetAvailableCurrencies()
if enCurr[0] != "BTCUSD" {
if enCurr[0].Pair().String() != "BTCUSD" {
t.Error("Test Failed - Exchange GetAvailableCurrencies() incorrect string")
}
}
func TestGetExchangeFormatCurrencySeperator(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
if err != nil {
t.Fatalf("Failed to load config file. Error: %s", err)
}
expected := true
actual := GetExchangeFormatCurrencySeperator("BTCE")
if expected != actual {
t.Errorf("Test failed - TestGetExchangeFormatCurrencySeperator expected %v != actual %v",
expected, actual)
}
expected = false
actual = GetExchangeFormatCurrencySeperator("LocalBitcoins")
if expected != actual {
t.Errorf("Test failed - TestGetExchangeFormatCurrencySeperator expected %v != actual %v",
expected, actual)
}
}
func TestGetAndFormatExchangeCurrencies(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
if err != nil {
t.Fatalf("Failed to load config file. Error: %s", err)
}
var pairs []pair.CurrencyPair
pairs = append(pairs, pair.NewCurrencyPairDelimiter("BTC_USD", "_"))
pairs = append(pairs, pair.NewCurrencyPairDelimiter("LTC_BTC", "_"))
actual, err := GetAndFormatExchangeCurrencies("Liqui", pairs)
if err != nil {
t.Errorf("Test failed - Exchange TestGetAndFormatExchangeCurrencies error %s", err)
}
expected := pair.CurrencyItem("btc_usd-ltc_btc")
if actual.String() != expected.String() {
t.Errorf("Test failed - Exchange TestGetAndFormatExchangeCurrencies %s != %s",
actual, expected)
}
}
func TestFormatExchangeCurrency(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
if err != nil {
t.Fatalf("Failed to load config file. Error: %s", err)
}
pair := pair.NewCurrencyPair("BTC", "USD")
expected := "BTC-USD"
actual := FormatExchangeCurrency("GDAX", pair)
if actual.String() != expected {
t.Errorf("Test failed - Exchange TestFormatExchangeCurrency %s != %s",
actual, expected)
}
}
func TestFormatCurrency(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
@@ -97,6 +183,23 @@ func TestSetAPIKeys(t *testing.T) {
SetAPIKeys.SetAPIKeys("RocketMan", "Digereedoo", "007", true)
}
func TestUpdateEnabledCurrencies(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
UAC := Base{Name: "ANX"}
enabledCurrencies := []string{"ltc", "btc", "usd", "aud"}
if err != nil {
t.Error(
"Test Failed - Exchange UpdateEnabledCurrencies() did not set correct values",
)
}
err2 := UAC.UpdateEnabledCurrencies(enabledCurrencies, false)
if err2 != nil {
t.Errorf("Test Failed - Exchange UpdateEnabledCurrencies() error: %s", err2)
}
}
func TestUpdateAvailableCurrencies(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
@@ -108,7 +211,7 @@ func TestUpdateAvailableCurrencies(t *testing.T) {
"Test Failed - Exchange UpdateAvailableCurrencies() did not set correct values",
)
}
err2 := UAC.UpdateAvailableCurrencies(exchangeProducts)
err2 := UAC.UpdateAvailableCurrencies(exchangeProducts, false)
if err2 != nil {
t.Errorf("Test Failed - Exchange UpdateAvailableCurrencies() error: %s", err2)
}

View File

@@ -46,6 +46,10 @@ func (g *GDAX) SetDefaults() {
g.Verbose = false
g.Websocket = false
g.RESTPollingDelay = 10
g.RequestCurrencyPairFormat.Delimiter = "-"
g.RequestCurrencyPairFormat.Uppercase = true
g.ConfigCurrencyPairFormat.Delimiter = ""
g.ConfigCurrencyPairFormat.Uppercase = true
}
func (g *GDAX) Setup(exch config.ExchangeConfig) {
@@ -61,6 +65,10 @@ func (g *GDAX) Setup(exch config.ExchangeConfig) {
g.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
g.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
g.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := g.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -37,16 +37,16 @@ func (g *GDAX) Run() {
currencies = append(currencies, x.ID[0:3]+x.ID[4:])
}
}
err = g.UpdateAvailableCurrencies(currencies)
err = g.UpdateAvailableCurrencies(currencies, false)
if err != nil {
log.Printf("%s Failed to get config.\n", g.GetName())
}
}
for g.Enabled {
for _, x := range g.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
currency.Delimiter = "-"
pairs := g.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := g.GetTickerPrice(currency)
@@ -88,12 +88,12 @@ func (g *GDAX) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
}
var tickerPrice ticker.TickerPrice
tick, err := g.GetTicker(p.Pair().String())
tick, err := g.GetTicker(exchange.FormatExchangeCurrency(g.Name, p).String())
if err != nil {
return ticker.TickerPrice{}, err
}
stats, err := g.GetStats(p.Pair().String())
stats, err := g.GetStats(exchange.FormatExchangeCurrency(g.Name, p).String())
if err != nil {
return ticker.TickerPrice{}, err

View File

@@ -45,6 +45,10 @@ func (g *Gemini) SetDefaults() {
g.Verbose = false
g.Websocket = false
g.RESTPollingDelay = 10
g.RequestCurrencyPairFormat.Delimiter = ""
g.RequestCurrencyPairFormat.Uppercase = true
g.ConfigCurrencyPairFormat.Delimiter = ""
g.ConfigCurrencyPairFormat.Uppercase = true
}
func (g *Gemini) Setup(exch config.ExchangeConfig) {
@@ -60,6 +64,10 @@ func (g *Gemini) Setup(exch config.ExchangeConfig) {
g.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
g.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
g.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := g.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -26,15 +26,16 @@ func (g *Gemini) Run() {
if err != nil {
log.Printf("%s Failed to get available symbols.\n", g.GetName())
} else {
err = g.UpdateAvailableCurrencies(exchangeProducts)
err = g.UpdateAvailableCurrencies(exchangeProducts, false)
if err != nil {
log.Printf("%s Failed to get config.\n", g.GetName())
}
}
for g.Enabled {
for _, x := range g.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := g.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := g.GetTickerPrice(currency)
if err != nil {

View File

@@ -29,6 +29,10 @@ func (h *HUOBI) SetDefaults() {
h.Verbose = false
h.Websocket = false
h.RESTPollingDelay = 10
h.RequestCurrencyPairFormat.Delimiter = ""
h.RequestCurrencyPairFormat.Uppercase = false
h.ConfigCurrencyPairFormat.Delimiter = ""
h.ConfigCurrencyPairFormat.Uppercase = true
}
func (h *HUOBI) Setup(exch config.ExchangeConfig) {
@@ -44,6 +48,10 @@ func (h *HUOBI) Setup(exch config.ExchangeConfig) {
h.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
h.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
h.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := h.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -29,8 +29,9 @@ func (h *HUOBI) Run() {
}
for h.Enabled {
for _, x := range h.EnabledPairs {
curr := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := h.GetEnabledCurrencies()
for x := range pairs {
curr := pairs[x]
go func() {
ticker, err := h.GetTickerPrice(curr)
if err != nil {

View File

@@ -31,6 +31,10 @@ func (i *ItBit) SetDefaults() {
i.Verbose = false
i.Websocket = false
i.RESTPollingDelay = 10
i.RequestCurrencyPairFormat.Delimiter = ""
i.RequestCurrencyPairFormat.Uppercase = true
i.ConfigCurrencyPairFormat.Delimiter = ""
i.ConfigCurrencyPairFormat.Uppercase = true
}
func (i *ItBit) Setup(exch config.ExchangeConfig) {
@@ -46,6 +50,10 @@ func (i *ItBit) Setup(exch config.ExchangeConfig) {
i.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
i.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
i.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := i.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -22,8 +22,9 @@ func (i *ItBit) Run() {
}
for i.Enabled {
for _, x := range i.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := i.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := i.GetTickerPrice(currency)
if err != nil {

View File

@@ -55,6 +55,11 @@ func (k *Kraken) SetDefaults() {
k.Websocket = false
k.RESTPollingDelay = 10
k.Ticker = make(map[string]KrakenTicker)
k.RequestCurrencyPairFormat.Delimiter = ""
k.RequestCurrencyPairFormat.Uppercase = true
k.RequestCurrencyPairFormat.Separator = ","
k.ConfigCurrencyPairFormat.Delimiter = ""
k.ConfigCurrencyPairFormat.Uppercase = true
}
func (k *Kraken) Setup(exch config.ExchangeConfig) {
@@ -70,6 +75,10 @@ func (k *Kraken) Setup(exch config.ExchangeConfig) {
k.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
k.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
k.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := k.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -4,7 +4,6 @@ import (
"log"
"time"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/orderbook"
@@ -30,21 +29,28 @@ func (k *Kraken) Run() {
for _, v := range assetPairs {
exchangeProducts = append(exchangeProducts, v.Altname)
}
err = k.UpdateAvailableCurrencies(exchangeProducts)
err = k.UpdateAvailableCurrencies(exchangeProducts, false)
if err != nil {
log.Printf("%s Failed to get config.\n", k.GetName())
}
}
for k.Enabled {
err := k.GetTicker(common.JoinStrings(k.EnabledPairs, ","))
pairs := k.GetEnabledCurrencies()
pairsCollated, err := exchange.GetAndFormatExchangeCurrencies(k.Name, pairs)
if err != nil {
log.Println(err)
continue
}
err = k.GetTicker(pairsCollated.String())
if err != nil {
log.Println(err)
} else {
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)
stats.AddExchangeInfo(k.GetName(), x[0:3], x[3:], ticker.Last, ticker.Volume)
for _, x := range pairs {
ticker := k.Ticker[x.Pair().String()]
log.Printf("Kraken %s Last %f High %f Low %f Volume %f\n", exchange.FormatCurrency(x).String(), ticker.Last, ticker.High, ticker.Low, ticker.Volume)
stats.AddExchangeInfo(k.GetName(), x.GetFirstCurrency().String(), x.GetSecondCurrency().String(),
ticker.Last, ticker.Volume)
}
}
time.Sleep(time.Second * k.RESTPollingDelay)

View File

@@ -42,6 +42,10 @@ func (l *LakeBTC) SetDefaults() {
l.Verbose = false
l.Websocket = false
l.RESTPollingDelay = 10
l.RequestCurrencyPairFormat.Delimiter = ""
l.RequestCurrencyPairFormat.Uppercase = true
l.ConfigCurrencyPairFormat.Delimiter = ""
l.ConfigCurrencyPairFormat.Uppercase = true
}
func (l *LakeBTC) Setup(exch config.ExchangeConfig) {
@@ -57,6 +61,10 @@ func (l *LakeBTC) Setup(exch config.ExchangeConfig) {
l.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
l.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
l.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := l.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -23,8 +23,9 @@ func (l *LakeBTC) Run() {
}
for l.Enabled {
for _, x := range l.EnabledPairs {
currency := pair.NewCurrencyPair(x[0:3], x[3:])
pairs := l.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
ticker, err := l.GetTickerPrice(currency)
if err != nil {
log.Println(err)

View File

@@ -46,6 +46,11 @@ func (l *Liqui) SetDefaults() {
l.Websocket = false
l.RESTPollingDelay = 10
l.Ticker = make(map[string]LiquiTicker)
l.RequestCurrencyPairFormat.Delimiter = "_"
l.RequestCurrencyPairFormat.Uppercase = false
l.RequestCurrencyPairFormat.Separator = "-"
l.ConfigCurrencyPairFormat.Delimiter = "_"
l.ConfigCurrencyPairFormat.Uppercase = true
}
func (l *Liqui) Setup(exch config.ExchangeConfig) {
@@ -61,6 +66,10 @@ func (l *Liqui) Setup(exch config.ExchangeConfig) {
l.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
l.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
l.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := l.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -29,23 +29,23 @@ func (l *Liqui) Run() {
log.Printf("%s Unable to fetch info.\n", l.GetName())
} else {
exchangeProducts := l.GetAvailablePairs(true)
err = l.UpdateAvailableCurrencies(exchangeProducts)
err = l.UpdateAvailableCurrencies(exchangeProducts, false)
if err != nil {
log.Printf("%s Failed to get config.\n", l.GetName())
}
}
pairs := []string{}
for _, x := range l.EnabledPairs {
currencies := common.SplitStrings(x, "_")
x = common.StringToLower(currencies[0]) + "_" + common.StringToLower(currencies[1])
pairs = append(pairs, x)
pairsString, err := exchange.GetAndFormatExchangeCurrencies(l.Name,
l.GetEnabledCurrencies())
if err != nil {
log.Println(err)
l.Enabled = false
return
}
pairsString := common.JoinStrings(pairs, "-")
for l.Enabled {
go func() {
ticker, err := l.GetTicker(pairsString)
ticker, err := l.GetTicker(pairsString.String())
if err != nil {
log.Println(err)
return
@@ -63,9 +63,9 @@ func (l *Liqui) Run() {
func (l *Liqui) GetTickerPrice(p pair.CurrencyPair) (ticker.TickerPrice, error) {
var tickerPrice ticker.TickerPrice
tick, ok := l.Ticker[p.Pair().Lower().String()]
tick, ok := l.Ticker[exchange.FormatExchangeCurrency(l.Name, p).String()]
if !ok {
return tickerPrice, errors.New("Unable to get currency.")
return tickerPrice, errors.New("unable to get currency")
}
tickerPrice.Pair = p
tickerPrice.Ask = tick.Buy
@@ -85,7 +85,7 @@ func (l *Liqui) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er
}
var orderBook orderbook.OrderbookBase
orderbookNew, err := l.GetDepth(p.Pair().Lower().String())
orderbookNew, err := l.GetDepth(exchange.FormatExchangeCurrency(l.Name, p).String())
if err != nil {
return orderBook, err
}

View File

@@ -38,6 +38,10 @@ func (l *LocalBitcoins) SetDefaults() {
l.Verbose = false
l.Websocket = false
l.RESTPollingDelay = 10
l.RequestCurrencyPairFormat.Delimiter = ""
l.RequestCurrencyPairFormat.Uppercase = true
l.ConfigCurrencyPairFormat.Delimiter = ""
l.ConfigCurrencyPairFormat.Uppercase = true
}
func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) {
@@ -53,6 +57,10 @@ func (l *LocalBitcoins) Setup(exch config.ExchangeConfig) {
l.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
l.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
l.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := l.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -22,8 +22,9 @@ func (l *LocalBitcoins) Run() {
}
for l.Enabled {
for _, x := range l.EnabledPairs {
currency := pair.NewCurrencyPair("BTC", x[3:])
pairs := l.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
ticker, err := l.GetTickerPrice(currency)
if err != nil {

View File

@@ -78,6 +78,13 @@ type OKCoin struct {
WebsocketConn *websocket.Conn
}
func (o *OKCoin) setCurrencyPairFormats() {
o.RequestCurrencyPairFormat.Delimiter = "_"
o.RequestCurrencyPairFormat.Uppercase = false
o.ConfigCurrencyPairFormat.Delimiter = ""
o.ConfigCurrencyPairFormat.Uppercase = true
}
func (o *OKCoin) SetDefaults() {
o.SetErrorDefaults()
o.SetWebsocketErrorDefaults()
@@ -92,10 +99,12 @@ func (o *OKCoin) SetDefaults() {
o.Name = "OKCOIN International"
o.WebsocketURL = OKCOIN_WEBSOCKET_URL
okcoinDefaultsSet = true
o.setCurrencyPairFormats()
} else {
o.APIUrl = OKCOIN_API_URL_CHINA
o.Name = "OKCOIN China"
o.WebsocketURL = OKCOIN_WEBSOCKET_URL_CHINA
o.setCurrencyPairFormats()
}
}
@@ -112,6 +121,10 @@ func (o *OKCoin) Setup(exch config.ExchangeConfig) {
o.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
o.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
o.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := o.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -29,14 +29,14 @@ func (o *OKCoin) Run() {
}
for o.Enabled {
for _, x := range o.EnabledPairs {
curr := pair.NewCurrencyPair(x[0:3], x[3:])
curr.Delimiter = "_"
pairs := o.GetEnabledCurrencies()
for x := range pairs {
curr := pairs[x]
if o.APIUrl == OKCOIN_API_URL {
for _, y := range o.FuturesValues {
futuresValue := y
go func() {
ticker, err := o.GetFuturesTicker(curr.Pair().Lower().String(), futuresValue)
ticker, err := o.GetFuturesTicker(exchange.FormatExchangeCurrency(o.Name, curr).String(), futuresValue)
if err != nil {
log.Println(err)
return
@@ -81,7 +81,7 @@ func (o *OKCoin) GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice,
}
var tickerPrice ticker.TickerPrice
tick, err := o.GetTicker(currency.Pair().Lower().String())
tick, err := o.GetTicker(exchange.FormatExchangeCurrency(o.Name, currency).String())
if err != nil {
return tickerPrice, err
}
@@ -103,7 +103,7 @@ func (o *OKCoin) GetOrderbookEx(currency pair.CurrencyPair) (orderbook.Orderbook
}
var orderBook orderbook.OrderbookBase
orderbookNew, err := o.GetOrderBook(currency.Pair().Lower().String(), 200, false)
orderbookNew, err := o.GetOrderBook(exchange.FormatExchangeCurrency(o.Name, currency).String(), 200, false)
if err != nil {
return orderBook, err
}

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"log"
"net/url"
"strconv"
"time"
@@ -57,6 +58,10 @@ func (p *Poloniex) SetDefaults() {
p.Verbose = false
p.Websocket = false
p.RESTPollingDelay = 10
p.RequestCurrencyPairFormat.Delimiter = "_"
p.RequestCurrencyPairFormat.Uppercase = true
p.ConfigCurrencyPairFormat.Delimiter = "_"
p.ConfigCurrencyPairFormat.Uppercase = true
}
func (p *Poloniex) Setup(exch config.ExchangeConfig) {
@@ -72,6 +77,10 @@ func (p *Poloniex) Setup(exch config.ExchangeConfig) {
p.BaseCurrencies = common.SplitStrings(exch.BaseCurrencies, ",")
p.AvailablePairs = common.SplitStrings(exch.AvailablePairs, ",")
p.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
err := p.SetCurrencyPairFormat()
if err != nil {
log.Fatal(err)
}
}
}

View File

@@ -28,8 +28,9 @@ func (p *Poloniex) Run() {
}
for p.Enabled {
for _, x := range p.EnabledPairs {
currency := pair.NewCurrencyPairDelimiter(x, "_")
pairs := p.GetEnabledCurrencies()
for x := range pairs {
currency := pairs[x]
go func() {
ticker, err := p.GetTickerPrice(currency)
if err != nil {