Skip to content
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

AmountToLotSize works incorrect #615

Open
ramilexe opened this issue Sep 5, 2024 · 3 comments
Open

AmountToLotSize works incorrect #615

ramilexe opened this issue Sep 5, 2024 · 3 comments

Comments

@ramilexe
Copy link

ramilexe commented Sep 5, 2024

There is MEWUSDT token on Binance futures with following parameters:

"pricePrecision": 7,
"filters": [
{
    "filterType": "PRICE_FILTER",
    "minPrice": "0.0000010",
    "tickSize": "0.0000010",
    "maxPrice": "200"
}]

When I call AmountToLotSize(0.0000010, 7, 0.003923153000000002) I get 0.0039229 but expected value is 0.003923. Because of that I get error <APIError> code=-4014, msg=Price not increased by tick size.

@xyq-c-cpp
Copy link
Collaborator

xyq-c-cpp commented Sep 6, 2024

thanks for your feedback, it is no longer applicable at present, I saw. @ramilexe I recommend that you follow tickSize completely, not pricePrecision. I would fix this function later.

{
			"filterType": "PRICE_FILTER",
			"maxPrice": "200",
			"minPrice": "0.0000010",
			"tickSize": "0.0000010"
		}

@ramilexe
Copy link
Author

ramilexe commented Sep 6, 2024

@xyq-c-cpp I replaced it with following function:

// RoundPriceToTickSize rounds the price to the nearest tick size
func RoundPriceToTickSize(price, tickSize float64) float64 {
	if tickSize == 0 {
		return price // To avoid division by zero
	}
	// Calculate the factor by which to multiply and divide the price to conform to the tick size.
	factor := 1 / tickSize

	// Round the price to the nearest tick size.
	roundedPrice := math.Round(price*factor) / factor

	return roundedPrice
}

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

No branches or pull requests

3 participants
@ramilexe @xyq-c-cpp and others