-
Notifications
You must be signed in to change notification settings - Fork 874
orderbook: consolidate slice array types to orderbook package #1992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -449,40 +449,28 @@ func stringToOrderStatus(status string) (order.Status, error) { | |
|
||
// SeedLocalCache seeds depth data | ||
func (e *Exchange) SeedLocalCache(ctx context.Context, p currency.Pair) error { | ||
ob, err := e.GetOrderBook(ctx, | ||
OrderBookDataRequestParams{ | ||
Symbol: p, | ||
Limit: 1000, | ||
}) | ||
ob, err := e.GetOrderBook(ctx, p, 1000) | ||
if err != nil { | ||
return err | ||
} | ||
return e.SeedLocalCacheWithBook(p, ob) | ||
} | ||
|
||
// SeedLocalCacheWithBook seeds the local orderbook cache | ||
func (e *Exchange) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBook) error { | ||
func (e *Exchange) SeedLocalCacheWithBook(p currency.Pair, orderbookNew *OrderBookResponse) error { | ||
t := orderbookNew.Timestamp.Time() | ||
if t.IsZero() { | ||
t = time.Now() // Time not provided for this REST book. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this handling still necessary? Are there ever books which don't return their time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah it seems like all spot orderbooks don't return a time value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, but GetOrderBook() is in the non-futures file, and has a timestamp in its response struct. If that can just receive futures responses too, don't worry, but if it's spot-only, I think including a timestamp field there if one is never returned is bad. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah you are right I was most likely thinking when I convert this over to manage other assets as well when I do a full ob pass that this will auto utilise the shared field. I can drop it if you really want but it might be missed in a future upgrade pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're better informed on the tradeoffs than me, so use your own judgement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will leave this unresolved for other peoples perspective. Either way when somebody is doing some hectic trading and they see a latency discrepancy they will be all like 👻 and open a holy PR that rectifies this issue. 🙏 |
||
} | ||
newOrderBook := orderbook.Book{ | ||
Pair: p, | ||
Asset: asset.Spot, | ||
Exchange: e.Name, | ||
LastUpdateID: orderbookNew.LastUpdateID, | ||
ValidateOrderbook: e.ValidateOrderbook, | ||
Bids: make(orderbook.Levels, len(orderbookNew.Bids)), | ||
Asks: make(orderbook.Levels, len(orderbookNew.Asks)), | ||
LastUpdated: time.Now(), // Time not provided in REST book. | ||
} | ||
for i := range orderbookNew.Bids { | ||
newOrderBook.Bids[i] = orderbook.Level{ | ||
Amount: orderbookNew.Bids[i].Quantity, | ||
Price: orderbookNew.Bids[i].Price, | ||
} | ||
} | ||
for i := range orderbookNew.Asks { | ||
newOrderBook.Asks[i] = orderbook.Level{ | ||
Amount: orderbookNew.Asks[i].Quantity, | ||
Price: orderbookNew.Asks[i].Price, | ||
} | ||
Bids: orderbookNew.Bids.Levels(), | ||
Asks: orderbookNew.Asks.Levels(), | ||
LastUpdated: t, | ||
} | ||
return e.Websocket.Orderbook.LoadSnapshot(&newOrderBook) | ||
} | ||
|
@@ -618,23 +606,9 @@ func (e *Exchange) manageSubs(ctx context.Context, op string, subs subscription. | |
|
||
// ProcessOrderbookUpdate processes the websocket orderbook update | ||
func (e *Exchange) ProcessOrderbookUpdate(cp currency.Pair, a asset.Item, ws *WebsocketDepthStream) error { | ||
updateBid := make([]orderbook.Level, len(ws.UpdateBids)) | ||
for i := range ws.UpdateBids { | ||
updateBid[i] = orderbook.Level{ | ||
Price: ws.UpdateBids[i][0].Float64(), | ||
Amount: ws.UpdateBids[i][1].Float64(), | ||
} | ||
} | ||
updateAsk := make([]orderbook.Level, len(ws.UpdateAsks)) | ||
for i := range ws.UpdateAsks { | ||
updateAsk[i] = orderbook.Level{ | ||
Price: ws.UpdateAsks[i][0].Float64(), | ||
Amount: ws.UpdateAsks[i][1].Float64(), | ||
} | ||
} | ||
return e.Websocket.Orderbook.Update(&orderbook.Update{ | ||
Bids: updateBid, | ||
Asks: updateAsk, | ||
Bids: ws.UpdateBids.Levels(), | ||
Asks: ws.UpdateAsks.Levels(), | ||
Pair: cp, | ||
UpdateID: ws.LastUpdateID, | ||
UpdateTime: ws.Timestamp.Time(), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With OrderBookDataRequestParams being removed, these comments explaining it should be too.