Skip to content

Conversation

dboyliao
Copy link
Collaborator

@dboyliao dboyliao commented Apr 9, 2025

  • refactor: move and export roundAndTruncatePrice in grid strategy
  • round and truncate price for xgap

@dboyliao dboyliao requested a review from c9s April 9, 2025 07:29
"github.com/stretchr/testify/assert"
)

func number(a interface{}) fixedpoint.Value {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a testhelper package you can import:

import . "github.com/c9s/bbgo/pkg/testing/testhelper"

// then you call Number()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

if pricePrecision <= 0 {
return price
}
rate := math.Pow(10, float64(-pricePrecision))*0.1 + 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps we can call RoundAndTruncatePrice directly, since Round(v * 10.0) / 10.0 almost equals to this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
rate := math.Pow(10, float64(-pricePrecision))*0.1 + 1
priceAdjusted := util.RoundAndTruncatePrice(price.Mul(fixedpoint.NewFromFloat(rate)), pricePrecision)
log.Infof("adjusted price: %s -> %s", price.String(), priceAdjusted.String())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log the price from the caller, not inside the function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return fixedpoint.Zero
}

func Test_RoundPrice(t *testing.T) {
Copy link
Owner

@c9s c9s Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name it as TestRoundAndTruncatePrice?

Test{func name} is the convention

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -320,7 +321,8 @@ func (s *Strategy) placeOrders(ctx context.Context) {
spreadPercentage.Percentage(),
bestAsk.Price.String(), bestBid.Price.String(), midPrice)

var price = midPrice
var price = adjustPrice(midPrice, s.tradingMarket.PricePrecision)
log.Infof("adjusted price: %s -> %s", midPrice.String(), price.String())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about logging price precision as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dboyliao dboyliao requested review from c9s and gx578007 April 9, 2025 08:32
@dboyliao dboyliao merged commit cb17a77 into main Apr 9, 2025
3 checks passed
@dboyliao dboyliao deleted the dboy/fix-xgap-mid-price branch April 9, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants