mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
add MaxExposurePosition settings
This commit is contained in:
parent
4ed95e6070
commit
13a8597d59
|
@ -50,12 +50,13 @@ type Strategy struct {
|
||||||
UpdateInterval types.Duration `json:"updateInterval"`
|
UpdateInterval types.Duration `json:"updateInterval"`
|
||||||
HedgeInterval types.Duration `json:"hedgeInterval"`
|
HedgeInterval types.Duration `json:"hedgeInterval"`
|
||||||
|
|
||||||
Margin fixedpoint.Value `json:"margin"`
|
Margin fixedpoint.Value `json:"margin"`
|
||||||
BidMargin fixedpoint.Value `json:"bidMargin"`
|
BidMargin fixedpoint.Value `json:"bidMargin"`
|
||||||
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"`
|
||||||
DisableHedge bool `json:"disableHedge"`
|
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`
|
||||||
|
DisableHedge bool `json:"disableHedge"`
|
||||||
|
|
||||||
NumLayers int `json:"numLayers"`
|
NumLayers int `json:"numLayers"`
|
||||||
Pips int `json:"pips"`
|
Pips int `json:"pips"`
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user