From de48b62731b34fb8784e8f97f7a2b40f133b460a Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Thu, 27 Jul 2017 17:28:55 +1000 Subject: [PATCH] Fixed stutter issues from exchange.go --- exchanges/alphapoint/alphapoint.go | 2 +- exchanges/alphapoint/alphapoint_wrapper.go | 6 ++-- exchanges/anx/anx.go | 2 +- exchanges/anx/anx_wrapper.go | 4 +-- exchanges/bitfinex/bitfinex.go | 2 +- exchanges/bitfinex/bitfinex_wrapper.go | 6 ++-- exchanges/bitstamp/bitstamp.go | 2 +- exchanges/bitstamp/bitstamp_wrapper.go | 12 +++---- exchanges/btcc/btcc.go | 2 +- exchanges/btcc/btcc_wrapper.go | 4 +-- exchanges/btce/btce.go | 2 +- exchanges/btce/btce_wrapper.go | 6 ++-- exchanges/btcmarkets/btcmarkets.go | 2 +- exchanges/btcmarkets/btcmarkets_wrapper.go | 6 ++-- exchanges/coinut/coinut.go | 2 +- exchanges/coinut/coinut_wrapper.go | 6 ++-- exchanges/exchange.go | 35 +++++++++---------- exchanges/exchange_test.go | 12 +++---- exchanges/gdax/gdax.go | 2 +- exchanges/gdax/gdax_wrapper.go | 6 ++-- exchanges/gemini/gemini.go | 2 +- exchanges/gemini/gemini_wrapper.go | 6 ++-- exchanges/huobi/huobi.go | 2 +- exchanges/huobi/huobi_wrapper.go | 4 +-- exchanges/itbit/itbit.go | 2 +- exchanges/itbit/itbit_wrapper.go | 4 +-- exchanges/kraken/kraken.go | 2 +- exchanges/kraken/kraken_wrapper.go | 4 +-- exchanges/lakebtc/lakebtc.go | 2 +- exchanges/lakebtc/lakebtc_wrapper.go | 6 ++-- exchanges/liqui/liqui.go | 2 +- exchanges/liqui/liqui_wrapper.go | 6 ++-- exchanges/localbitcoins/localbitcoins.go | 2 +- .../localbitcoins/localbitcoins_wrapper.go | 6 ++-- exchanges/okcoin/okcoin.go | 2 +- exchanges/okcoin/okcoin_wrapper.go | 12 +++---- exchanges/poloniex/poloniex.go | 2 +- exchanges/poloniex/poloniex_wrapper.go | 6 ++-- main.go | 2 +- wallet_routes.go | 14 ++++---- 40 files changed, 104 insertions(+), 105 deletions(-) diff --git a/exchanges/alphapoint/alphapoint.go b/exchanges/alphapoint/alphapoint.go index 4da8105f..6aea4d3a 100644 --- a/exchanges/alphapoint/alphapoint.go +++ b/exchanges/alphapoint/alphapoint.go @@ -37,7 +37,7 @@ const ( ) type Alphapoint struct { - exchange.ExchangeBase + exchange.Base WebsocketConn *websocket.Conn } diff --git a/exchanges/alphapoint/alphapoint_wrapper.go b/exchanges/alphapoint/alphapoint_wrapper.go index 4548c6ad..973ad751 100644 --- a/exchanges/alphapoint/alphapoint_wrapper.go +++ b/exchanges/alphapoint/alphapoint_wrapper.go @@ -10,15 +10,15 @@ import ( ) //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Alphapoint exchange -func (e *Alphapoint) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Alphapoint) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() account, err := e.GetAccountInfo() if err != nil { return response, err } for i := 0; i < len(account.Currencies); i++ { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = account.Currencies[i].Name exchangeCurrency.TotalValue = float64(account.Currencies[i].Balance) exchangeCurrency.Hold = float64(account.Currencies[i].Hold) diff --git a/exchanges/anx/anx.go b/exchanges/anx/anx.go index c8e985b9..7be5faa0 100644 --- a/exchanges/anx/anx.go +++ b/exchanges/anx/anx.go @@ -28,7 +28,7 @@ const ( ) type ANX struct { - exchange.ExchangeBase + exchange.Base } func (a *ANX) SetDefaults() { diff --git a/exchanges/anx/anx_wrapper.go b/exchanges/anx/anx_wrapper.go index 8e00e11c..12d5d5d7 100644 --- a/exchanges/anx/anx_wrapper.go +++ b/exchanges/anx/anx_wrapper.go @@ -66,8 +66,8 @@ func (e *ANX) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, erro } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ANX exchange -func (e *ANX) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *ANX) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() return response, nil } diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index d4b941df..6a272d42 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -55,7 +55,7 @@ const ( ) type Bitfinex struct { - exchange.ExchangeBase + exchange.Base WebsocketConn *websocket.Conn WebsocketSubdChannels map[int]BitfinexWebsocketChanInfo } diff --git a/exchanges/bitfinex/bitfinex_wrapper.go b/exchanges/bitfinex/bitfinex_wrapper.go index 7702c700..e205d57e 100644 --- a/exchanges/bitfinex/bitfinex_wrapper.go +++ b/exchanges/bitfinex/bitfinex_wrapper.go @@ -106,8 +106,8 @@ func (b *Bitfinex) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitfinex exchange -func (e *Bitfinex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Bitfinex) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountBalance() if err != nil { @@ -118,7 +118,7 @@ func (e *Bitfinex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error } for i := 0; i < len(accountBalance); i++ { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = common.StringToUpper(accountBalance[i].Currency) exchangeCurrency.TotalValue = accountBalance[i].Amount exchangeCurrency.Hold = accountBalance[i].Available diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index 92e4fa58..577e387d 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -45,7 +45,7 @@ const ( ) type Bitstamp struct { - exchange.ExchangeBase + exchange.Base Balance BitstampBalances } diff --git a/exchanges/bitstamp/bitstamp_wrapper.go b/exchanges/bitstamp/bitstamp_wrapper.go index c824a6a1..65ccd114 100644 --- a/exchanges/bitstamp/bitstamp_wrapper.go +++ b/exchanges/bitstamp/bitstamp_wrapper.go @@ -95,33 +95,33 @@ func (b *Bitstamp) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitstamp exchange -func (e *Bitstamp) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Bitstamp) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetBalance() if err != nil { return response, err } - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "BTC", TotalValue: accountBalance.BTCAvailable, Hold: accountBalance.BTCReserved, }) - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "XRP", TotalValue: accountBalance.XRPAvailable, Hold: accountBalance.XRPReserved, }) - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "USD", TotalValue: accountBalance.USDAvailable, Hold: accountBalance.USDReserved, }) - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "EUR", TotalValue: accountBalance.EURAvailable, Hold: accountBalance.EURReserved, diff --git a/exchanges/btcc/btcc.go b/exchanges/btcc/btcc.go index 83147794..dfae06c7 100644 --- a/exchanges/btcc/btcc.go +++ b/exchanges/btcc/btcc.go @@ -43,7 +43,7 @@ const ( ) type BTCC struct { - exchange.ExchangeBase + exchange.Base } func (b *BTCC) SetDefaults() { diff --git a/exchanges/btcc/btcc_wrapper.go b/exchanges/btcc/btcc_wrapper.go index ed634df6..0ed067a1 100644 --- a/exchanges/btcc/btcc_wrapper.go +++ b/exchanges/btcc/btcc_wrapper.go @@ -92,8 +92,8 @@ func (b *BTCC) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err //TODO: Retrieve BTCC info //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange -func (e *BTCC) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *BTCC) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() return response, nil } diff --git a/exchanges/btce/btce.go b/exchanges/btce/btce.go index 856d8b53..d3b399ae 100644 --- a/exchanges/btce/btce.go +++ b/exchanges/btce/btce.go @@ -36,7 +36,7 @@ const ( ) type BTCE struct { - exchange.ExchangeBase + exchange.Base Ticker map[string]BTCeTicker } diff --git a/exchanges/btce/btce_wrapper.go b/exchanges/btce/btce_wrapper.go index 5f4433e0..04cdffa8 100644 --- a/exchanges/btce/btce_wrapper.go +++ b/exchanges/btce/btce_wrapper.go @@ -94,8 +94,8 @@ func (b *BTCE) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCE exchange -func (e *BTCE) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *BTCE) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountInfo() if err != nil { @@ -103,7 +103,7 @@ func (e *BTCE) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { } for x, y := range accountBalance.Funds { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = common.StringToUpper(x) exchangeCurrency.TotalValue = y exchangeCurrency.Hold = 0 diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index 7271df4e..97903d82 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -27,7 +27,7 @@ const ( ) type BTCMarkets struct { - exchange.ExchangeBase + exchange.Base Ticker map[string]BTCMarketsTicker } diff --git a/exchanges/btcmarkets/btcmarkets_wrapper.go b/exchanges/btcmarkets/btcmarkets_wrapper.go index 99ebe701..52c279a9 100644 --- a/exchanges/btcmarkets/btcmarkets_wrapper.go +++ b/exchanges/btcmarkets/btcmarkets_wrapper.go @@ -89,15 +89,15 @@ func (b *BTCMarkets) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBas } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCMarkets exchange -func (e *BTCMarkets) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *BTCMarkets) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountBalance() if err != nil { return response, err } for i := 0; i < len(accountBalance); i++ { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = accountBalance[i].Currency exchangeCurrency.TotalValue = accountBalance[i].Balance exchangeCurrency.Hold = accountBalance[i].PendingFunds diff --git a/exchanges/coinut/coinut.go b/exchanges/coinut/coinut.go index 9acecfac..c85e857c 100644 --- a/exchanges/coinut/coinut.go +++ b/exchanges/coinut/coinut.go @@ -33,7 +33,7 @@ const ( ) type COINUT struct { - exchange.ExchangeBase + exchange.Base WebsocketConn *websocket.Conn InstrumentMap map[string]int } diff --git a/exchanges/coinut/coinut_wrapper.go b/exchanges/coinut/coinut_wrapper.go index 213db2e2..82ca99b1 100644 --- a/exchanges/coinut/coinut_wrapper.go +++ b/exchanges/coinut/coinut_wrapper.go @@ -63,8 +63,8 @@ func (c *COINUT) Run() { } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the COINUT exchange -func (e *COINUT) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo /* response.ExchangeName = e.GetName() accountBalance, err := e.GetAccounts() @@ -72,7 +72,7 @@ func (e *COINUT) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) return response, err } for i := 0; i < len(accountBalance); i++ { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = accountBalance[i].Currency exchangeCurrency.TotalValue = accountBalance[i].Available exchangeCurrency.Hold = accountBalance[i].Hold diff --git a/exchanges/exchange.go b/exchanges/exchange.go index be24b4c1..997d95b6 100644 --- a/exchanges/exchange.go +++ b/exchanges/exchange.go @@ -17,22 +17,22 @@ const ( ErrExchangeNotFound = "Exchange not found in dataset." ) -// ExchangeAccountInfo is a Generic type to hold each exchange's holdings in +// AccountInfo is a Generic type to hold each exchange's holdings in // all enabled currencies -type ExchangeAccountInfo struct { +type AccountInfo struct { ExchangeName string - Currencies []ExchangeAccountCurrencyInfo + Currencies []AccountCurrencyInfo } -// ExchangeAccountCurrencyInfo is a sub type to store currency name and value -type ExchangeAccountCurrencyInfo struct { +// AccountCurrencyInfo is a sub type to store currency name and value +type AccountCurrencyInfo struct { CurrencyName string TotalValue float64 Hold float64 } -// ExchangeBase stores the individual exchange information -type ExchangeBase struct { +// Base stores the individual exchange information +type Base struct { Name string Enabled bool Verbose bool @@ -59,32 +59,32 @@ type IBotExchange interface { GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error) GetOrderbookEx(currency pair.CurrencyPair) (orderbook.OrderbookBase, error) GetEnabledCurrencies() []string - GetExchangeAccountInfo() (ExchangeAccountInfo, error) + GetExchangeAccountInfo() (AccountInfo, error) } // GetName is a method that returns the name of the exchange base -func (e *ExchangeBase) GetName() string { +func (e *Base) GetName() string { return e.Name } // GetEnabledCurrencies is a method that returns the enabled currency pairs of // the exchange base -func (e *ExchangeBase) GetEnabledCurrencies() []string { +func (e *Base) GetEnabledCurrencies() []string { return e.EnabledPairs } // SetEnabled is a method that sets if the exchange is enabled -func (e *ExchangeBase) SetEnabled(enabled bool) { +func (e *Base) SetEnabled(enabled bool) { e.Enabled = enabled } // IsEnabled is a method that returns if the current exchange is enabled -func (e *ExchangeBase) IsEnabled() bool { +func (e *Base) IsEnabled() bool { return e.Enabled } // SetAPIKeys is a method that sets the current API keys for the exchange -func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) { +func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) { e.APIKey = APIKey e.ClientID = ClientID @@ -102,7 +102,7 @@ func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode // UpdateAvailableCurrencies is a method that sets new pairs to the current // exchange -func (e *ExchangeBase) UpdateAvailableCurrencies(exchangeProducts []string) error { +func (e *Base) UpdateAvailableCurrencies(exchangeProducts []string) error { exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",") diff := common.StringSliceDifference(e.AvailablePairs, exchangeProducts) if len(diff) > 0 { @@ -110,11 +110,10 @@ func (e *ExchangeBase) UpdateAvailableCurrencies(exchangeProducts []string) erro exch, err := cfg.GetExchangeConfig(e.Name) if err != nil { return err - } else { - log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff) - exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",") - cfg.UpdateExchangeConfig(exch) } + log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff) + exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",") + cfg.UpdateExchangeConfig(exch) } return nil } diff --git a/exchanges/exchange_test.go b/exchanges/exchange_test.go index 9c7062f3..d3043a7c 100644 --- a/exchanges/exchange_test.go +++ b/exchanges/exchange_test.go @@ -7,7 +7,7 @@ import ( ) func TestGetName(t *testing.T) { - GetName := ExchangeBase{ + GetName := Base{ Name: "TESTNAME", } @@ -19,7 +19,7 @@ func TestGetName(t *testing.T) { func TestGetEnabledCurrencies(t *testing.T) { enabledPairs := []string{"BTCUSD", "BTCAUD", "LTCUSD", "LTCAUD"} - GetEnabledCurrencies := ExchangeBase{ + GetEnabledCurrencies := Base{ Name: "TESTNAME", EnabledPairs: enabledPairs, } @@ -31,7 +31,7 @@ func TestGetEnabledCurrencies(t *testing.T) { } func TestSetEnabled(t *testing.T) { - SetEnabled := ExchangeBase{ + SetEnabled := Base{ Name: "TESTNAME", Enabled: false, } @@ -43,7 +43,7 @@ func TestSetEnabled(t *testing.T) { } func TestIsEnabled(t *testing.T) { - IsEnabled := ExchangeBase{ + IsEnabled := Base{ Name: "TESTNAME", Enabled: false, } @@ -54,7 +54,7 @@ func TestIsEnabled(t *testing.T) { } func TestSetAPIKeys(t *testing.T) { - SetAPIKeys := ExchangeBase{ + SetAPIKeys := Base{ Name: "TESTNAME", Enabled: false, } @@ -69,7 +69,7 @@ func TestSetAPIKeys(t *testing.T) { func TestUpdateAvailableCurrencies(t *testing.T) { cfg := config.GetConfig() err := cfg.LoadConfig(config.ConfigTestFile) - UAC := ExchangeBase{Name: "ANX"} + UAC := Base{Name: "ANX"} exchangeProducts := []string{"ltc", "btc", "usd", "aud"} if err != nil { diff --git a/exchanges/gdax/gdax.go b/exchanges/gdax/gdax.go index 35c8abf9..856f4f52 100644 --- a/exchanges/gdax/gdax.go +++ b/exchanges/gdax/gdax.go @@ -34,7 +34,7 @@ const ( ) type GDAX struct { - exchange.ExchangeBase + exchange.Base } func (g *GDAX) SetDefaults() { diff --git a/exchanges/gdax/gdax_wrapper.go b/exchanges/gdax/gdax_wrapper.go index 861b389a..5953d5db 100644 --- a/exchanges/gdax/gdax_wrapper.go +++ b/exchanges/gdax/gdax_wrapper.go @@ -63,15 +63,15 @@ func (g *GDAX) Run() { } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the GDAX exchange -func (e *GDAX) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *GDAX) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetAccounts() if err != nil { return response, err } for i := 0; i < len(accountBalance); i++ { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = accountBalance[i].Currency exchangeCurrency.TotalValue = accountBalance[i].Available exchangeCurrency.Hold = accountBalance[i].Hold diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index 1ab640cf..a0d923fe 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -36,7 +36,7 @@ const ( ) type Gemini struct { - exchange.ExchangeBase + exchange.Base } func (g *Gemini) SetDefaults() { diff --git a/exchanges/gemini/gemini_wrapper.go b/exchanges/gemini/gemini_wrapper.go index a14d156a..c723a2ab 100644 --- a/exchanges/gemini/gemini_wrapper.go +++ b/exchanges/gemini/gemini_wrapper.go @@ -50,15 +50,15 @@ func (g *Gemini) Run() { } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Gemini exchange -func (e *Gemini) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Gemini) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetBalances() if err != nil { return response, err } for i := 0; i < len(accountBalance); i++ { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = accountBalance[i].Currency exchangeCurrency.TotalValue = accountBalance[i].Amount exchangeCurrency.Hold = accountBalance[i].Available diff --git a/exchanges/huobi/huobi.go b/exchanges/huobi/huobi.go index 2e1c14f9..deede501 100644 --- a/exchanges/huobi/huobi.go +++ b/exchanges/huobi/huobi.go @@ -19,7 +19,7 @@ const ( ) type HUOBI struct { - exchange.ExchangeBase + exchange.Base } func (h *HUOBI) SetDefaults() { diff --git a/exchanges/huobi/huobi_wrapper.go b/exchanges/huobi/huobi_wrapper.go index 23056756..f4a57b1e 100644 --- a/exchanges/huobi/huobi_wrapper.go +++ b/exchanges/huobi/huobi_wrapper.go @@ -99,8 +99,8 @@ func (h *HUOBI) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er //TODO: retrieve HUOBI balance info //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the HUOBI exchange -func (e *HUOBI) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *HUOBI) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() return response, nil } diff --git a/exchanges/itbit/itbit.go b/exchanges/itbit/itbit.go index 180dbc6a..9f275f6c 100644 --- a/exchanges/itbit/itbit.go +++ b/exchanges/itbit/itbit.go @@ -19,7 +19,7 @@ const ( ) type ItBit struct { - exchange.ExchangeBase + exchange.Base } func (i *ItBit) SetDefaults() { diff --git a/exchanges/itbit/itbit_wrapper.go b/exchanges/itbit/itbit_wrapper.go index a73df974..99bec337 100644 --- a/exchanges/itbit/itbit_wrapper.go +++ b/exchanges/itbit/itbit_wrapper.go @@ -105,8 +105,8 @@ func (i *ItBit) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er //TODO Get current holdings from ItBit //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ItBit exchange -func (e *ItBit) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *ItBit) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() return response, nil } diff --git a/exchanges/kraken/kraken.go b/exchanges/kraken/kraken.go index f08f0369..36cf5dde 100644 --- a/exchanges/kraken/kraken.go +++ b/exchanges/kraken/kraken.go @@ -41,7 +41,7 @@ const ( ) type Kraken struct { - exchange.ExchangeBase + exchange.Base CryptoFee, FiatFee float64 Ticker map[string]KrakenTicker } diff --git a/exchanges/kraken/kraken_wrapper.go b/exchanges/kraken/kraken_wrapper.go index 64fb1780..7c5626bc 100644 --- a/exchanges/kraken/kraken_wrapper.go +++ b/exchanges/kraken/kraken_wrapper.go @@ -72,8 +72,8 @@ func (k *Kraken) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, e //TODO: Retrieve Kraken info //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange -func (e *Kraken) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Kraken) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() return response, nil } diff --git a/exchanges/lakebtc/lakebtc.go b/exchanges/lakebtc/lakebtc.go index 58ed2710..83f2c01e 100644 --- a/exchanges/lakebtc/lakebtc.go +++ b/exchanges/lakebtc/lakebtc.go @@ -31,7 +31,7 @@ const ( ) type LakeBTC struct { - exchange.ExchangeBase + exchange.Base } func (l *LakeBTC) SetDefaults() { diff --git a/exchanges/lakebtc/lakebtc_wrapper.go b/exchanges/lakebtc/lakebtc_wrapper.go index 09c0d4c3..36b65e5d 100644 --- a/exchanges/lakebtc/lakebtc_wrapper.go +++ b/exchanges/lakebtc/lakebtc_wrapper.go @@ -90,8 +90,8 @@ func (l *LakeBTC) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, return orderBook, nil } -func (l *LakeBTC) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (l *LakeBTC) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = l.GetName() accountInfo, err := l.GetAccountInfo() if err != nil { @@ -101,7 +101,7 @@ func (l *LakeBTC) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) for x, y := range accountInfo.Balance { for z, w := range accountInfo.Locked { if z == x { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = common.StringToUpper(x) exchangeCurrency.TotalValue, _ = strconv.ParseFloat(y, 64) exchangeCurrency.Hold, _ = strconv.ParseFloat(w, 64) diff --git a/exchanges/liqui/liqui.go b/exchanges/liqui/liqui.go index 5f862e91..0a58328a 100644 --- a/exchanges/liqui/liqui.go +++ b/exchanges/liqui/liqui.go @@ -33,7 +33,7 @@ const ( ) type Liqui struct { - exchange.ExchangeBase + exchange.Base Ticker map[string]LiquiTicker Info LiquiInfo } diff --git a/exchanges/liqui/liqui_wrapper.go b/exchanges/liqui/liqui_wrapper.go index eef40b9c..8eb59312 100644 --- a/exchanges/liqui/liqui_wrapper.go +++ b/exchanges/liqui/liqui_wrapper.go @@ -105,8 +105,8 @@ func (l *Liqui) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Liqui exchange -func (e *Liqui) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Liqui) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountInfo() if err != nil { @@ -114,7 +114,7 @@ func (e *Liqui) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { } for x, y := range accountBalance.Funds { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = common.StringToUpper(x) exchangeCurrency.TotalValue = y exchangeCurrency.Hold = 0 diff --git a/exchanges/localbitcoins/localbitcoins.go b/exchanges/localbitcoins/localbitcoins.go index 6710adb5..47ffd5df 100644 --- a/exchanges/localbitcoins/localbitcoins.go +++ b/exchanges/localbitcoins/localbitcoins.go @@ -28,7 +28,7 @@ const ( ) type LocalBitcoins struct { - exchange.ExchangeBase + exchange.Base } func (l *LocalBitcoins) SetDefaults() { diff --git a/exchanges/localbitcoins/localbitcoins_wrapper.go b/exchanges/localbitcoins/localbitcoins_wrapper.go index d8ad0517..7f088a39 100644 --- a/exchanges/localbitcoins/localbitcoins_wrapper.go +++ b/exchanges/localbitcoins/localbitcoins_wrapper.go @@ -65,14 +65,14 @@ func (l *LocalBitcoins) GetOrderbookEx(p pair.CurrencyPair) (orderbook.Orderbook } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the LocalBitcoins exchange -func (e *LocalBitcoins) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *LocalBitcoins) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetWalletBalance() if err != nil { return response, err } - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = "BTC" exchangeCurrency.TotalValue = accountBalance.Total.Balance diff --git a/exchanges/okcoin/okcoin.go b/exchanges/okcoin/okcoin.go index 56145305..d13feb8f 100644 --- a/exchanges/okcoin/okcoin.go +++ b/exchanges/okcoin/okcoin.go @@ -70,7 +70,7 @@ var ( ) type OKCoin struct { - exchange.ExchangeBase + exchange.Base RESTErrors map[string]string WebsocketErrors map[string]string FuturesValues []string diff --git a/exchanges/okcoin/okcoin_wrapper.go b/exchanges/okcoin/okcoin_wrapper.go index 153e831a..58094685 100644 --- a/exchanges/okcoin/okcoin_wrapper.go +++ b/exchanges/okcoin/okcoin_wrapper.go @@ -122,33 +122,33 @@ func (o *OKCoin) GetOrderbookEx(currency pair.CurrencyPair) (orderbook.Orderbook return orderBook, nil } -func (e *OKCoin) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *OKCoin) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() assets, err := e.GetUserInfo() if err != nil { return response, err } - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "BTC", TotalValue: assets.Info.Funds.Free.BTC, Hold: assets.Info.Funds.Freezed.BTC, }) - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "LTC", TotalValue: assets.Info.Funds.Free.LTC, Hold: assets.Info.Funds.Freezed.LTC, }) - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "USD", TotalValue: assets.Info.Funds.Free.USD, Hold: assets.Info.Funds.Freezed.USD, }) - response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{ + response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{ CurrencyName: "CNY", TotalValue: assets.Info.Funds.Free.CNY, Hold: assets.Info.Funds.Freezed.CNY, diff --git a/exchanges/poloniex/poloniex.go b/exchanges/poloniex/poloniex.go index 52daa37a..af016140 100644 --- a/exchanges/poloniex/poloniex.go +++ b/exchanges/poloniex/poloniex.go @@ -47,7 +47,7 @@ const ( ) type Poloniex struct { - exchange.ExchangeBase + exchange.Base } func (p *Poloniex) SetDefaults() { diff --git a/exchanges/poloniex/poloniex_wrapper.go b/exchanges/poloniex/poloniex_wrapper.go index f85c2a38..69c6ea74 100644 --- a/exchanges/poloniex/poloniex_wrapper.go +++ b/exchanges/poloniex/poloniex_wrapper.go @@ -96,8 +96,8 @@ func (p *Poloniex) GetOrderbookEx(currencyPair pair.CurrencyPair) (orderbook.Ord } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Poloniex exchange -func (e *Poloniex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { - var response exchange.ExchangeAccountInfo +func (e *Poloniex) GetExchangeAccountInfo() (exchange.AccountInfo, error) { + var response exchange.AccountInfo response.ExchangeName = e.GetName() accountBalance, err := e.GetBalances() if err != nil { @@ -105,7 +105,7 @@ func (e *Poloniex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error } for x, y := range accountBalance.Currency { - var exchangeCurrency exchange.ExchangeAccountCurrencyInfo + var exchangeCurrency exchange.AccountCurrencyInfo exchangeCurrency.CurrencyName = x exchangeCurrency.TotalValue = y response.Currencies = append(response.Currencies, exchangeCurrency) diff --git a/main.go b/main.go index de51b53d..5e30c2d7 100644 --- a/main.go +++ b/main.go @@ -251,7 +251,7 @@ func Shutdown() { } // SeedExchangeAccountInfo seeds account info -func SeedExchangeAccountInfo(data []exchange.ExchangeAccountInfo) { +func SeedExchangeAccountInfo(data []exchange.AccountInfo) { if len(data) == 0 { return } diff --git a/wallet_routes.go b/wallet_routes.go index 93b6b570..61dec117 100644 --- a/wallet_routes.go +++ b/wallet_routes.go @@ -11,14 +11,14 @@ import ( // AllEnabledExchangeAccounts holds all enabled accounts info type AllEnabledExchangeAccounts struct { - Data []exchange.ExchangeAccountInfo `json:"data"` + Data []exchange.AccountInfo `json:"data"` } // GetCollatedExchangeAccountInfoByCoin collates individual exchange account // information and turns into into a map string of -// exchange.ExchangeAccountCurrencyInfo -func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInfo) map[string]exchange.ExchangeAccountCurrencyInfo { - result := make(map[string]exchange.ExchangeAccountCurrencyInfo) +// exchange.AccountCurrencyInfo +func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.AccountInfo) map[string]exchange.AccountCurrencyInfo { + result := make(map[string]exchange.AccountCurrencyInfo) for i := 0; i < len(accounts); i++ { for j := 0; j < len(accounts[i].Currencies); j++ { currencyName := accounts[i].Currencies[j].CurrencyName @@ -27,7 +27,7 @@ func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInf info, ok := result[currencyName] if !ok { - accountInfo := exchange.ExchangeAccountCurrencyInfo{CurrencyName: currencyName, Hold: onHold, TotalValue: avail} + accountInfo := exchange.AccountCurrencyInfo{CurrencyName: currencyName, Hold: onHold, TotalValue: avail} result[currencyName] = accountInfo } else { info.Hold += onHold @@ -40,13 +40,13 @@ func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInf } // GetAccountCurrencyInfoByExchangeName returns info for an exchange -func GetAccountCurrencyInfoByExchangeName(accounts []exchange.ExchangeAccountInfo, exchangeName string) (exchange.ExchangeAccountInfo, error) { +func GetAccountCurrencyInfoByExchangeName(accounts []exchange.AccountInfo, exchangeName string) (exchange.AccountInfo, error) { for i := 0; i < len(accounts); i++ { if accounts[i].ExchangeName == exchangeName { return accounts[i], nil } } - return exchange.ExchangeAccountInfo{}, errors.New(exchange.ErrExchangeNotFound) + return exchange.AccountInfo{}, errors.New(exchange.ErrExchangeNotFound) } // GetAllEnabledExchangeAccountInfo returns all the current enabled exchanges