mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-31 07:26:44 +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:
@@ -512,60 +512,44 @@ func (e *Exchange) UpdateTicker(ctx context.Context, p currency.Pair, a asset.It
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (e *Exchange) UpdateOrderbook(ctx context.Context, p currency.Pair, assetType asset.Item) (*orderbook.Book, error) {
|
||||
func (e *Exchange) UpdateOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Book, error) {
|
||||
if p.IsEmpty() {
|
||||
return nil, currency.ErrCurrencyPairEmpty
|
||||
}
|
||||
if err := e.CurrencyPairs.IsAssetEnabled(assetType); err != nil {
|
||||
if err := e.CurrencyPairs.IsAssetEnabled(a); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
book := &orderbook.Book{
|
||||
Exchange: e.Name,
|
||||
Pair: p,
|
||||
Asset: assetType,
|
||||
ValidateOrderbook: e.ValidateOrderbook,
|
||||
}
|
||||
var orderbookNew *OrderBook
|
||||
var err error
|
||||
|
||||
switch assetType {
|
||||
var orderbookNew *OrderBookResponse
|
||||
var err error
|
||||
switch a {
|
||||
case asset.Spot, asset.Margin:
|
||||
orderbookNew, err = e.GetOrderBook(ctx,
|
||||
OrderBookDataRequestParams{
|
||||
Symbol: p,
|
||||
Limit: 1000,
|
||||
})
|
||||
orderbookNew, err = e.GetOrderBook(ctx, p, 1000)
|
||||
case asset.USDTMarginedFutures:
|
||||
orderbookNew, err = e.UFuturesOrderbook(ctx, p, 1000)
|
||||
case asset.CoinMarginedFutures:
|
||||
orderbookNew, err = e.GetFuturesOrderbook(ctx, p, 1000)
|
||||
default:
|
||||
return nil, fmt.Errorf("[%s] %w", assetType, asset.ErrNotSupported)
|
||||
return nil, fmt.Errorf("[%s] %w", a, asset.ErrNotSupported)
|
||||
}
|
||||
if err != nil {
|
||||
return book, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
book.Bids = make(orderbook.Levels, len(orderbookNew.Bids))
|
||||
for x := range orderbookNew.Bids {
|
||||
book.Bids[x] = orderbook.Level{
|
||||
Amount: orderbookNew.Bids[x].Quantity,
|
||||
Price: orderbookNew.Bids[x].Price,
|
||||
}
|
||||
}
|
||||
book.Asks = make(orderbook.Levels, len(orderbookNew.Asks))
|
||||
for x := range orderbookNew.Asks {
|
||||
book.Asks[x] = orderbook.Level{
|
||||
Amount: orderbookNew.Asks[x].Quantity,
|
||||
Price: orderbookNew.Asks[x].Price,
|
||||
}
|
||||
ob := &orderbook.Book{
|
||||
Exchange: e.Name,
|
||||
Pair: p,
|
||||
Asset: a,
|
||||
ValidateOrderbook: e.ValidateOrderbook,
|
||||
Bids: orderbookNew.Bids.Levels(),
|
||||
Asks: orderbookNew.Asks.Levels(),
|
||||
}
|
||||
|
||||
err = book.Process()
|
||||
if err != nil {
|
||||
return book, err
|
||||
if err := ob.Process(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return orderbook.Get(e.Name, p, assetType)
|
||||
|
||||
return orderbook.Get(e.Name, p, a)
|
||||
}
|
||||
|
||||
// UpdateAccountInfo retrieves balances for all enabled currencies for the
|
||||
|
||||
Reference in New Issue
Block a user