A completely broken commit which starts the process of retrieving all exchanges and currency data in one call for a frontend dashboard/db

This commit is contained in:
Scott
2016-06-30 21:22:30 +10:00
parent bc34e2f94c
commit d561bac891
6 changed files with 39 additions and 20 deletions

View File

@@ -216,6 +216,8 @@ func (a *Alphapoint) GetTickerPrice(currency string) TickerPrice {
return tickerPrice
}
func (a *Alphapoint) GetTrades(symbol string, startIndex, count int) (AlphapointTrades, error) {
request := make(map[string]interface{})
request["ins"] = symbol

View File

@@ -197,6 +197,10 @@ func (a *ANX) GetTickerPrice(currency string) TickerPrice {
return tickerPrice
}
func (a *ANX) GetEnabledCurrencies() []string {
return a.EnabledPairs
}
func (a *ANX) GetAPIKey(username, password, otp, deviceID string) (string, string) {
request := make(map[string]interface{})
request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13]

View File

@@ -7,5 +7,6 @@ type IBotExchange interface {
GetName() string
IsEnabled() bool
GetTickerPrice(currency string) TickerPrice
//GetEnabledCurrencies() []string
}

View File

@@ -2,7 +2,6 @@ package main
import (
"net/http"
"github.com/gorilla/mux"
)

View File

@@ -12,22 +12,5 @@ type Route struct {
type Routes []Route
var routes = Routes{
Route{
"Index",
"GET",
"/",
Index,
},
Route{
"TodoIndex",
"GET",
"/todos",
TodoIndex,
},
Route{
"TodoShow",
"GET",
"/todos/{todoId}",
TodoShow,
},
}

View File

@@ -26,9 +26,39 @@ func jsonTickerResponse(w http.ResponseWriter, r *http.Request) {
}
}
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))
}
}
}
}
}
}
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{
"Index",
"AllActiveExchangesAndCurrencies",
"GET",
"/exchanges/enabled/latest/all",
getAllActiveTickersResponse,
},
Route{
"IndividualExchangeAndCurrency",
"GET",
"/exchanges/{exchangeName}/latest/{currency}",
jsonTickerResponse,