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 335 forks source link

Calling `equity_buy_to_cover_market()` results in ValueError: quantity must be positive #326

Closed robertdadamo closed 1 year ago

robertdadamo commented 1 year ago

Windows 10 Python 3.9 in a conda environment tda-api version 1.6.0

Description of Bug When calling equity_buy_to_cover_market() my script raises ValueError: quantity must be positive

Code to Reproduce This is line 376 as referenced in the error message

closeShortMarketOrder = (equity_buy_to_cover_market(symbol = orderSym,
                                       quantity = orderQty)
                .set_session(session=Session.NORMAL)
                .set_duration(duration=Duration.DAY)
        )
        orderSpec = closeShortMarketOrder.build()

orderSym has the value 'FDX' and orderQty has the value 1 with class int

Expected Behavior I am expecting this code to place a market buy to close order.

Actual Behavior Results in ValueError: quantity must be positive

Error/Exception Log, If Applicable Traceback (most recent call last): File "C:\Users\Robert\Anaconda3\envs\tda-api_1.6.0\Scripts\trading_strategy_TSX2_local_PC_version_long_and_short_trades_2022_11-28.py", line 914, in placeOrderReturnValue = placeOrder(client = client_short, File "C:\Users\Robert\Anaconda3\envs\tda-api_1.6.0\Scripts\trading_strategy_TSX2_local_PC_version_long_and_short_trades_2022_11-28.py", line 376, in placeOrder closeShortMarketOrder = (equity_buy_to_cover_market(symbol = orderSym, File "C:\Users\Robert\Anaconda3\envs\tda-api_1.6.0\lib\site-packages\tda\orders\equities.py", line 133, in equity_buy_to_cover_market return (OrderBuilder() File "C:\Users\Robert\Anaconda3\envs\tda-api_1.6.0\lib\site-packages\tda\orders\generic.py", line 442, in add_equity_leg return self.__add_order_leg( File "C:\Users\Robert\Anaconda3\envs\tda-api_1.6.0\lib\site-packages\tda\orders\generic.py", line 418, in __add_order_leg raise ValueError('quantity must be positive') ValueError: quantity must be positive

robertdadamo commented 1 year ago

The problem resulted from an incorrectly named variable in my code.