mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-23 15:10:15 +00:00
Refactor Exchange code
This commit is contained in:
@@ -29,21 +29,10 @@ func (b *Bitfinex) Run() {
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available symbols.\n", b.GetName())
|
||||
} else {
|
||||
log.Println(exchangeProducts)
|
||||
/*
|
||||
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
|
||||
diff := common.StringSliceDifference(b.AvailablePairs, exchangeProducts)
|
||||
if len(diff) > 0 {
|
||||
exch, err := bot.config.GetExchangeConfig(b.Name)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Printf("%s Updating available pairs. Difference: %s.\n", b.Name, diff)
|
||||
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
|
||||
bot.config.UpdateExchangeConfig(exch)
|
||||
}
|
||||
}
|
||||
*/
|
||||
err = b.UpdateAvailableCurrencies(exchangeProducts)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get config.\n", b.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
for b.Enabled {
|
||||
|
||||
@@ -83,3 +83,20 @@ func (e *ExchangeBase) SetAPIKeys(APIKey, APISecret, ClientID string, b64Decode
|
||||
e.APISecret = APISecret
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ExchangeBase) UpdateAvailableCurrencies(exchangeProducts []string) error {
|
||||
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
|
||||
diff := common.StringSliceDifference(e.AvailablePairs, exchangeProducts)
|
||||
if len(diff) > 0 {
|
||||
cfg := config.GetConfig()
|
||||
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)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -29,26 +29,16 @@ func (g *GDAX) Run() {
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available products.\n", g.GetName())
|
||||
} else {
|
||||
log.Println(exchangeProducts)
|
||||
/*
|
||||
currencies := []string{}
|
||||
for _, x := range exchangeProducts {
|
||||
if x.ID != "BTC" && x.ID != "USD" && x.ID != "GBP" {
|
||||
currencies = append(currencies, x.ID[0:3]+x.ID[4:])
|
||||
}
|
||||
currencies := []string{}
|
||||
for _, x := range exchangeProducts {
|
||||
if x.ID != "BTC" && x.ID != "USD" && x.ID != "GBP" {
|
||||
currencies = append(currencies, x.ID[0:3]+x.ID[4:])
|
||||
}
|
||||
diff := common.StringSliceDifference(g.AvailablePairs, currencies)
|
||||
if len(diff) > 0 {
|
||||
exch, err := bot.config.GetExchangeConfig(g.Name)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Printf("%s Updating available pairs. Difference: %s.\n", g.Name, diff)
|
||||
exch.AvailablePairs = common.JoinStrings(currencies, ",")
|
||||
bot.config.UpdateExchangeConfig(exch)
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
err = g.UpdateAvailableCurrencies(currencies)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get config.\n", g.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
for g.Enabled {
|
||||
|
||||
@@ -23,21 +23,10 @@ func (g *Gemini) Run() {
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available symbols.\n", g.GetName())
|
||||
} else {
|
||||
log.Println(exchangeProducts)
|
||||
/*
|
||||
exchangeProducts = common.SplitStrings(common.StringToUpper(common.JoinStrings(exchangeProducts, ",")), ",")
|
||||
diff := common.StringSliceDifference(g.AvailablePairs, exchangeProducts)
|
||||
if len(diff) > 0 {
|
||||
exch, err := bot.config.GetExchangeConfig(g.Name)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Printf("%s Updating available pairs. Difference: %s.\n", g.Name, diff)
|
||||
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
|
||||
bot.config.UpdateExchangeConfig(exch)
|
||||
}
|
||||
}
|
||||
*/
|
||||
err = g.UpdateAvailableCurrencies(exchangeProducts)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get config.\n", g.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
for g.Enabled {
|
||||
|
||||
@@ -24,24 +24,14 @@ func (k *Kraken) Run() {
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get available symbols.\n", k.GetName())
|
||||
} else {
|
||||
log.Println(assetPairs)
|
||||
/*
|
||||
var exchangeProducts []string
|
||||
for _, v := range assetPairs {
|
||||
exchangeProducts = append(exchangeProducts, v.Altname)
|
||||
}
|
||||
diff := common.StringSliceDifference(k.AvailablePairs, exchangeProducts)
|
||||
if len(diff) > 0 {
|
||||
exch, err := bot.config.GetExchangeConfig(k.Name)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Printf("%s Updating available pairs. Difference: %s.\n", k.Name, diff)
|
||||
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
|
||||
bot.config.UpdateExchangeConfig(exch)
|
||||
}
|
||||
}
|
||||
*/
|
||||
var exchangeProducts []string
|
||||
for _, v := range assetPairs {
|
||||
exchangeProducts = append(exchangeProducts, v.Altname)
|
||||
}
|
||||
err = k.UpdateAvailableCurrencies(exchangeProducts)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get config.\n", k.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
for k.Enabled {
|
||||
|
||||
@@ -27,20 +27,10 @@ func (l *Liqui) Run() {
|
||||
log.Printf("%s Unable to fetch info.\n", l.GetName())
|
||||
} else {
|
||||
exchangeProducts := l.GetAvailablePairs(true)
|
||||
log.Println(exchangeProducts)
|
||||
/*
|
||||
diff := common.StringSliceDifference(l.AvailablePairs, exchangeProducts)
|
||||
if len(diff) > 0 {
|
||||
exch, err := bot.config.GetExchangeConfig(l.Name)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
} else {
|
||||
log.Printf("%s Updating available pairs. Difference: %s.\n", l.Name, diff)
|
||||
exch.AvailablePairs = common.JoinStrings(exchangeProducts, ",")
|
||||
bot.config.UpdateExchangeConfig(exch)
|
||||
}
|
||||
}
|
||||
*/
|
||||
err = l.UpdateAvailableCurrencies(exchangeProducts)
|
||||
if err != nil {
|
||||
log.Printf("%s Failed to get config.\n", l.GetName())
|
||||
}
|
||||
}
|
||||
|
||||
pairs := []string{}
|
||||
|
||||
Reference in New Issue
Block a user