mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
fix distribution chart
This commit is contained in:
parent
54a5e41c4f
commit
261da73a9a
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user