mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 23:16:53 +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:
@@ -170,35 +170,18 @@ func (e *Exchange) GetTicker(ctx context.Context, symbol string, hourly bool) (*
|
||||
// the amount.
|
||||
func (e *Exchange) GetOrderbook(ctx context.Context, symbol string) (*Orderbook, error) {
|
||||
type response struct {
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
Bids [][2]types.Number `json:"bids"`
|
||||
Asks [][2]types.Number `json:"asks"`
|
||||
Timestamp types.Time `json:"timestamp"`
|
||||
Bids orderbook.LevelsArrayPriceAmount `json:"bids"`
|
||||
Asks orderbook.LevelsArrayPriceAmount `json:"asks"`
|
||||
}
|
||||
|
||||
path := "/v" + bitstampAPIVersion + "/" + bitstampAPIOrderbook + "/" + strings.ToLower(symbol) + "/"
|
||||
var resp response
|
||||
err := e.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp)
|
||||
if err != nil {
|
||||
if err := e.SendHTTPRequest(ctx, exchange.RestSpot, path, &resp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ob := &Orderbook{
|
||||
Timestamp: resp.Timestamp.Time(),
|
||||
Bids: make([]OrderbookBase, len(resp.Bids)),
|
||||
Asks: make([]OrderbookBase, len(resp.Asks)),
|
||||
}
|
||||
|
||||
for x := range resp.Bids {
|
||||
ob.Bids[x].Price = resp.Bids[x][0].Float64()
|
||||
ob.Bids[x].Amount = resp.Bids[x][1].Float64()
|
||||
}
|
||||
|
||||
for x := range resp.Asks {
|
||||
ob.Asks[x].Price = resp.Asks[x][0].Float64()
|
||||
ob.Asks[x].Amount = resp.Asks[x][1].Float64()
|
||||
}
|
||||
|
||||
return ob, nil
|
||||
return &Orderbook{Timestamp: resp.Timestamp.Time(), Bids: resp.Bids.Levels(), Asks: resp.Asks.Levels()}, nil
|
||||
}
|
||||
|
||||
// GetTradingPairs returns a list of trading pairs which Bitstamp
|
||||
|
||||
Reference in New Issue
Block a user