1

我正在 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 以在后续代码中使用。

已经感谢您的帮助!

4

1 回答 1

2

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

于 2019-05-17T15:51:40.747 回答