diff --git a/alphapointhttp.go b/alphapointhttp.go index 2714fa93..b3d360e2 100644 --- a/alphapointhttp.go +++ b/alphapointhttp.go @@ -350,8 +350,8 @@ func (a *Alphapoint) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { for i := 0; i < len(account.Currencies); i++ { var exchangeCurrency ExchangeAccountCurrencyInfo exchangeCurrency.CurrencyName = account.Currencies[i].Name - exchangeCurrency.TotalValue = account.Currencies[i].Balance - exchangeCurrency.Hold = account.Currencies[i].Hold + exchangeCurrency.TotalValue = float64(account.Currencies[i].Balance) + exchangeCurrency.Hold = float64(account.Currencies[i].Hold) response.Currencies = append(response.Currencies, exchangeCurrency) } diff --git a/anxhttp.go b/anxhttp.go index f23e0e49..4bcb2ffd 100644 --- a/anxhttp.go +++ b/anxhttp.go @@ -427,6 +427,12 @@ func (a *ANX) GetDepositAddress(currency, name string, new bool) (string, error) return response.Address, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ANX exchange +func (e *ANX) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} + func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interface{}, result interface{}) (err error) { request := make(map[string]interface{}) request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13] diff --git a/bitfinexhttp.go b/bitfinexhttp.go index f3503482..5bbd0349 100644 --- a/bitfinexhttp.go +++ b/bitfinexhttp.go @@ -858,6 +858,24 @@ func (b *Bitfinex) GetAccountBalance() ([]BitfinexBalance, error) { return response, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitfinex exchange +func (b *Bitfinex) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := b.GetAccountBalance() + if err != nil { + return response, err + } + for i := 0; i < len(accountBalance); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = accountBalance[i].Currency + exchangeCurrency.TotalValue = accountBalance[i].Amount + exchangeCurrency.Hold = accountBalance[i].Available + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + return response, nil +} + func (b *Bitfinex) GetMarginInfo() ([]BitfinexMarginInfo, error) { response := []BitfinexMarginInfo{} err := b.SendAuthenticatedHTTPRequest("POST", BITFINEX_MARGIN_INFO, nil, &response) diff --git a/bitstamphttp.go b/bitstamphttp.go index e2d35311..f55ba4ac 100644 --- a/bitstamphttp.go +++ b/bitstamphttp.go @@ -333,6 +333,29 @@ func (b *Bitstamp) GetBalance() (BitstampAccountBalance, error) { return balance, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitstamp exchange +func (e *Bitstamp) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetBalance() + if err != nil { + return response, err + } + + var btcExchangeInfo ExchangeAccountCurrencyInfo + btcExchangeInfo.CurrencyName = "BTC" + btcExchangeInfo.TotalValue = accountBalance.BTCBalance + btcExchangeInfo.Hold = accountBalance.BTCReserved + response.Currencies = append(response.Currencies, btcExchangeInfo) + + var usdExchangeInfo ExchangeAccountCurrencyInfo + usdExchangeInfo.CurrencyName = "USD" + usdExchangeInfo.TotalValue = accountBalance.USDBalance + usdExchangeInfo.Hold = accountBalance.USDReserved + response.Currencies = append(response.Currencies, usdExchangeInfo) + + return response, nil +} + func (b *Bitstamp) GetUserTransactions(values url.Values) ([]BitstampUserTransactions, error) { response := []BitstampUserTransactions{} err := b.SendAuthenticatedHTTPRequest(BITSTAMP_API_USER_TRANSACTIONS, values, &response) diff --git a/brightonpeakhttp.go b/brightonpeakhttp.go index 8e80e14a..cd5f2308 100644 --- a/brightonpeakhttp.go +++ b/brightonpeakhttp.go @@ -190,6 +190,24 @@ func (b *BrightonPeak) GetAccountInfo() (AlphapointAccountInfo, error) { return b.API.GetAccountInfo() } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BrightonPeak exchange +func (e *BrightonPeak) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetAccountInfo() + if err != nil { + return response, err + } + for i := 0; i < len(accountBalance.Currencies); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = accountBalance.Currencies[i].Name + exchangeCurrency.TotalValue = float64(accountBalance.Currencies[i].Balance) + exchangeCurrency.Hold = float64(accountBalance.Currencies[i].Hold) + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + return response, nil +} + func (b *BrightonPeak) GetAccountTrades(symbol string, startIndex, count int) (AlphapointTrades, error) { return b.API.GetAccountTrades(symbol, startIndex, count) } diff --git a/btcchttp.go b/btcchttp.go index 13f042d1..9f7fb0b4 100644 --- a/btcchttp.go +++ b/btcchttp.go @@ -347,6 +347,13 @@ func (b *BTCC) GetAccountInfo(infoType string) { } } +//TODO: Retrieve BTCC info +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange +func (e *BTCC) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} + func (b *BTCC) PlaceOrder(buyOrder bool, price, amount float64, market string) { params := make([]interface{}, 0) params = append(params, strconv.FormatFloat(price, 'f', -1, 64)) diff --git a/btcehttp.go b/btcehttp.go index 6715f8b6..ea9778cb 100644 --- a/btcehttp.go +++ b/btcehttp.go @@ -276,6 +276,84 @@ func (b *BTCE) GetAccountInfo() (BTCEAccountInfo, error) { return result, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCE exchange +func (e *BTCE) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetAccountInfo() + if err != nil { + return response, err + } + + //Surely there's a better way to transform the object + //This will do for now + var btcValue ExchangeAccountCurrencyInfo + btcValue.CurrencyName = "BTC" + btcValue.TotalValue = accountBalance.Funds.BTC + response.Currencies = append(response.Currencies, btcValue) + + var cnhValue ExchangeAccountCurrencyInfo + cnhValue.CurrencyName = "CNH" + cnhValue.TotalValue = accountBalance.Funds.CNH + response.Currencies = append(response.Currencies, cnhValue) + + var eurValue ExchangeAccountCurrencyInfo + eurValue.CurrencyName = "EUR" + eurValue.TotalValue = accountBalance.Funds.EUR + response.Currencies = append(response.Currencies, eurValue) + + var ftcValue ExchangeAccountCurrencyInfo + ftcValue.CurrencyName = "FTC" + ftcValue.TotalValue = accountBalance.Funds.FTC + response.Currencies = append(response.Currencies, ftcValue) + + var gpbValue ExchangeAccountCurrencyInfo + gpbValue.CurrencyName = "GBP" + gpbValue.TotalValue = accountBalance.Funds.GBP + response.Currencies = append(response.Currencies, gpbValue) + + var ltcValue ExchangeAccountCurrencyInfo + ltcValue.CurrencyName = "LTC" + ltcValue.TotalValue = accountBalance.Funds.LTC + response.Currencies = append(response.Currencies, ltcValue) + + var nmcValue ExchangeAccountCurrencyInfo + nmcValue.CurrencyName = "NMC" + nmcValue.TotalValue = accountBalance.Funds.NMC + response.Currencies = append(response.Currencies, nmcValue) + + var nvcValue ExchangeAccountCurrencyInfo + nvcValue.CurrencyName = "NVC" + nvcValue.TotalValue = accountBalance.Funds.NVC + response.Currencies = append(response.Currencies, nvcValue) + + var ppcValue ExchangeAccountCurrencyInfo + ppcValue.CurrencyName = "PPC" + ppcValue.TotalValue = accountBalance.Funds.PPC + response.Currencies = append(response.Currencies, ppcValue) + + var rurValue ExchangeAccountCurrencyInfo + rurValue.CurrencyName = "RUR" + rurValue.TotalValue = accountBalance.Funds.RUR + response.Currencies = append(response.Currencies, rurValue) + + var trcValue ExchangeAccountCurrencyInfo + trcValue.CurrencyName = "TRC" + trcValue.TotalValue = accountBalance.Funds.TRC + response.Currencies = append(response.Currencies, trcValue) + + var usdValue ExchangeAccountCurrencyInfo + usdValue.CurrencyName = "USD" + usdValue.TotalValue = accountBalance.Funds.USD + response.Currencies = append(response.Currencies, usdValue) + + var xpmValue ExchangeAccountCurrencyInfo + xpmValue.CurrencyName = "XPM" + xpmValue.TotalValue = accountBalance.Funds.XPM + response.Currencies = append(response.Currencies, xpmValue) + + return response, nil +} + type BTCEActiveOrders struct { Pair string `json:"pair"` Type string `json:"sell"` diff --git a/btcmarkets.go b/btcmarkets.go index cec733ee..217920a6 100644 --- a/btcmarkets.go +++ b/btcmarkets.go @@ -422,6 +422,24 @@ func (b *BTCMarkets) GetAccountBalance() ([]BTCMarketsAccountBalance, error) { return balance, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCMarkets exchange +func (e *BTCMarkets) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetAccountBalance() + if err != nil { + return response, err + } + for i := 0; i < len(accountBalance); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = accountBalance[i].Currency + exchangeCurrency.TotalValue = accountBalance[i].Balance + exchangeCurrency.Hold = accountBalance[i].PendingFunds + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + return response, nil +} + func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path string, data interface{}, result interface{}) (err error) { nonce := strconv.FormatInt(time.Now().UnixNano(), 10)[0:13] request := "" diff --git a/gdaxhttp.go b/gdaxhttp.go index 396bd489..5ac123b1 100644 --- a/gdaxhttp.go +++ b/gdaxhttp.go @@ -462,6 +462,24 @@ func (g *GDAX) GetAccount(account string) (GDAXAccountResponse, error) { return resp, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the GDAX exchange +func (e *GDAX) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetAccounts() + if err != nil { + return response, err + } + for i := 0; i < len(accountBalance); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = accountBalance[i].Currency + exchangeCurrency.TotalValue = accountBalance[i].Balance + exchangeCurrency.Hold = accountBalance[i].Hold + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + return response, nil +} + type GDAXAccountLedgerResponse struct { ID string `json:"id"` CreatedAt string `json:"created_at"` diff --git a/geminihttp.go b/geminihttp.go index 548d5ff6..db121269 100644 --- a/geminihttp.go +++ b/geminihttp.go @@ -313,6 +313,24 @@ func (g *Gemini) GetBalances() ([]GeminiBalance, error) { return response, nil } +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Gemini exchange +func (e *Gemini) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetBalances() + if err != nil { + return response, err + } + for i := 0; i < len(accountBalance); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = accountBalance[i].Currency + exchangeCurrency.TotalValue = accountBalance[i].Amount + exchangeCurrency.Hold = accountBalance[i].Available + + response.Currencies = append(response.Currencies, exchangeCurrency) + } + return response, nil +} + func (g *Gemini) PostHeartbeat() (bool, error) { type Response struct { Result bool `json:"result"` diff --git a/huobihttp.go b/huobihttp.go index bed18289..8a1c133d 100644 --- a/huobihttp.go +++ b/huobihttp.go @@ -291,3 +291,12 @@ func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) error { return nil } + +//Interface methods + +//TODO: retrieve HUOBI balance info +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the HUOBI exchange +func (e *HUOBI) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} diff --git a/interfaces.go b/interfaces.go index c2d7a718..97819aea 100644 --- a/interfaces.go +++ b/interfaces.go @@ -9,5 +9,5 @@ type IBotExchange interface { IsEnabled() bool GetTickerPrice(currency string) TickerPrice GetEnabledCurrencies() []string - GetExchangeAccountInfo() ExchangeAccountInfo + GetExchangeAccountInfo() (ExchangeAccountInfo, error) } diff --git a/itbithttp.go b/itbithttp.go index 253221c0..2d607369 100644 --- a/itbithttp.go +++ b/itbithttp.go @@ -192,6 +192,13 @@ func (i *ItBit) GetWallets(params url.Values) { } } +//TODO Get current holdings from ItBit +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ItBit exchange +func (e *ItBit) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} + func (i *ItBit) CreateWallet(walletName string) { path := "/wallets" params := make(map[string]interface{}) diff --git a/kraken.go b/kraken.go index 3bad879d..6a2ccfee 100644 --- a/kraken.go +++ b/kraken.go @@ -321,6 +321,13 @@ func (k *Kraken) GetBalance() { log.Println(result) } +//TODO: Retrieve Kraken info +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange +func (e *Kraken) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} + func (k *Kraken) GetTradeBalance(symbol, asset string) { values := url.Values{} diff --git a/lakebtchttp.go b/lakebtchttp.go index edea18fd..8b80bf6b 100644 --- a/lakebtchttp.go +++ b/lakebtchttp.go @@ -200,6 +200,13 @@ func (l *LakeBTC) GetAccountInfo() { } } +//TODO Get current holdings from LakeBTC +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the LakeBTC exchange +func (e *LakeBTC) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} + func (l *LakeBTC) Trade(orderType int, amount, price float64, currency string) { params := strconv.FormatFloat(price, 'f', -1, 64) + "," + strconv.FormatFloat(amount, 'f', -1, 64) + "," + currency err := errors.New("") diff --git a/localbitcoinshttp.go b/localbitcoinshttp.go index fba44eaf..f04235f6 100644 --- a/localbitcoinshttp.go +++ b/localbitcoinshttp.go @@ -444,3 +444,20 @@ func (l *LocalBitcoins) SendAuthenticatedHTTPRequest(method, path string, values return nil } + +//Interface methods + +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the LocalBitcoins exchange +func (e *LocalBitcoins) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetWalletBalance() + if err != nil { + return response, err + } + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = "BTC" + exchangeCurrency.TotalValue = accountBalance.Total.Balance + + response.Currencies = append(response.Currencies, exchangeCurrency) + return response, nil +} diff --git a/okcoinhttp.go b/okcoinhttp.go index af740559..ae254414 100644 --- a/okcoinhttp.go +++ b/okcoinhttp.go @@ -1090,6 +1090,13 @@ func (o *OKCoin) GetAccountRecords(symbol string, recType, currentPage, pageLeng return result.Records, nil } +//TODO support for retrieving holdings from OKCOIN +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the OKCoin exchange +func (e *OKCoin) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + return response, nil +} + func (o *OKCoin) GetFuturesUserInfo() { err := o.SendAuthenticatedHTTPRequest(OKCOIN_FUTURES_USERINFO, url.Values{}, nil) diff --git a/poloniexhttp.go b/poloniexhttp.go index 198c5ff0..b88f0a59 100644 --- a/poloniexhttp.go +++ b/poloniexhttp.go @@ -1028,3 +1028,22 @@ func (p *Poloniex) SendAuthenticatedHTTPRequest(method, endpoint string, values } return nil } + +//Interface methods + +//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Poloniex exchange +func (e *Poloniex) GetExchangeAccountInfo() (ExchangeAccountInfo, error) { + var response ExchangeAccountInfo + accountBalance, err := e.GetBalances() + if err != nil { + return response, err + } + currencies := e.GetEnabledCurrencies() + for i := 0; i < len(currencies); i++ { + var exchangeCurrency ExchangeAccountCurrencyInfo + exchangeCurrency.CurrencyName = currencies[i] + exchangeCurrency.TotalValue = accountBalance.Currency[currencies[i]] + response.Currencies = append(response.Currencies, exchangeCurrency) + } + return response, nil +} diff --git a/wallet.go b/wallet.go index af6df3e0..f886e3f2 100644 --- a/wallet.go +++ b/wallet.go @@ -2,12 +2,13 @@ package main //ExchangeAccountInfo : Generic type to hold each exchange's holdings in all enabled currencies type ExchangeAccountInfo struct { - Currencies []ExchangeAccountCurrencyInfo + ExchangeName string + Currencies []ExchangeAccountCurrencyInfo } //ExchangeAccountCurrencyInfo : Sub type to store currency name and value type ExchangeAccountCurrencyInfo struct { CurrencyName string - TotalValue int - Hold int + TotalValue float64 + Hold float64 }