mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-09 07:26:48 +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:
@@ -656,13 +656,13 @@ func (bi *Binanceus) SynchroniseWebsocketOrderbook() {
|
||||
|
||||
// ProcessOrderbookUpdate processes the websocket orderbook update
|
||||
func (bi *Binanceus) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, wsDSUpdate *WebsocketDepthStream) error {
|
||||
updateBid := make([]orderbook.Tranche, len(wsDSUpdate.UpdateBids))
|
||||
updateBid := make([]orderbook.Level, len(wsDSUpdate.UpdateBids))
|
||||
for i := range wsDSUpdate.UpdateBids {
|
||||
updateBid[i].Price = wsDSUpdate.UpdateBids[i][0].Float64()
|
||||
updateBid[i].Amount = wsDSUpdate.UpdateBids[i][1].Float64()
|
||||
}
|
||||
|
||||
updateAsk := make([]orderbook.Tranche, len(wsDSUpdate.UpdateAsks))
|
||||
updateAsk := make([]orderbook.Level, len(wsDSUpdate.UpdateAsks))
|
||||
for i := range wsDSUpdate.UpdateAsks {
|
||||
updateAsk[i].Price = wsDSUpdate.UpdateAsks[i][0].Float64()
|
||||
updateAsk[i].Amount = wsDSUpdate.UpdateAsks[i][1].Float64()
|
||||
@@ -804,24 +804,24 @@ func (bi *Binanceus) SeedLocalCache(ctx context.Context, p currency.Pair) error
|
||||
|
||||
// SeedLocalCacheWithBook seeds the local orderbook cache
|
||||
func (bi *Binanceus) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBook) error {
|
||||
newOrderBook := orderbook.Base{
|
||||
newOrderBook := orderbook.Book{
|
||||
Pair: p,
|
||||
Asset: asset.Spot,
|
||||
Exchange: bi.Name,
|
||||
LastUpdateID: orderbookNew.LastUpdateID,
|
||||
VerifyOrderbook: bi.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,
|
||||
}
|
||||
@@ -985,7 +985,7 @@ func (o *orderbookManager) stopNeedsFetchingBook(pair currency.Pair) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
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]
|
||||
@@ -1019,7 +1019,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
|
||||
|
||||
@@ -311,14 +311,14 @@ func (bi *Binanceus) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (bi *Binanceus) UpdateOrderbook(ctx context.Context, pair currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (bi *Binanceus) UpdateOrderbook(ctx context.Context, pair currency.Pair, assetType asset.Item) (*orderbook.Book, error) {
|
||||
if pair.IsEmpty() {
|
||||
return nil, currency.ErrCurrencyPairEmpty
|
||||
}
|
||||
if err := bi.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
book := &orderbook.Base{
|
||||
book := &orderbook.Book{
|
||||
Exchange: bi.Name,
|
||||
Pair: pair,
|
||||
Asset: assetType,
|
||||
@@ -332,16 +332,16 @@ func (bi *Binanceus) UpdateOrderbook(ctx context.Context, pair currency.Pair, as
|
||||
if err != nil {
|
||||
return book, err
|
||||
}
|
||||
book.Bids = make([]orderbook.Tranche, len(orderbookNew.Bids))
|
||||
book.Bids = make([]orderbook.Level, 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.Tranche, len(orderbookNew.Asks))
|
||||
book.Asks = make([]orderbook.Level, 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