mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
buffer/orderbook: shift orderbook update logic from buffer package to orderbook package (#1908)
* buffer/orderbook: shift orderbook update logic from buffer package to orderbook package * Update exchanges/orderbook/depth.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * linter: fixes * spelling: fix * samboss: add in some todos * sammy nit: add unlock on error * sammy nits: rm ptr to slice field buffer in orderbookHolder * sammy nits: Add more coverage bro * sammy nits: even more coverage * gk: nits on commentary * gk: nits change sort.Slice to slices.SortFunc * gk: fix commentary on buffer clearing * gk: nits fin * linter: fix * Update exchange/websocket/buffer/buffer.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchange/websocket/buffer/buffer.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/tranches.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchange/websocket/buffer/buffer_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchange/websocket/buffer/buffer_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/incremental_updates.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: refresh action types and names * gk nits: consolidate error vars and naming * gk nits: more name changes * gk nits; buffer tests update * gk nits: error var names change * linter: FIX * it gets inlined but there is an alloc * rn field in TODO * Update exchanges/binance/binance_websocket.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/binance/binance_websocket.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * orderbook: shift verify/validate funcs to validate.go and rn Verify() -> Validate() * orderbook: validate even in presence of checksum and allow cowboy mode * buffer; fix test * kraken: fix futures orderbook by reversing incoming bids * okx: change default spread pair * Update exchanges/orderbook/validate.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/validate.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/validate.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/validate.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/validate.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: initial nits * rn fields V(v)erifyorderbook to V(v)alidateOrderbook * buffer/orderbook: nilguard in validate and change method receiver w -> o --------- Co-authored-by: Ryan O'Hara-Reid <ryan.oharareid@thrasher.io> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -3081,18 +3081,14 @@ func TestGetOrderbookMovement(t *testing.T) {
|
||||
t.Parallel()
|
||||
em := NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName("binance")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "NewExchangeByName must not error")
|
||||
|
||||
exch.SetDefaults()
|
||||
b := exch.GetBase()
|
||||
b.Name = fakeExchangeName
|
||||
b.Enabled = true
|
||||
|
||||
cp, err := currency.NewPairFromString("btc-metal")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := currency.NewPairWithDelimiter("btc", "metal", "-")
|
||||
|
||||
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
||||
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
||||
@@ -3134,9 +3130,7 @@ func TestGetOrderbookMovement(t *testing.T) {
|
||||
}
|
||||
|
||||
depth, err := orderbook.DeployDepth(req.Exchange, currency.NewPair(currency.BTC, currency.METAL), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "orderbook.DeployDepth must not error")
|
||||
|
||||
bid := []orderbook.Level{
|
||||
{Price: 10, Amount: 1},
|
||||
@@ -3150,10 +3144,8 @@ func TestGetOrderbookMovement(t *testing.T) {
|
||||
{Price: 13, Amount: 1},
|
||||
{Price: 14, Amount: 1},
|
||||
}
|
||||
err = depth.LoadSnapshot(bid, ask, 0, time.Now(), time.Now(), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = depth.LoadSnapshot(&orderbook.Book{Bids: bid, Asks: ask, LastUpdated: time.Now(), LastPushed: time.Now(), RestSnapshot: true})
|
||||
require.NoError(t, err, "depth.LoadSnapshot must not error")
|
||||
|
||||
_, err = s.GetOrderbookMovement(t.Context(), req)
|
||||
if err.Error() != "quote amount invalid" {
|
||||
@@ -3182,18 +3174,14 @@ func TestGetOrderbookAmountByNominal(t *testing.T) {
|
||||
t.Parallel()
|
||||
em := NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName("binance")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "NewExchangeByName must not error")
|
||||
|
||||
exch.SetDefaults()
|
||||
b := exch.GetBase()
|
||||
b.Name = fakeExchangeName
|
||||
b.Enabled = true
|
||||
|
||||
cp, err := currency.NewPairFromString("btc-meme")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := currency.NewPairWithDelimiter("btc", "meme", "-")
|
||||
|
||||
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
||||
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
||||
@@ -3235,9 +3223,7 @@ func TestGetOrderbookAmountByNominal(t *testing.T) {
|
||||
}
|
||||
|
||||
depth, err := orderbook.DeployDepth(req.Exchange, currency.NewPair(currency.BTC, currency.MEME), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "orderbook.DeployDepth must not error")
|
||||
|
||||
bid := []orderbook.Level{
|
||||
{Price: 10, Amount: 1},
|
||||
@@ -3251,10 +3237,8 @@ func TestGetOrderbookAmountByNominal(t *testing.T) {
|
||||
{Price: 13, Amount: 1},
|
||||
{Price: 14, Amount: 1},
|
||||
}
|
||||
err = depth.LoadSnapshot(bid, ask, 0, time.Now(), time.Now(), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = depth.LoadSnapshot(&orderbook.Book{Bids: bid, Asks: ask, LastUpdated: time.Now(), LastPushed: time.Now(), RestSnapshot: true})
|
||||
require.NoError(t, err, "depth.LoadSnapshot must not error")
|
||||
|
||||
nominal, err := s.GetOrderbookAmountByNominal(t.Context(), req)
|
||||
require.NoError(t, err)
|
||||
@@ -3276,18 +3260,14 @@ func TestGetOrderbookAmountByImpact(t *testing.T) {
|
||||
t.Parallel()
|
||||
em := NewExchangeManager()
|
||||
exch, err := em.NewExchangeByName("binance")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "NewExchangeByName must not error")
|
||||
|
||||
exch.SetDefaults()
|
||||
b := exch.GetBase()
|
||||
b.Name = fakeExchangeName
|
||||
b.Enabled = true
|
||||
|
||||
cp, err := currency.NewPairFromString("btc-mad")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cp := currency.NewPairWithDelimiter("btc", "mad", "-")
|
||||
|
||||
b.CurrencyPairs.Pairs = make(map[asset.Item]*currency.PairStore)
|
||||
b.CurrencyPairs.Pairs[asset.Spot] = ¤cy.PairStore{
|
||||
@@ -3329,9 +3309,7 @@ func TestGetOrderbookAmountByImpact(t *testing.T) {
|
||||
}
|
||||
|
||||
depth, err := orderbook.DeployDepth(req.Exchange, currency.NewPair(currency.BTC, currency.MAD), asset.Spot)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.NoError(t, err, "orderbook.DeployDepth must not error")
|
||||
|
||||
bid := []orderbook.Level{
|
||||
{Price: 10, Amount: 1},
|
||||
@@ -3345,10 +3323,8 @@ func TestGetOrderbookAmountByImpact(t *testing.T) {
|
||||
{Price: 13, Amount: 1},
|
||||
{Price: 14, Amount: 1},
|
||||
}
|
||||
err = depth.LoadSnapshot(bid, ask, 0, time.Now(), time.Now(), true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = depth.LoadSnapshot(&orderbook.Book{Bids: bid, Asks: ask, LastUpdated: time.Now(), LastPushed: time.Now(), RestSnapshot: true})
|
||||
require.NoError(t, err, "depth.LoadSnapshot must not error")
|
||||
|
||||
req.ImpactPercentage = 9.090909090909092
|
||||
impact, err := s.GetOrderbookAmountByImpact(t.Context(), req)
|
||||
|
||||
Reference in New Issue
Block a user