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