Fixed stutter issues from exchange.go

This commit is contained in:
Ryan O'Hara-Reid
2017-07-27 17:28:55 +10:00
committed by Adrian Gallagher
parent 7042da1e03
commit de48b62731
40 changed files with 104 additions and 105 deletions

View File

@@ -37,7 +37,7 @@ const (
)
type Alphapoint struct {
exchange.ExchangeBase
exchange.Base
WebsocketConn *websocket.Conn
}

View File

@@ -10,15 +10,15 @@ import (
)
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Alphapoint exchange
func (e *Alphapoint) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Alphapoint) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
account, err := e.GetAccountInfo()
if err != nil {
return response, err
}
for i := 0; i < len(account.Currencies); i++ {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = account.Currencies[i].Name
exchangeCurrency.TotalValue = float64(account.Currencies[i].Balance)
exchangeCurrency.Hold = float64(account.Currencies[i].Hold)

View File

@@ -28,7 +28,7 @@ const (
)
type ANX struct {
exchange.ExchangeBase
exchange.Base
}
func (a *ANX) SetDefaults() {

View File

@@ -66,8 +66,8 @@ func (e *ANX) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, erro
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ANX exchange
func (e *ANX) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *ANX) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
return response, nil
}

View File

@@ -55,7 +55,7 @@ const (
)
type Bitfinex struct {
exchange.ExchangeBase
exchange.Base
WebsocketConn *websocket.Conn
WebsocketSubdChannels map[int]BitfinexWebsocketChanInfo
}

View File

@@ -106,8 +106,8 @@ func (b *Bitfinex) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase,
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitfinex exchange
func (e *Bitfinex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Bitfinex) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetAccountBalance()
if err != nil {
@@ -118,7 +118,7 @@ func (e *Bitfinex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error
}
for i := 0; i < len(accountBalance); i++ {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = common.StringToUpper(accountBalance[i].Currency)
exchangeCurrency.TotalValue = accountBalance[i].Amount
exchangeCurrency.Hold = accountBalance[i].Available

View File

@@ -45,7 +45,7 @@ const (
)
type Bitstamp struct {
exchange.ExchangeBase
exchange.Base
Balance BitstampBalances
}

View File

@@ -95,33 +95,33 @@ func (b *Bitstamp) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase,
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Bitstamp exchange
func (e *Bitstamp) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Bitstamp) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetBalance()
if err != nil {
return response, err
}
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "BTC",
TotalValue: accountBalance.BTCAvailable,
Hold: accountBalance.BTCReserved,
})
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "XRP",
TotalValue: accountBalance.XRPAvailable,
Hold: accountBalance.XRPReserved,
})
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "USD",
TotalValue: accountBalance.USDAvailable,
Hold: accountBalance.USDReserved,
})
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "EUR",
TotalValue: accountBalance.EURAvailable,
Hold: accountBalance.EURReserved,

View File

@@ -43,7 +43,7 @@ const (
)
type BTCC struct {
exchange.ExchangeBase
exchange.Base
}
func (b *BTCC) SetDefaults() {

View File

@@ -92,8 +92,8 @@ func (b *BTCC) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err
//TODO: Retrieve BTCC info
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange
func (e *BTCC) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *BTCC) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
return response, nil
}

View File

@@ -36,7 +36,7 @@ const (
)
type BTCE struct {
exchange.ExchangeBase
exchange.Base
Ticker map[string]BTCeTicker
}

View File

