Q & A

Rent-a-Coder

Contents

About IBridgePy installation






Q: Installing Python64 and PythonXY

A: IBridgePy does not support PythonXY any more for Nov 2017. Please uninstall Python XY if you are using it and install Anaconda Python from here.

Q: Does IBridgePy support Python 3.x?

A: Yes. 64-bit Anaconda Python 3.6.

Q: I set up the system following the instruction but python complained “ImportError: cannot import name IBCpp” when it ran. How can I solve the issue?

A: This error message will show up if you install IBridgePy for windows on Linux or Mac. Also, this error will show up if there are multiple Python installed in your computer. The solution is to uninstall the extra python..

Q: Which Windows version are you supporting? it’s already Windows 10 compatible? It’s 32 bits or 64 bit, or it doesn’t matter?

A: The short answer is that it doesn’t matter.

IBridgePy was tested on windows 7 32-bit, windows Vista SP2 32-bit, windows 10 64-bit and windows 7 SP1 64-bit and it ran well.

Q: I saw the following error codes: “from IBridgePy import IBCpp ImportError: DLL load failed: %1 is not a valid Win32 application”. How can I solve the issue?

A: The IBridgePy supports both of 64-bit python and 32-bit python. So, the users need to download the correct version of IBridgePy based on their Python version. Therefore, you will see this error message if you are using 64-bit python and has installed IBridgePy for 32-bit python. For Python 3.6, IBridgePy only supports 64-bit Python 3.6.

Q: NameError: name ‘runfile’ is not defined. Can you help?

A: Please check what your Python version is, 32-bit or 64-bit, and download the IBridgePy 32-bit or 64-bit accordingly. Be careful that 64-bit windows does not necessarily have 64-bit python installed.

Q: ‘ascii’ codec can’t decode byte 0xb2 in position 20: ordinal not in range(128) What cause this error?

A: Please double check your python version 2.7 or 3.x and 32-bit Python or 64-bit Python and download the IBridgePy matching with your python version.

Q: The error message is “from IBridgePy import IBCpp ImportError: DLL load failed: The specified module could not be found.” What can I do?

A: This error message will show up when the user’s Python version does not match the Python platform when IBridgePy was developed. IBridgePy does not support PythonXY any more. Please uninstall PythonXY and install Anaconda Python here. Also, please check if you are using Python verison 2.7 or 3.6, 32-bit or 64-bit python.

The ultimate solution is to install Visual Studio from https://www.visualstudio.com/downloads/ for Windows users.

Q: I am using IBridgePy on Ubuntu but see the error message of “undefined symbol: GENERAL_NAME_free”. Can you help?

A: It is very likely that user’s operating system does not match the operating system when IBridgePy on Ubuntu was developed. The IBridgePy on Ubuntu was built on Ubuntu 16.04.3 LTS with native Python 2.7.10 64-bit, not Anaconda, from version 2.20171004. Please let us know if you successfully run IBridgePy on Ubuntu other than the above system. We will share information here with other users.

Q: [Errno 10038] An operation was attempted on something that is not a socket

A: IBridgePy does not support PythonXY any more. Please uninstall PythonXY and install Anaconda Python here. https://www.anaconda.com/download/

Q: [Errno 10093] Either the application has not called WSAStartup, or WSAStartup failed

A: IBridgePy does not support PythonXY any more. Please uninstall PythonXY and install Anaconda Python here. https://www.anaconda.com/download/

Q: IBridgePy on Ubuntu has errorCode = 509, error message: Exception caught while reading socket – Inappropriate ioctl for device

A: This error will show up if Anaconda Python is used on Ubuntu. Right now, IBridgePy on Ubuntu was built using Ubuntu native Python 2.7 and Anaconda Python on Ubuntu is not supported yet. Please uninstall Anaconda and try again. If you really need to run IBridgePy using Anaconda Python, please send email to IBridgePy@gmail.com

Q: ImportError: dynamic module does not define module export function (PyInit_IBCpp)

