mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
Merge pull request #1652 from c9s/c9s/fix-xgap-spread-too-large-issue
FIX: [xgap] fix empty source book pricing issue
This commit is contained in:
commit
7a4f9347f1
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user