mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 08:15:15 +00:00
liqmaker: add AdjustmentOrderPriceType
This commit is contained in:
parent
0036a57904
commit
ced8b5f742
|
@ -41,7 +41,8 @@ type Strategy struct {
|
||||||
LiquidityUpdateInterval types.Interval `json:"liquidityUpdateInterval"`
|
LiquidityUpdateInterval types.Interval `json:"liquidityUpdateInterval"`
|
||||||
|
|
||||||
AdjustmentUpdateInterval types.Interval `json:"adjustmentUpdateInterval"`
|
AdjustmentUpdateInterval types.Interval `json:"adjustmentUpdateInterval"`
|
||||||
MaxAdjustmentOrderQuantity fixedpoint.Value `json:"maxAdjustmentOrderQuantity"`
|
AdjustmentOrderMaxQuantity fixedpoint.Value `json:"adjustmentOrderMaxQuantity"`
|
||||||
|
AdjustmentOrderPriceType types.PriceType `json:"adjustmentOrderPriceType"`
|
||||||
|
|
||||||
NumOfLiquidityLayers int `json:"numOfLiquidityLayers"`
|
NumOfLiquidityLayers int `json:"numOfLiquidityLayers"`
|
||||||
LiquiditySlideRule *bbgo.SlideRule `json:"liquidityScale"`
|
LiquiditySlideRule *bbgo.SlideRule `json:"liquidityScale"`
|
||||||
|
@ -92,6 +93,22 @@ func (s *Strategy) Subscribe(session *bbgo.ExchangeSession) {
|
||||||
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LiquidityUpdateInterval})
|
session.Subscribe(types.KLineChannel, s.Symbol, types.SubscribeOptions{Interval: s.LiquidityUpdateInterval})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Strategy) Defaults() error {
|
||||||
|
if s.AdjustmentOrderPriceType == "" {
|
||||||
|
s.AdjustmentOrderPriceType = types.PriceTypeMaker
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.LiquidityUpdateInterval == "" {
|
||||||
|
s.LiquidityUpdateInterval = types.Interval1h
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.AdjustmentUpdateInterval == "" {
|
||||||
|
s.AdjustmentUpdateInterval = types.Interval5m
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
func (s *Strategy) Run(ctx context.Context, _ bbgo.OrderExecutor, session *bbgo.ExchangeSession) error {
|
||||||
if s.ProfitFixerBundle.ProfitFixerConfig != nil {
|
if s.ProfitFixerBundle.ProfitFixerConfig != nil {
|
||||||
market, _ := session.Market(s.Symbol)
|
market, _ := session.Market(s.Symbol)
|
||||||
|
@ -193,14 +210,15 @@ func (s *Strategy) placeAdjustmentOrders(ctx context.Context) {
|
||||||
|
|
||||||
posSize := s.Position.Base.Abs()
|
posSize := s.Position.Base.Abs()
|
||||||
|
|
||||||
if !s.MaxAdjustmentOrderQuantity.IsZero() {
|
if !s.AdjustmentOrderMaxQuantity.IsZero() {
|
||||||
posSize = fixedpoint.Min(posSize, s.MaxAdjustmentOrderQuantity)
|
posSize = fixedpoint.Min(posSize, s.AdjustmentOrderMaxQuantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
tickSize := s.Market.TickSize
|
tickSize := s.Market.TickSize
|
||||||
|
|
||||||
if s.Position.IsShort() {
|
if s.Position.IsShort() {
|
||||||
price := profitProtectedPrice(types.SideTypeBuy, s.Position.AverageCost, ticker.Sell.Add(tickSize.Neg()), s.Session.MakerFeeRate, s.MinProfit)
|
price := s.AdjustmentOrderPriceType.GetPrice(ticker, types.SideTypeBuy)
|
||||||
|
price = profitProtectedPrice(types.SideTypeBuy, s.Position.AverageCost, price.Add(tickSize.Neg()), s.Session.MakerFeeRate, s.MinProfit)
|
||||||
quoteQuantity := fixedpoint.Min(price.Mul(posSize), quoteBal.Available)
|
quoteQuantity := fixedpoint.Min(price.Mul(posSize), quoteBal.Available)
|
||||||
bidQuantity := quoteQuantity.Div(price)
|
bidQuantity := quoteQuantity.Div(price)
|
||||||
|
|
||||||
|
@ -218,7 +236,8 @@ func (s *Strategy) placeAdjustmentOrders(ctx context.Context) {
|
||||||
TimeInForce: types.TimeInForceGTC,
|
TimeInForce: types.TimeInForceGTC,
|
||||||
})
|
})
|
||||||
} else if s.Position.IsLong() {
|
} else if s.Position.IsLong() {
|
||||||
price := profitProtectedPrice(types.SideTypeSell, s.Position.AverageCost, ticker.Buy.Add(tickSize), s.Session.MakerFeeRate, s.MinProfit)
|
price := s.AdjustmentOrderPriceType.GetPrice(ticker, types.SideTypeSell)
|
||||||
|
price = profitProtectedPrice(types.SideTypeSell, s.Position.AverageCost, price.Add(tickSize), s.Session.MakerFeeRate, s.MinProfit)
|
||||||
askQuantity := fixedpoint.Min(posSize, baseBal.Available)
|
askQuantity := fixedpoint.Min(posSize, baseBal.Available)
|
||||||
|
|
||||||
if s.Market.IsDustQuantity(askQuantity, price) {
|
if s.Market.IsDustQuantity(askQuantity, price) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user