Remove non-needed getter functions for currency pairs

Fixes https://github.com/thrasher-/gocryptotrader/issues/180
This commit is contained in:
Adrian Gallagher
2018-09-20 15:01:11 +10:00
parent 042c4bfef2
commit 96cbf90446
9 changed files with 21 additions and 31 deletions

View File

@@ -32,16 +32,6 @@ type CurrencyPair struct {
SecondCurrency CurrencyItem `json:"second_currency"`
}
// GetFirstCurrency returns the first currency item
func (c CurrencyPair) GetFirstCurrency() CurrencyItem {
return c.FirstCurrency
}
// GetSecondCurrency returns the second currency item
func (c CurrencyPair) GetSecondCurrency() CurrencyItem {
return c.SecondCurrency
}
// Pair returns a currency pair string
func (c CurrencyPair) Pair() CurrencyItem {
return c.FirstCurrency + CurrencyItem(c.Delimiter) + c.SecondCurrency

View File

@@ -37,10 +37,10 @@ func TestString(t *testing.T) {
}
}
func TestGetFirstCurrency(t *testing.T) {
func TestFirstCurrency(t *testing.T) {
t.Parallel()
pair := NewCurrencyPair("BTC", "USD")
actual := pair.GetFirstCurrency()
actual := pair.FirstCurrency
expected := CurrencyItem("BTC")
if actual != expected {
t.Errorf(
@@ -50,10 +50,10 @@ func TestGetFirstCurrency(t *testing.T) {
}
}
func TestGetSecondCurrency(t *testing.T) {
func TestSecondCurrency(t *testing.T) {
t.Parallel()
pair := NewCurrencyPair("BTC", "USD")
actual := pair.GetSecondCurrency()
actual := pair.SecondCurrency
expected := CurrencyItem("USD")
if actual != expected {
t.Errorf(

View File

@@ -149,7 +149,7 @@ func TestCheckFXString(t *testing.T) {
t.Parallel()
p := pair.NewCurrencyPairDelimiter("FXBTC_JPY", "_")
p = b.CheckFXString(p)
if p.GetFirstCurrency().String() != "FX_BTC" {
if p.FirstCurrency.String() != "FX_BTC" {
t.Error("test failed - Bitflyer - CheckFXString() error")
}
}

View File

@@ -81,7 +81,7 @@ func (b *Bitflyer) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker
// CheckFXString upgrades currency pair if needed
func (b *Bitflyer) CheckFXString(p pair.CurrencyPair) pair.CurrencyPair {
if common.StringContains(p.GetFirstCurrency().String(), "FX") {
if common.StringContains(p.FirstCurrency.String(), "FX") {
p.FirstCurrency = "FX_BTC"
return p
}

View File

@@ -64,7 +64,7 @@ func (b *Bithumb) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pr
}
for _, x := range b.GetEnabledCurrencies() {
currency := x.GetFirstCurrency().String()
currency := x.FirstCurrency.String()
var tp ticker.Price
tp.Pair = x
tp.Ask = tickers[currency].SellPrice
@@ -99,7 +99,7 @@ func (b *Bithumb) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *Bithumb) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
currency := p.GetFirstCurrency().String()
currency := p.FirstCurrency.String()
orderbookNew, err := b.GetOrderBook(currency)
if err != nil {

View File

@@ -59,8 +59,8 @@ func (b *BTCMarkets) Run() {
// UpdateTicker updates and returns the ticker for a currency pair
func (b *BTCMarkets) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error) {
var tickerPrice ticker.Price
tick, err := b.GetTicker(p.GetFirstCurrency().String(),
p.GetSecondCurrency().String())
tick, err := b.GetTicker(p.FirstCurrency.String(),
p.SecondCurrency.String())
if err != nil {
return tickerPrice, err
}
@@ -93,8 +93,8 @@ func (b *BTCMarkets) GetOrderbookEx(p pair.CurrencyPair, assetType string) (orde
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (b *BTCMarkets) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := b.GetOrderbook(p.GetFirstCurrency().String(),
p.GetSecondCurrency().String())
orderbookNew, err := b.GetOrderbook(p.FirstCurrency.String(),
p.SecondCurrency.String())
if err != nil {
return orderBook, err
}
@@ -151,7 +151,7 @@ func (b *BTCMarkets) GetExchangeHistory(p pair.CurrencyPair, assetType string) (
// SubmitExchangeOrder submits a new order
func (b *BTCMarkets) SubmitExchangeOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (int64, error) {
return b.NewOrder(p.GetFirstCurrency().Upper().String(), p.GetSecondCurrency().Upper().String(), price, amount, side.Format(b.GetName()), orderType.Format(b.GetName()), clientID)
return b.NewOrder(p.FirstCurrency.Upper().String(), p.SecondCurrency.Upper().String(), price, amount, side.Format(b.GetName()), orderType.Format(b.GetName()), clientID)
}
// ModifyExchangeOrder will allow of changing orderbook placement and limit to

View File

@@ -69,7 +69,7 @@ func (l *LocalBitcoins) GetOrderbookEx(p pair.CurrencyPair, assetType string) (o
// UpdateOrderbook updates and returns the orderbook for a currency pair
func (l *LocalBitcoins) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error) {
var orderBook orderbook.Base
orderbookNew, err := l.GetOrderbook(p.GetSecondCurrency().String())
orderbookNew, err := l.GetOrderbook(p.SecondCurrency.String())
if err != nil {
return orderBook, err
}

View File

@@ -83,7 +83,7 @@ func GetOrderbook(exchange string, p pair.CurrencyPair, orderbookType string) (B
return Base{}, err
}
if !FirstCurrencyExists(exchange, p.GetFirstCurrency()) {
if !FirstCurrencyExists(exchange, p.FirstCurrency) {
return Base{}, errors.New(ErrPrimaryCurrencyNotFound)
}
@@ -91,7 +91,7 @@ func GetOrderbook(exchange string, p pair.CurrencyPair, orderbookType string) (B
return Base{}, errors.New(ErrSecondaryCurrencyNotFound)
}
return orderbook.Orderbook[p.GetFirstCurrency()][p.GetSecondCurrency()][orderbookType], nil
return orderbook.Orderbook[p.FirstCurrency][p.SecondCurrency][orderbookType], nil
}
// GetOrderbookByExchange returns an exchange orderbook
@@ -128,8 +128,8 @@ func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
defer m.Unlock()
for _, y := range Orderbooks {
if y.ExchangeName == exchange {
if _, ok := y.Orderbook[p.GetFirstCurrency()]; ok {
if _, ok := y.Orderbook[p.GetFirstCurrency()][p.GetSecondCurrency()]; ok {
if _, ok := y.Orderbook[p.FirstCurrency]; ok {
if _, ok := y.Orderbook[p.FirstCurrency][p.SecondCurrency]; ok {
return true
}
}
@@ -175,7 +175,7 @@ func ProcessOrderbook(exchangeName string, p pair.CurrencyPair, orderbookNew Bas
return
}
if FirstCurrencyExists(exchangeName, p.GetFirstCurrency()) {
if FirstCurrencyExists(exchangeName, p.FirstCurrency) {
if !SecondCurrencyExists(exchangeName, p) {
m.Lock()
a := orderbook.Orderbook[p.FirstCurrency]

View File

@@ -121,8 +121,8 @@ func SecondCurrencyExists(exchange string, p pair.CurrencyPair) bool {
defer m.Unlock()
for _, y := range Tickers {
if y.ExchangeName == exchange {
if _, ok := y.Price[p.GetFirstCurrency()]; ok {
if _, ok := y.Price[p.GetFirstCurrency()][p.GetSecondCurrency()]; ok {
if _, ok := y.Price[p.FirstCurrency]; ok {
if _, ok := y.Price[p.FirstCurrency][p.SecondCurrency]; ok {
return true
}
}