AttributeError: 'TradingApp' object has no attribute 'nextValidOrderId' - python

Keep seeing this error message
Hi guys,
I tried to run this code for IBKR API.
I literally just copy/pasted what I learned in the udemy course but still getting this message.
Some additional info below:
I did it twice in two of my computers, but seeing the same error.
I made sure TWS files are in the right location when I opened Spyder(python) in my anaconda virtual environment. Some summaries of code I used in terminal below:
conda create —name quant python=3.8
conda info —envs (it will tell all the environments created in the computer)
conda activate quant
conda install -c anaconda spyder
conda install pandas==0.24.1
conda install threading
conda install times
cd “....\TWS API\source\pythonclient”
conda activate quant
python setup.py install
spyder
spyder —new-instance (use this if spyder is already running in different environment)

That's your second problem. First is you don't have a connection. I'm guessing the course has a section on how to make TWS accept a connection.
note: The code is not how IB recommends using the api, you should never need to use sleep. However, once TWS accepts a connection the code will probably work.
Follow the program flow. After TWS accepts a connection, nextValidId is fired, then self.nextValidOrderId is set and can be accessed later.

Related

Anaconda failure to "solve environment" repeatedly

I want to update my python version. When running
conda update python
from my base environment I get the message:
The environment is inconsistent, please check the package plan carefully
and then I get a message about trying to solve using flexible solve, where the terminal just runs without completing.
I have tried everything here and here and all lead to my terminal freezing on the same message.
I have also tried to uninstall conda but the clean command here also leads to freezing.
How can I completely uninstall conda and remove all packages/dependencies and reinstall a new version?
For me the solution was to use navigate to Users/name/opt/ and run
rm -rf ~/anaconda3
which removed the base environment and all scripts related to anaconda and to reinstall using the GUI here for the version of python I needed.
This is the only thing that fixed my problem. Likely there are many packages that I will now need to reinstall...

How to connect to AWS Neptune graph-notebook from JupyterLab?

I followed the steps in - https://github.com/aws/graph-notebook , and I was able to run the magic commands from my Mac. But I need to get this configured in JupyterLab.
Here is what I did:
Created a new conda env in JupyterLab
Installed all required packages in conda env
When i run the magic commands like %status, I get "UsageError: Line magic function %status not found.". Please note that ipython, graph-notebook and all required libraries are installed in conda environment.
I skipped the last step in the instruction - python -m graph_notebook.start_notebook --notebooks-dir ~/notebook/destination/dir. Running this created a new notebook, which Im unable to access. (Note: JupyterLab is in remote server)
I want to connect to AWS Neptune and visualize graphs in JupyterLab using gremlin queries/magic commands.
Currently, graph-notebook only supports Jupyter not JupyterLabs, so you will not be able to use the notebook widgets. There is an open issue on adding support for this, so please +1 this feature request, so we can help prioritize this work. https://github.com/aws/graph-notebook/issues/55

"r.start is not a function" Fermipy Conda Error

I've been using the Fermipy conda environment on Python 2.7.14 64-bit on macOS Catalina 10.15.5 and overnight received the error "r.start is not a function" when trying to connect to the Jyputer server through Vscode (if I try on Jupyter Notebook/Lab the server instantly dies). I had a bunch of clutter on my system so I ended up formatting it and reinstalling all the dependencies needed (such as Conda through Homebrew, Fermitools through Conda and Fermipy through the install script on their site), but still get the same error, although I was previously running python scripts just fine. It gives me no other error or output, if it did I would attach it here. This is the error I get.
Edit: I get the same error using any version of Python 2.7.XX and not for python 3.7.XX.
As answered here, https://github.com/microsoft/vscode-python/issues/12355#issuecomment-652515770
VSCode changed how it launches jupyter kernels, and the new method is incompatible with python 2.7.
Add this line to your VSCode settings.json file and restart.
"python.experiments.optOutFrom": ["LocalZMQKernel - experiment"]
I got the same message. (r.start is not a function.) I had an old uninstalled version of anaconda on the computer which had left behind a folder containing its python version. Jupyter was supposed to be running from new venv after setting both python and jupyter path in vscode. I fully deleted remaining files from old anaconda install - message went away and notebook ran fine. Maybe try getting rid of all conda stuff and pip install jupyter and anything else you need.

