From 00d2024e5a4244e197b7407d688787e0ea9aa513 Mon Sep 17 00:00:00 2001 From: Ryan O'Hara-Reid Date: Sat, 22 Jul 2017 09:55:53 +1000 Subject: [PATCH] Changed const naming convention assoc. with common.go --- exchanges/alphapoint/alphapoint.go | 2 +- exchanges/anx/anx.go | 2 +- exchanges/bitfinex/bitfinex.go | 2 +- exchanges/bitfinex/bitfinex_websocket.go | 2 +- exchanges/bitstamp/bitstamp.go | 2 +- exchanges/btcc/btcc.go | 2 +- exchanges/btce/btce.go | 2 +- exchanges/btcmarkets/btcmarkets.go | 34 ++++++++++++------------ exchanges/coinut/coinut.go | 2 +- exchanges/gdax/gdax.go | 2 +- exchanges/gemini/gemini.go | 2 +- exchanges/itbit/itbit.go | 2 +- exchanges/kraken/kraken.go | 2 +- exchanges/lakebtc/lakebtc.go | 2 +- exchanges/liqui/liqui.go | 2 +- exchanges/localbitcoins/localbitcoins.go | 2 +- exchanges/poloniex/poloniex.go | 2 +- portfolio/portfolio.go | 22 +++++++++++++-- tools/portfolio/portfolio.go | 2 +- 19 files changed, 54 insertions(+), 36 deletions(-) diff --git a/exchanges/alphapoint/alphapoint.go b/exchanges/alphapoint/alphapoint.go index 510e1f96..4da8105f 100644 --- a/exchanges/alphapoint/alphapoint.go +++ b/exchanges/alphapoint/alphapoint.go @@ -415,7 +415,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.ClientID+a.APIKey), []byte(a.APISecret)) + hmac := common.GetHMAC(common.HashSHA256, []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/anx/anx.go b/exchanges/anx/anx.go index 0a23846e..c8e985b9 100644 --- a/exchanges/anx/anx.go +++ b/exchanges/anx/anx.go @@ -306,7 +306,7 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf log.Printf("Request JSON: %s\n", PayloadJson) } - hmac := common.GetHMAC(common.HASH_SHA512, []byte(path+string("\x00")+string(PayloadJson)), []byte(a.APISecret)) + hmac := common.GetHMAC(common.HashSHA512, []byte(path+string("\x00")+string(PayloadJson)), []byte(a.APISecret)) headers := make(map[string]string) headers["Rest-Key"] = a.APIKey headers["Rest-Sign"] = common.Base64Encode([]byte(hmac)) diff --git a/exchanges/bitfinex/bitfinex.go b/exchanges/bitfinex/bitfinex.go index 22f7dade..d4b941df 100644 --- a/exchanges/bitfinex/bitfinex.go +++ b/exchanges/bitfinex/bitfinex.go @@ -613,7 +613,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[ } PayloadBase64 := common.Base64Encode(PayloadJson) - hmac := common.GetHMAC(common.HASH_SHA512_384, []byte(PayloadBase64), []byte(b.APISecret)) + hmac := common.GetHMAC(common.HashSHA512_384, []byte(PayloadBase64), []byte(b.APISecret)) headers := make(map[string]string) headers["X-BFX-APIKEY"] = b.APIKey headers["X-BFX-PAYLOAD"] = PayloadBase64 diff --git a/exchanges/bitfinex/bitfinex_websocket.go b/exchanges/bitfinex/bitfinex_websocket.go index dc4a86b7..9d1673e2 100644 --- a/exchanges/bitfinex/bitfinex_websocket.go +++ b/exchanges/bitfinex/bitfinex_websocket.go @@ -74,7 +74,7 @@ func (b *Bitfinex) WebsocketSendAuth() error { payload := "AUTH" + strconv.FormatInt(time.Now().UnixNano(), 10)[:13] request["event"] = "auth" request["apiKey"] = b.APIKey - request["authSig"] = common.HexEncodeToString(common.GetHMAC(common.HASH_SHA512_384, []byte(payload), []byte(b.APISecret))) + request["authSig"] = common.HexEncodeToString(common.GetHMAC(common.HashSHA512_384, []byte(payload), []byte(b.APISecret))) request["authPayload"] = payload return b.WebsocketSend(request) } diff --git a/exchanges/bitstamp/bitstamp.go b/exchanges/bitstamp/bitstamp.go index 3803a6d0..92e4fa58 100644 --- a/exchanges/bitstamp/bitstamp.go +++ b/exchanges/bitstamp/bitstamp.go @@ -476,7 +476,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, v2 bool, values url values.Set("key", b.APIKey) values.Set("nonce", nonce) - hmac := common.GetHMAC(common.HASH_SHA256, []byte(nonce+b.ClientID+b.APIKey), []byte(b.APISecret)) + hmac := common.GetHMAC(common.HashSHA256, []byte(nonce+b.ClientID+b.APIKey), []byte(b.APISecret)) values.Set("signature", common.StringToUpper(common.HexEncodeToString(hmac))) if v2 { diff --git a/exchanges/btcc/btcc.go b/exchanges/btcc/btcc.go index b277ab3b..83147794 100644 --- a/exchanges/btcc/btcc.go +++ b/exchanges/btcc/btcc.go @@ -558,7 +558,7 @@ func (b *BTCC) SendAuthenticatedHTTPRequest(method string, params []interface{}) log.Println(encoded) } - hmac := common.GetHMAC(common.HASH_SHA1, []byte(encoded), []byte(b.APISecret)) + hmac := common.GetHMAC(common.HashSHA1, []byte(encoded), []byte(b.APISecret)) postData := make(map[string]interface{}) postData["method"] = method postData["params"] = params diff --git a/exchanges/btce/btce.go b/exchanges/btce/btce.go index 97e56118..856d8b53 100644 --- a/exchanges/btce/btce.go +++ b/exchanges/btce/btce.go @@ -298,7 +298,7 @@ func (b *BTCE) SendAuthenticatedHTTPRequest(method string, values url.Values, re values.Set("method", method) encoded := values.Encode() - hmac := common.GetHMAC(common.HASH_SHA512, []byte(encoded), []byte(b.APISecret)) + hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(b.APISecret)) if b.Verbose { log.Printf("Sending POST request to %s calling method %s with params %s\n", BTCE_API_PRIVATE_URL, method, encoded) diff --git a/exchanges/btcmarkets/btcmarkets.go b/exchanges/btcmarkets/btcmarkets.go index b154e14f..7271df4e 100644 --- a/exchanges/btcmarkets/btcmarkets.go +++ b/exchanges/btcmarkets/btcmarkets.go @@ -105,8 +105,8 @@ func (b *BTCMarkets) Order(currency, instrument string, price, amount int64, ord order := Order{} order.Currency = currency order.Instrument = instrument - order.Price = price * common.SATOSHIS_PER_BTC - order.Volume = amount * common.SATOSHIS_PER_BTC + order.Price = price * common.SatoshisPerBTC + order.Volume = amount * common.SatoshisPerBTC order.OrderSide = orderSide order.OrderType = orderType order.ClientRequestId = clientReq @@ -212,14 +212,14 @@ func (b *BTCMarkets) GetOrders(currency, instrument string, limit, since int64, } for i := range resp.Orders { - resp.Orders[i].Price = resp.Orders[i].Price / common.SATOSHIS_PER_BTC - resp.Orders[i].OpenVolume = resp.Orders[i].OpenVolume / common.SATOSHIS_PER_BTC - resp.Orders[i].Volume = resp.Orders[i].Volume / common.SATOSHIS_PER_BTC + resp.Orders[i].Price = resp.Orders[i].Price / common.SatoshisPerBTC + resp.Orders[i].OpenVolume = resp.Orders[i].OpenVolume / common.SatoshisPerBTC + resp.Orders[i].Volume = resp.Orders[i].Volume / common.SatoshisPerBTC for x := range resp.Orders[i].Trades { - resp.Orders[i].Trades[x].Fee = resp.Orders[i].Trades[x].Fee / common.SATOSHIS_PER_BTC - resp.Orders[i].Trades[x].Price = resp.Orders[i].Trades[x].Price / common.SATOSHIS_PER_BTC - resp.Orders[i].Trades[x].Volume = resp.Orders[i].Trades[x].Volume / common.SATOSHIS_PER_BTC + resp.Orders[i].Trades[x].Fee = resp.Orders[i].Trades[x].Fee / common.SatoshisPerBTC + resp.Orders[i].Trades[x].Price = resp.Orders[i].Trades[x].Price / common.SatoshisPerBTC + resp.Orders[i].Trades[x].Volume = resp.Orders[i].Trades[x].Volume / common.SatoshisPerBTC } } return resp.Orders, nil @@ -251,14 +251,14 @@ func (b *BTCMarkets) GetOrderDetail(orderID []int64) ([]BTCMarketsOrder, error) } for i := range resp.Orders { - resp.Orders[i].Price = resp.Orders[i].Price / common.SATOSHIS_PER_BTC - resp.Orders[i].OpenVolume = resp.Orders[i].OpenVolume / common.SATOSHIS_PER_BTC - resp.Orders[i].Volume = resp.Orders[i].Volume / common.SATOSHIS_PER_BTC + resp.Orders[i].Price = resp.Orders[i].Price / common.SatoshisPerBTC + resp.Orders[i].OpenVolume = resp.Orders[i].OpenVolume / common.SatoshisPerBTC + resp.Orders[i].Volume = resp.Orders[i].Volume / common.SatoshisPerBTC for x := range resp.Orders[i].Trades { - resp.Orders[i].Trades[x].Fee = resp.Orders[i].Trades[x].Fee / common.SATOSHIS_PER_BTC - resp.Orders[i].Trades[x].Price = resp.Orders[i].Trades[x].Price / common.SATOSHIS_PER_BTC - resp.Orders[i].Trades[x].Volume = resp.Orders[i].Trades[x].Volume / common.SATOSHIS_PER_BTC + resp.Orders[i].Trades[x].Fee = resp.Orders[i].Trades[x].Fee / common.SatoshisPerBTC + resp.Orders[i].Trades[x].Price = resp.Orders[i].Trades[x].Price / common.SatoshisPerBTC + resp.Orders[i].Trades[x].Volume = resp.Orders[i].Trades[x].Volume / common.SatoshisPerBTC } } return resp.Orders, nil @@ -274,8 +274,8 @@ func (b *BTCMarkets) GetAccountBalance() ([]BTCMarketsAccountBalance, error) { for i := range balance { if balance[i].Currency == "LTC" || balance[i].Currency == "BTC" { - balance[i].Balance = balance[i].Balance / common.SATOSHIS_PER_BTC - balance[i].PendingFunds = balance[i].PendingFunds / common.SATOSHIS_PER_BTC + balance[i].Balance = balance[i].Balance / common.SatoshisPerBTC + balance[i].PendingFunds = balance[i].PendingFunds / common.SatoshisPerBTC } } return balance, nil @@ -296,7 +296,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data interfa request = path + "\n" + nonce + "\n" } - hmac := common.GetHMAC(common.HASH_SHA512, []byte(request), []byte(b.APISecret)) + hmac := common.GetHMAC(common.HashSHA512, []byte(request), []byte(b.APISecret)) if b.Verbose { log.Printf("Sending %s request to URL %s with params %s\n", reqType, BTCMARKETS_API_URL+path, request) diff --git a/exchanges/coinut/coinut.go b/exchanges/coinut/coinut.go index 0e1400ca..9acecfac 100644 --- a/exchanges/coinut/coinut.go +++ b/exchanges/coinut/coinut.go @@ -290,7 +290,7 @@ func (c *COINUT) SendAuthenticatedHTTPRequest(apiRequest string, params map[stri log.Printf("Request JSON: %s\n", payload) } - hmac := common.GetHMAC(common.HASH_SHA256, []byte(payload), []byte(c.APIKey)) + hmac := common.GetHMAC(common.HashSHA256, []byte(payload), []byte(c.APIKey)) headers := make(map[string]string) headers["X-USER"] = c.ClientID headers["X-SIGNATURE"] = common.HexEncodeToString(hmac) diff --git a/exchanges/gdax/gdax.go b/exchanges/gdax/gdax.go index 13033e4c..35c8abf9 100644 --- a/exchanges/gdax/gdax.go +++ b/exchanges/gdax/gdax.go @@ -387,7 +387,7 @@ func (g *GDAX) SendAuthenticatedHTTPRequest(method, path string, params map[stri } message := timestamp + method + "/" + path + string(payload) - hmac := common.GetHMAC(common.HASH_SHA256, []byte(message), []byte(g.APISecret)) + hmac := common.GetHMAC(common.HashSHA256, []byte(message), []byte(g.APISecret)) headers := make(map[string]string) headers["CB-ACCESS-SIGN"] = common.Base64Encode([]byte(hmac)) headers["CB-ACCESS-TIMESTAMP"] = timestamp diff --git a/exchanges/gemini/gemini.go b/exchanges/gemini/gemini.go index e473bc7f..1ab640cf 100644 --- a/exchanges/gemini/gemini.go +++ b/exchanges/gemini/gemini.go @@ -266,7 +266,7 @@ func (g *Gemini) SendAuthenticatedHTTPRequest(method, path string, params map[st } PayloadBase64 := common.Base64Encode(PayloadJson) - hmac := common.GetHMAC(common.HASH_SHA512_384, []byte(PayloadBase64), []byte(g.APISecret)) + hmac := common.GetHMAC(common.HashSHA512_384, []byte(PayloadBase64), []byte(g.APISecret)) headers := make(map[string]string) headers["X-GEMINI-APIKEY"] = g.APIKey headers["X-GEMINI-PAYLOAD"] = PayloadBase64 diff --git a/exchanges/itbit/itbit.go b/exchanges/itbit/itbit.go index 2351b562..180dbc6a 100644 --- a/exchanges/itbit/itbit.go +++ b/exchanges/itbit/itbit.go @@ -266,7 +266,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params } hash := common.GetSHA256([]byte(nonceStr + string(message))) - hmac := common.GetHMAC(common.HASH_SHA512, []byte(url+string(hash)), []byte(i.APISecret)) + hmac := common.GetHMAC(common.HashSHA512, []byte(url+string(hash)), []byte(i.APISecret)) signature := common.Base64Encode(hmac) headers := make(map[string]string) diff --git a/exchanges/kraken/kraken.go b/exchanges/kraken/kraken.go index 56f6d4a7..f08f0369 100644 --- a/exchanges/kraken/kraken.go +++ b/exchanges/kraken/kraken.go @@ -518,7 +518,7 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values) } shasum := common.GetSHA256([]byte(values.Get("nonce") + values.Encode())) - signature := common.Base64Encode(common.GetHMAC(common.HASH_SHA512, append([]byte(path), shasum...), secret)) + signature := common.Base64Encode(common.GetHMAC(common.HashSHA512, append([]byte(path), shasum...), secret)) if k.Verbose { log.Printf("Sending POST request to %s, path: %s.", KRAKEN_API_URL, path) diff --git a/exchanges/lakebtc/lakebtc.go b/exchanges/lakebtc/lakebtc.go index 0559c7e7..58ed2710 100644 --- a/exchanges/lakebtc/lakebtc.go +++ b/exchanges/lakebtc/lakebtc.go @@ -274,7 +274,7 @@ func (l *LakeBTC) CreateWithdraw(amount float64, accountID int64) (LakeBTCWithdr func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result interface{}) (err error) { nonce := strconv.FormatInt(time.Now().UnixNano(), 10) req := fmt.Sprintf("tonce=%s&accesskey=%s&requestmethod=post&id=1&method=%s¶ms=%s", nonce, l.APIKey, method, params) - hmac := common.GetHMAC(common.HASH_SHA1, []byte(req), []byte(l.APISecret)) + hmac := common.GetHMAC(common.HashSHA1, []byte(req), []byte(l.APISecret)) if l.Verbose { log.Printf("Sending POST request to %s calling method %s with params %s\n", LAKEBTC_API_URL, method, req) diff --git a/exchanges/liqui/liqui.go b/exchanges/liqui/liqui.go index e0e7e8ab..5f862e91 100644 --- a/exchanges/liqui/liqui.go +++ b/exchanges/liqui/liqui.go @@ -254,7 +254,7 @@ func (l *Liqui) SendAuthenticatedHTTPRequest(method string, values url.Values, r values.Set("method", method) encoded := values.Encode() - hmac := common.GetHMAC(common.HASH_SHA512, []byte(encoded), []byte(l.APISecret)) + hmac := common.GetHMAC(common.HashSHA512, []byte(encoded), []byte(l.APISecret)) if l.Verbose { log.Printf("Sending POST request to %s calling method %s with params %s\n", LIQUI_API_PRIVATE_URL, method, encoded) diff --git a/exchanges/localbitcoins/localbitcoins.go b/exchanges/localbitcoins/localbitcoins.go index 337290c2..6710adb5 100644 --- a/exchanges/localbitcoins/localbitcoins.go +++ b/exchanges/localbitcoins/localbitcoins.go @@ -276,7 +276,7 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, values } message := string(nonce) + l.APIKey + path + payload - hmac := common.GetHMAC(common.HASH_SHA256, []byte(message), []byte(l.APISecret)) + hmac := common.GetHMAC(common.HashSHA256, []byte(message), []byte(l.APISecret)) headers := make(map[string]string) headers["Apiauth-Key"] = l.APIKey headers["Apiauth-Nonce"] = string(nonce) diff --git a/exchanges/poloniex/poloniex.go b/exchanges/poloniex/poloniex.go index 0db968a2..52daa37a 100644 --- a/exchanges/poloniex/poloniex.go +++ b/exchanges/poloniex/poloniex.go @@ -755,7 +755,7 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values values.Set("nonce", nonceStr) values.Set("command", endpoint) - hmac := common.GetHMAC(common.HASH_SHA512, []byte(values.Encode()), []byte(p.APISecret)) + hmac := common.GetHMAC(common.HashSHA512, []byte(values.Encode()), []byte(p.APISecret)) headers["Sign"] = common.HexEncodeToString(hmac) path := fmt.Sprintf("%s/%s", POLONIEX_API_URL, POLONIEX_API_TRADING_ENDPOINT) diff --git a/portfolio/portfolio.go b/portfolio/portfolio.go index 49946b66..deb11930 100644 --- a/portfolio/portfolio.go +++ b/portfolio/portfolio.go @@ -66,13 +66,13 @@ type EtherchainBalanceResponse struct { } `json:"data"` } -//ExchangeAccountInfo : Generic type to hold each exchange's holdings in all enabled currencies +// ExchangeAccountInfo : Generic type to hold each exchange's holdings in all enabled currencies type ExchangeAccountInfo struct { ExchangeName string Currencies []ExchangeAccountCurrencyInfo } -//ExchangeAccountCurrencyInfo : Sub type to store currency name and value +// ExchangeAccountCurrencyInfo : Sub type to store currency name and value type ExchangeAccountCurrencyInfo struct { CurrencyName string TotalValue float64 @@ -80,6 +80,13 @@ type ExchangeAccountCurrencyInfo struct { } func GetEthereumBalance(address []string) (EtherchainBalanceResponse, error) { + for _, add := range address { + valid, _ := common.IsValidCryptoAddress(add, "eth") + if !valid { + return EtherchainBalanceResponse{}, errors.New("Not an ethereum address") + } + } + addresses := common.JoinStrings(address, ",") url := fmt.Sprintf("%s/%s/%s", ETHERCHAIN_API_URL, ETHERCHAIN_ACCOUNT_MULTIPLE, addresses) result := EtherchainBalanceResponse{} @@ -94,6 +101,11 @@ func GetEthereumBalance(address []string) (EtherchainBalanceResponse, error) { } func GetBlockrBalanceSingle(address string, coinType string) (BlockrAddressBalanceSingle, error) { + valid, _ := common.IsValidCryptoAddress(address, coinType) + if !valid { + return BlockrAddressBalanceSingle{}, errors.New(fmt.Sprintf("Not a %s address", common.StringToUpper(coinType))) + } + url := fmt.Sprintf("https://%s.%s/v%s/%s/%s", common.StringToLower(coinType), BLOCKR_API_URL, BLOCKR_API_VERSION, BLOCKR_ADDRESS_BALANCE, address) result := BlockrAddressBalanceSingle{} err := common.SendHTTPGetRequest(url, true, &result) @@ -107,6 +119,12 @@ func GetBlockrBalanceSingle(address string, coinType string) (BlockrAddressBalan } func GetBlockrAddressMulti(addresses []string, coinType string) (BlockrAddressBalanceMulti, error) { + for _, add := range addresses { + valid, _ := common.IsValidCryptoAddress(add, coinType) + if !valid { + return BlockrAddressBalanceMulti{}, errors.New(fmt.Sprintf("Not a %s address", common.StringToUpper(coinType))) + } + } addressesStr := common.JoinStrings(addresses, ",") url := fmt.Sprintf("https://%s.%s/v%s/%s/%s", common.StringToLower(coinType), BLOCKR_API_URL, BLOCKR_API_VERSION, BLOCKR_ADDRESS_BALANCE, addressesStr) result := BlockrAddressBalanceMulti{} diff --git a/tools/portfolio/portfolio.go b/tools/portfolio/portfolio.go index c6f65b0d..6ca8daf0 100644 --- a/tools/portfolio/portfolio.go +++ b/tools/portfolio/portfolio.go @@ -62,7 +62,7 @@ func main() { for x, y := range result { if x == "ETH" { - y = y / common.WEI_PER_ETHER + y = y / common.WeiPerEther } pf := PortfolioTemp{}