mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-08 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:
@@ -2212,12 +2212,12 @@ type WsFuturesAndOptionsOrderbookUpdate struct {
|
||||
ContractName currency.Pair `json:"s"`
|
||||
FirstUpdatedID int64 `json:"U"`
|
||||
LastUpdatedID int64 `json:"u"`
|
||||
Bids []Tranche `json:"b"`
|
||||
Asks []Tranche `json:"a"`
|
||||
Bids []Level `json:"b"`
|
||||
Asks []Level `json:"a"`
|
||||
}
|
||||
|
||||
// Tranche represents a tranche of orderbook data
|
||||
type Tranche struct {
|
||||
// Level represents a level of orderbook data
|
||||
type Level struct {
|
||||
Price types.Number `json:"p"`
|
||||
Size float64 `json:"s"`
|
||||
}
|
||||
@@ -2227,8 +2227,8 @@ type WsFuturesOrderbookSnapshot struct {
|
||||
Timestamp types.Time `json:"t"`
|
||||
Contract currency.Pair `json:"contract"`
|
||||
OrderbookID int64 `json:"id"`
|
||||
Asks []Tranche `json:"asks"`
|
||||
Bids []Tranche `json:"bids"`
|
||||
Asks []Level `json:"asks"`
|
||||
Bids []Level `json:"bids"`
|
||||
}
|
||||
|
||||
// WsFuturesOrderbookUpdateEvent represents futures orderbook push data with the event 'update'
|
||||
|
||||
@@ -358,14 +358,14 @@ func (g *Gateio) processOrderbookTicker(incoming []byte, lastPushed time.Time) e
|
||||
if err := json.Unmarshal(incoming, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
return g.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
|
||||
return g.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
|
||||
Exchange: g.Name,
|
||||
Pair: data.Pair,
|
||||
Asset: asset.Spot,
|
||||
LastUpdated: data.UpdateTime.Time(),
|
||||
LastPushed: lastPushed,
|
||||
Bids: []orderbook.Tranche{{Price: data.BestBidPrice.Float64(), Amount: data.BestBidAmount.Float64()}},
|
||||
Asks: []orderbook.Tranche{{Price: data.BestAskPrice.Float64(), Amount: data.BestAskAmount.Float64()}},
|
||||
Bids: []orderbook.Level{{Price: data.BestBidPrice.Float64(), Amount: data.BestBidAmount.Float64()}},
|
||||
Asks: []orderbook.Level{{Price: data.BestAskPrice.Float64(), Amount: data.BestAskAmount.Float64()}},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -374,12 +374,12 @@ func (g *Gateio) processOrderbookUpdate(ctx context.Context, incoming []byte, la
|
||||
if err := json.Unmarshal(incoming, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
asks := make([]orderbook.Tranche, len(data.Asks))
|
||||
asks := make([]orderbook.Level, len(data.Asks))
|
||||
for x := range data.Asks {
|
||||
asks[x].Price = data.Asks[x][0].Float64()
|
||||
asks[x].Amount = data.Asks[x][1].Float64()
|
||||
}
|
||||
bids := make([]orderbook.Tranche, len(data.Bids))
|
||||
bids := make([]orderbook.Level, len(data.Bids))
|
||||
for x := range data.Bids {
|
||||
bids[x].Price = data.Bids[x][0].Float64()
|
||||
bids[x].Amount = data.Bids[x][1].Float64()
|
||||
@@ -402,12 +402,12 @@ func (g *Gateio) processOrderbookSnapshot(incoming []byte, lastPushed time.Time)
|
||||
return err
|
||||
}
|
||||
|
||||
asks := make([]orderbook.Tranche, len(data.Asks))
|
||||
asks := make([]orderbook.Level, len(data.Asks))
|
||||
for x := range data.Asks {
|
||||
asks[x].Price = data.Asks[x][0].Float64()
|
||||
asks[x].Amount = data.Asks[x][1].Float64()
|
||||
}
|
||||
bids := make([]orderbook.Tranche, len(data.Bids))
|
||||
bids := make([]orderbook.Level, len(data.Bids))
|
||||
for x := range data.Bids {
|
||||
bids[x].Price = data.Bids[x][0].Float64()
|
||||
bids[x].Amount = data.Bids[x][1].Float64()
|
||||
@@ -415,7 +415,7 @@ func (g *Gateio) processOrderbookSnapshot(incoming []byte, lastPushed time.Time)
|
||||
|
||||
for _, a := range standardMarginAssetTypes {
|
||||
if enabled, _ := g.CurrencyPairs.IsPairEnabled(data.CurrencyPair, a); enabled {
|
||||
if err := g.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
|
||||
if err := g.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
|
||||
Exchange: g.Name,
|
||||
Pair: data.CurrencyPair,
|
||||
Asset: a,
|
||||
|
||||
@@ -411,12 +411,12 @@ func (g *Gateio) processFuturesOrderbookUpdate(ctx context.Context, incoming []b
|
||||
if err := json.Unmarshal(incoming, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
asks := make([]orderbook.Tranche, len(data.Asks))
|
||||
asks := make([]orderbook.Level, len(data.Asks))
|
||||
for x := range data.Asks {
|
||||
asks[x].Price = data.Asks[x].Price.Float64()
|
||||
asks[x].Amount = data.Asks[x].Size
|
||||
}
|
||||
bids := make([]orderbook.Tranche, len(data.Bids))
|
||||
bids := make([]orderbook.Level, len(data.Bids))
|
||||
for x := range data.Bids {
|
||||
bids[x].Price = data.Bids[x].Price.Float64()
|
||||
bids[x].Amount = data.Bids[x].Size
|
||||
@@ -441,7 +441,7 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base := orderbook.Base{
|
||||
base := orderbook.Book{
|
||||
Asset: assetType,
|
||||
Exchange: g.Name,
|
||||
Pair: data.Contract,
|
||||
@@ -449,12 +449,12 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte,
|
||||
LastPushed: lastPushed,
|
||||
VerifyOrderbook: g.CanVerifyOrderbook,
|
||||
}
|
||||
base.Asks = make([]orderbook.Tranche, len(data.Asks))
|
||||
base.Asks = make([]orderbook.Level, len(data.Asks))
|
||||
for x := range data.Asks {
|
||||
base.Asks[x].Amount = data.Asks[x].Size
|
||||
base.Asks[x].Price = data.Asks[x].Price.Float64()
|
||||
}
|
||||
base.Bids = make([]orderbook.Tranche, len(data.Bids))
|
||||
base.Bids = make([]orderbook.Level, len(data.Bids))
|
||||
for x := range data.Bids {
|
||||
base.Bids[x].Amount = data.Bids[x].Size
|
||||
base.Bids[x].Price = data.Bids[x].Price.Float64()
|
||||
@@ -466,19 +466,19 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dataMap := map[string][2][]orderbook.Tranche{}
|
||||
dataMap := map[string][2][]orderbook.Level{}
|
||||
for x := range data {
|
||||
ab, ok := dataMap[data[x].CurrencyPair]
|
||||
if !ok {
|
||||
ab = [2][]orderbook.Tranche{}
|
||||
ab = [2][]orderbook.Level{}
|
||||
}
|
||||
if data[x].Amount > 0 {
|
||||
ab[1] = append(ab[1], orderbook.Tranche{
|
||||
ab[1] = append(ab[1], orderbook.Level{
|
||||
Price: data[x].Price.Float64(),
|
||||
Amount: data[x].Amount,
|
||||
})
|
||||
} else {
|
||||
ab[0] = append(ab[0], orderbook.Tranche{
|
||||
ab[0] = append(ab[0], orderbook.Level{
|
||||
Price: data[x].Price.Float64(),
|
||||
Amount: -data[x].Amount,
|
||||
})
|
||||
@@ -495,7 +495,7 @@ func (g *Gateio) processFuturesOrderbookSnapshot(event string, incoming []byte,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
|
||||
Asks: ab[0],
|
||||
Bids: ab[1],
|
||||
Asset: assetType,
|
||||
|
||||
@@ -503,12 +503,12 @@ func (g *Gateio) processOptionsOrderbookUpdate(ctx context.Context, incoming []b
|
||||
if err := json.Unmarshal(incoming, &data); err != nil {
|
||||
return err
|
||||
}
|
||||
asks := make([]orderbook.Tranche, len(data.Asks))
|
||||
asks := make([]orderbook.Level, len(data.Asks))
|
||||
for x := range data.Asks {
|
||||
asks[x].Price = data.Asks[x].Price.Float64()
|
||||
asks[x].Amount = data.Asks[x].Size
|
||||
}
|
||||
bids := make([]orderbook.Tranche, len(data.Bids))
|
||||
bids := make([]orderbook.Level, len(data.Bids))
|
||||
for x := range data.Bids {
|
||||
bids[x].Price = data.Bids[x].Price.Float64()
|
||||
bids[x].Amount = data.Bids[x].Size
|
||||
@@ -532,7 +532,7 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
base := orderbook.Base{
|
||||
base := orderbook.Book{
|
||||
Asset: asset.Options,
|
||||
Exchange: g.Name,
|
||||
Pair: data.Contract,
|
||||
@@ -540,12 +540,12 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming
|
||||
LastPushed: lastPushed,
|
||||
VerifyOrderbook: g.CanVerifyOrderbook,
|
||||
}
|
||||
base.Asks = make([]orderbook.Tranche, len(data.Asks))
|
||||
base.Asks = make([]orderbook.Level, len(data.Asks))
|
||||
for x := range data.Asks {
|
||||
base.Asks[x].Amount = data.Asks[x].Size
|
||||
base.Asks[x].Price = data.Asks[x].Price.Float64()
|
||||
}
|
||||
base.Bids = make([]orderbook.Tranche, len(data.Bids))
|
||||
base.Bids = make([]orderbook.Level, len(data.Bids))
|
||||
for x := range data.Bids {
|
||||
base.Bids[x].Amount = data.Bids[x].Size
|
||||
base.Bids[x].Price = data.Bids[x].Price.Float64()
|
||||
@@ -557,18 +557,18 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dataMap := map[string][2][]orderbook.Tranche{}
|
||||
dataMap := map[string][2][]orderbook.Level{}
|
||||
for x := range data {
|
||||
ab, ok := dataMap[data[x].CurrencyPair]
|
||||
if !ok {
|
||||
ab = [2][]orderbook.Tranche{}
|
||||
ab = [2][]orderbook.Level{}
|
||||
}
|
||||
if data[x].Amount > 0 {
|
||||
ab[1] = append(ab[1], orderbook.Tranche{
|
||||
ab[1] = append(ab[1], orderbook.Level{
|
||||
Price: data[x].Price.Float64(), Amount: data[x].Amount,
|
||||
})
|
||||
} else {
|
||||
ab[0] = append(ab[0], orderbook.Tranche{
|
||||
ab[0] = append(ab[0], orderbook.Level{
|
||||
Price: data[x].Price.Float64(), Amount: -data[x].Amount,
|
||||
})
|
||||
}
|
||||
@@ -584,7 +584,7 @@ func (g *Gateio) processOptionsOrderbookSnapshotPushData(event string, incoming
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
|
||||
Asks: ab[0],
|
||||
Bids: ab[1],
|
||||
Asset: asset.Options,
|
||||
|
||||
@@ -649,12 +649,12 @@ func (g *Gateio) UpdateTickers(ctx context.Context, a asset.Item) error {
|
||||
}
|
||||
|
||||
// UpdateOrderbook updates and returns the orderbook for a currency pair
|
||||
func (g *Gateio) UpdateOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Base, error) {
|
||||
func (g *Gateio) UpdateOrderbook(ctx context.Context, p currency.Pair, a asset.Item) (*orderbook.Book, error) {
|
||||
return g.UpdateOrderbookWithLimit(ctx, p, a, 0)
|
||||
}
|
||||
|
||||
// UpdateOrderbookWithLimit updates and returns the orderbook for a currency pair with a set orderbook size limit
|
||||
func (g *Gateio) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair, a asset.Item, limit uint64) (*orderbook.Base, error) {
|
||||
func (g *Gateio) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair, a asset.Item, limit uint64) (*orderbook.Book, error) {
|
||||
p, err := g.FormatExchangeCurrency(p, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -688,7 +688,7 @@ func (g *Gateio) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
book := &orderbook.Base{
|
||||
book := &orderbook.Book{
|
||||
Exchange: g.Name,
|
||||
Asset: a,
|
||||
VerifyOrderbook: g.CanVerifyOrderbook,
|
||||
@@ -697,16 +697,16 @@ func (g *Gateio) UpdateOrderbookWithLimit(ctx context.Context, p currency.Pair,
|
||||
LastUpdated: o.Update.Time(),
|
||||
LastPushed: o.Current.Time(),
|
||||
}
|
||||
book.Bids = make(orderbook.Tranches, len(o.Bids))
|
||||
book.Bids = make(orderbook.Levels, len(o.Bids))
|
||||
for x := range o.Bids {
|
||||
book.Bids[x] = orderbook.Tranche{
|
||||
book.Bids[x] = orderbook.Level{
|
||||
Amount: o.Bids[x].Amount.Float64(),
|
||||
Price: o.Bids[x].Price.Float64(),
|
||||
}
|
||||
}
|
||||
book.Asks = make(orderbook.Tranches, len(o.Asks))
|
||||
book.Asks = make(orderbook.Levels, len(o.Asks))
|
||||
for x := range o.Asks {
|
||||
book.Asks[x] = orderbook.Tranche{
|
||||
book.Asks[x] = orderbook.Level{
|
||||
Amount: o.Asks[x].Amount.Float64(),
|
||||
Price: o.Asks[x].Price.Float64(),
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ func TestProcessOrderbookUpdate(t *testing.T) {
|
||||
assert.ErrorIs(t, err, currency.ErrCurrencyPairEmpty)
|
||||
|
||||
pair := currency.NewPair(currency.BABY, currency.BABYDOGE)
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
|
||||
err = g.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
|
||||
Exchange: g.Name,
|
||||
Pair: pair,
|
||||
Asset: asset.USDTMarginedFutures,
|
||||
Bids: []orderbook.Tranche{{Price: 1, Amount: 1}},
|
||||
Asks: []orderbook.Tranche{{Price: 1, Amount: 1}},
|
||||
Bids: []orderbook.Level{{Price: 1, Amount: 1}},
|
||||
Asks: []orderbook.Level{{Price: 1, Amount: 1}},
|
||||
LastUpdated: time.Now(),
|
||||
LastPushed: time.Now(),
|
||||
LastUpdateID: 1336,
|
||||
@@ -145,12 +145,12 @@ func TestApplyPendingUpdates(t *testing.T) {
|
||||
|
||||
m := newWsOBUpdateManager(defaultWSSnapshotSyncDelay)
|
||||
pair := currency.NewPair(currency.LTC, currency.USDT)
|
||||
err := g.Websocket.Orderbook.LoadSnapshot(&orderbook.Base{
|
||||
err := g.Websocket.Orderbook.LoadSnapshot(&orderbook.Book{
|
||||
Exchange: g.Name,
|
||||
Pair: pair,
|
||||
Asset: asset.USDTMarginedFutures,
|
||||
Bids: []orderbook.Tranche{{Price: 1, Amount: 1}},
|
||||
Asks: []orderbook.Tranche{{Price: 1, Amount: 1}},
|
||||
Bids: []orderbook.Level{{Price: 1, Amount: 1}},
|
||||
Asks: []orderbook.Level{{Price: 1, Amount: 1}},
|
||||
LastUpdated: time.Now(),
|
||||
LastPushed: time.Now(),
|
||||
LastUpdateID: 1335,
|
||||
|
||||
Reference in New Issue
Block a user