Problem running Spyder 4.0.0+ on a New Environments on Anaconda

Windows 10 - 64x.
I am new to Python as well as to Anaconda. I downloaded what I believe is the latest version of Anaconda from the official webpage, and I wanted to create a new environment for a new project for which I need Spyder.
Every time I try to launch Spyder, the program doesn't respond and I get the following error:
[16748:16200:0331/091204.775:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D)[3424:6876:0331/091204.775:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D)
Please note that in the "base" environment i managed to make Spyder work just using the command:
conda update anaconda
after which version 4.0.1 of Spyder is running smoothly. Still, I cannot make the same version working on any other new environment I create. Neither the following Spyder versions work.
Please help!

Cannot connect to Jupyter Notebook

My environment:
Windows 10 Professional
Python 3.7.2
virtualenv 16.4.3
I created a new virtual environment with D:\Python37\Scripts\virualenv env
Then I activated the virtual environment with env\Scripts\activate
Then I installed jupyter with pip install --upgrade jupyter
Finally, I started jupyter with jupyter notebook
Everything starts up fine, and I create a new Python 3 notebook. Unfortunately, the notebook never connects to the server. I get the following error message in powershell
Replacing stale connection: (token)
In the browser, I get the following error message:
"A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration."
My two prior virtual environments (with Jupyter) work fine. I've deleted .ipython, .jupyter, AppData\Roaming\jupyter, without any luck.
I've cleared cookies from my browser and have tried a different browser. Nothing works.
I've created two other virtual environments before, and both of those still work.
All jupyter notebooks in the two working environments start up as untrusted, whereas the new environment starts up as trusted. I'm guessing that I clicked on something and now the notebook is looking to start up in a trusted fashion - which may require HTTPS.
Where do I look to fix this problem?
This appears to be a tornado issue. I found clues here.
Jupyter no connection to server
Jupyter kernel not connecting
I looked at the version of tornado (from the above links) in an environment that was working. It turns out that the version was 5.1.1.
I looked at the version of tornado in an environment that was NOT working. It turns out that the version was 6.0.
I downgraded the version of tornado in my non-working environment to 5.1.1 with the following command.
pip install --upgrade tornado==5.1.1
And now the non-working environment works!
Anaconda is pretty good at handling any dependencies.I just tried this using Anaconda in the terminal:
# see current envs
conda info -e
# make new environment, feel free to add your version of python with python=3.7 handle
conda create -n test
activate test
conda list #This should appear empty
conda install jupyter #y to install everything.
jupyter notebook #launch jupyter notebook
Mine comes up as 'trusted'. The method above may not necessarily be the most minimalist way of doing things, but at least nothing breaks and you're up in running in no time. I'm using conda version: 4.6.2
Since this is one of the top answers to a Google search on the error :
"A connection to the notebook server could not be established. The notebook will continue trying to reconnect. Check your network connection or notebook server configuration."
This might also have nothing to do with any install or library.
It may just be a proxy setting in your browser or on your system directly.
One solution may be to deactivate the proxy or add an exception to Jupyter's URI.
In my case, the situation was different. It was a browser caching issue, i.e., I would call jupyter-lab using a batch script and it would just open a tab. Closing all explicitly tabs and then the browser worked me.
If there was an old instance of another disconnected jupyter-lab, it would somehow not establish a proper connection.
This solution work for me :
pip uninstall Pyzmq
pip install Pyzmq==19.0.2
Using pip to install some packages resulted in confusing the jupyter installation. So you can uninstall the packages installed with pip, disable the jupyter_contrib_nbextensions, then try to use conda install as possible.
jupyter labextension disable my-extension

Categories