12.1 Interactive Brokers

2020-04-29  本文已影响0人  wanggs66

Interactive Brokers

The integration with Interactive Brokers supports both:

Test any strategy thoroughly with a Paper Trading account or the TWS Demo before going in production.

IBStore - the store

The store is the keystone of the live data feed/trade support, providing a layer of adaptation between the IbPy module and the needs of a data feed and a broker proxy. Store是建立在IbPy上的一个自适应层,以便于和Backtrader的交互,提供DataFeed
和 Broker Proxy.

A store 的功能主要有:

IBStore提供了以下功能:

IBData feeds

Data Options

Data Contract Check

During the start phase, the data feed will try to download the details of the specified contract (see the reference for how to specify it). If no such contract is found or multiple matches are found, the data will refuse to carry on and will notify it to the system. Some examples.

data = ibstore.getdata(dataname='TWTR')  # Twitter
data = ibstore.getdata(dataname='AAPL')  # Error -> multiple contracts
data = ibstore.getdata(dataname='AAPL-STK-SMART-USD')  # 1 contract found
Data Notifications

The data feed will report the current status via one or more of the following (check the Cerebro and Strategy reference)

Example:

class IBStrategy(bt.Strategy):

    def notify_data(self, data, status, *args, **kwargs):

        if status == data.LIVE:  # the data has switched to live data
           # do something
           pass

Notifications includes:

Developers of strategies should consider which actions to undertake in cases like when a disconnection takes place or when receiving delayed data.

上一篇下一篇

猜你喜欢

热点阅读