Open JordanMandel opened 2 years ago
I've been looking at the truncation issue too. JordanMandel - while your approach looks good to me, why not bypass the whole issue and pass the price as a string? Oh wait, the docs say
You can sidestep this entire process by passing your price as a string, although be forewarned that TDAmeritrade may reject your order or even interpret it in unexpected ways.
Does anyone know the circumstances where the TDAmeritrade weirdness happens? Fetched quotes routinely arrive with 4 decimals places of precision - eg 77.1234. Would placing a buy_limit order using the string "77.1234" ever give unexpected results?
truncate_float(price) is not working 4.1 is giving "4.09"
https://github.com/alexgolec/tda-api/blob/master/tda/orders/generic.py#L35
I am passing the price as string for now.
Description of Bug Certain price values (such as 5.06) are not respected when creating a limit order
Code to Reproduce
Expected Behavior The resulting order should have a limit price of 5.06
Actual Behavior Instead, the limit order has a price of 5.05
The error is in
truncate_float
due to floating point rounding errors.Notice how
flt * 100
is505.99999999999994
. A possible fix might be to add a small epsilon value (haven't tested negative values though):