Giter Site home page Giter Site logo

quantrocket-llc / ibapi-grease Goto Github PK

View Code? Open in Web Editor NEW
19.0 6.0 8.0 25 KB

Monkey patches to grease the Interactive Brokers Python API

License: Apache License 2.0

Python 100.00%
interactive-brokers quantitative-finance algorithmic-trading python

ibapi-grease's Introduction

ibapi-grease

NOTE: the bottlenecks this package addresses are resolved as of IB API version 973.07, so this package is no longer needed.

The official Interactive Brokers Python API has a few design choices which make it run slowly. Specifically: excessive debug logging, and an overly cautious lock on the socket connection (private repo; request access here). ibapi-grease provides monkey patches that eliminate these bottlenecks by turning off the logging and removing the locks.

As an example of the speedup, making a socket connection to TWS goes from taking a second or more without ibapi-grease to a few milliseconds with it.

Without:

In [1]: from ibapi.client import EClient

In [2]: from ibapi.wrapper import EWrapper

In [3]: class App(EWrapper, EClient):
   ...:
   ...:      def __init__(self):
   ...:          EWrapper.__init__(self)
   ...:          EClient.__init__(self, wrapper=self)
   ...:

In [4]: app = App()

In [5]: %time app.connect("localhost", 4001, 1)
CPU times: user 3.74 ms, sys: 2.44 ms, total: 6.17 ms
Wall time: 1.03 s

With:

In [1]: from ibapi.client import EClient

In [2]: from ibapi.wrapper import EWrapper

In [3]: from ibapi_grease import patch_all

In [4]: patch_all()

In [5]: class App(EWrapper, EClient):
   ...:
   ...:      def __init__(self):
   ...:          EWrapper.__init__(self)
   ...:          EClient.__init__(self, wrapper=self)
   ...:

In [6]: app = App()

In [7]: %time app.connect("localhost", 4001, 1)
CPU times: user 3.83 ms, sys: 1.72 ms, total: 5.55 ms
Wall time: 13.9 ms

Installation

pip install ibapi-grease

Usage

from ibapi_grease import patch_all
patch_all()

Requirements

Naturally, ibapi-grease requires the Interactive Brokers Python API.

License

ibapi-grease is distributed under the Apache 2.0 License. See the LICENSE file in the release for details.

Note

ibapi-grease is not a product of Interactive Brokers, nor is this project affiliated with IB.

ibapi-grease's People

Contributors

brian-from-quantrocket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.