Fix regression after merge

This commit is contained in:
Adrian Gallagher
2017-03-29 13:56:48 +11:00
parent 4bd2c92ec3
commit 8243360867
4 changed files with 44 additions and 42 deletions

View File

@@ -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
}
}

View File

@@ -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
}

View File

@@ -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)

View File

@@ -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)
}
}