mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Merge pull request #1721 from c9s/c9s/xmaker/fix-agg-price-method
FIX: [xmaker] fix aggregatePrice method
This commit is contained in:
commit
8e91a023ca
|
@ -167,29 +167,23 @@ func (s *Strategy) CrossSubscribe(sessions map[string]*bbgo.ExchangeSession) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func aggregatePrice(pvs types.PriceVolumeSlice, requiredQuantity fixedpoint.Value) (price fixedpoint.Value) {
|
func aggregatePrice(pvs types.PriceVolumeSlice, requiredQuantity fixedpoint.Value) (price fixedpoint.Value) {
|
||||||
q := requiredQuantity
|
|
||||||
totalAmount := fixedpoint.Zero
|
|
||||||
|
|
||||||
if len(pvs) == 0 {
|
if len(pvs) == 0 {
|
||||||
price = fixedpoint.Zero
|
price = fixedpoint.Zero
|
||||||
return price
|
return price
|
||||||
} else if pvs[0].Volume.Compare(requiredQuantity) >= 0 {
|
|
||||||
return pvs[0].Price
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sumAmount := fixedpoint.Zero
|
||||||
|
sumQty := fixedpoint.Zero
|
||||||
for i := 0; i < len(pvs); i++ {
|
for i := 0; i < len(pvs); i++ {
|
||||||
pv := pvs[i]
|
pv := pvs[i]
|
||||||
if pv.Volume.Compare(q) >= 0 {
|
sumQty = sumQty.Add(pv.Volume)
|
||||||
totalAmount = totalAmount.Add(q.Mul(pv.Price))
|
sumAmount = sumAmount.Add(pv.Volume.Mul(pv.Price))
|
||||||
|
if sumQty.Compare(requiredQuantity) >= 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
q = q.Sub(pv.Volume)
|
|
||||||
totalAmount = totalAmount.Add(pv.Volume.Mul(pv.Price))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
price = totalAmount.Div(requiredQuantity)
|
return sumAmount.Div(sumQty)
|
||||||
return price
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Strategy) Initialize() error {
|
func (s *Strategy) Initialize() error {
|
||||||
|
@ -573,6 +567,7 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
s.logger.Infof("maker best bid price %f", bidPrice.Float64())
|
||||||
makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64())
|
makerBestBidPriceMetrics.With(labels).Set(bidPrice.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -640,6 +635,7 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
s.logger.Infof("maker best ask price %f", askPrice.Float64())
|
||||||
makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64())
|
makerBestAskPriceMetrics.With(labels).Set(askPrice.Float64())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user