mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
implement distruction api
This commit is contained in:
parent
891bf50101
commit
54a5e41c4f
|
@ -57,6 +57,30 @@ type StockManager struct {
|
|||
PendingSells StockSlice
|
||||
}
|
||||
|
||||
type Distribution struct {
|
||||
Quantities map[int]float64 `json:"quantities"`
|
||||
Stocks map[int]StockSlice `json:"stocks"`
|
||||
}
|
||||
|
||||
func (m *StockManager) Distribution(level int) *Distribution {
|
||||
var d = Distribution{
|
||||
Quantities: map[int]float64{},
|
||||
Stocks: map[int]StockSlice{},
|
||||
}
|
||||
|
||||
for _, stock := range m.Stocks {
|
||||
n := math.Ceil(math.Log10(stock.Price))
|
||||
digits := int(n - math.Max(float64(level), 1.0))
|
||||
div := math.Pow10(digits)
|
||||
priceLevel := int(math.Floor(stock.Price / div) * div)
|
||||
|
||||
d.Stocks[priceLevel] = append(d.Stocks[priceLevel], stock)
|
||||
d.Quantities[priceLevel] += stock.Quantity
|
||||
}
|
||||
|
||||
return &d
|
||||
}
|
||||
|
||||
func (m *StockManager) stock(stock Stock) error {
|
||||
m.mu.Lock()
|
||||
m.Stocks = append(m.Stocks, stock)
|
||||
|
|
Loading…
Reference in New Issue
Block a user