From 9adedc186f754860314a6596ab6a10a88699e0bb Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 11 Jun 2024 16:28:48 +0800 Subject: [PATCH 1/2] xgap: fix empty source book pricing issue --- pkg/strategy/xgap/strategy.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/strategy/xgap/strategy.go b/pkg/strategy/xgap/strategy.go index 95e7faee1..d80b958cf 100644 --- a/pkg/strategy/xgap/strategy.go +++ b/pkg/strategy/xgap/strategy.go @@ -21,7 +21,7 @@ const ID = "xgap" var log = logrus.WithField("strategy", ID) -var StepPercentageGap = fixedpoint.NewFromFloat(0.05) +var maxStepPercentageGap = fixedpoint.NewFromFloat(0.05) var Two = fixedpoint.NewFromInt(2) @@ -74,6 +74,7 @@ type Strategy struct { DailyMaxVolume fixedpoint.Value `json:"dailyMaxVolume,omitempty"` UpdateInterval types.Duration `json:"updateInterval"` SimulateVolume bool `json:"simulateVolume"` + SimulatePrice bool `json:"simulatePrice"` sourceSession, tradingSession *bbgo.ExchangeSession sourceMarket, tradingMarket types.Market @@ -274,8 +275,8 @@ func (s *Strategy) placeOrders(ctx context.Context) { log.Infof("trading book spread=%s %s", spread.String(), spreadPercentage.Percentage()) - // use the source book price if the spread percentage greater than 10% - if spreadPercentage.Compare(StepPercentageGap) > 0 { + // use the source book price if the spread percentage greater than 5% + if s.SimulatePrice && spreadPercentage.Compare(maxStepPercentageGap) > 0 { log.Warnf("spread too large (%s %s), using source book", spread.String(), spreadPercentage.Percentage()) bestBid, hasBid = s.sourceBook.BestBid() @@ -335,12 +336,12 @@ func (s *Strategy) placeOrders(ctx context.Context) { minQuantity := s.tradingMarket.AdjustQuantityByMinNotional(s.tradingMarket.MinQuantity, price) - if baseBalance.Available.Compare(minQuantity) < 0 { + if baseBalance.Available.Compare(minQuantity) <= 0 { log.Infof("base balance: %s %s is not enough, skip", baseBalance.Available.String(), s.tradingMarket.BaseCurrency) return } - if quoteBalance.Available.Div(price).Compare(minQuantity) < 0 { + if quoteBalance.Available.Div(price).Compare(minQuantity) <= 0 { log.Infof("quote balance: %s %s is not enough, skip", quoteBalance.Available.String(), s.tradingMarket.QuoteCurrency) return } From b562e46c5573e3cdb04301afc65962a6321c366e Mon Sep 17 00:00:00 2001 From: edwin Date: Tue, 11 Jun 2024 17:35:14 +0800 Subject: [PATCH 2/2] pkg/exchange: adjust the time since of unit test --- pkg/exchange/bitget/exchange_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/exchange/bitget/exchange_test.go b/pkg/exchange/bitget/exchange_test.go index efacc667e..3d5a5763b 100644 --- a/pkg/exchange/bitget/exchange_test.go +++ b/pkg/exchange/bitget/exchange_test.go @@ -1116,7 +1116,7 @@ func TestExchange_QueryClosedOrders(t *testing.T) { assert = assert.New(t) ex = New("key", "secret", "passphrase") expBtcSymbol = "BTCUSDT" - since = types.NewMillisecondTimestampFromInt(1709645944272).Time() + since = time.Now().Add(-24 * time.Hour) until = since.Add(time.Hour) lastOrderId = uint64(0) url = "/api/v2/spot/trade/history-orders" @@ -1417,7 +1417,7 @@ func TestExchange_QueryTrades(t *testing.T) { assert = assert.New(t) ex = New("key", "secret", "passphrase") expApeSymbol = "APEUSDT" - since = types.NewMillisecondTimestampFromInt(1709645944272).Time() + since = time.Now().Add(-24 * time.Hour) until = since.Add(time.Hour) options = &types.TradeQueryOptions{ StartTime: &since,