如何在Colab中安装和使用IB API?

时间:2019-05-17 13:57:53

标签: google-colaboratory ib-api

我正在Google Colab上创建一个笔记本,以运行在Interactive Brokers(IB)上执行的交易算法。我想为此使用IB API。

我当前的代码下载并安装了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 *   

最后一行返回错误:

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'

由于安装程序似乎可以正常运行,所以我不明白为什么我不能导入API以便在后续代码中使用。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

通过直接从.egg文件安装库找到了一种解决方法: ''' ib_path ='/ usr / local / lib / python3.6 / dist-packages / ibapi-9.75.1-py3.6.egg' sys.path.append(ib_path) 从ibapi导入* '''