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:
@@ -461,24 +461,24 @@ func (b *Binance) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
|
||||
// SeedLocalCacheWithBook seeds the local orderbook cache
|
||||
func (b *Binance) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBook) error {
|
||||
newOrderBook := orderbook.Base{
|
||||
newOrderBook := orderbook.Book{
|
||||
Pair: p,
|
||||
Asset: asset.Spot,
|
||||
Exchange: b.Name,
|
||||
LastUpdateID: orderbookNew.LastUpdateID,
|
||||
VerifyOrderbook: b.CanVerifyOrderbook,
|
||||
Bids: make(orderbook.Tranches, len(orderbookNew.Bids)),
|
||||
Asks: make(orderbook.Tranches, len(orderbookNew.Asks)),
|
||||
Bids: make(orderbook.Levels, len(orderbookNew.Bids)),
|
||||
Asks: make(orderbook.Levels, len(orderbookNew.Asks)),
|
||||
LastUpdated: time.Now(), // Time not provided in REST book.
|
||||
}
|
||||
for i := range orderbookNew.Bids {
|
||||
newOrderBook.Bids[i] = orderbook.Tranche{
|
||||
newOrderBook.Bids[i] = orderbook.Level{
|
||||
Amount: orderbookNew.Bids[i].Quantity,
|
||||
Price: orderbookNew.Bids[i].Price,
|
||||
}
|
||||
}
|
||||
for i := range orderbookNew.Asks {
|
||||
newOrderBook.Asks[i] = orderbook.Tranche{
|
||||
newOrderBook.Asks[i] = orderbook.Level{
|
||||
Amount: orderbookNew.Asks[i].Quantity,
|
||||
Price: orderbookNew.Asks[i].Price,
|
||||
}
|
||||
@@ -615,16 +615,16 @@ func (b *Binance) manageSubs(op string, subs subscription.List) error {
|
||||
|
||||
// ProcessOrderbookUpdate processes the websocket orderbook update
|
||||
func (b *Binance) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, ws *WebsocketDepthStream) error {
|
||||
updateBid := make([]orderbook.Tranche, len(ws.UpdateBids))
|
||||
updateBid := make([]orderbook.Level, len(ws.UpdateBids))
|
||||
for i := range ws.UpdateBids {
|
||||
updateBid[i] = orderbook.Tranche{
|
||||
updateBid[i] = orderbook.Level{
|
||||
Price: ws.UpdateBids[i][0].Float64(),
|
||||
Amount: ws.UpdateBids[i][1].Float64(),
|
||||
}
|
||||
}
|
||||
updateAsk := make([]orderbook.Tranche, len(ws.UpdateAsks))
|
||||
updateAsk := make([]orderbook.Level, len(ws.UpdateAsks))
|
||||
for i := range ws.UpdateAsks {
|
||||
updateAsk[i] = orderbook.Tranche{
|
||||
updateAsk[i] = orderbook.Level{
|
||||
Price: ws.UpdateAsks[i][0].Float64(),
|
||||
Amount: ws.UpdateAsks[i][1].Float64(),
|
||||
}
|
||||
@@ -919,7 +919,7 @@ func (o *orderbookManager) fetchBookViaREST(pair currency.Pair) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *orderbookManager) checkAndProcessOrderbookUpdate(processor func(currency.Pair, asset.Item, *WebsocketDepthStream) error, pair currency.Pair, recent *orderbook.Base) error {
|
||||
func (o *orderbookManager) checkAndProcessOrderbookUpdate(processor func(currency.Pair, asset.Item, *WebsocketDepthStream) error, pair currency.Pair, recent *orderbook.Book) error {
|
||||
o.Lock()
|
||||
defer o.Unlock()
|
||||
state, ok := o.state[pair.Base][pair.Quote][asset.Spot]
|
||||
@@ -953,7 +953,7 @@ buffer:
|
||||
}
|
||||
|
||||
// validate checks for correct update alignment
|
||||
func (u *update) validate(updt *WebsocketDepthStream, recent *orderbook.Base) (bool, error) {
|
||||
func (u *update) validate(updt *WebsocketDepthStream, recent *orderbook.Book) (bool, error) {
|
||||
if updt.LastUpdateID <= recent.LastUpdateID {
|
||||
// Drop any event where u is <= lastUpdateId in the snapshot.
|
||||
return false, nil
|
||||
|
||||
@@ -513,14 +513,14 @@ func (b *Binance) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Ite
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Binance) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Binance) 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,
|
||||
@@ -547,16 +547,16 @@ func (b *Binance) UpdateOrderbook(ctx context.Context, p currency.Pair, assetTyp
|
||||
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].Quantity,
|
||||
Price: orderbookNew.Bids[x].Price,
|
||||
}
|
||||
}
|
||||
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].Quantity,
|
||||
Price: orderbookNew.Asks[x].Price,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user