2

I am creating a notebook on Google Colab to run trading algorithms which execute on Interactive Brokers (IB). I want to use the IB API for this.

My current code downloads and installs the API:

# Install IB and related libraries
!wget -cq http://interactivebrokers.github.io/downloads/twsapi_macunix.975.01.zip
!unzip -qq -o twsapi_macunix.975.01.zip
!cd IBJts/source/pythonclient && python setup.py build install
!pip install ib_insync
!pip install ibapi

# Import generic libraries
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import datetime  # For datetime objects
import os.path  # To manage paths
import sys  # To find out the script name (in argv[0])
import pandas as pd
import numpy as np
import matplotlib as plt
import time
from datetime import datetime
import argparse

# Import IB and IB_InSync, and start an IB connection
from ib_insync import *
from ibapi import *   

The last line returns an error:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-4-3cdef93fab15> in <module>()
     48 from ib_insync import *
---> 49 from ibapi import *


ModuleNotFoundError: No module named 'ibapi'

As the installation seems to run properly, I do not understand why I cannot import the API for use in the subsequent code.

Thanks already for your help!

Neeraj Sewani
  • 3,952
  • 6
  • 38
  • 55
AM Delhez
  • 51
  • 4

1 Answers1

3

Found a workaround by installing the library directly from the .egg file: ''' ib_path='/usr/local/lib/python3.6/dist-packages/ibapi-9.75.1-py3.6.egg' sys.path.append(ib_path) from ibapi import * '''

AM Delhez
  • 51
  • 4