add MaxExposurePosition settings

This commit is contained in:
c9s 2021-04-04 11:14:09 +08:00
parent 4ed95e6070
commit 13a8597d59

View File

@ -55,6 +55,7 @@ type Strategy struct {
AskMargin fixedpoint.Value `json:"askMargin"` AskMargin fixedpoint.Value `json:"askMargin"`
Quantity fixedpoint.Value `json:"quantity"` Quantity fixedpoint.Value `json:"quantity"`
QuantityMultiplier fixedpoint.Value `json:"quantityMultiplier"` QuantityMultiplier fixedpoint.Value `json:"quantityMultiplier"`
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`
DisableHedge bool `json:"disableHedge"` DisableHedge bool `json:"disableHedge"`
NumLayers int `json:"numLayers"` NumLayers int `json:"numLayers"`
@ -150,6 +151,18 @@ func (s *Strategy) updateQuote(ctx context.Context) {
} }
} }
// if max exposure position is configured, we should not:
// 1. place bid orders when we already bought too much
// 2. place ask orders when we already sold too much
if s.MaxExposurePosition > 0 {
pos := s.state.HedgePosition.AtomicLoad()
if pos < -s.MaxExposurePosition {
disableMakerAsk = true
} else if pos > s.MaxExposurePosition {
disableMakerBid = true
}
}
hedgeBalances := s.sourceSession.Account.Balances() hedgeBalances := s.sourceSession.Account.Balances()
hedgeQuota := &bbgo.QuotaTransaction{} hedgeQuota := &bbgo.QuotaTransaction{}
if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok { if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok {
@ -481,4 +494,3 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
return nil return nil
} }