xmaker: fix aggregatePriceVolumeSliceWithPriceFilter
Some checks failed
Go / build (1.21, 6.2) (push) Has been cancelled
golang-lint / lint (push) Has been cancelled

This commit is contained in:
c9s 2024-10-06 12:18:03 +08:00
parent efc3bbeb5b
commit a0cdfc2b8e
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -924,11 +924,17 @@ func (s *Strategy) makerOrderCreateCallback(createdOrder types.Order) {
s.activeMakerOrders.Add(createdOrder)
}
func aggregatePriceVolumeSliceWithPriceFilter(pvs types.PriceVolumeSlice, filterPrice fixedpoint.Value) types.PriceVolume {
func aggregatePriceVolumeSliceWithPriceFilter(
side types.SideType,
pvs types.PriceVolumeSlice,
filterPrice fixedpoint.Value,
) types.PriceVolume {
var totalVolume = fixedpoint.Zero
var lastPrice = fixedpoint.Zero
for _, pv := range pvs {
if pv.Price.Compare(filterPrice) > 0 {
if side == types.SideTypeSell && pv.Price.Compare(filterPrice) > 0 {
break
} else if side == types.SideTypeBuy && pv.Price.Compare(filterPrice) < 0 {
break
}
@ -960,7 +966,7 @@ func (s *Strategy) tryArbitrage(ctx context.Context, quote *Quote, makerBalances
}
askPvs := s.makerBook.SideBook(types.SideTypeSell)
sumPv := aggregatePriceVolumeSliceWithPriceFilter(askPvs, marginBidPrice)
sumPv := aggregatePriceVolumeSliceWithPriceFilter(types.SideTypeSell, askPvs, marginBidPrice)
qty := fixedpoint.Min(quoteBalance.Available.Div(sumPv.Price), sumPv.Volume)
if sourceBase, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok {
@ -970,6 +976,10 @@ func (s *Strategy) tryArbitrage(ctx context.Context, quote *Quote, makerBalances
return false, nil
}
if qty.IsZero() {
return false, nil
}
iocOrders = append(iocOrders, types.SubmitOrder{
Symbol: s.Symbol,
Type: types.OrderTypeLimit,
@ -986,7 +996,7 @@ func (s *Strategy) tryArbitrage(ctx context.Context, quote *Quote, makerBalances
}
bidPvs := s.makerBook.SideBook(types.SideTypeBuy)
sumPv := aggregatePriceVolumeSliceWithPriceFilter(bidPvs, marginAskPrice)
sumPv := aggregatePriceVolumeSliceWithPriceFilter(types.SideTypeBuy, bidPvs, marginAskPrice)
qty := fixedpoint.Min(baseBalance.Available, sumPv.Volume)
if sourceQuote, ok := hedgeBalances[s.sourceMarket.QuoteCurrency]; ok {
@ -996,6 +1006,10 @@ func (s *Strategy) tryArbitrage(ctx context.Context, quote *Quote, makerBalances
return false, nil
}
if qty.IsZero() {
return false, nil
}
// send ioc order for arbitrage
iocOrders = append(iocOrders, types.SubmitOrder{
Symbol: s.Symbol,