mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 23:16:54 +00:00
orderbook: consolidate slice array types to orderbook package (#1992)
* orderbook: consolidate slice array types to orderbook package * Update exchanges/bybit/bybit_types.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * linter: fix and add test * cranktakular: nits * cranktakular: nits * Update exchanges/orderbook/orderbook_types.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * Update exchanges/gateio/gateio_test.go Co-authored-by: Gareth Kirwan <gbjkirwan@gmail.com> * gk: nits consolidation * gk: rm unifySpotOrderbook func * gk: nit but different * linter: fix * gk: nits * glorious: nits * Update exchanges/binance/binance.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/binance/binance_cfutures.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * Update exchanges/binanceus/binanceus.go Co-authored-by: Adrian Gallagher <adrian.gallagher@thrasher.io> * thrasher-:nits * thrasher-: more nit --------- 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:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/types"
|
||||
)
|
||||
|
||||
@@ -29,9 +30,9 @@ type TickerResponse struct {
|
||||
type MarketDepthResponse struct {
|
||||
ErrCapture
|
||||
Data struct {
|
||||
Asks [][2]types.Number `json:"asks"`
|
||||
Bids [][2]types.Number `json:"bids"`
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
Asks orderbook.LevelsArrayPriceAmount `json:"asks"`
|
||||
Bids orderbook.LevelsArrayPriceAmount `json:"bids"`
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
|
||||
@@ -210,28 +210,17 @@ func (e *Exchange) UpdateOrderbook(ctx context.Context, p currency.Pair, assetTy
|
||||
return nil, err
|
||||
}
|
||||
|
||||
book := &orderbook.Book{
|
||||
ob := &orderbook.Book{
|
||||
Exchange: e.Name,
|
||||
Pair: p,
|
||||
Asset: assetType,
|
||||
ValidateOrderbook: e.ValidateOrderbook,
|
||||
Asks: make(orderbook.Levels, len(d.Data.Asks)),
|
||||
Bids: make(orderbook.Levels, len(d.Data.Bids)),
|
||||
Asks: d.Data.Asks.Levels(),
|
||||
Bids: d.Data.Bids.Levels(),
|
||||
}
|
||||
|
||||
for i := range d.Data.Asks {
|
||||
book.Asks[i].Price = d.Data.Asks[i][0].Float64()
|
||||
book.Asks[i].Amount = d.Data.Asks[i][1].Float64()
|
||||
}
|
||||
for i := range d.Data.Bids {
|
||||
book.Bids[i].Price = d.Data.Bids[i][0].Float64()
|
||||
book.Bids[i].Amount = d.Data.Bids[i][1].Float64()
|
||||
}
|
||||
|
||||
if err := book.Process(); err != nil {
|
||||
if err := ob.Process(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return orderbook.Get(e.Name, p, assetType)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user