diff --git a/anxhttp.go b/anxhttp.go index 4e5b849f..f23e0e49 100644 --- a/anxhttp.go +++ b/anxhttp.go @@ -193,7 +193,12 @@ func (a *ANX) GetTickerPrice(currency string) TickerPrice { ticker := a.GetTicker(currency) tickerPrice.Ask = ticker.Data.Buy.Value tickerPrice.Bid = ticker.Data.Sell.Value - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Data.Low.Value + tickerPrice.Last = ticker.Data.Last.Value + tickerPrice.Volume = ticker.Data.Vol.Value + tickerPrice.High = ticker.Data.High.Value + return tickerPrice } diff --git a/bitfinexhttp.go b/bitfinexhttp.go index ef4b1ef1..f3503482 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -3,12 +3,13 @@ package main import ( "errors" "fmt" - "github.com/gorilla/websocket" "log" "net/url" "strconv" "strings" "time" + + "github.com/gorilla/websocket" ) const ( @@ -211,6 +212,10 @@ func (b *Bitfinex) Setup(exch Exchanges) { } } +func (k *Bitfinex) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (b *Bitfinex) Start() { go b.Run() } @@ -284,7 +289,6 @@ func (b *Bitfinex) GetTicker(symbol string, values url.Values) (BitfinexTicker, return response, nil } - func (b *Bitfinex) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker, err := b.GetTicker(currency, nil) @@ -294,7 +298,12 @@ func (b *Bitfinex) GetTickerPrice(currency string) TickerPrice { } tickerPrice.Ask = ticker.Ask tickerPrice.Bid = ticker.Bid - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Low + tickerPrice.Last = ticker.Last + tickerPrice.Volume = ticker.Volume + tickerPrice.High = ticker.High + return tickerPrice } diff --git a/bitstamphttp.go b/bitstamphttp.go index 7648a9fc..e2d35311 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -169,6 +169,10 @@ func (b *Bitstamp) Setup(exch Exchanges) { } } +func (k *Bitstamp) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (b *Bitstamp) SetEnabled(enabled bool) { b.Enabled = enabled } @@ -243,7 +247,12 @@ func (b *Bitstamp) GetTickerPrice(currency string) TickerPrice { } tickerPrice.Ask = ticker.Ask tickerPrice.Bid = ticker.Bid - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Low + tickerPrice.Last = ticker.Last + tickerPrice.Volume = ticker.Volume + tickerPrice.High = ticker.High + return tickerPrice } diff --git a/brightonpeakhttp.go b/brightonpeakhttp.go index 872fc314..8e80e14a 100644 --- a/brightonpeakhttp.go +++ b/brightonpeakhttp.go @@ -61,6 +61,10 @@ func (b *BrightonPeak) Setup(exch Exchanges) { } } +func (k *BrightonPeak) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (b *BrightonPeak) Start() { go b.Run() } @@ -134,7 +138,7 @@ func (b *BrightonPeak) GetTicker(symbol string) (AlphapointTicker, error) { return b.API.GetTicker(symbol) } -func (b *BrightonPeak) GetTickerPrice(currency string) TickerPrice { +func (b *BrightonPeak) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker, err := b.GetTicker(currency) if err != nil { @@ -143,7 +147,12 @@ func (b *BrightonPeak) GetTickerPrice(currency string) TickerPrice { } tickerPrice.Ask = ticker.Ask tickerPrice.Bid = ticker.Bid - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Low + tickerPrice.Last = ticker.Last + tickerPrice.Volume = ticker.Volume + tickerPrice.High = ticker.High + return tickerPrice } diff --git a/btcchttp.go b/btcchttp.go index 652fb8b0..13f042d1 100644 --- a/btcchttp.go +++ b/btcchttp.go @@ -198,6 +198,10 @@ func (b *BTCC) Setup(exch Exchanges) { } } +func (k *BTCC) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + //Start is run if exchange is enabled, after Setup func (b *BTCC) Start() { go b.Run() @@ -272,12 +276,17 @@ func (b *BTCC) GetTicker(symbol string) BTCCTicker { return resp.Ticker } -func (b *BTCC) GetTickerPrice(currency string) TickerPrice { +func (b *BTCC) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker := b.GetTicker(currency) tickerPrice.Ask = ticker.Sell tickerPrice.Bid = ticker.Buy - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Low + tickerPrice.Last = ticker.Last + tickerPrice.Volume = ticker.Vol + tickerPrice.High = ticker.High + return tickerPrice } diff --git a/btcehttp.go b/btcehttp.go index e9b65c17..a220ae9b 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -116,6 +116,10 @@ func (b *BTCE) Setup(exch Exchanges) { } } +func (k *BTCE) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (b *BTCE) Start() { go b.Run() } diff --git a/btcmarkets.go b/btcmarkets.go index 5f50adfa..cec733ee 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -125,6 +125,10 @@ func (b *BTCMarkets) Setup(exch Exchanges) { } } +func (k *BTCMarkets) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (b *BTCMarkets) Start() { go b.Run() } @@ -197,7 +201,9 @@ func (b *BTCMarkets) GetTickerPrice(currency string) TickerPrice { } tickerPrice.Ask = ticker.BestAsk tickerPrice.Bid = ticker.BestBID - + tickerPrice.CryptoCurrency = currency + tickerPrice.Last = ticker.LastPrice + return tickerPrice } diff --git a/coinbasehttp.go b/coinbasehttp.go index d157fca6..fc0d916c 100644 --- a/coinbasehttp.go +++ b/coinbasehttp.go @@ -159,6 +159,10 @@ func (c *Coinbase) Setup(exch Exchanges) { } } +func (k *Coinbase) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (c *Coinbase) Start() { go c.Run() } @@ -367,7 +371,9 @@ func (c *Coinbase) GetTickerPrice(currency string) TickerPrice { return TickerPrice{} } tickerPrice.Ask = ticker.Price - + tickerPrice.CryptoCurrency = currency + tickerPrice.Volume = ticker.Size + return tickerPrice } diff --git a/geminihttp.go b/geminihttp.go index f5594e95..548d5ff6 100644 --- a/geminihttp.go +++ b/geminihttp.go @@ -137,6 +137,10 @@ func (g *Gemini) Setup(exch Exchanges) { } } +func (k *Gemini) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (g *Gemini) Start() { go g.Run() } @@ -189,7 +193,7 @@ func (g *Gemini) Run() { /// Once GetTicker is created, then add in GetTickerPrice code plz - Scott func (g *Gemini) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice - + return tickerPrice } diff --git a/huobihttp.go b/huobihttp.go index acc3aecf..bed18289 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -79,6 +79,10 @@ func (h *HUOBI) Setup(exch Exchanges) { } } +func (k *HUOBI) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (h *HUOBI) Start() { go h.Run() } @@ -137,7 +141,12 @@ func (h *HUOBI) GetTickerPrice(currency string) TickerPrice { ticker := h.GetTicker(currency) tickerPrice.Ask = ticker.Sell tickerPrice.Bid = ticker.Buy - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Low + tickerPrice.Last = ticker.Last + tickerPrice.Volume = ticker.Vol + tickerPrice.High = ticker.High + return tickerPrice } diff --git a/interfaces.go b/interfaces.go index add48245..f6d66d03 100644 --- a/interfaces.go +++ b/interfaces.go @@ -6,7 +6,6 @@ type IBotExchange interface { SetDefaults() GetName() string IsEnabled() bool - GetTickerPrice(currency string) TickerPrice - //GetEnabledCurrencies() []string + GetTickerPrice(currency string) TickerPrice + GetEnabledCurrencies() []string } - diff --git a/itbithttp.go b/itbithttp.go index c249c5cb..253221c0 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -86,6 +86,10 @@ func (i *ItBit) Setup(exch Exchanges) { } } +func (k *ItBit) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (i *ItBit) Start() { go i.Run() } @@ -140,7 +144,7 @@ func (i *ItBit) GetTickerPrice(currency string) TickerPrice { tickerPrice.Ask = ticker.Ask tickerPrice.Bid = ticker.Bid - + return tickerPrice } diff --git a/kraken.go b/kraken.go index 71a56106..3bad879d 100644 --- a/kraken.go +++ b/kraken.go @@ -90,6 +90,10 @@ func (k *Kraken) Setup(exch Exchanges) { } } +func (k *Kraken) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (k *Kraken) Start() { go k.Run() } @@ -233,13 +237,13 @@ func (k *Kraken) GetTicker(symbol string) error { func (k *Kraken) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice /* - ticker, err := i.GetTicker(currency) - if err != nil { - log.Println(err) - return tickerPrice - } - tickerPrice.Ask = ticker.Ask - tickerPrice.Bid = ticker.Bid + ticker, err := i.GetTicker(currency) + if err != nil { + log.Println(err) + return tickerPrice + } + tickerPrice.Ask = ticker.Ask + tickerPrice.Bid = ticker.Bid */ return tickerPrice } diff --git a/lakebtchttp.go b/lakebtchttp.go index a84d3133..edea18fd 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -95,6 +95,10 @@ func (l *LakeBTC) Setup(exch Exchanges) { } } +func (k *LakeBTC) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (l *LakeBTC) Start() { go l.Run() } @@ -151,15 +155,17 @@ func (l *LakeBTC) GetTicker() LakeBTCTickerResponse { func (l *LakeBTC) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker := l.GetTicker() - - if(currency == "USD") { + + if currency == "USD" { tickerPrice.Ask = ticker.USD.Ask tickerPrice.Bid = ticker.USD.Bid - } else if(currency =="CNY") { + } else if currency == "CNY" { tickerPrice.Ask = ticker.CNY.Ask tickerPrice.Bid = ticker.CNY.Bid } + tickerPrice.CryptoCurrency = currency + return tickerPrice } diff --git a/localbitcoinshttp.go b/localbitcoinshttp.go index c5ad4219..fba44eaf 100644 --- a/localbitcoinshttp.go +++ b/localbitcoinshttp.go @@ -74,6 +74,10 @@ func (l *LocalBitcoins) Setup(exch Exchanges) { } } +func (k *LocalBitcoins) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (l *LocalBitcoins) Start() { go l.Run() } @@ -144,7 +148,8 @@ func (l *LocalBitcoins) GetTickerPrice(currency string) TickerPrice { return tickerPrice } tickerPrice.Ask = ticker[currency].Rates.Last - + tickerPrice.CryptoCurrency = currency + return tickerPrice } diff --git a/main.go b/main.go index ae0f7990..fa670b73 100644 --- a/main.go +++ b/main.go @@ -3,12 +3,12 @@ package main import ( "errors" "log" + "net/http" "os" "os/signal" "runtime" "strconv" "syscall" - "net/http" ) type Exchange struct { @@ -41,8 +41,9 @@ type Bot struct { var bot Bot func SetupBotConfiguration(s IBotExchange, exch Exchanges) { - s.Setup(exch) + s.SetDefaults() if s.GetName() == exch.Name { + s.Setup(exch) if s.IsEnabled() { log.Printf("%s: Exchange support: %s (Authenticated API support: %s - Verbose mode: %s).\n", exch.Name, IsEnabled(exch.Enabled), IsEnabled(exch.AuthenticatedAPISupport), IsEnabled(exch.Verbose)) s.Start() @@ -85,8 +86,6 @@ func main() { log.Println("SMS support disabled.") } - - log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n", len(bot.config.Exchanges), GetEnabledExchanges()) log.Println("Bot Exchange support:") @@ -94,25 +93,24 @@ func main() { bot.exchange.okcoinChina.APIUrl = OKCOIN_API_URL_CHINA bot.exchanges = []IBotExchange{ - &bot.exchange.anx, - &bot.exchange.kraken, - &bot.exchange.btcc, - &bot.exchange.bitstamp, - &bot.exchange.brightonpeak, - &bot.exchange.bitfinex, - &bot.exchange.btce, - &bot.exchange.btcmarkets, - &bot.exchange.coinbase, - &bot.exchange.gemini, - &bot.exchange.okcoinChina, - &bot.exchange.okcoinIntl, - &bot.exchange.itbit, - &bot.exchange.lakebtc, - &bot.exchange.localbitcoins, - &bot.exchange.poloniex, - &bot.exchange.huobi, + new(ANX), + new(Kraken), + new(BTCC), + new(Bitstamp), + new(BrightonPeak), + new(Bitfinex), + new(BTCE), + new(BTCMarkets), + new(Coinbase), + new(Gemini), + new(OKCoin), + new(OKCoin), + new(ItBit), + new(LakeBTC), + new(LocalBitcoins), + new(Poloniex), + new(HUOBI), } - for i := 0; i < len(bot.exchanges); i++ { if bot.exchanges[i] != nil { bot.exchanges[i].SetDefaults() @@ -133,22 +131,22 @@ func main() { } } } - - if bot.config.Webserver.Enabled { + + if bot.config.Webserver.Enabled { err := CheckWebserverValues() if err != nil { log.Println(err) // non fatal event - bot.config.Webserver.Enabled = false + //bot.config.Webserver.Enabled = false } else { log.Println("HTTP Webserver support enabled.") - router := NewRouter(bot.exchanges) - log.Fatal(http.ListenAndServe(bot.config.Webserver.ListenAddress, router)) + router := NewRouter(bot.exchanges) + log.Fatal(http.ListenAndServe(bot.config.Webserver.ListenAddress, router)) } } if !bot.config.Webserver.Enabled { log.Println("HTTP Webserver support disabled.") } - + <-bot.shutdown Shutdown() } diff --git a/okcoinhttp.go b/okcoinhttp.go index 1411ee2a..a1cb3343 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -2,12 +2,13 @@ package main import ( "errors" - "github.com/gorilla/websocket" "log" "net/url" "strconv" "strings" "time" + + "github.com/gorilla/websocket" ) const ( @@ -229,6 +230,10 @@ func (o *OKCoin) Setup(exch Exchanges) { } } +func (k *OKCoin) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (o *OKCoin) Start() { go o.Run() } @@ -322,7 +327,7 @@ func (o *OKCoin) GetTicker(symbol string) (OKCoinTicker, error) { return resp.Ticker, nil } -func (o *OKCoin) GetTickerPrice(currency string) TickerPrice { +func (o *OKCoin) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker, err := o.GetTicker(currency) if err != nil { @@ -331,7 +336,12 @@ func (o *OKCoin) GetTickerPrice(currency string) TickerPrice { } tickerPrice.Ask = ticker.Sell tickerPrice.Bid = ticker.Buy - + tickerPrice.CryptoCurrency = currency + tickerPrice.Low = ticker.Low + tickerPrice.Last = ticker.Last + tickerPrice.Volume = ticker.Vol + tickerPrice.High = ticker.High + return tickerPrice } diff --git a/poloniexhttp.go b/poloniexhttp.go index 4e525c64..198c5ff0 100644 --- a/poloniexhttp.go +++ b/poloniexhttp.go @@ -105,6 +105,10 @@ func (p *Poloniex) Setup(exch Exchanges) { } } +func (k *Poloniex) GetEnabledCurrencies() []string { + return k.EnabledPairs +} + func (p *Poloniex) Start() { go p.Run() } @@ -161,16 +165,21 @@ func (p *Poloniex) GetTicker() (map[string]PoloniexTicker, error) { return resp.Data, nil } -func (p *Poloniex) GetTickerPrice(currency string) TickerPrice { +func (p *Poloniex) GetTickerPrice(currency string) TickerPrice { var tickerPrice TickerPrice ticker, err := p.GetTicker() if err != nil { log.Println(err) return tickerPrice } + tickerPrice.CryptoCurrency = currency tickerPrice.Ask = ticker[currency].Last tickerPrice.Bid = ticker[currency].HighestBid - + tickerPrice.High = ticker[currency].HighestBid + tickerPrice.Last = ticker[currency].Last + tickerPrice.Low = ticker[currency].LowestAsk + tickerPrice.Volume = ticker[currency].BaseVolume + return tickerPrice } diff --git a/poloniexwebsocket.go b/poloniexwebsocket.go index 2ae9b3d2..59e76f47 100644 --- a/poloniexwebsocket.go +++ b/poloniexwebsocket.go @@ -1,9 +1,10 @@ package main import ( - "gopkg.in/jcelliott/turnpike.v2" "log" "strconv" + + "gopkg.in/jcelliott/turnpike.v2" ) const ( @@ -132,7 +133,7 @@ func PoloniexOnDepthOrTrade(args []interface{}, kwargs map[string]interface{}) { func (p *Poloniex) WebsocketClient() { for p.Enabled && p.Websocket { - c, err := turnpike.NewWebsocketClient(turnpike.JSON, POLONIEX_WEBSOCKET_ADDRESS) + c, err := turnpike.NewWebsocketClient(turnpike.JSON, POLONIEX_WEBSOCKET_ADDRESS, nil) if err != nil { log.Printf("%s Unable to connect to Websocket. Error: %s\n", p.GetName(), err) continue diff --git a/restfulHandlers.go b/restfulHandlers.go index 83cc1b89..bdc5c32c 100644 --- a/restfulHandlers.go +++ b/restfulHandlers.go @@ -1,34 +1,11 @@ package main import ( - "encoding/json" - "fmt" - "net/http" - "github.com/gorilla/mux" + "fmt" + "net/http" ) func Index(w http.ResponseWriter, r *http.Request) { - fmt.Fprintln(w,bot.exchanges[0].GetName()) - - + fmt.Fprintln(w, bot.exchanges[0].GetName()) + } - -func TodoIndex(w http.ResponseWriter, r *http.Request) { - - todos := Todos{ - Todo{Name: "Write presentation"}, - Todo{Name: "Host meetup"}, - } - - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - if err := json.NewEncoder(w).Encode(todos); err != nil { - panic(err) - } -} - -func TodoShow(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - todoId := vars["todoId"] - fmt.Fprintln(w, "Todo show:", todoId) -} \ No newline at end of file diff --git a/restfulRouter.go b/restfulRouter.go index b412908a..0ed2d18b 100644 --- a/restfulRouter.go +++ b/restfulRouter.go @@ -1,24 +1,25 @@ package main import ( - "net/http" - "github.com/gorilla/mux" + "net/http" + + "github.com/gorilla/mux" ) func NewRouter(exchanges []IBotExchange) *mux.Router { - router := mux.NewRouter().StrictSlash(true) - allRoutes := append(routes,exchangeRoutes...) - for _, route := range allRoutes { - var handler http.Handler - handler = route.HandlerFunc - handler = Logger(handler, route.Name) + router := mux.NewRouter().StrictSlash(true) + allRoutes := append(routes, exchangeRoutes...) + for _, route := range allRoutes { + var handler http.Handler + handler = route.HandlerFunc + handler = Logger(handler, route.Name) - router. - Methods(route.Method). - Path(route.Pattern). - Name(route.Name). - Handler(handler) + router. + Methods(route.Method). + Path(route.Pattern). + Name(route.Name). + Handler(handler) - } - return router -} \ No newline at end of file + } + return router +} diff --git a/restfulTodo.go b/restfulTodo.go deleted file mode 100644 index 36e5fa32..00000000 --- a/restfulTodo.go +++ /dev/null @@ -1,11 +0,0 @@ -package main - -import "time" - -type Todo struct { - Name string `json:"name"` - Completed bool `json:"completed"` - Due time.Time `json:"due"` -} - -type Todos []Todo diff --git a/ticker.go b/ticker.go index c73dc505..3e36fe4a 100644 --- a/ticker.go +++ b/ticker.go @@ -5,14 +5,14 @@ import ( ) type TickerPrice struct { - CryptoCurrency string - FiatCurrency string - Last float64 - High float64 - Low float64 - Bid float64 - Ask float64 - Volume float64 + CryptoCurrency string `json:"CryptoCurrency"` + FiatCurrency string `json:"FiatCurrency"` + Last float64 `json:"Last"` + High float64 `json:"High"` + Low float64 `json:"Low"` + Bid float64 `json:"Bid"` + Ask float64 `json:"Ask"` + Volume float64 `json:"Volume"` } type Ticker struct { diff --git a/tickerRoutes.go b/tickerRoutes.go index 47404dda..ccc81d23 100644 --- a/tickerRoutes.go +++ b/tickerRoutes.go @@ -1,66 +1,84 @@ package main import ( - "encoding/json" - "net/http" - "github.com/gorilla/mux" + "encoding/json" + "log" + "net/http" + + "github.com/gorilla/mux" ) func jsonTickerResponse(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - currency := vars["currency"] - exchangeName := vars["exchangeName"] - var response TickerPrice; - for i := 0; i < len(bot.exchanges); i++ { - if bot.exchanges[i] != nil { - if(bot.exchanges[i].IsEnabled() && bot.exchanges[i].GetName() == exchangeName) { - response = bot.exchanges[i].GetTickerPrice(currency) - } - } - } + vars := mux.Vars(r) + currency := vars["currency"] + exchangeName := vars["exchangeName"] + var response TickerPrice + for i := 0; i < len(bot.exchanges); i++ { + if bot.exchanges[i] != nil { + if bot.exchanges[i].IsEnabled() && bot.exchanges[i].GetName() == exchangeName { + response = bot.exchanges[i].GetTickerPrice(currency) + } + } + } - 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) - } + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + encoder := json.NewEncoder(w) + + if err := encoder.Encode(response); err != nil { + panic(err) + } +} + +type AllEnabledExchangeCurrencies struct { + Data []EnabledExchangeCurrencies `json:"data"` +} + +type EnabledExchangeCurrencies struct { + ExchangeName string `json:"exchangeName"` + ExchangeValues []TickerPrice `json:"exchangeValues"` } func getAllActiveTickersResponse(w http.ResponseWriter, r *http.Request) { - var response[] TickerPrice - //bot.config.Cryptocurrencies - for i := 0; i < len(bot.exchanges); i++ { - if bot.exchanges[i] != nil { - if(bot.exchanges[i].IsEnabled()) { - for _, exch := range bot.config.Exchanges { - if(bot.exchanges[i].GetName() == exch.Name) { - for _, enabledPair := range exch.BaseCurrencies { - response = append(response, bot.exchanges[i].GetTickerPrice(enabledPair)) - } - } - } - } - } - } + var response AllEnabledExchangeCurrencies + log.Println(bot.exchanges[15]) - 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) - } + for _, individualBot := range bot.exchanges { + if individualBot != nil && individualBot.IsEnabled() { + var individualExchange EnabledExchangeCurrencies + individualExchange.ExchangeName = individualBot.GetName() + log.Println("Getting enabled currencies for '" + individualBot.GetName() + "'") + currencies := individualBot.GetEnabledCurrencies() + log.Println(currencies) + for _, currency := range currencies { + tickerPrice := individualBot.GetTickerPrice(currency) + log.Println(tickerPrice) + + individualExchange.ExchangeValues = append(individualExchange.ExchangeValues, tickerPrice) + } + response.Data = append(response.Data, individualExchange) + } + } + + log.Println(response) + 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 exchangeRoutes = Routes{ - Route{ - "AllActiveExchangesAndCurrencies", - "GET", - "/exchanges/enabled/latest/all", - getAllActiveTickersResponse, - }, - Route{ - "IndividualExchangeAndCurrency", - "GET", - "/exchanges/{exchangeName}/latest/{currency}", - jsonTickerResponse, - }, -} \ No newline at end of file + Route{ + "AllActiveExchangesAndCurrencies", + "GET", + "/exchanges/enabled/latest/all", + getAllActiveTickersResponse, + }, + Route{ + "IndividualExchangeAndCurrency", + "GET", + "/exchanges/{exchangeName}/latest/{currency}", + jsonTickerResponse, + }, +}