Skip to content

Commit

Permalink
Adds exchange name to account info retrieval
Browse files Browse the repository at this point in the history
Adds walletRoutes.go
Adds method to get all exchange account stuff  in go
Adds method to get all exchange account stuff in server.js
  • Loading branch information
gloriousCode committed Sep 12, 2016
1 parent 055e82c commit f37bf8d
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 16 deletions.
9 changes: 7 additions & 2 deletions alphapointhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions anxhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 7 additions & 2 deletions bitfinexhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions bitstamphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions brightonpeakhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions btcchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions btcehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions btcmarkets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion configRoutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func SaveAllSettings(w http.ResponseWriter, r *http.Request) {
}
}

var configRoutes = Routes{
var ConfigRoutes = Routes{
Route{
"GetAllSettings",
"GET",
Expand Down
1 change: 1 addition & 0 deletions gdaxhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions geminihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions huobihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions itbithttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions lakebtchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions localbitcoinshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions okcoinhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions poloniexhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions restfulRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +21,6 @@ func NewRouter(exchanges []IBotExchange) *mux.Router {
Path(route.Pattern).
Name(route.Name).
Handler(handler)

}
return router
}
12 changes: 5 additions & 7 deletions restfulRoutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{

}
var routes = Routes{}
2 changes: 1 addition & 1 deletion tickerRoutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func getAllActiveTickersResponse(w http.ResponseWriter, r *http.Request) {
}
}

var exchangeRoutes = Routes{
var ExchangeRoutes = Routes{
Route{
"AllActiveExchangesAndCurrencies",
"GET",
Expand Down
39 changes: 39 additions & 0 deletions walletRoutes.go
Original file line number Diff line number Diff line change
@@ -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,
},
}
8 changes: 8 additions & 0 deletions web/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit f37bf8d

Please sign in to comment.