nicknochnack / MLTradingBot

706 stars 280 forks source link

ERROR: Strategy.create_order() got an unexpected keyword argument 'type' #15

Open peterboivin opened 4 months ago

peterboivin commented 4 months ago

Running on MacOS Silicon. Prep my system exactly to your README.

python tradingbot.py Starting backtest for MLTrader... INFO:backtest_stats:Starting backtest... Progress |██---------------------------------------------------------------------------------------------------| 2.29% [Elapsed: 0:00:05 ETA: 0:03:38]2024-03-04 19:31:31,208: root: ERROR: Strategy.create_order() got an unexpected keyword argument 'type' 2024-03-04 19:31:31,209: root: ERROR: Traceback (most recent call last): File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 822, in run self._run_trading_session() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 773, in _run_trading_session self._on_trading_iteration() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 286, in func_output result = func_input(self, *args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 310, in func_output result = func_input(self, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 86, in func_output return func_input(self, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 388, in _on_trading_iteration on_trading_iteration() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/tools/decorators.py", line 62, in func_output frame, result = call_function_get_frame(func_input, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/tools/decorators.py", line 30, in call_function_get_frame result = func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/peterboivin/Documents/VisualStudioProjects/MLTradingBot/tradingbot.py", line 69, in on_trading_iteration order = self.create_order( ^^^^^^^^^^^^^^^^^^ TypeError: Strategy.create_order() got an unexpected keyword argument 'type'

Exception in thread MLTrader: Traceback (most recent call last): File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 822, in run self._run_trading_session() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 773, in _run_trading_session self._on_trading_iteration() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 286, in func_output result = func_input(self, *args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 310, in func_output result = func_input(self, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 86, in func_output return func_input(self, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 388, in _on_trading_iteration on_trading_iteration() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/tools/decorators.py", line 62, in func_output frame, result = call_function_get_frame(func_input, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/tools/decorators.py", line 30, in call_function_get_frame result = func(args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/Users/peterboivin/Documents/VisualStudioProjects/MLTradingBot/tradingbot.py", line 69, in on_trading_iteration order = self.create_order( ^^^^^^^^^^^^^^^^^^ TypeError: Strategy.create_order() got an unexpected keyword argument 'type'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/opt/anaconda3/lib/python3.11/threading.py", line 1045, in _bootstrap_inner self.run() File "/opt/anaconda3/lib/python3.11/site-packages/lumibot/strategies/strategy_executor.py", line 835, in run raise RuntimeError("Exception encountered, stopping BackTest.") from e RuntimeError: Exception encountered, stopping BackTest.

Creating trades plot...

Creating indicators plot...

Creating tearsheet... 2024-03-04 19:31:31,328: root: ERROR: Not enough data to create a tearsheet, at least 2 days of data are required. Skipping

peterboivin commented 4 months ago

I changed it to : order = self.create_order( self.symbol, quantity, "sell", take_profit_price=last_price.8, stop_loss_price=last_price1.05 )

from advice from Strategy class:

For a bracket order

order = self.create_order( "SPY", 100, "sell", take_profit_price=limit, stop_loss_price=stop_loss, stop_loss_limit_price=stop_loss_limit, )

cannuri commented 3 months ago

so you don't define the type at all? How would it know it is a bracket order then?

aceacs123 commented 3 months ago

I was hoping to make limit buy/sells with this code. so I need to better understand this part.

yannie95 commented 3 months ago

Anyone who has the solution for the type argument error?

OWEBS commented 3 months ago

Not sure if this answers your question, but I had this error and I simply got rid of the type="bracket" since the error states it is not expecting it. This allowed has allowed my program to finish. Hope this helps.

order = self.create_order( self.symbol, quantity, "sell",

type="bracket",

                take_profit_price=last_price*.8, 
                stop_loss_price=last_price*1.05
            )
yannie95 commented 3 months ago

Thanks for your answer! But how can I submit a limit order now?

M-Brock commented 3 months ago

Lumibot changed the parameters apparently, type is not valid anymore. How to make a limit order or other types of orders (like a bracket order) can be found on their documentation https://lumibot.lumiwealth.com/entities.order.html#advanced-order-types.