Adds support for new function GetAccountInfo which retrieves your holdings for an exchange

This commit is contained in:
Scott
2016-09-11 14:05:50 +10:00
parent 244cdcb48c
commit a24e908c24
19 changed files with 284 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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"`

View File

@@ -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 := ""

View File

@@ -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"`

View File

@@ -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"`

View File

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

View File

@@ -9,5 +9,5 @@ type IBotExchange interface {
IsEnabled() bool
GetTickerPrice(currency string) TickerPrice
GetEnabledCurrencies() []string
GetExchangeAccountInfo() ExchangeAccountInfo
GetExchangeAccountInfo() (ExchangeAccountInfo, error)
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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