Periodic available pairs update for manual exchanges

This commit is contained in:
Adrian Gallagher
2018-10-11 15:47:12 +11:00
parent 9b85b431ab
commit be561dd077
7 changed files with 68 additions and 52 deletions

View File

@@ -251,7 +251,8 @@ func (e *Base) SetAssetTypes() error {
exch.AssetTypes = common.JoinStrings(e.AssetTypes, ",")
update = true
} else {
e.AssetTypes = common.SplitStrings(exch.AssetTypes, ",")
exch.AssetTypes = common.JoinStrings(e.AssetTypes, ",")
update = true
}
if update {

View File

@@ -101,18 +101,19 @@ func (o *OKCoin) SetDefaults() {
o.Verbose = false
o.Websocket = false
o.RESTPollingDelay = 10
o.FuturesValues = []string{"this_week", "next_week", "quarter"}
o.AssetTypes = []string{ticker.Spot}
o.SupportsAutoPairUpdating = false
o.SupportsRESTTickerBatching = false
if okcoinDefaultsSet {
o.AssetTypes = append(o.AssetTypes, o.FuturesValues...)
o.APIUrlDefault = okcoinAPIURL
o.APIUrl = o.APIUrlDefault
o.Name = "OKCOIN International"
o.WebsocketURL = okcoinWebsocketURL
o.setCurrencyPairFormats()
o.RequestCurrencyPairFormat.Delimiter = "_"
o.RequestCurrencyPairFormat.Uppercase = false
o.ConfigCurrencyPairFormat.Delimiter = "_"
o.ConfigCurrencyPairFormat.Uppercase = true
o.Requester = request.New(o.Name,
request.NewRateLimit(time.Second, okcoinAuthRate),
request.NewRateLimit(time.Second, okcoinUnauthRate),

View File

@@ -29,6 +29,34 @@ func (o *OKCoin) Run() {
log.Printf("%s %d currencies enabled: %s.\n", o.GetName(), len(o.EnabledPairs), o.EnabledPairs)
}
if o.APIUrl == okcoinAPIURL {
// OKCoin International
forceUpgrade := false
if !common.StringDataContains(o.EnabledPairs, "_") || !common.StringDataContains(o.AvailablePairs, "_") {
forceUpgrade = true
}
var currencies []string
for x := range o.AvailablePairs {
currencies = append(currencies, o.AvailablePairs[x][0:3]+"_"+o.AvailablePairs[x][3:])
}
if forceUpgrade {
enabledPairs := []string{"btc_usd"}
log.Println("WARNING: Available pairs for OKCoin International reset due to config upgrade, please enable the pairs you would like again.")
err := o.UpdateCurrencies(enabledPairs, true, true)
if err != nil {
log.Printf("%s failed to update currencies. Err: %s", o.Name, err)
}
err = o.UpdateCurrencies(currencies, false, true)
if err != nil {
log.Printf("%s failed to update currencies. Err: %s", o.Name, err)
}
}
}
if o.Websocket {
go o.WebsocketClient()
}

View File

@@ -16,6 +16,7 @@ import (
"github.com/thrasher-/gocryptotrader/config"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/exchanges/request"
"github.com/thrasher-/gocryptotrader/exchanges/ticker"
)
const (
@@ -114,6 +115,7 @@ func (o *OKEX) SetDefaults() {
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
o.APIUrlDefault = apiURL
o.APIUrl = o.APIUrlDefault
o.AssetTypes = []string{ticker.Spot}
}
// Setup method sets current configuration details if enabled

View File

@@ -40,10 +40,6 @@ func (o *OKEX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price
var tickerPrice ticker.Price
if assetType != ticker.Spot {
if p.SecondCurrency.String() == common.StringToLower("USDT") {
p.SecondCurrency = "usd"
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
}
tick, err := o.GetContractPrice(currency, assetType)
if err != nil {
return tickerPrice, err
@@ -58,11 +54,6 @@ func (o *OKEX) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price
tickerPrice.High = tick.Ticker.High
ticker.ProcessTicker(o.GetName(), p, tickerPrice, assetType)
} else {
if p.SecondCurrency.String() == common.StringToLower("USD") {
p.SecondCurrency = "usdt"
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
}
tick, err := o.GetSpotTicker(currency)
if err != nil {
return tickerPrice, err
@@ -104,10 +95,6 @@ func (o *OKEX) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook
currency := exchange.FormatExchangeCurrency(o.Name, p).String()
if assetType != ticker.Spot {
if p.SecondCurrency.String() == common.StringToLower("USDT") {
p.SecondCurrency = "usd"
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
}
orderbookNew, err := o.GetContractMarketDepth(currency, assetType)
if err != nil {
return orderBook, err
@@ -124,11 +111,6 @@ func (o *OKEX) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook
}
} else {
if p.SecondCurrency.String() == common.StringToLower("USD") {
p.SecondCurrency = "usdt"
currency = exchange.FormatExchangeCurrency(o.Name, p).String()
}
orderbookNew, err := o.GetSpotMarketDepth(ActualSpotDepthRequestParams{
Symbol: currency,
Size: 200,