mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 23:05:15 +00:00
scmaker: add MaxExposure option
This commit is contained in:
parent
8360931497
commit
2448fa6f83
|
@ -46,6 +46,8 @@ type Strategy struct {
|
||||||
LiquiditySlideRule *bbgo.SlideRule `json:"liquidityScale"`
|
LiquiditySlideRule *bbgo.SlideRule `json:"liquidityScale"`
|
||||||
LiquidityLayerTickSize fixedpoint.Value `json:"liquidityLayerTickSize"`
|
LiquidityLayerTickSize fixedpoint.Value `json:"liquidityLayerTickSize"`
|
||||||
|
|
||||||
|
MaxExposure fixedpoint.Value `json:"maxExposure"`
|
||||||
|
|
||||||
MinProfit fixedpoint.Value `json:"minProfit"`
|
MinProfit fixedpoint.Value `json:"minProfit"`
|
||||||
|
|
||||||
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
Position *types.Position `json:"position,omitempty" persistence:"position"`
|
||||||
|
@ -264,10 +266,6 @@ func (s *Strategy) placeLiquidityOrders(ctx context.Context) {
|
||||||
midPriceEMA := s.ewma.Last(0)
|
midPriceEMA := s.ewma.Last(0)
|
||||||
midPrice := fixedpoint.NewFromFloat(midPriceEMA)
|
midPrice := fixedpoint.NewFromFloat(midPriceEMA)
|
||||||
|
|
||||||
makerQuota := &bbgo.QuotaTransaction{}
|
|
||||||
makerQuota.QuoteAsset.Add(quoteBal.Available)
|
|
||||||
makerQuota.BaseAsset.Add(baseBal.Available)
|
|
||||||
|
|
||||||
bandWidth := s.boll.Last(0)
|
bandWidth := s.boll.Last(0)
|
||||||
|
|
||||||
log.Infof("spread: %f mid price ema: %f boll band width: %f", spread.Float64(), midPriceEMA, bandWidth)
|
log.Infof("spread: %f mid price ema: %f boll band width: %f", spread.Float64(), midPriceEMA, bandWidth)
|
||||||
|
@ -294,11 +292,11 @@ func (s *Strategy) placeLiquidityOrders(ctx context.Context) {
|
||||||
askPrice = midPrice.Add(sp)
|
askPrice = midPrice.Add(sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if i > 0 && bidPrice.Compare(ticker.Buy) < 0 {
|
if i > 0 && bidPrice.Compare(ticker.Buy) > 0 {
|
||||||
bidPrice = ticker.Buy.Sub(sp)
|
bidPrice = ticker.Buy.Sub(sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if i > 0 && askPrice.Compare(ticker.Sell) > 0 {
|
if i > 0 && askPrice.Compare(ticker.Sell) < 0 {
|
||||||
askPrice = ticker.Sell.Add(sp)
|
askPrice = ticker.Sell.Add(sp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,6 +310,20 @@ func (s *Strategy) placeLiquidityOrders(ctx context.Context) {
|
||||||
availableBase := baseBal.Available
|
availableBase := baseBal.Available
|
||||||
availableQuote := quoteBal.Available
|
availableQuote := quoteBal.Available
|
||||||
|
|
||||||
|
// check max exposure
|
||||||
|
if s.MaxExposure.Sign() > 0 {
|
||||||
|
availableQuote = fixedpoint.Min(availableQuote, s.MaxExposure)
|
||||||
|
|
||||||
|
baseQuoteValue := availableBase.Mul(ticker.Sell)
|
||||||
|
if baseQuoteValue.Compare(s.MaxExposure) > 0 {
|
||||||
|
availableBase = s.MaxExposure.Div(ticker.Sell)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
makerQuota := &bbgo.QuotaTransaction{}
|
||||||
|
makerQuota.QuoteAsset.Add(availableQuote)
|
||||||
|
makerQuota.BaseAsset.Add(availableBase)
|
||||||
|
|
||||||
log.Infof("balances before liq orders: %s, %s",
|
log.Infof("balances before liq orders: %s, %s",
|
||||||
baseBal.String(),
|
baseBal.String(),
|
||||||
quoteBal.String())
|
quoteBal.String())
|
||||||
|
|
|
@ -8,8 +8,17 @@ import (
|
||||||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||||
)
|
)
|
||||||
|
|
||||||
func number(v float64) fixedpoint.Value {
|
func number(v interface{}) fixedpoint.Value {
|
||||||
return fixedpoint.NewFromFloat(v)
|
switch tv := v.(type) {
|
||||||
|
case float64:
|
||||||
|
return fixedpoint.NewFromFloat(tv)
|
||||||
|
|
||||||
|
case string:
|
||||||
|
return fixedpoint.MustNewFromString(tv)
|
||||||
|
|
||||||
|
default:
|
||||||
|
panic("invalid number input")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTradeStats_consecutiveCounterAndAmount(t *testing.T) {
|
func TestTradeStats_consecutiveCounterAndAmount(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user