mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 07:26:47 +00:00
Asset update to fix minor stutter (#316)
This commit is contained in:
committed by
Adrian Gallagher
parent
b901c4b670
commit
20c24601fb
@@ -4,14 +4,14 @@ import (
|
||||
"sort"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/assets"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
// Item holds various fields for storing currency pair stats
|
||||
type Item struct {
|
||||
Exchange string
|
||||
Pair currency.Pair
|
||||
AssetType assets.AssetType
|
||||
AssetType asset.Item
|
||||
Price float64
|
||||
Volume float64
|
||||
}
|
||||
@@ -50,7 +50,7 @@ func (b ByVolume) Swap(i, j int) {
|
||||
}
|
||||
|
||||
// Add adds or updates the item stats
|
||||
func Add(exchange string, p currency.Pair, assetType assets.AssetType, price, volume float64) {
|
||||
func Add(exchange string, p currency.Pair, assetType asset.Item, price, volume float64) {
|
||||
if exchange == "" ||
|
||||
assetType == "" ||
|
||||
price == 0 ||
|
||||
@@ -75,7 +75,7 @@ func Add(exchange string, p currency.Pair, assetType assets.AssetType, price, vo
|
||||
|
||||
// Append adds or updates the item stats for a specific
|
||||
// currency pair and asset type
|
||||
func Append(exchange string, p currency.Pair, assetType assets.AssetType, price, volume float64) {
|
||||
func Append(exchange string, p currency.Pair, assetType asset.Item, price, volume float64) {
|
||||
if AlreadyExists(exchange, p, assetType, price, volume) {
|
||||
return
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func Append(exchange string, p currency.Pair, assetType assets.AssetType, price,
|
||||
|
||||
// AlreadyExists checks to see if item info already exists
|
||||
// for a specific currency pair and asset type
|
||||
func AlreadyExists(exchange string, p currency.Pair, assetType assets.AssetType, price, volume float64) bool {
|
||||
func AlreadyExists(exchange string, p currency.Pair, assetType asset.Item, price, volume float64) bool {
|
||||
for i := range Items {
|
||||
if Items[i].Exchange == exchange &&
|
||||
Items[i].Pair.EqualIncludeReciprocal(p) &&
|
||||
@@ -108,7 +108,7 @@ func AlreadyExists(exchange string, p currency.Pair, assetType assets.AssetType,
|
||||
// SortExchangesByVolume sorts item info by volume for a specific
|
||||
// currency pair and asset type. Reverse will reverse the order from lowest to
|
||||
// highest
|
||||
func SortExchangesByVolume(p currency.Pair, assetType assets.AssetType, reverse bool) []Item {
|
||||
func SortExchangesByVolume(p currency.Pair, assetType asset.Item, reverse bool) []Item {
|
||||
var result []Item
|
||||
for x := range Items {
|
||||
if Items[x].Pair.EqualIncludeReciprocal(p) &&
|
||||
@@ -128,7 +128,7 @@ func SortExchangesByVolume(p currency.Pair, assetType assets.AssetType, reverse
|
||||
// SortExchangesByPrice sorts item info by volume for a specific
|
||||
// currency pair and asset type. Reverse will reverse the order from lowest to
|
||||
// highest
|
||||
func SortExchangesByPrice(p currency.Pair, assetType assets.AssetType, reverse bool) []Item {
|
||||
func SortExchangesByPrice(p currency.Pair, assetType asset.Item, reverse bool) []Item {
|
||||
var result []Item
|
||||
for x := range Items {
|
||||
if Items[x].Pair.EqualIncludeReciprocal(p) &&
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-/gocryptotrader/currency"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/assets"
|
||||
"github.com/thrasher-/gocryptotrader/exchanges/asset"
|
||||
)
|
||||
|
||||
func TestLenByPrice(t *testing.T) {
|
||||
@@ -13,7 +13,7 @@ func TestLenByPrice(t *testing.T) {
|
||||
{
|
||||
Exchange: "ANX",
|
||||
Pair: p,
|
||||
AssetType: assets.AssetTypeSpot,
|
||||
AssetType: asset.Spot,
|
||||
Price: 1200,
|
||||
Volume: 5,
|
||||
},
|
||||
@@ -31,14 +31,14 @@ func TestLessByPrice(t *testing.T) {
|
||||
{
|
||||
Exchange: "alphapoint",
|
||||
Pair: p,
|
||||
AssetType: assets.AssetTypeSpot,
|
||||
AssetType: asset.Spot,
|
||||
Price: 1200,
|
||||
Volume: 5,
|
||||
},
|
||||
{
|
||||
Exchange: "bitfinex",
|
||||
Pair: p,
|
||||
AssetType: assets.AssetTypeSpot,
|
||||
AssetType: asset.Spot,
|
||||
Price: 1198,
|
||||
Volume: 20,
|
||||
},
|
||||
@@ -59,14 +59,14 @@ func TestSwapByPrice(t *testing.T) {
|
||||
{
|
||||
Exchange: "bitstamp",
|
||||
Pair: p,
|
||||
AssetType: assets.AssetTypeSpot,
|
||||
AssetType: asset.Spot,
|
||||
Price: 1324,
|
||||
Volume: 5,
|
||||
},
|
||||
{
|
||||
Exchange: "bitfinex",
|
||||
Pair: p,
|
||||
AssetType: assets.AssetTypeSpot,
|
||||
AssetType: asset.Spot,
|
||||
Price: 7863,
|
||||
Volume: 20,
|
||||
},
|
||||
@@ -104,7 +104,7 @@ func TestSwapByVolume(t *testing.T) {
|
||||
func TestAdd(t *testing.T) {
|
||||
Items = Items[:0]
|
||||
p := currency.NewPairFromStrings("BTC", "USD")
|
||||
Add("ANX", p, assets.AssetTypeSpot, 1200, 42)
|
||||
Add("ANX", p, asset.Spot, 1200, 42)
|
||||
|
||||
if len(Items) < 1 {
|
||||
t.Error("Test Failed - stats Add did not add exchange info.")
|
||||
@@ -117,14 +117,14 @@ func TestAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
p.Base = currency.XBT
|
||||
Add("ANX", p, assets.AssetTypeSpot, 1201, 43)
|
||||
Add("ANX", p, asset.Spot, 1201, 43)
|
||||
|
||||
if Items[1].Pair.String() != "XBTUSD" {
|
||||
t.Fatal("Test failed. stats Add did not add exchange info.")
|
||||
}
|
||||
|
||||
p = currency.NewPairFromStrings("ETH", "USDT")
|
||||
Add("ANX", p, assets.AssetTypeSpot, 300, 1000)
|
||||
Add("ANX", p, asset.Spot, 300, 1000)
|
||||
|
||||
if Items[2].Pair.String() != "ETHUSD" {
|
||||
t.Fatal("Test failed. stats Add did not add exchange info.")
|
||||
@@ -133,12 +133,12 @@ func TestAdd(t *testing.T) {
|
||||
|
||||
func TestAppend(t *testing.T) {
|
||||
p := currency.NewPairFromStrings("BTC", "USD")
|
||||
Append("sillyexchange", p, assets.AssetTypeSpot, 1234, 45)
|
||||
Append("sillyexchange", p, asset.Spot, 1234, 45)
|
||||
if len(Items) < 2 {
|
||||
t.Error("Test Failed - stats Append did not add exchange values.")
|
||||
}
|
||||
|
||||
Append("sillyexchange", p, assets.AssetTypeSpot, 1234, 45)
|
||||
Append("sillyexchange", p, asset.Spot, 1234, 45)
|
||||
if len(Items) == 3 {
|
||||
t.Error("Test Failed - stats Append added exchange values")
|
||||
}
|
||||
@@ -146,23 +146,23 @@ func TestAppend(t *testing.T) {
|
||||
|
||||
func TestAlreadyExists(t *testing.T) {
|
||||
p := currency.NewPairFromStrings("BTC", "USD")
|
||||
if !AlreadyExists("ANX", p, assets.AssetTypeSpot, 1200, 42) {
|
||||
if !AlreadyExists("ANX", p, asset.Spot, 1200, 42) {
|
||||
t.Error("Test Failed - stats AlreadyExists exchange does not exist.")
|
||||
}
|
||||
p.Base = currency.NewCode("dii")
|
||||
if AlreadyExists("bla", p, assets.AssetTypeSpot, 1234, 123) {
|
||||
if AlreadyExists("bla", p, asset.Spot, 1234, 123) {
|
||||
t.Error("Test Failed - stats AlreadyExists found incorrect exchange.")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortExchangesByVolume(t *testing.T) {
|
||||
p := currency.NewPairFromStrings("BTC", "USD")
|
||||
topVolume := SortExchangesByVolume(p, assets.AssetTypeSpot, true)
|
||||
topVolume := SortExchangesByVolume(p, asset.Spot, true)
|
||||
if topVolume[0].Exchange != "sillyexchange" {
|
||||
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
|
||||
}
|
||||
|
||||
topVolume = SortExchangesByVolume(p, assets.AssetTypeSpot, false)
|
||||
topVolume = SortExchangesByVolume(p, asset.Spot, false)
|
||||
if topVolume[0].Exchange != "ANX" {
|
||||
t.Error("Test Failed - stats SortExchangesByVolume incorrectly sorted values.")
|
||||
}
|
||||
@@ -170,12 +170,12 @@ func TestSortExchangesByVolume(t *testing.T) {
|
||||
|
||||
func TestSortExchangesByPrice(t *testing.T) {
|
||||
p := currency.NewPairFromStrings("BTC", "USD")
|
||||
topPrice := SortExchangesByPrice(p, assets.AssetTypeSpot, true)
|
||||
topPrice := SortExchangesByPrice(p, asset.Spot, true)
|
||||
if topPrice[0].Exchange != "sillyexchange" {
|
||||
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
|
||||
}
|
||||
|
||||
topPrice = SortExchangesByPrice(p, assets.AssetTypeSpot, false)
|
||||
topPrice = SortExchangesByPrice(p, asset.Spot, false)
|
||||
if topPrice[0].Exchange != "ANX" {
|
||||
t.Error("Test Failed - stats SortExchangesByPrice incorrectly sorted values.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user