mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
Bithumb: Filter zero quantity values in GetOrderBook (#1969)
* #1947 bugfix: added a filter to eliminate zero quantity of bids and asks at bithumb::GetOrderBook feature: added assertions in TestGetOrderBook * resolved comments * refactor: rename FilterZeros to FilterZeroQuantities and update orderbook filtering logic --------- Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
committed by
GitHub
parent
dcf596c72b
commit
edf5d84d34
@@ -132,9 +132,23 @@ func (e *Exchange) GetOrderBook(ctx context.Context, symbol string) (*Orderbook,
|
||||
return nil, errors.New(response.Message)
|
||||
}
|
||||
|
||||
response.Data.Bids.FilterZeroQuantities()
|
||||
response.Data.Asks.FilterZeroQuantities()
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
// FilterZeroQuantities filters out orderbook levels with zero quantity
|
||||
func (o *OrderbookLevels) FilterZeroQuantities() {
|
||||
b := (*o)[:0]
|
||||
for _, x := range *o {
|
||||
if x.Quantity > 0 {
|
||||
b = append(b, x)
|
||||
}
|
||||
}
|
||||
*o = b
|
||||
}
|
||||
|
||||
// GetAssetStatus returns the withdrawal and deposit status for the symbol
|
||||
func (e *Exchange) GetAssetStatus(ctx context.Context, symbol string) (*Status, error) {
|
||||
if symbol == "" {
|
||||
|
||||
@@ -88,6 +88,22 @@ func TestGetOrderBook(t *testing.T) {
|
||||
assert.NotEmpty(t, ob.Data.PaymentCurrency, "PaymentCurrency should not be empty")
|
||||
}
|
||||
|
||||
func TestOrderbookLevelsFilterZeroQuantities(t *testing.T) {
|
||||
t.Parallel()
|
||||
bids := OrderbookLevels{
|
||||
{Price: 99, Quantity: 0},
|
||||
{Price: 98, Quantity: 2},
|
||||
}
|
||||
asks := OrderbookLevels{
|
||||
{Price: 100, Quantity: 0},
|
||||
{Price: 101, Quantity: 1},
|
||||
}
|
||||
bids.FilterZeroQuantities()
|
||||
asks.FilterZeroQuantities()
|
||||
assert.Len(t, asks, 1, "Asks should have 1 item")
|
||||
assert.Len(t, bids, 1, "Bids should have 1 item")
|
||||
}
|
||||
|
||||
func TestGetTransactionHistory(t *testing.T) {
|
||||
t.Parallel()
|
||||
sharedtestvalues.SkipTestIfCredentialsUnset(t, e)
|
||||
|
||||
@@ -40,17 +40,11 @@ type TickersResponse struct {
|
||||
type Orderbook struct {
|
||||
Status string `json:"status"`
|
||||
Data struct {
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
OrderCurrency string `json:"order_currency"`
|
||||
PaymentCurrency string `json:"payment_currency"`
|
||||
Bids []struct {
|
||||
Quantity float64 `json:"quantity,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
} `json:"bids"`
|
||||
Asks []struct {
|
||||
Quantity float64 `json:"quantity,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
} `json:"asks"`
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
OrderCurrency string `json:"order_currency"`
|
||||
PaymentCurrency string `json:"payment_currency"`
|
||||
Bids OrderbookLevels `json:"bids"`
|
||||
Asks OrderbookLevels `json:"asks"`
|
||||
} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
@@ -330,3 +324,12 @@ type StatusAll struct {
|
||||
} `json:"data"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// OrderbookLevel defines a single level in the orderbook
|
||||
type OrderbookLevel struct {
|
||||
Quantity float64 `json:"quantity,string"`
|
||||
Price float64 `json:"price,string"`
|
||||
}
|
||||
|
||||
// OrderbookLevels defines a slice of OrderbookLevel
|
||||
type OrderbookLevels []OrderbookLevel
|
||||
|
||||
Reference in New Issue
Block a user