mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +00:00
Compare commits
3 Commits
ad6056834e
...
4d1c357c3d
Author | SHA1 | Date | |
---|---|---|---|
|
4d1c357c3d | ||
|
a4833524cf | ||
|
ed073264f1 |
|
@ -119,6 +119,8 @@ type Strategy struct {
|
|||
// MaxExposurePosition defines the unhedged quantity of stop
|
||||
MaxExposurePosition fixedpoint.Value `json:"maxExposurePosition"`
|
||||
|
||||
MaxHedgeAccountLeverage fixedpoint.Value `json:"maxHedgeAccountLeverage"`
|
||||
|
||||
DisableHedge bool `json:"disableHedge"`
|
||||
|
||||
NotifyTrade bool `json:"notifyTrade"`
|
||||
|
@ -479,6 +481,7 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
|||
makerQuota.BaseAsset.Add(b.Available)
|
||||
} else {
|
||||
disableMakerAsk = true
|
||||
s.logger.Infof("%s maker ask disabled: insufficient base balance %s", s.Symbol, b.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -487,6 +490,7 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
|||
makerQuota.QuoteAsset.Add(b.Available)
|
||||
} else {
|
||||
disableMakerBid = true
|
||||
s.logger.Infof("%s maker bid disabled: insufficient quote balance %s", s.Symbol, b.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,10 +536,9 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
|||
// calculate credit buffer
|
||||
s.logger.Infof("hedge account net value in usd: %f", netValueInUsd.Float64())
|
||||
|
||||
maximumHedgeAccountLeverage := fixedpoint.NewFromFloat(1.2)
|
||||
maximumValueInUsd := netValueInUsd.Mul(maximumHedgeAccountLeverage)
|
||||
maximumValueInUsd := netValueInUsd.Mul(s.MaxHedgeAccountLeverage)
|
||||
|
||||
s.logger.Infof("hedge account maximum leveraged value in usd: %f", maximumValueInUsd.Float64())
|
||||
s.logger.Infof("hedge account maximum leveraged value in usd: %f (%f x)", maximumValueInUsd.Float64(), s.MaxHedgeAccountLeverage.Float64())
|
||||
|
||||
if quote, ok := hedgeAccount.Balance(s.sourceMarket.QuoteCurrency); ok {
|
||||
debt := quote.Debt()
|
||||
|
@ -562,7 +565,6 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
if b, ok := hedgeBalances[s.sourceMarket.BaseCurrency]; ok {
|
||||
// to make bid orders, we need enough base asset in the foreign exchange,
|
||||
|
@ -572,13 +574,13 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
|||
if b.Available.Compare(minAvailable) > 0 {
|
||||
hedgeQuota.BaseAsset.Add(b.Available.Sub(minAvailable))
|
||||
} else {
|
||||
s.logger.Warnf("%s maker bid disabled: insufficient base balance %s", s.Symbol, b.String())
|
||||
s.logger.Warnf("%s maker bid disabled: insufficient hedge base balance %s", s.Symbol, b.String())
|
||||
disableMakerBid = true
|
||||
}
|
||||
} else if b.Available.Compare(s.sourceMarket.MinQuantity) > 0 {
|
||||
hedgeQuota.BaseAsset.Add(b.Available)
|
||||
} else {
|
||||
s.logger.Warnf("%s maker bid disabled: insufficient base balance %s", s.Symbol, b.String())
|
||||
s.logger.Warnf("%s maker bid disabled: insufficient hedge base balance %s", s.Symbol, b.String())
|
||||
disableMakerBid = true
|
||||
}
|
||||
}
|
||||
|
@ -591,17 +593,16 @@ func (s *Strategy) updateQuote(ctx context.Context) {
|
|||
if b.Available.Compare(minAvailable) > 0 {
|
||||
hedgeQuota.QuoteAsset.Add(b.Available.Sub(minAvailable))
|
||||
} else {
|
||||
s.logger.Warnf("%s maker ask disabled: insufficient quote balance %s", s.Symbol, b.String())
|
||||
s.logger.Warnf("%s maker ask disabled: insufficient hedge quote balance %s", s.Symbol, b.String())
|
||||
disableMakerAsk = true
|
||||
}
|
||||
} else if b.Available.Compare(s.sourceMarket.MinNotional) > 0 {
|
||||
hedgeQuota.QuoteAsset.Add(b.Available)
|
||||
} else {
|
||||
s.logger.Warnf("%s maker ask disabled: insufficient quote balance %s", s.Symbol, b.String())
|
||||
s.logger.Warnf("%s maker ask disabled: insufficient hedge quote balance %s", s.Symbol, b.String())
|
||||
disableMakerAsk = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if max exposure position is configured, we should not:
|
||||
|
@ -1037,6 +1038,10 @@ func (s *Strategy) Defaults() error {
|
|||
s.MinMarginLevel = fixedpoint.NewFromFloat(3.0)
|
||||
}
|
||||
|
||||
if s.MaxHedgeAccountLeverage.IsZero() {
|
||||
s.MaxHedgeAccountLeverage = fixedpoint.NewFromFloat(1.2)
|
||||
}
|
||||
|
||||
if s.BidMargin.IsZero() {
|
||||
if !s.Margin.IsZero() {
|
||||
s.BidMargin = s.Margin
|
||||
|
@ -1295,9 +1300,8 @@ func (s *Strategy) CrossRun(
|
|||
return errors.New("tradesSince time can not be zero")
|
||||
}
|
||||
|
||||
makerMarket, _ := makerSession.Market(s.Symbol)
|
||||
position := types.NewPositionFromMarket(makerMarket)
|
||||
profitStats := types.NewProfitStats(makerMarket)
|
||||
position := types.NewPositionFromMarket(s.makerMarket)
|
||||
profitStats := types.NewProfitStats(s.makerMarket)
|
||||
|
||||
fixer := common.NewProfitFixer()
|
||||
// fixer.ConverterManager = s.ConverterManager
|
||||
|
@ -1312,7 +1316,7 @@ func (s *Strategy) CrossRun(
|
|||
fixer.AddExchange(sourceSession.Name, ss)
|
||||
}
|
||||
|
||||
if err2 := fixer.Fix(ctx, makerMarket.Symbol,
|
||||
if err2 := fixer.Fix(ctx, s.makerMarket.Symbol,
|
||||
s.ProfitFixerConfig.TradesSince.Time(),
|
||||
time.Now(),
|
||||
profitStats,
|
||||
|
|
Loading…
Reference in New Issue
Block a user