From 824336086769f380befe260f67f8af9a2384d225 Mon Sep 17 00:00:00 2001 From: Adrian Gallagher Date: Wed, 29 Mar 2017 13:56:48 +1100 Subject: [PATCH] Fix regression after merge --- events/events.go | 13 +++++--- exchanges/alphapoint/alphapoint_wrapper.go | 35 ++++++++++++++++----- exchanges/alphapoint/alphapointhttp.go | 28 ++--------------- exchanges/alphapoint/alphapointwebsocket.go | 10 +++--- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/events/events.go b/events/events.go index db46b2fc..97a2e753 100644 --- a/events/events.go +++ b/events/events.go @@ -7,7 +7,9 @@ import ( "strconv" "github.com/thrasher-/gocryptotrader/common" + "github.com/thrasher-/gocryptotrader/config" "github.com/thrasher-/gocryptotrader/exchanges/ticker" + "github.com/thrasher-/gocryptotrader/smsglobal" ) const ( @@ -96,9 +98,9 @@ func (e *Event) ExecuteAction() bool { if action[0] == ACTION_SMS_NOTIFY { message := fmt.Sprintf("Event triggered: %s", e.EventToString()) if action[1] == "ALL" { - SMSSendToAll(message) + smsglobal.SMSSendToAll(message, &config.GetConfig()) } else { - SMSNotify(SMSGetNumberByName(action[1]), message) + smsglobal.SMSNotify(smsglobal.SMSGetNumberByName(action[1]), message, &config.GetConfig()) } } } else { @@ -189,7 +191,7 @@ func IsValidEvent(Exchange, Item, Condition, Action string) error { return ErrInvalidAction } - if action[1] != "ALL" && SMSGetNumberByName(action[1]) == ErrSMSContactNotFound { + if action[1] != "ALL" && smsglobal.SMSGetNumberByName(action[1], &config.GetConfig().SMS) == smsglobal.ErrSMSContactNotFound { return ErrInvalidAction } } else { @@ -218,8 +220,9 @@ func CheckEvents() { } func IsValidExchange(Exchange string) bool { - for x, _ := range bot.exchanges { - if bot.exchanges[x].GetName() == Exchange && bot.exchanges[x].IsEnabled() { + cfg := config.GetConfig() + for _, x := range cfg.Exchanges { + if x.Name == Exchange && x.Enabled { return true } } diff --git a/exchanges/alphapoint/alphapoint_wrapper.go b/exchanges/alphapoint/alphapoint_wrapper.go index 6ac6e1e3..0f33ff19 100644 --- a/exchanges/alphapoint/alphapoint_wrapper.go +++ b/exchanges/alphapoint/alphapoint_wrapper.go @@ -3,18 +3,39 @@ package alphapoint import ( "log" - "github.com/thraser-/gocryptotrader/exchanges/ticker" + "github.com/thrasher-/gocryptotrader/exchanges" + "github.com/thrasher-/gocryptotrader/exchanges/ticker" ) -func (a *Alphapoint) GetTickerPrice(currency string) TickerPrice { - var tickerPrice TickerPrice - ticker, err := a.GetTicker(currency) +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Alphapoint exchange +func (e *Alphapoint) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) { + var response exchange.ExchangeAccountInfo + 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 + exchangeCurrency.CurrencyName = account.Currencies[i].Name + exchangeCurrency.TotalValue = float64(account.Currencies[i].Balance) + exchangeCurrency.Hold = float64(account.Currencies[i].Hold) + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + //If it all works out + return response, nil +} + +func (a *Alphapoint) GetTickerPrice(currency string) ticker.TickerPrice { + var tickerPrice ticker.TickerPrice + tick, err := a.GetTicker(currency) if err != nil { log.Println(err) - return TickerPrice{} + return ticker.TickerPrice{} } - tickerPrice.Ask = ticker.Ask - tickerPrice.Bid = ticker.Bid + tickerPrice.Ask = tick.Ask + tickerPrice.Bid = tick.Bid return tickerPrice } diff --git a/exchanges/alphapoint/alphapointhttp.go b/exchanges/alphapoint/alphapointhttp.go index c691ab3f..761c6b39 100644 --- a/exchanges/alphapoint/alphapointhttp.go +++ b/exchanges/alphapoint/alphapointhttp.go @@ -10,6 +10,7 @@ import ( "github.com/gorilla/websocket" "github.com/thrasher-/gocryptotrader/common" + "github.com/thrasher-/gocryptotrader/exchanges" ) const ( @@ -36,6 +37,7 @@ const ( ) type Alphapoint struct { + exchange.ExchangeBase WebsocketConn *websocket.Conn } @@ -182,30 +184,6 @@ 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 (e *Alphapoint) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { - var response ExchangeAccountInfo - response.ExchangeName = e.GetName() - account, err := e.GetAccountInfo() - if err != nil { - return response, err - } - for i := 0; i < len(account.Currencies); i++ { - var exchangeCurrency ExchangeAccountCurrencyInfo - exchangeCurrency.CurrencyName = account.Currencies[i].Name - exchangeCurrency.TotalValue = float64(account.Currencies[i].Balance) - exchangeCurrency.Hold = float64(account.Currencies[i].Hold) - - response.Currencies = append(response.Currencies, exchangeCurrency) - } - //If it all works out - return response, nil -} - func (a *Alphapoint) GetAccountTrades(symbol string, startIndex, count int) (AlphapointTrades, error) { request := make(map[string]interface{}) request["ins"] = symbol @@ -434,7 +412,7 @@ func (a *Alphapoint) SendAuthenticatedHTTPRequest(method, path string, data map[ nonce := time.Now().UnixNano() nonceStr := strconv.FormatInt(nonce, 10) data["apiNonce"] = nonce - hmac := common.GetHMAC(common.HASH_SHA256, []byte(nonceStr+a.UserID+a.APIKey), []byte(a.APISecret)) + hmac := common.GetHMAC(common.HASH_SHA256, []byte(nonceStr+a.ClientID+a.APIKey), []byte(a.APISecret)) data["apiSig"] = common.StringToUpper(common.HexEncodeToString(hmac)) path = fmt.Sprintf("%s/ajax/v%s/%s", a.APIUrl, ALPHAPOINT_API_VERSION, path) PayloadJson, err := common.JSONEncode(data) diff --git a/exchanges/alphapoint/alphapointwebsocket.go b/exchanges/alphapoint/alphapointwebsocket.go index 38bd851c..ac114fdc 100644 --- a/exchanges/alphapoint/alphapointwebsocket.go +++ b/exchanges/alphapoint/alphapointwebsocket.go @@ -13,18 +13,18 @@ const ( ) func (a *Alphapoint) WebsocketClient() { - for a.ExchangeEnabled && a.WebsocketEnabled { + for a.Enabled && a.Websocket { var Dialer websocket.Dialer var err error a.WebsocketConn, _, err = Dialer.Dial(a.WebsocketURL, http.Header{}) if err != nil { - log.Printf("%s Unable to connect to Websocket. Error: %s\n", a.ExchangeName, err) + log.Printf("%s Unable to connect to Websocket. Error: %s\n", a.Name, err) continue } if a.Verbose { - log.Printf("%s Connected to Websocket.\n", a.ExchangeName) + log.Printf("%s Connected to Websocket.\n", a.Name) } err = a.WebsocketConn.WriteMessage(websocket.TextMessage, []byte(`{"messageType": "logon"}`)) @@ -34,7 +34,7 @@ func (a *Alphapoint) WebsocketClient() { return } - for a.ExchangeEnabled && a.WebsocketEnabled { + for a.Enabled && a.Websocket { msgType, resp, err := a.WebsocketConn.ReadMessage() if err != nil { log.Println(err) @@ -66,6 +66,6 @@ func (a *Alphapoint) WebsocketClient() { } } a.WebsocketConn.Close() - log.Printf("%s Websocket client disconnected.", a.ExchangeName) + log.Printf("%s Websocket client disconnected.", a.Name) } }