From f37bf8d89fc08bf7e5763054d06b35057e47f297 Mon Sep 17 00:00:00 2001 From: Scott Date: Mon, 12 Sep 2016 20:06:01 +1000 Subject: [PATCH] Adds exchange name to account info retrieval Adds walletRoutes.go Adds method to get all exchange account stuff in go Adds method to get all exchange account stuff in server.js --- alphapointhttp.go | 9 +++++++-- anxhttp.go | 1 + bitfinexhttp.go | 9 +++++++-- bitstamphttp.go | 1 + brightonpeakhttp.go | 1 + btcchttp.go | 1 + btcehttp.go | 1 + btcmarkets.go | 1 + configRoutes.go | 2 +- gdaxhttp.go | 1 + geminihttp.go | 1 + huobihttp.go | 1 + itbithttp.go | 1 + kraken.go | 1 + lakebtchttp.go | 1 + localbitcoinshttp.go | 1 + okcoinhttp.go | 1 + poloniexhttp.go | 1 + restfulRouter.go | 6 +++--- restfulRoutes.go | 12 +++++------- tickerRoutes.go | 2 +- walletRoutes.go | 39 +++++++++++++++++++++++++++++++++++++++ web/server.js | 8 ++++++++ 23 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 walletRoutes.go diff --git a/alphapointhttp.go b/alphapointhttp.go index b3d360e2..c0424583 100644 --- a/alphapointhttp.go +++ b/alphapointhttp.go @@ -340,10 +340,15 @@ func (a *Alphapoint) GetAccountInfo() (AlphapointAccountInfo, error) { return response, nil } +func (a *Alphapoint) GetName() string { + return a.ExchangeName +} + //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Alphapoint exchange -func (a *Alphapoint) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { +func (e *Alphapoint) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo - account, err := a.GetAccountInfo() + response.ExchangeName = e.GetName() + account, err := e.GetAccountInfo() if err != nil { return response, err } diff --git a/anxhttp.go b/anxhttp.go index 4bcb2ffd..fe39110d 100644 --- a/anxhttp.go +++ b/anxhttp.go @@ -430,6 +430,7 @@ func (a *ANX) GetDepositAddress(currency, name string, new bool) (string, error) //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ANX exchange func (e *ANX) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/bitfinexhttp.go b/bitfinexhttp.go index 5bbd0349..b6ee9b56 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -859,12 +859,17 @@ func (b *Bitfinex) GetAccountBalance() ([]BitfinexBalance, error) { } //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitfinex exchange -func (b *Bitfinex) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { +func (e *Bitfinex) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo - accountBalance, err := b.GetAccountBalance() + response.ExchangeName = e.GetName() + accountBalance, err := e.GetAccountBalance() if err != nil { return response, err } + if !e.Enabled { + return response, nil + } + for i := 0; i < len(accountBalance); i++ { var exchangeCurrency ExchangeAccountCurrencyInfo exchangeCurrency.CurrencyName = accountBalance[i].Currency diff --git a/bitstamphttp.go b/bitstamphttp.go index f55ba4ac..69cd76fc 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -336,6 +336,7 @@ func (b *Bitstamp) GetBalance() (BitstampAccountBalance, error) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitstamp exchange func (e *Bitstamp) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetBalance() if err != nil { return response, err diff --git a/brightonpeakhttp.go b/brightonpeakhttp.go index cd5f2308..9b6d43d9 100644 --- a/brightonpeakhttp.go +++ b/brightonpeakhttp.go @@ -193,6 +193,7 @@ func (b *BrightonPeak) GetAccountInfo() (AlphapointAccountInfo, error) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BrightonPeak exchange func (e *BrightonPeak) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountInfo() if err != nil { return response, err diff --git a/btcchttp.go b/btcchttp.go index 9f7fb0b4..26ce56bd 100644 --- a/btcchttp.go +++ b/btcchttp.go @@ -351,6 +351,7 @@ func (b *BTCC) GetAccountInfo(infoType string) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange func (e *BTCC) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/btcehttp.go b/btcehttp.go index ea9778cb..8953115e 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -279,6 +279,7 @@ func (b *BTCE) GetAccountInfo() (BTCEAccountInfo, error) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCE exchange func (e *BTCE) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountInfo() if err != nil { return response, err diff --git a/btcmarkets.go b/btcmarkets.go index 217920a6..a158b9d2 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -425,6 +425,7 @@ func (b *BTCMarkets) GetAccountBalance() ([]BTCMarketsAccountBalance, error) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCMarkets exchange func (e *BTCMarkets) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetAccountBalance() if err != nil { return response, err diff --git a/configRoutes.go b/configRoutes.go index 9e34216f..c2daab85 100644 --- a/configRoutes.go +++ b/configRoutes.go @@ -52,7 +52,7 @@ func SaveAllSettings(w http.ResponseWriter, r *http.Request) { } } -var configRoutes = Routes{ +var ConfigRoutes = Routes{ Route{ "GetAllSettings", "GET", diff --git a/gdaxhttp.go b/gdaxhttp.go index 5ac123b1..3c606167 100644 --- a/gdaxhttp.go +++ b/gdaxhttp.go @@ -465,6 +465,7 @@ func (g *GDAX) GetAccount(account string) (GDAXAccountResponse, error) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the GDAX exchange func (e *GDAX) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetAccounts() if err != nil { return response, err diff --git a/geminihttp.go b/geminihttp.go index db121269..1f7774fe 100644 --- a/geminihttp.go +++ b/geminihttp.go @@ -316,6 +316,7 @@ func (g *Gemini) GetBalances() ([]GeminiBalance, error) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Gemini exchange func (e *Gemini) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetBalances() if err != nil { return response, err diff --git a/huobihttp.go b/huobihttp.go index bc41de25..2cf7192e 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -296,5 +296,6 @@ func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) error { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the HUOBI exchange func (e *HUOBI) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/itbithttp.go b/itbithttp.go index 2d607369..3b5ff3c7 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -196,6 +196,7 @@ func (i *ItBit) GetWallets(params url.Values) { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ItBit exchange func (e *ItBit) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/kraken.go b/kraken.go index 6a2ccfee..b7d69223 100644 --- a/kraken.go +++ b/kraken.go @@ -325,6 +325,7 @@ func (k *Kraken) GetBalance() { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange func (e *Kraken) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/lakebtchttp.go b/lakebtchttp.go index 8b80bf6b..1cd90218 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -204,6 +204,7 @@ func (l *LakeBTC) GetAccountInfo() { //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the LakeBTC exchange func (e *LakeBTC) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/localbitcoinshttp.go b/localbitcoinshttp.go index 208f67a6..79861549 100644 --- a/localbitcoinshttp.go +++ b/localbitcoinshttp.go @@ -448,6 +448,7 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, values //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the LocalBitcoins exchange func (e *LocalBitcoins) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetWalletBalance() if err != nil { return response, err diff --git a/okcoinhttp.go b/okcoinhttp.go index ae254414..b1245c1d 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -1094,6 +1094,7 @@ func (o *OKCoin) GetAccountRecords(symbol string, recType, currentPage, pageLeng //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the OKCoin exchange func (e *OKCoin) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() return response, nil } diff --git a/poloniexhttp.go b/poloniexhttp.go index fcf02c47..c07fa501 100644 --- a/poloniexhttp.go +++ b/poloniexhttp.go @@ -1032,6 +1032,7 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values //GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Poloniex exchange func (e *Poloniex) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { var response ExchangeAccountInfo + response.ExchangeName = e.GetName() accountBalance, err := e.GetBalances() if err != nil { return response, err diff --git a/restfulRouter.go b/restfulRouter.go index 3cf23ef4..c8037e68 100644 --- a/restfulRouter.go +++ b/restfulRouter.go @@ -8,8 +8,9 @@ import ( func NewRouter(exchanges []IBotExchange) *mux.Router { router := mux.NewRouter().StrictSlash(true) - allRoutes := append(routes, exchangeRoutes...) - allRoutes = append(allRoutes, configRoutes...) + allRoutes := append(routes, ExchangeRoutes...) + allRoutes = append(allRoutes, ConfigRoutes...) + allRoutes = append(allRoutes, WalletRoutes...) for _, route := range allRoutes { var handler http.Handler handler = route.HandlerFunc @@ -20,7 +21,6 @@ func NewRouter(exchanges []IBotExchange) *mux.Router { Path(route.Pattern). Name(route.Name). Handler(handler) - } return router } diff --git a/restfulRoutes.go b/restfulRoutes.go index 1941d55d..1e7a9626 100644 --- a/restfulRoutes.go +++ b/restfulRoutes.go @@ -3,14 +3,12 @@ package main import "net/http" type Route struct { - Name string - Method string - Pattern string - HandlerFunc http.HandlerFunc + Name string + Method string + Pattern string + HandlerFunc http.HandlerFunc } type Routes []Route -var routes = Routes{ - -} \ No newline at end of file +var routes = Routes{} diff --git a/tickerRoutes.go b/tickerRoutes.go index ffe67fc0..3c4338ea 100644 --- a/tickerRoutes.go +++ b/tickerRoutes.go @@ -65,7 +65,7 @@ func getAllActiveTickersResponse(w http.ResponseWriter, r *http.Request) { } } -var exchangeRoutes = Routes{ +var ExchangeRoutes = Routes{ Route{ "AllActiveExchangesAndCurrencies", "GET", diff --git a/walletRoutes.go b/walletRoutes.go new file mode 100644 index 00000000..7fcefc5c --- /dev/null +++ b/walletRoutes.go @@ -0,0 +1,39 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" +) + +type AllEnabledExchangeAccounts struct { + Data []ExchangeAccountInfo `json:"data"` +} + +func GetAllEnabledAccountInfo(w http.ResponseWriter, r *http.Request) { + var response AllEnabledExchangeAccounts + + for _, individualBot := range bot.exchanges { + if individualBot != nil && individualBot.IsEnabled() { + individualExchange, err := individualBot.GetExchangeAccountInfo() + if err != nil { + log.Println("Error encountered retrieving exchange account for '" + individualExchange.ExchangeName + "'") + } + response.Data = append(response.Data, individualExchange) + } + } + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + if err := json.NewEncoder(w).Encode(response); err != nil { + panic(err) + } +} + +var WalletRoutes = Routes{ + Route{ + "AllEnabledAccountInfo", + "GET", + "/exchanges/enabled/accounts/all", + GetAllEnabledAccountInfo, + }, +} diff --git a/web/server.js b/web/server.js index ae5b763a..eb96a2fd 100644 --- a/web/server.js +++ b/web/server.js @@ -24,6 +24,14 @@ app.get('/data/all-enabled-currencies', function (req, res) { }) }); +app.get('/data/all-enabled-exchange-account-info', function (req, res) { + request({ + url :'http://localhost:9050/exchanges/enabled/accounts/all' + },function(err, resp, body){ + res.send(body); + }) +}); + app.get('/config/all', function (req, res) { request({ url :'http://localhost:9050/config/all'