Suppose I have some number x, and would like to set the trigger price for an order to be as close as possible to x. How would you recommend accomplishing this simple task?
My current solution is: IOrder.setOpenPrice(sanitizePrice(x))
where...
protected static double sanitizePrice(double price) {
double pipValue = 0.0001;
double atom = pipValue / 10;
return Math.round(price / atom) * atom;
}
However, for some x this doesn't work. For example, you can check for yourself in Java that sanitizePrice(1.32907)==1.3290700000000002
So IOrder.setOpenPrice(sanitizePrice(1.32907)) results in
ORDER_CHANGED_REJECTED message wrote:
Invalid price format - please use increments of 0.1 pip.
How should it be done?