mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +00:00
add MaxExposurePosition settings
This commit is contained in:
parent
4ed95e6070
commit
13a8597d59
|
@ -55,6 +55,7 @@ type Strategy struct {
|
|||
AskMargin fixedpoint.Value `json:"askMargin"`
|
||||
Quantity fixedpoint.Value `json:"quantity"`
|
||||
QuantityMultiplier fixedpoint.Value `json:"quantityMultiplier"`
|
||||
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`
|
||||
DisableHedge bool `json:"disableHedge"`
|
||||
|
||||
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()
|
||||
hedgeQuota := &bbgo.QuotaTransaction{}
|
||||
if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok {
|
||||
|
@ -481,4 +494,3 @@ func (s *Strategy) CrossRun(ctx context.Context, _ bbgo.OrderExecutionRouter, se
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user