Anaconda Spyder / IBridgePy - getting errors in file moving_average_crossover.py

Hi,



I have donwloaded IBridgePy and Installed the IB TWS on my system. When I open a Strategy file from the Strategy folder, Spyder is showing me errors in the file. e.g. If I 'open moving_average_crossover.py' Straegy in Spyder, It is showing me Undefined name 'symbol' for Line 21 (i.e. for the code -> context.security = symbol('SPY') )



Similarly it is giving such errors for other functions as well.



I feel like I am missing some settings in my Spyder environment for the libraries it needs to access. Can someone help me with this?



Thanks!!

Hi Anshumn



My answer is based on the assumption that you are enrolled in the “Automated Trading with IBridgePy using Interactive Brokers Platform”.

I believe you are trying to run the “example_moving_average_cross.py” directly in spyder. This is not the right approach.

Please follow the steps outlined below:

  1. Save your strategy code in the “Strategies” folder.
  2. Open the “RUN_ME.py” file in spyder and edit the “filename” variable to the name of your strategy file, in this case, “example_moving_average_cross.py”.
  3. Change the “accountCode” value as per the value for your IB account.
  4. Save the changes in the above.
  5. Open a python terminal and navigate to the IBridgePy folder.
  6. Type the command - “python RUN_ME.py”

The detailed approach with screenshots is specified in Section 3, Unit 7 of the course.

Do let me know if this works for you!

Thanks, 
Rishabh
 

Hi Rishabh,



Yes, I followed the steps and the Strategy is being rum from RUN_ME.py file only. It was working fine.

What I wanted to know was whether Spyder would recognize ibridgepy functions and not show them as errors in the IDE when a straegy file is open. But it looks like those will be like that only.



Thanks,

Anshumn

Hi Anshumn,



If you are using a demo account while fetching the data, then you will not have access to all the tickers. Your access will be limited to Forex pairs mostly.



Can you try the below currency pair:

context.security=symbol('CASH,EUR,USD')

If you are still getting the same error, please let us know.



Thanks!