dydx-v3-python icon indicating copy to clipboard operation
dydx-v3-python copied to clipboard

ValueError: Amount 0.65 is not a multiple of the quantum size 1e-09

Open adminha opened this issue 2 years ago • 1 comments

I'm trying to place an order for ETH-USD pair with amount of 0.65 ETH, but it shows this error message: ValueError: Amount 0.65 is not a multiple of the quantum size 1e-09 I can't understand what this means? would you please clarify & show me a solution? FYI, I get this amount based on some calculations of my open position & market data. So I need a way to open or close a position with exactly the amount returned by the calculations, not even 0.1% more or less.

adminha avatar Feb 18 '22 17:02 adminha

Amount 0.03 is not a multiple of the quantum size 1e-09 is my error

So computers can't count when adding or subtracting numbers that have decimal places 😁. On the python interpreter prompt type the following.

>>> 1.2 - 1.0
0.19999999999999996 

So my work-around is to convert my figures into int then do my calculation and convert back to float. I do this by having a constant J which is a large arbitrary number

J = 10000000000

Then my math includes J to convert to and from float to int

    totalSize += int(orderSize * J) / J
    totalCash += (int(orderSize * J) * orderPrice) / J

Basically get rid of the decimals by multiplying, do the math then divide to bring the result back to what you need. The error doesn't show because the string seems to be truncated in the code.

jangita avatar Dec 06 '22 17:12 jangita