A: The error shows up when Anaconda is installed to the Mac. Another reason is that Mac has Python 2.7 and Python 3.6. IBridgePy on Mac is based on Python 2.7 right now. The solution is to uninstall Anaconda package from Mac. We are working on a better solution to this issue.

Q: Assertion failed: Successful WSASTARTUP not yet performed (bundled\zeromq\src\signaler.cpp:255)

A: It is a Spyder internal error, not related to IBridgePy. Restart Spyder will solve the issue.

Q: “Kernel died, restarting” It happened many time. Why? How to prevent it?

A: This is a known issue related to Spyder. It is not caused by IBridgePy. The error happens when your computer is slow to create a kernel (because it lacks enough RAM or it’s undergoing high CPU usage). The solution is to restart kernel regularly. In Spyder, go to Consoles — > Restart kernel.

About trading




Q: Is it possible to request real time values of index, for example, SPX, NDX?

A: Yes. They can be received through IBridgePy as long as there is real time data subscription for the indexes in the account. Please check out the function of symbol( ) for specifying index.

Q: How can I use IBridgePy to acquire delayed quotes?

A: Delayed quotes are available in TWS for many contracts but not through the API, so that you cannot do that by IBridgePy.

Q: Can you give me an example for Futures Option symbology ? Say ES Dec 16 2200 call?

A: symbol(‘OPT, ES, USD, 20161216, 2200, C, 100). The format is Option, ES, base currency, expiry, strike price, Call/Put, multiplier.

Q: Is it possible to view the current Implied Volatility on Options contracts with IBridgePy, or do I need to calculate those myself?

A: Yes, IB supplies Implied Volatility values and you don’t need to calculate them by yourselves. However, you need to do a little bit coding to request these values from the IB server.

Q: When display_all is called the Positions ‘Latest_profit’ is always NA?

What is the reason for this?
##    POSITIONS    ##
Symbol Amount Cost_basis Latest_profit
CASH,EUR,USD 1000 1.05444285 NA
A: The last_price is not available at the moment when display_positions ( ) is called. The solution is to request real time prices from IB before display_positions ( ) is called.

Q: How can I get security string from position?

A: The positions are recorded in the context.portfolio.positions by an instance of SecurityClass. security.__str__ will return a security string.

Q: I was using a DEMO account and kept getting “validateAccountCode issue”. How can I solve it?

A: When you are using a demo account, the accountCode changes every time after you get connected to IB server. For some unknown reasons, the behavior of the demo account is NOT as same as the real account or your paper account. If the error message says it is a read-only account, it is a read-only account. You cannot do a lot of things using that account. It is not something that IBridgePy can solve.

Q: Is there any way for me to save history data using IBridgePy?

A: Yes. Please check out the tutorial. http://www.ibridgepy.com/2017/06/17/export-historical-data-and-save-them-to-csv-files/

Q: Instead of localhost connection, can we connect IB gateway remotely?

A: Yes. In RUN_ME.py, add remoteHostIP=”xx.xx.xx.xx”  (xx is your real remote host IP). Also, you need to disable “localhost host connection only” option in your IB gateway first and then add trusted IP in the list before you do the remote connection.

Q: I saw many errors warned by Spyder, for example, symbol and get_datetime is not defined. What am I missing?

img_2228

A: It is normal if you are talking about the errors highlighted by Spyder. You can just click “run” to see results after it is connected to IB Gateway. If you are curious what functions are supported, you may open define_functions.txt to see the exhausted list of all functions defined.

Q: error message: Requested market data is not subscribed.Error&BEST/STK/Top&BEST/STK/Top. What does it mean?

A: IBridgePy always requests real time data and historical data from IB server. If you see this error message, it means that you have not subscribed market data for the requested security. You need to contact with IB representative and subscribe the market data that you are interested in. Also, you need to share the subscription between your live accounts and your paper accounts, which can be done at IB’s account management website.  The market data cannot be shared by live account and paper account at same time. This is a common reason for error messages. IBridgePy does not hard-code any market data subscription requirements to run any codes.

