mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-03 15:10:49 +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:
@@ -39,13 +39,13 @@ type WsTicker struct {
|
||||
VolumePower float64 `json:"volumePower,string"`
|
||||
}
|
||||
|
||||
// WsOrderbooks defines an amalgamated bid ask orderbook tranche list
|
||||
// WsOrderbooks defines an amalgamated bid ask orderbook level list
|
||||
type WsOrderbooks struct {
|
||||
List []WsOrderbook `json:"list"`
|
||||
DateTime types.Time `json:"datetime"`
|
||||
}
|
||||
|
||||
// WsOrderbook defines a singular orderbook tranche
|
||||
// WsOrderbook defines a singular orderbook level
|
||||
type WsOrderbook struct {
|
||||
Symbol currency.Pair `json:"symbol"`
|
||||
OrderSide string `json:"orderType"`
|
||||
|
||||
@@ -256,14 +256,14 @@ func (b *Bithumb) UpdateTicker(ctx context.Context, p currency.Pair, a asset.Ite
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (b *Bithumb) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Base, error) {
|
||||
func (b *Bithumb) 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,
|
||||
@@ -276,17 +276,17 @@ func (b *Bithumb) UpdateOrderbook(ctx context.Context, p currency.Pair, assetTyp
|
||||
return book, err
|
||||
}
|
||||
|
||||
book.Bids = make(orderbook.Tranches, len(orderbookNew.Data.Bids))
|
||||
book.Bids = make(orderbook.Levels, len(orderbookNew.Data.Bids))
|
||||
for i := range orderbookNew.Data.Bids {
|
||||
book.Bids[i] = orderbook.Tranche{
|
||||
book.Bids[i] = orderbook.Level{
|
||||
Amount: orderbookNew.Data.Bids[i].Quantity,
|
||||
Price: orderbookNew.Data.Bids[i].Price,
|
||||
}
|
||||
}
|
||||
|
||||
book.Asks = make(orderbook.Tranches, len(orderbookNew.Data.Asks))
|
||||
book.Asks = make(orderbook.Levels, len(orderbookNew.Data.Asks))
|
||||
for i := range orderbookNew.Data.Asks {
|
||||
book.Asks[i] = orderbook.Tranche{
|
||||
book.Asks[i] = orderbook.Level{
|
||||
Amount: orderbookNew.Data.Asks[i].Quantity,
|
||||
Price: orderbookNew.Data.Asks[i].Price,
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ const (
|
||||
)
|
||||
|
||||
func (b *Bithumb) processBooks(updates *WsOrderbooks) error {
|
||||
bids := make([]orderbook.Tranche, 0, len(updates.List))
|
||||
asks := make([]orderbook.Tranche, 0, len(updates.List))
|
||||
bids := make([]orderbook.Level, 0, len(updates.List))
|
||||
asks := make([]orderbook.Level, 0, len(updates.List))
|
||||
for x := range updates.List {
|
||||
i := orderbook.Tranche{Price: updates.List[x].Price, Amount: updates.List[x].Quantity}
|
||||
i := orderbook.Level{Price: updates.List[x].Price, Amount: updates.List[x].Quantity}
|
||||
if updates.List[x].OrderSide == "bid" {
|
||||
bids = append(bids, i)
|
||||
continue
|
||||
@@ -351,7 +351,7 @@ func (o *orderbookManager) fetchBookViaREST(pair currency.Pair) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (o *orderbookManager) checkAndProcessOrderbookUpdate(processor func(*WsOrderbooks) error, pair currency.Pair, recent *orderbook.Base) error {
|
||||
func (o *orderbookManager) checkAndProcessOrderbookUpdate(processor func(*WsOrderbooks) error, pair currency.Pair, recent *orderbook.Book) error {
|
||||
o.Lock()
|
||||
defer o.Unlock()
|
||||
state, ok := o.state[pair.Base][pair.Quote][asset.Spot]
|
||||
@@ -382,7 +382,7 @@ buffer:
|
||||
}
|
||||
|
||||
// validate checks for correct update alignment
|
||||
func (u *update) validate(updt *WsOrderbooks, recent *orderbook.Base) bool {
|
||||
func (u *update) validate(updt *WsOrderbooks, recent *orderbook.Book) bool {
|
||||
return updt.DateTime.Time().After(recent.LastUpdated)
|
||||
}
|
||||
|
||||
@@ -425,17 +425,17 @@ func (b *Bithumb) SeedLocalCache(ctx context.Context, p currency.Pair) error {
|
||||
|
||||
// SeedLocalCacheWithBook seeds the local orderbook cache
|
||||
func (b *Bithumb) SeedLocalCacheWithBook(p currency.Pair, o *Orderbook) error {
|
||||
var newOrderBook orderbook.Base
|
||||
newOrderBook.Bids = make(orderbook.Tranches, len(o.Data.Bids))
|
||||
var newOrderBook orderbook.Book
|
||||
newOrderBook.Bids = make(orderbook.Levels, len(o.Data.Bids))
|
||||
for i := range o.Data.Bids {
|
||||
newOrderBook.Bids[i] = orderbook.Tranche{
|
||||
newOrderBook.Bids[i] = orderbook.Level{
|
||||
Amount: o.Data.Bids[i].Quantity,
|
||||
Price: o.Data.Bids[i].Price,
|
||||
}
|
||||
}
|
||||
newOrderBook.Asks = make(orderbook.Tranches, len(o.Data.Asks))
|
||||
newOrderBook.Asks = make(orderbook.Levels, len(o.Data.Asks))
|
||||
for i := range o.Data.Asks {
|
||||
newOrderBook.Asks[i] = orderbook.Tranche{
|
||||
newOrderBook.Asks[i] = orderbook.Level{
|
||||
Amount: o.Data.Asks[i].Quantity,
|
||||
Price: o.Data.Asks[i].Price,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user