mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
xdepthmaker: add HedgeStrategyBboQueue1 hedge method
This commit is contained in:
parent
59191cf6bf
commit
60d5126b61
|
@ -594,8 +594,10 @@ func (s *Strategy) Hedge(ctx context.Context, pos fixedpoint.Value) error {
|
||||||
return s.executeHedgeMarket(ctx, side, quantity)
|
return s.executeHedgeMarket(ctx, side, quantity)
|
||||||
case HedgeStrategyBboCounterParty1:
|
case HedgeStrategyBboCounterParty1:
|
||||||
return s.executeHedgeBboCounterParty1(ctx, side, quantity)
|
return s.executeHedgeBboCounterParty1(ctx, side, quantity)
|
||||||
|
case HedgeStrategyBboQueue1:
|
||||||
|
return s.executeHedgeBboQueue1(ctx, side, quantity)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("unsupported hedge strategy %s, please check your configuration", s.HedgeStrategy)
|
return fmt.Errorf("unsupported or invalid hedge strategy setup %q, please check your configuration", s.HedgeStrategy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -643,6 +645,50 @@ func (s *Strategy) executeHedgeBboCounterParty1(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Strategy) executeHedgeBboQueue1(
|
||||||
|
ctx context.Context,
|
||||||
|
side types.SideType,
|
||||||
|
quantity fixedpoint.Value,
|
||||||
|
) error {
|
||||||
|
price := s.lastSourcePrice.Get()
|
||||||
|
if sourcePrice := s.getSourceBboPrice(side); sourcePrice.Sign() > 0 {
|
||||||
|
price = sourcePrice
|
||||||
|
}
|
||||||
|
|
||||||
|
if price.IsZero() {
|
||||||
|
return ErrZeroPrice
|
||||||
|
}
|
||||||
|
|
||||||
|
// adjust quantity according to the balances
|
||||||
|
account := s.hedgeSession.GetAccount()
|
||||||
|
|
||||||
|
quantity = xmaker.AdjustHedgeQuantityWithAvailableBalance(account,
|
||||||
|
s.hedgeMarket,
|
||||||
|
side,
|
||||||
|
quantity,
|
||||||
|
price)
|
||||||
|
|
||||||
|
// truncate quantity for the supported precision
|
||||||
|
quantity = s.hedgeMarket.TruncateQuantity(quantity)
|
||||||
|
if quantity.IsZero() {
|
||||||
|
return ErrZeroQuantity
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.hedgeMarket.IsDustQuantity(quantity, price) {
|
||||||
|
return ErrDustQuantity
|
||||||
|
}
|
||||||
|
|
||||||
|
// submit order as limit taker
|
||||||
|
return s.executeHedgeOrder(ctx, types.SubmitOrder{
|
||||||
|
Market: s.hedgeMarket,
|
||||||
|
Symbol: s.hedgeMarket.Symbol,
|
||||||
|
Type: types.OrderTypeLimit,
|
||||||
|
Price: price,
|
||||||
|
Side: side,
|
||||||
|
Quantity: quantity,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Strategy) executeHedgeMarket(
|
func (s *Strategy) executeHedgeMarket(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
side types.SideType,
|
side types.SideType,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user