Also, you may check what data package you need to subscribe by visiting this website after you log into your IB account. IB market data assistant.

Q: I got error: “Requested market data is not subscribed” or “No market data permissions for AMEX STK” when I use paper account but I do have data subscription in my live account. What may cause the problem?

A: See the answer above.

Q: I got an error: No market data permissions for  AMEX STK / ISLAND STK. What should I do?

A: See the answer above.
 

Others




Q: Do you support live trading for institutional account holders?

A: Yes, we support both individual account holders and institutional account holders.

Q: Can I change a port number other than 7496?

A: Yes. In configuration.txt, you will see a link

c=MarketManager(trader, host=remoteHostIP, port=7496, clientId=clientId)

You can change the port accordingly. Alternatively, change the port in your TWS global configuration, under section “API” -> “Settings” -> Socket port.

Q: Will IBridgePy collect my trading secrets or other information without my permission?

A: IBridgePy does NOT collect any information without user’s permission.

Q: With all due respect, how can we trust you if you shut down like Quantopian?

A: You will set up your own computing environment using IBridgePy so that you don’t need to give password to Quantopian any more. That is the main motivation of IBridgePy. You can still run your codes on your computers using IBridgePy even if our team discontinues. That is totally different than running codes on Quantopian. You have 100% control on everything.

Q: It seems the  stock of “XYZ” is not in the file of ‘IBridgePy/security_info.csv’. I wonder for what purpose you use this csv file? What should I do?




A: This file works as a database of stock information. IBridgePy will look for the symbol in this file and obtain the related information for further processing. The stock symbols in this file are not a complete list so that users may not find the securities that they want to trade in this file. In that case, users need to manually add additional rows to this file.

For example, there is a position of “STK, ZZZ, USD” in your account. In the IBridgePy initialization stage, it will receive all of the positions from IB server and IBridgePy will search these positions in security_info.csv to look for exchange and primaryExchange. However, “STK, ZZZ, USD” is not in the security_info.csv. Therefore, IBridgePy does not know how to handle this position and it stops. The solution is to add this security into security_info.csv and re-run the code.

When you are editing the security_info.csv, it is recommended to open the file using Microsoft Excel because you can easily see the names of every columns. Two critical columns are “primaryExchange” and “exchange”. You need to put correct information there after you check it at https://www.interactivebrokers.com/en/index.php?f=463 Occasionally, you still see the same error messages after you make the changes. Then, you need to talk to an IB representative and ask them what the correct primaryExchange and exchange are.

security_info

Q: May I set the frequency of handle_data function call more than 60s? Default is 1s, quantopian is 60s. But I don’t need that frequent.

A: Yes. In the RUN_ME.py, add a line. “repBarFreq = 120”. Then, handle_data ( ) will run every two minutes. However, you need to pay attention to the performance of schedule_function ( ) because it may not run as you scheduled if it is not set up correctly.

Q: request_data() got an unexpected keyword argument ‘historyData’. Why?

A: request_data ( ) is deprecated from version 2.20171004. To request historical data, please use request_historical_data ( ). The documentation is here http://www.ibridgepy.com/ibridgepy-documentation/#request_historical_data.

Q: Deprecation Warning: Panel is deprecated and will be removed in a future version. Why does it happen? How can I solve it?

A: This warning message shows up because you request historical data of multiple securities with multiple fields and the returned results are saved in a Pandas Panel, following Quantopian’s data.history ( ) implementation. However, Pandas Panel is deprecated and Pandas package gives this warning. The solution is to avoid using data.history ( ) in this way.

Q: What is “pacing violation”?

A: https://interactivebrokers.github.io/tws-api/historical_limitations.html#gsc.tab=0

Q: The error is KeyError: ‘currency’ . How to solve it?

A: Open “security_info.csv” in the folder of IBridgePy using Excel. It should have a column called “currency”. Please double check that the name of column “currency” should be all lower case.