alexgolec / tda-api

A TD Ameritrade API client for Python. Includes historical data for equities and ETFs, options chains, streaming order book data, complex order construction, and more.
https://tda-api.readthedocs.io
MIT License
1.26k stars 338 forks source link

Question on prices under 1 #282

Closed binbap closed 2 years ago

binbap commented 2 years ago

I am unclear if this is expected behavior but when creating an limit option order in which the price is under 1, the order sent has the limit is formatted to 4 digits. Recently when I tried to submit an order under 1, it was rejected (I believe it is because it of the 4 digits). The following is the code that appears to format prices under 1 to 4 digits. Is this intentional?

def truncate_float(flt): if abs(flt) < 1 and flt != 0.0: return '{:.4f}'.format(float(int(flt 10000)) / 10000.0) else: return '{:.2f}'.format(float(int(flt 100)) / 100.0)

pssolanki111 commented 2 years ago

yes. the documentation mentions truncation of the prices when they are passed around as floats.

to avoid this, just cast the value into a string and pass that string for the price. Don't worry about how a string is supposed to represent a numerical price.

so something like:

val = str(your_price_value)

# now you can pass the val into function calls

when you do that, prices will not be truncated and used as they are.

binbap commented 2 years ago

Thanks!

pssolanki111 commented 2 years ago

@alexgolec consider closing this