reduce side book copy

This commit is contained in:
c9s 2021-05-23 00:42:44 +08:00
parent 9fa10ee1fd
commit 9efb45b133

View File

@ -63,19 +63,9 @@ func (e *TwapExecution) connectUserData(ctx context.Context) {
} }
} }
func (e *TwapExecution) getSideBook() (pvs types.PriceVolumeSlice, err error) {
book := e.orderBook.Copy()
pvs = book.SideBook(e.Side)
return pvs, err
}
func (e *TwapExecution) newBestPriceOrder() (orderForm types.SubmitOrder, err error) { func (e *TwapExecution) newBestPriceOrder() (orderForm types.SubmitOrder, err error) {
book := e.orderBook.Copy() book := e.orderBook.Copy()
sideBook := book.SideBook(e.Side)
sideBook, err := e.getSideBook()
if err != nil {
return orderForm, err
}
first, ok := sideBook.First() first, ok := sideBook.First()
if !ok { if !ok {
@ -212,11 +202,8 @@ func (e *TwapExecution) newBestPriceOrder() (orderForm types.SubmitOrder, err er
} }
func (e *TwapExecution) updateOrder(ctx context.Context) error { func (e *TwapExecution) updateOrder(ctx context.Context) error {
book := e.orderBook.Copy()
sideBook, err := e.getSideBook() sideBook := book.SideBook(e.Side)
if err != nil {
return err
}
first, ok := sideBook.First() first, ok := sideBook.First()
if !ok { if !ok {