fix distribution chart

This commit is contained in:
c9s 2020-08-11 10:24:56 +08:00
parent 54a5e41c4f
commit 261da73a9a

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"github.com/c9s/bbgo/pkg/bbgo/types" "github.com/c9s/bbgo/pkg/bbgo/types"
"math" "math"
"sort"
"strings" "strings"
"sync" "sync"
) )
@ -58,6 +59,7 @@ type StockManager struct {
} }
type Distribution struct { type Distribution struct {
PriceLevels []int `json:"priceLevels"`
Quantities map[int]float64 `json:"quantities"` Quantities map[int]float64 `json:"quantities"`
Stocks map[int]StockSlice `json:"stocks"` Stocks map[int]StockSlice `json:"stocks"`
} }
@ -78,6 +80,12 @@ func (m *StockManager) Distribution(level int) *Distribution {
d.Quantities[priceLevel] += stock.Quantity d.Quantities[priceLevel] += stock.Quantity
} }
for level := range d.Stocks {
d.PriceLevels = append(d.PriceLevels, level)
}
sort.Ints(d.PriceLevels)
return &d return &d
} }