mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-21 22:43:52 +00:00
xmaker: fix aggregatePriceVolumeSliceWithPriceFilter
This commit is contained in:
parent
efc3bbeb5b
commit
a0cdfc2b8e
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user