Add/improve common string functions, currency pair handling, fix LBTC orderbook amount

This commit is contained in:
Adrian Gallagher
2018-02-08 11:59:54 +11:00
parent 5f10897b5b
commit e8f8e32609
19 changed files with 129 additions and 51 deletions

View File

@@ -462,7 +462,7 @@ func (b *Binance) SendAuthHTTPRequest(method, path string, params url.Values, re
// CheckLimit checks value against a variable list
func (b *Binance) CheckLimit(limit int64) error {
if !common.DataContains(b.validLimits, strconv.FormatInt(limit, 10)) {
if !common.StringDataCompare(b.validLimits, strconv.FormatInt(limit, 10)) {
return errors.New("Incorrect limit values - valid values are 5, 10, 20, 50, 100, 500, 1000")
}
return nil
@@ -470,7 +470,7 @@ func (b *Binance) CheckLimit(limit int64) error {
// CheckSymbol checks value against a variable list
func (b *Binance) CheckSymbol(symbol string) error {
if !common.DataContains(b.AvailablePairs, symbol) {
if !common.StringDataCompare(b.AvailablePairs, symbol) {
return errors.New("Incorrect symbol values - please check available pairs in configuration")
}
return nil
@@ -478,7 +478,7 @@ func (b *Binance) CheckSymbol(symbol string) error {
// CheckIntervals checks value against a variable list
func (b *Binance) CheckIntervals(interval string) error {
if !common.DataContains(b.validIntervals, interval) {
if !common.StringDataCompare(b.validIntervals, interval) {
return errors.New(`Incorrect interval values - valid values are "1m","3m","5m","15m","30m","1h","2h","4h","6h","8h","12h","1d","3d","1w","1M"`)
}
return nil

View File

@@ -160,7 +160,7 @@ func TestGetSymbols(t *testing.T) {
if len(expectedCurrencies) <= len(symbols) {
for _, explicitSymbol := range expectedCurrencies {
if common.DataContains(expectedCurrencies, explicitSymbol) {
if common.StringDataCompare(expectedCurrencies, explicitSymbol) {
break
} else {
t.Error("BitfinexGetSymbols currency mismatch with: ", explicitSymbol)

View File

@@ -27,7 +27,7 @@ func (b *Bittrex) Run() {
log.Printf("%s Failed to get available symbols.\n", b.GetName())
} else {
forceUpgrade := false
if !common.DataContains(b.EnabledPairs, "-") || !common.DataContains(b.AvailablePairs, "-") {
if !common.StringDataContains(b.EnabledPairs, "-") || !common.StringDataContains(b.AvailablePairs, "-") {
forceUpgrade = true
}
var currencies []string

View File

@@ -28,7 +28,7 @@ func (b *BTCC) Run() {
go b.WebsocketClient()
}
if common.DataContains(b.EnabledPairs, "CNY") || common.DataContains(b.AvailablePairs, "CNY") || common.DataContains(b.BaseCurrencies, "CNY") {
if common.StringDataContains(b.EnabledPairs, "CNY") || common.StringDataContains(b.AvailablePairs, "CNY") || common.StringDataContains(b.BaseCurrencies, "CNY") {
log.Println("WARNING: BTCC only supports BTCUSD now, upgrading available, enabled and base currencies to BTCUSD/USD")
pairs := []string{"BTCUSD"}
cfg := config.GetConfig()

View File

@@ -23,7 +23,7 @@ func (b *BTCMarkets) Run() {
log.Printf("%s %d currencies enabled: %s.\n", b.GetName(), len(b.EnabledPairs), b.EnabledPairs)
}
if !common.DataContains(b.EnabledPairs, "AUD") || !common.DataContains(b.EnabledPairs, "AUD") {
if !common.StringDataContains(b.EnabledPairs, "AUD") || !common.StringDataContains(b.EnabledPairs, "AUD") {
enabledPairs := []string{}
for x := range b.EnabledPairs {
enabledPairs = append(enabledPairs, b.EnabledPairs[x]+"AUD")

View File

@@ -56,7 +56,7 @@ func TestSetAssetTypes(t *testing.T) {
t.Fatalf("Test failed. TestSetAssetTypes. Error %s", err)
}
if !common.DataContains(b.AssetTypes, ticker.Spot) {
if !common.StringDataCompare(b.AssetTypes, ticker.Spot) {
t.Fatal("Test failed. TestSetAssetTypes assetTypes is not set")
}
}
@@ -73,7 +73,7 @@ func TestGetExchangeAssetTypes(t *testing.T) {
t.Fatal("Test failed. Unable to obtain Bitfinex asset types")
}
if !common.DataContains(result, ticker.Spot) {
if !common.StringDataCompare(result, ticker.Spot) {
t.Fatal("Test failed. Bitfinex does not contain default asset type 'SPOT'")
}

View File

@@ -32,7 +32,7 @@ func (p *HitBTC) Run() {
log.Printf("%s Failed to get available symbols.\n", p.GetName())
} else {
forceUpgrade := false
if !common.DataContains(p.EnabledPairs, "-") || !common.DataContains(p.AvailablePairs, "-") {
if !common.StringDataContains(p.EnabledPairs, "-") || !common.StringDataContains(p.AvailablePairs, "-") {
forceUpgrade = true
}
var currencies []string

View File

@@ -33,11 +33,11 @@ func (h *HUOBI) Run() {
log.Printf("%s Failed to get available symbols.\n", h.GetName())
} else {
forceUpgrade := false
if common.DataContains(h.EnabledPairs, "CNY") || common.DataContains(h.AvailablePairs, "CNY") {
if common.StringDataContains(h.EnabledPairs, "CNY") || common.StringDataContains(h.AvailablePairs, "CNY") {
forceUpgrade = true
}
if common.DataContains(h.BaseCurrencies, "CNY") {
if common.StringDataContains(h.BaseCurrencies, "CNY") {
cfg := config.GetConfig()
exchCfg, err := cfg.GetExchangeConfig(h.Name)
if err != nil {

View File

@@ -30,7 +30,7 @@ func (k *Kraken) Run() {
log.Printf("%s Failed to get available symbols.\n", k.GetName())
} else {
forceUpgrade := false
if !common.DataContains(k.EnabledPairs, "-") || !common.DataContains(k.AvailablePairs, "-") {
if !common.StringDataContains(k.EnabledPairs, "-") || !common.StringDataContains(k.AvailablePairs, "-") {
forceUpgrade = true
}

View File

@@ -70,12 +70,12 @@ func (l *LocalBitcoins) UpdateOrderbook(p pair.CurrencyPair, assetType string) (
for x := range orderbookNew.Bids {
data := orderbookNew.Bids[x]
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: data.Amount, Price: data.Price})
orderBook.Bids = append(orderBook.Bids, orderbook.Item{Amount: data.Amount / data.Price, Price: data.Price})
}
for x := range orderbookNew.Asks {
data := orderbookNew.Asks[x]
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Amount, Price: data.Price})
orderBook.Asks = append(orderBook.Asks, orderbook.Item{Amount: data.Amount / data.Price, Price: data.Price})
}
orderbook.ProcessOrderbook(l.GetName(), p, orderBook, assetType)

View File

@@ -971,7 +971,7 @@ func (o *OKEX) SetCheckVarDefaults() {
// CheckContractPosition checks to see if the string is a valid position for okex
func (o *OKEX) CheckContractPosition(position string) error {
if !common.DataContains(o.ContractPosition, position) {
if !common.StringDataCompare(o.ContractPosition, position) {
return errors.New("invalid position string - e.g. 1 = open long position, 2 = open short position, 3 = liquidate long position, 4 = liquidate short position")
}
return nil
@@ -979,7 +979,7 @@ func (o *OKEX) CheckContractPosition(position string) error {
// CheckSymbol checks to see if the string is a valid symbol for okex
func (o *OKEX) CheckSymbol(symbol string) error {
if !common.DataContains(o.CurrencyPairs, symbol) {
if !common.StringDataCompare(o.CurrencyPairs, symbol) {
return errors.New("invalid symbol string")
}
return nil
@@ -987,7 +987,7 @@ func (o *OKEX) CheckSymbol(symbol string) error {
// CheckContractType checks to see if the string is a correct asset
func (o *OKEX) CheckContractType(contractType string) error {
if !common.DataContains(o.ContractTypes, contractType) {
if !common.StringDataCompare(o.ContractTypes, contractType) {
return errors.New("invalid contract type string")
}
return nil
@@ -995,7 +995,7 @@ func (o *OKEX) CheckContractType(contractType string) error {
// CheckType checks to see if the string is a correct type
func (o *OKEX) CheckType(typeInput string) error {
if !common.DataContains(o.Types, typeInput) {
if !common.StringDataCompare(o.Types, typeInput) {
return errors.New("invalid type string")
}
return nil

View File

@@ -32,7 +32,7 @@ func (p *Poloniex) Run() {
log.Printf("%s Failed to get available symbols.\n", p.GetName())
} else {
forceUpdate := false
if common.DataContains(p.AvailablePairs, "BTC_USDT") {
if common.StringDataCompare(p.AvailablePairs, "BTC_USDT") {
log.Printf("%s contains invalid pair, forcing upgrade of available currencies.\n",
p.GetName())
forceUpdate = true