mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 23:16:48 +00:00
Changed const naming convention assoc. with common.go
This commit is contained in:
committed by
Adrian Gallagher
parent
c4e09fad08
commit
00d2024e5a
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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{}
|
||||
|
||||
@@ -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{}
|
||||
|
||||
Reference in New Issue
Block a user