@@ -94,8 +94,8 @@ func (b *BTCE) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, err
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCE exchange
func (e *BTCE) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *BTCE) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetAccountInfo()
if err != nil {
@@ -103,7 +103,7 @@ func (e *BTCE) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
}
for x, y := range accountBalance.Funds {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = common.StringToUpper(x)
exchangeCurrency.TotalValue = y
exchangeCurrency.Hold = 0

View File

@@ -27,7 +27,7 @@ const (
)
type BTCMarkets struct {
exchange.ExchangeBase
exchange.Base
Ticker map[string]BTCMarketsTicker
}

View File

@@ -89,15 +89,15 @@ func (b *BTCMarkets) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBas
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the BTCMarkets exchange
func (e *BTCMarkets) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *BTCMarkets) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetAccountBalance()
if err != nil {
return response, err
}
for i := 0; i < len(accountBalance); i++ {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = accountBalance[i].Currency
exchangeCurrency.TotalValue = accountBalance[i].Balance
exchangeCurrency.Hold = accountBalance[i].PendingFunds

View File

@@ -33,7 +33,7 @@ const (
)
type COINUT struct {
exchange.ExchangeBase
exchange.Base
WebsocketConn *websocket.Conn
InstrumentMap map[string]int
}

View File

@@ -63,8 +63,8 @@ func (c *COINUT) Run() {
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the COINUT exchange
func (e *COINUT) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *COINUT) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
/*
response.ExchangeName = e.GetName()
accountBalance, err := e.GetAccounts()
@@ -72,7 +72,7 @@ func (e *COINUT) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error)
return response, err
}
for i := 0; i < len(accountBalance); i++ {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = accountBalance[i].Currency
exchangeCurrency.TotalValue = accountBalance[i].Available
exchangeCurrency.Hold = accountBalance[i].Hold

View File

@@ -17,22 +17,22 @@ const (
ErrExchangeNotFound = "Exchange not found in dataset."
)
// ExchangeAccountInfo is a Generic type to hold each exchange's holdings in
// AccountInfo is a Generic type to hold each exchange's holdings in
// all enabled currencies
type ExchangeAccountInfo struct {
type AccountInfo struct {
ExchangeName string
Currencies []ExchangeAccountCurrencyInfo
Currencies []AccountCurrencyInfo
}
// ExchangeAccountCurrencyInfo is a sub type to store currency name and value
type ExchangeAccountCurrencyInfo struct {
// AccountCurrencyInfo is a sub type to store currency name and value
type AccountCurrencyInfo struct {
CurrencyName string
TotalValue float64
Hold float64
}
// ExchangeBase stores the individual exchange information
type ExchangeBase struct {
// Base stores the individual exchange information
type Base struct {
Name string
Enabled bool
Verbose bool
@@ -59,32 +59,32 @@ type IBotExchange interface {
GetTickerPrice(currency pair.CurrencyPair) (ticker.TickerPrice, error)
GetOrderbookEx(currency pair.CurrencyPair) (orderbook.OrderbookBase, error)
GetEnabledCurrencies() []string
GetExchangeAccountInfo() (ExchangeAccountInfo, error)
GetExchangeAccountInfo() (AccountInfo, error)
}
// GetName is a method that returns the name of the exchange base
func (e *ExchangeBase) GetName() string {
func (e *Base) GetName() string {
return e.Name
}
// GetEnabledCurrencies is a method that returns the enabled currency pairs of
// the exchange base
func (e *ExchangeBase) GetEnabledCurrencies() []string {
func (e *Base) GetEnabledCurrencies() []string {
return e.EnabledPairs
}
// SetEnabled is a method that sets if the exchange is enabled
func (e *ExchangeBase) SetEnabled(enabled bool) {
func (e *Base) SetEnabled(enabled bool) {
e.Enabled = enabled
}
// IsEnabled is a method that returns if the current exchange is enabled
func (e *ExchangeBase) IsEnabled() bool {
func (e *Base) IsEnabled() bool {
return e.Enabled
}
// SetAPIKeys is a method that sets the current API keys for the exchange
func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) {
func (e *Base) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode bool) {
e.APIKey = APIKey
e.ClientID = ClientID
@@ -102,7 +102,7 @@ func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode
// UpdateAvailableCurrencies is a method that sets new pairs to the current
// exchange
func (e *ExchangeBase) UpdateAvailableCurrencies(exchangeProducts []string) error {
func (e *Base) UpdateAvailableCurrencies(exchangeProducts []string) error {
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
diff := common.StringSliceDifference(e.AvailablePairs, exchangeProducts)
if len(diff) > 0 {
@@ -110,11 +110,10 @@ func (e *ExchangeBase) UpdateAvailableCurrencies(exchangeProducts []string) erro
exch, err := cfg.GetExchangeConfig(e.Name)
if err != nil {
return err
} else {
log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff)
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
cfg.UpdateExchangeConfig(exch)
}
log.Printf("%s Updating available pairs. Difference: %s.\n", e.Name, diff)
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
cfg.UpdateExchangeConfig(exch)
}
return nil
}

View File

@@ -7,7 +7,7 @@ import (
)
func TestGetName(t *testing.T) {
GetName := ExchangeBase{
GetName := Base{
Name: "TESTNAME",
}
@@ -19,7 +19,7 @@ func TestGetName(t *testing.T) {
func TestGetEnabledCurrencies(t *testing.T) {
enabledPairs := []string{"BTCUSD", "BTCAUD", "LTCUSD", "LTCAUD"}
GetEnabledCurrencies := ExchangeBase{
GetEnabledCurrencies := Base{
Name: "TESTNAME",
EnabledPairs: enabledPairs,
}
@@ -31,7 +31,7 @@ func TestGetEnabledCurrencies(t *testing.T) {
}
func TestSetEnabled(t *testing.T) {
SetEnabled := ExchangeBase{
SetEnabled := Base{
Name: "TESTNAME",
Enabled: false,
}
@@ -43,7 +43,7 @@ func TestSetEnabled(t *testing.T) {
}
func TestIsEnabled(t *testing.T) {
IsEnabled := ExchangeBase{
IsEnabled := Base{
Name: "TESTNAME",
Enabled: false,
}
@@ -54,7 +54,7 @@ func TestIsEnabled(t *testing.T) {
}
func TestSetAPIKeys(t *testing.T) {
SetAPIKeys := ExchangeBase{
SetAPIKeys := Base{
Name: "TESTNAME",
Enabled: false,
}
@@ -69,7 +69,7 @@ func TestSetAPIKeys(t *testing.T) {
func TestUpdateAvailableCurrencies(t *testing.T) {
cfg := config.GetConfig()
err := cfg.LoadConfig(config.ConfigTestFile)
UAC := ExchangeBase{Name: "ANX"}
UAC := Base{Name: "ANX"}
exchangeProducts := []string{"ltc", "btc", "usd", "aud"}
if err != nil {

View File

@@ -34,7 +34,7 @@ const (
)
type GDAX struct {
exchange.ExchangeBase
exchange.Base
}
func (g *GDAX) SetDefaults() {

View File

@@ -63,15 +63,15 @@ func (g *GDAX) Run() {
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the GDAX exchange
func (e *GDAX) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *GDAX) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetAccounts()
if err != nil {
return response, err
}
for i := 0; i < len(accountBalance); i++ {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = accountBalance[i].Currency
exchangeCurrency.TotalValue = accountBalance[i].Available
exchangeCurrency.Hold = accountBalance[i].Hold

View File

@@ -36,7 +36,7 @@ const (
)
type Gemini struct {
exchange.ExchangeBase
exchange.Base
}
func (g *Gemini) SetDefaults() {

View File

@@ -50,15 +50,15 @@ func (g *Gemini) Run() {
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Gemini exchange
func (e *Gemini) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Gemini) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetBalances()
if err != nil {
return response, err
}
for i := 0; i < len(accountBalance); i++ {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = accountBalance[i].Currency
exchangeCurrency.TotalValue = accountBalance[i].Amount
exchangeCurrency.Hold = accountBalance[i].Available

View File

@@ -19,7 +19,7 @@ const (
)
type HUOBI struct {
exchange.ExchangeBase
exchange.Base
}
func (h *HUOBI) SetDefaults() {

View File

@@ -99,8 +99,8 @@ func (h *HUOBI) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er
//TODO: retrieve HUOBI balance info
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the HUOBI exchange
func (e *HUOBI) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *HUOBI) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
return response, nil
}

View File

@@ -19,7 +19,7 @@ const (
)
type ItBit struct {
exchange.ExchangeBase
exchange.Base
}
func (i *ItBit) SetDefaults() {

View File

@@ -105,8 +105,8 @@ func (i *ItBit) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er
//TODO Get current holdings from ItBit
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the ItBit exchange
func (e *ItBit) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *ItBit) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
return response, nil
}

View File

@@ -41,7 +41,7 @@ const (
)
type Kraken struct {
exchange.ExchangeBase
exchange.Base
CryptoFee, FiatFee float64
Ticker map[string]KrakenTicker
}

View File

@@ -72,8 +72,8 @@ func (k *Kraken) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, e
//TODO: Retrieve Kraken info
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Kraken exchange
func (e *Kraken) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Kraken) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
return response, nil
}

View File

@@ -31,7 +31,7 @@ const (
)
type LakeBTC struct {
exchange.ExchangeBase
exchange.Base
}
func (l *LakeBTC) SetDefaults() {

View File

@@ -90,8 +90,8 @@ func (l *LakeBTC) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase,
return orderBook, nil
}
func (l *LakeBTC) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (l *LakeBTC) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = l.GetName()
accountInfo, err := l.GetAccountInfo()
if err != nil {
@@ -101,7 +101,7 @@ func (l *LakeBTC) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error)
for x, y := range accountInfo.Balance {
for z, w := range accountInfo.Locked {
if z == x {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = common.StringToUpper(x)
exchangeCurrency.TotalValue, _ = strconv.ParseFloat(y, 64)
exchangeCurrency.Hold, _ = strconv.ParseFloat(w, 64)

View File

@@ -33,7 +33,7 @@ const (
)
type Liqui struct {
exchange.ExchangeBase
exchange.Base
Ticker map[string]LiquiTicker
Info LiquiInfo
}

View File

@@ -105,8 +105,8 @@ func (l *Liqui) GetOrderbookEx(p pair.CurrencyPair) (orderbook.OrderbookBase, er
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Liqui exchange
func (e *Liqui) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Liqui) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetAccountInfo()
if err != nil {
@@ -114,7 +114,7 @@ func (e *Liqui) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
}
for x, y := range accountBalance.Funds {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = common.StringToUpper(x)
exchangeCurrency.TotalValue = y
exchangeCurrency.Hold = 0

View File

@@ -28,7 +28,7 @@ const (
)
type LocalBitcoins struct {
exchange.ExchangeBase
exchange.Base
}
func (l *LocalBitcoins) SetDefaults() {

View File

@@ -65,14 +65,14 @@ func (l *LocalBitcoins) GetOrderbookEx(p pair.CurrencyPair) (orderbook.Orderbook
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the LocalBitcoins exchange
func (e *LocalBitcoins) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *LocalBitcoins) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetWalletBalance()
if err != nil {
return response, err
}
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = "BTC"
exchangeCurrency.TotalValue = accountBalance.Total.Balance

View File

@@ -70,7 +70,7 @@ var (
)
type OKCoin struct {
exchange.ExchangeBase
exchange.Base
RESTErrors map[string]string
WebsocketErrors map[string]string
FuturesValues []string

View File

@@ -122,33 +122,33 @@ func (o *OKCoin) GetOrderbookEx(currency pair.CurrencyPair) (orderbook.Orderbook
return orderBook, nil
}
func (e *OKCoin) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *OKCoin) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
assets, err := e.GetUserInfo()
if err != nil {
return response, err
}
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "BTC",
TotalValue: assets.Info.Funds.Free.BTC,
Hold: assets.Info.Funds.Freezed.BTC,
})
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "LTC",
TotalValue: assets.Info.Funds.Free.LTC,
Hold: assets.Info.Funds.Freezed.LTC,
})
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "USD",
TotalValue: assets.Info.Funds.Free.USD,
Hold: assets.Info.Funds.Freezed.USD,
})
response.Currencies = append(response.Currencies, exchange.ExchangeAccountCurrencyInfo{
response.Currencies = append(response.Currencies, exchange.AccountCurrencyInfo{
CurrencyName: "CNY",
TotalValue: assets.Info.Funds.Free.CNY,
Hold: assets.Info.Funds.Freezed.CNY,

View File

@@ -47,7 +47,7 @@ const (
)
type Poloniex struct {
exchange.ExchangeBase
exchange.Base
}
func (p *Poloniex) SetDefaults() {

View File

@@ -96,8 +96,8 @@ func (p *Poloniex) GetOrderbookEx(currencyPair pair.CurrencyPair) (orderbook.Ord
}
//GetExchangeAccountInfo : Retrieves balances for all enabled currencies for the Poloniex exchange
func (e *Poloniex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error) {
var response exchange.ExchangeAccountInfo
func (e *Poloniex) GetExchangeAccountInfo() (exchange.AccountInfo, error) {
var response exchange.AccountInfo
response.ExchangeName = e.GetName()
accountBalance, err := e.GetBalances()
if err != nil {
@@ -105,7 +105,7 @@ func (e *Poloniex) GetExchangeAccountInfo() (exchange.ExchangeAccountInfo, error
}
for x, y := range accountBalance.Currency {
var exchangeCurrency exchange.ExchangeAccountCurrencyInfo
var exchangeCurrency exchange.AccountCurrencyInfo
exchangeCurrency.CurrencyName = x
exchangeCurrency.TotalValue = y
response.Currencies = append(response.Currencies, exchangeCurrency)

View File

@@ -251,7 +251,7 @@ func Shutdown() {
}
// SeedExchangeAccountInfo seeds account info
func SeedExchangeAccountInfo(data []exchange.ExchangeAccountInfo) {
func SeedExchangeAccountInfo(data []exchange.AccountInfo) {
if len(data) == 0 {
return
}

View File

@@ -11,14 +11,14 @@ import (
// AllEnabledExchangeAccounts holds all enabled accounts info
type AllEnabledExchangeAccounts struct {
Data []exchange.ExchangeAccountInfo `json:"data"`
Data []exchange.AccountInfo `json:"data"`
}
// GetCollatedExchangeAccountInfoByCoin collates individual exchange account
// information and turns into into a map string of
// exchange.ExchangeAccountCurrencyInfo
func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInfo) map[string]exchange.ExchangeAccountCurrencyInfo {
result := make(map[string]exchange.ExchangeAccountCurrencyInfo)
// exchange.AccountCurrencyInfo
func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.AccountInfo) map[string]exchange.AccountCurrencyInfo {
result := make(map[string]exchange.AccountCurrencyInfo)
for i := 0; i < len(accounts); i++ {
for j := 0; j < len(accounts[i].Currencies); j++ {
currencyName := accounts[i].Currencies[j].CurrencyName
@@ -27,7 +27,7 @@ func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInf
info, ok := result[currencyName]
if !ok {
accountInfo := exchange.ExchangeAccountCurrencyInfo{CurrencyName: currencyName, Hold: onHold, TotalValue: avail}
accountInfo := exchange.AccountCurrencyInfo{CurrencyName: currencyName, Hold: onHold, TotalValue: avail}
result[currencyName] = accountInfo
} else {
info.Hold += onHold
@@ -40,13 +40,13 @@ func GetCollatedExchangeAccountInfoByCoin(accounts []exchange.ExchangeAccountInf
}
// GetAccountCurrencyInfoByExchangeName returns info for an exchange
func GetAccountCurrencyInfoByExchangeName(accounts []exchange.ExchangeAccountInfo, exchangeName string) (exchange.ExchangeAccountInfo, error) {
func GetAccountCurrencyInfoByExchangeName(accounts []exchange.AccountInfo, exchangeName string) (exchange.AccountInfo, error) {
for i := 0; i < len(accounts); i++ {
if accounts[i].ExchangeName == exchangeName {
return accounts[i], nil
}
}
return exchange.ExchangeAccountInfo{}, errors.New(exchange.ErrExchangeNotFound)
return exchange.AccountInfo{}, errors.New(exchange.ErrExchangeNotFound)
}
// GetAllEnabledExchangeAccountInfo returns all the current enabled exchanges