-
-
Notifications
You must be signed in to change notification settings - Fork 345
FIX: [xgap] adjust mid price (round and truncate by price precision) #1971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rt it for sharing among modules
…truncation; include unit tests
pkg/util/round_precision_test.go
Outdated
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func number(a interface{}) fixedpoint.Value { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/strategy/xgap/strategy.go
Outdated
if pricePrecision <= 0 { | ||
return price | ||
} | ||
rate := math.Pow(10, float64(-pricePrecision))*0.1 + 1 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/strategy/xgap/strategy.go
Outdated
} | ||
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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/util/round_precision_test.go
Outdated
return fixedpoint.Zero | ||
} | ||
|
||
func Test_RoundPrice(t *testing.T) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
pkg/strategy/xgap/strategy.go
Outdated
@@ -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()) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
roundAndTruncatePrice
ingrid
strategyxgap