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

Price rounding may yield incorrect results #241

Open
royrichter opened this issue Jul 6, 2021 · 1 comment
Open

Price rounding may yield incorrect results #241

royrichter opened this issue Jul 6, 2021 · 1 comment

Comments

@royrichter
Copy link

Description of Bug
When submitting an order, the function that rounds to two or four decimal places very occasionally rounds down an additional number. This function truncate_float is called with many order submissions. The issue is floating point arithmetic: e.g., 4.64*100=4.6399999999999994. I suggest using the python native function round() instead: return round(flt, 2) etc.

Code to Reproduce
from tda.orders.generic import truncate_float
a = 4.64
b = truncate_float(a)
print(a, b)

Expected Behavior
4.64 4.64

Actual Behavior
4.64 4.63

Error/Exception Log, If Applicable
N/A

@tirthb
Copy link

tirthb commented Feb 16, 2023

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.

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

2 participants