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

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

Open
peterboivin opened this issue Mar 5, 2024 · 7 comments

Comments

@peterboivin
Copy link

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
Copy link
Author

I changed it to :
order = self.create_order(
self.symbol,
quantity,
"sell",
take_profit_price=last_price*.8,
stop_loss_price=last_price*1.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
Copy link

cannuri commented Mar 17, 2024

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

@aceacs123
Copy link

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

@yannie95
Copy link

Anyone who has the solution for the type argument error?

@OWEBS
Copy link

OWEBS commented Mar 24, 2024

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
Copy link

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

@M-Brock
Copy link

M-Brock commented Apr 2, 2024

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.

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

6 participants