Skip to content

Commit

Permalink
Adds support for new function GetAccountInfo which retrieves your hol…
Browse files Browse the repository at this point in the history
…dings for an exchange
  • Loading branch information
gloriousCode committed Sep 11, 2016
1 parent 244cdcb commit a24e908
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 6 deletions.
4 changes: 2 additions & 2 deletions alphapointhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions anxhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
18 changes: 18 additions & 0 deletions bitfinexhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 23 additions & 0 deletions bitstamphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions brightonpeakhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions btcchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
78 changes: 78 additions & 0 deletions btcehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 18 additions & 0 deletions btcmarkets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := ""
Expand Down
18 changes: 18 additions & 0 deletions gdaxhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
18 changes: 18 additions & 0 deletions geminihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
9 changes: 9 additions & 0 deletions huobihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ type IBotExchange interface {
IsEnabled() bool
GetTickerPrice(currency string) TickerPrice
GetEnabledCurrencies() []string
GetExchangeAccountInfo() ExchangeAccountInfo
GetExchangeAccountInfo() (ExchangeAccountInfo, error)
}
7 changes: 7 additions & 0 deletions itbithttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
7 changes: 7 additions & 0 deletions kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
7 changes: 7 additions & 0 deletions lakebtchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down
17 changes: 17 additions & 0 deletions localbitcoinshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 7 additions & 0 deletions okcoinhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 19 additions & 0 deletions poloniexhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading

0 comments on commit a24e908

Please sign in to comment.