Skip to content

Commit

Permalink
Remove non-needed getter functions for currency pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Sep 20, 2018
1 parent 042c4bf commit 96cbf90
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 31 deletions.
10 changes: 0 additions & 10 deletions currency/pair/pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions currency/pair/pair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitflyer/bitflyer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion exchanges/bitflyer/bitflyer_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions exchanges/bithumb/bithumb_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions exchanges/btcmarkets/btcmarkets_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exchanges/localbitcoins/localbitcoins_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 5 additions & 5 deletions exchanges/orderbook/orderbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ 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)
}

if !SecondCurrencyExists(exchange, p) {
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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions exchanges/ticker/ticker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 96cbf90

Please sign in to comment.