mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-06 23:16:53 +00:00
orderbook: change Base struct name to Book (#1914)
* orderbook: change Base struct name to Snapshot * linter: fix * Update exchanges/exchange.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/depth.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_types.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Snapshot -> Book * Tranche(s) -> Level(s) * Tranche(s) -> Level(s) * rm tranche ref * linter: fix * linter: rides again * update tests * Update exchange/websocket/buffer/buffer.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update backtester/eventhandlers/exchange/slippage/slippage.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchange/websocket/buffer/buffer.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchange/websocket/buffer/buffer.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/orderbook/orderbook_types.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/orderbook/orderbook_types.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * fixup tests * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_types.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/orderbook/orderbook_types.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: nits and rm stuff that is not needed * Update exchanges/orderbook/orderbook_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: nits --------- Co-authored-by: shazbert <ryan.oharareid@thrasher.io> Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io>
This commit is contained in:
@@ -639,7 +639,7 @@ func parseTime(dateTime string) (time.Time, error) {
|
||||
return time.Parse(bitstampTimeLayout, dateTime)
|
||||
}
|
||||
|
||||
func filterOrderbookZeroBidPrice(ob *orderbook.Base) {
|
||||
func filterOrderbookZeroBidPrice(ob *orderbook.Book) {
|
||||
if len(ob.Bids) == 0 || ob.Bids[len(ob.Bids)-1].Price != 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -941,14 +941,14 @@ func TestGetHistoricTrades(t *testing.T) {
|
||||
func TestOrderbookZeroBidPrice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ob := &orderbook.Base{
|
||||
ob := &orderbook.Book{
|
||||
Exchange: "Bitstamp",
|
||||
Pair: btcusdPair,
|
||||
Asset: asset.Spot,
|
||||
}
|
||||
filterOrderbookZeroBidPrice(ob)
|
||||
|
||||
ob.Bids = orderbook.Tranches{
|
||||
ob.Bids = orderbook.Levels{
|
||||
{Price: 69, Amount: 1337},
|
||||
{Price: 0, Amount: 69},
|
||||
}
|
||||
@@ -957,7 +957,7 @@ func TestOrderbookZeroBidPrice(t *testing.T) {
|
||||
t.Error("invalid orderbook bid values")
|
||||
}
|
||||
|
||||
ob.Bids = orderbook.Tranches{
|
||||
ob.Bids = orderbook.Levels{
|
||||
{Price: 59, Amount: 1337},
|
||||
{Price: 42, Amount: 8595},
|
||||
}
|
||||
|
||||
@@ -296,9 +296,9 @@ func (b *Bitstamp) handleWSOrderbook(msg []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
obUpdate := &orderbook.Base{
|
||||
Bids: make(orderbook.Tranches, len(wsOrderBookResp.Data.Bids)),
|
||||
Asks: make(orderbook.Tranches, len(wsOrderBookResp.Data.Asks)),
|
||||
obUpdate := &orderbook.Book{
|
||||
Bids: make(orderbook.Levels, len(wsOrderBookResp.Data.Bids)),
|
||||
Asks: make(orderbook.Levels, len(wsOrderBookResp.Data.Asks)),
|
||||
Pair: p,
|
||||
LastUpdated: wsOrderBookResp.Data.Microtimestamp.Time(),
|
||||
Asset: asset.Spot,
|
||||
@@ -334,24 +334,24 @@ func (b *Bitstamp) seedOrderBook(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
newOrderBook := &orderbook.Base{
|
||||
newOrderBook := &orderbook.Book{
|
||||
Pair: p[x],
|
||||
Asset: asset.Spot,
|
||||
Exchange: b.Name,
|
||||
VerifyOrderbook: b.CanVerifyOrderbook,
|
||||
Bids: make(orderbook.Tranches, len(orderbookSeed.Bids)),
|
||||
Asks: make(orderbook.Tranches, len(orderbookSeed.Asks)),
|
||||
Bids: make(orderbook.Levels, len(orderbookSeed.Bids)),
|
||||
Asks: make(orderbook.Levels, len(orderbookSeed.Asks)),
|
||||
LastUpdated: orderbookSeed.Timestamp,
|
||||
}
|
||||
|
||||
for i := range orderbookSeed.Asks {
|
||||
newOrderBook.Asks[i] = orderbook.Tranche{
|
||||
newOrderBook.Asks[i] = orderbook.Level{
|
||||
Price: orderbookSeed.Asks[i].Price,
|
||||
Amount: orderbookSeed.Asks[i].Amount,
|
||||
}
|
||||
}
|
||||
for i := range orderbookSeed.Bids {
|
||||
newOrderBook.Bids[i] = orderbook.Tranche{
|
||||
newOrderBook.Bids[i] = orderbook.Level{
|
||||
Price: orderbookSeed.Bids[i].Price,
|
||||
Amount: orderbookSeed.Bids[i].Amount,
|
||||
}
|
||||
|
||||
@@ -288,14 +288,14 @@ func (b *Bitstamp) GetFeeByType(ctx context.Context, feeBuilder *exchange.FeeBui
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Bitstamp) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Bitstamp) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Book, error) {
|
||||
if p.IsEmpty() {
|
||||
return nil, currency.ErrCurrencyPairEmpty
|
||||
}
|
||||
if err := b.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
book := &orderbook.Base{
|
||||
book := &orderbook.Book{
|
||||
Exchange: b.Name,
|
||||
Pair: p,
|
||||
Asset: assetType,
|
||||
@@ -311,9 +311,9 @@ func (b *Bitstamp) UpdateOrderbook(ctx context.Context, p currency.Pair, assetTy
|
||||
return book, err
|
||||
}
|
||||
|
||||
book.Bids = make(orderbook.Tranches, len(orderbookNew.Bids))
|
||||
book.Bids = make(orderbook.Levels, len(orderbookNew.Bids))
|
||||
for x := range orderbookNew.Bids {
|
||||
book.Bids[x] = orderbook.Tranche{
|
||||
book.Bids[x] = orderbook.Level{
|
||||
Amount: orderbookNew.Bids[x].Amount,
|
||||
Price: orderbookNew.Bids[x].Price,
|
||||
}
|
||||
@@ -321,9 +321,9 @@ func (b *Bitstamp) UpdateOrderbook(ctx context.Context, p currency.Pair, assetTy
|
||||
|
||||
filterOrderbookZeroBidPrice(book)
|
||||
|
||||
book.Asks = make(orderbook.Tranches, len(orderbookNew.Asks))
|
||||
book.Asks = make(orderbook.Levels, len(orderbookNew.Asks))
|
||||
for x := range orderbookNew.Asks {
|
||||
book.Asks[x] = orderbook.Tranche{
|
||||
book.Asks[x] = orderbook.Level{
|
||||
Amount: orderbookNew.Asks[x].Amount,
|
||||
Price: orderbookNew.Asks[x].Price,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user