mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
orderbook: extract String() from Print()
This commit is contained in:
parent
43275d08bc
commit
cd6457f5c0
|
@ -3,6 +3,7 @@ package types
|
|||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
@ -227,16 +228,30 @@ func (b *OrderBook) Update(book OrderBook) {
|
|||
}
|
||||
|
||||
func (b *OrderBook) Print() {
|
||||
fmt.Printf("BOOK %s\n", b.Symbol)
|
||||
fmt.Printf("ASKS:\n")
|
||||
fmt.Printf(b.String())
|
||||
}
|
||||
|
||||
func (b *OrderBook) String() string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
sb.WriteString("BOOK ")
|
||||
sb.WriteString(b.Symbol)
|
||||
sb.WriteString("\n")
|
||||
sb.WriteString("ASKS:\n")
|
||||
for i := len(b.Asks) - 1; i >= 0; i-- {
|
||||
fmt.Printf("- ASK: %s\n", b.Asks[i].String())
|
||||
sb.WriteString("- ASK: ")
|
||||
sb.WriteString(b.Asks[i].String())
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
fmt.Printf("BIDS:\n")
|
||||
sb.WriteString("BIDS:\n")
|
||||
for _, bid := range b.Bids {
|
||||
fmt.Printf("- BID: %s\n", bid.String())
|
||||
sb.WriteString("- BID: ")
|
||||
sb.WriteString(bid.String())
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
type MutexOrderBook struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user