Skip to content

schalekamp/ibapipy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ibapipy

Interactive Brokers API (IB API) native Python port

Introduction

Python provides some excellent libraries for working with financial data: NumPy, SciPy, matplotlib, and scikit-learn are a few that I've found to be invaluable.

Interactive Brokers provides fantastic access to a wide variety of markets through their own API (IB API) or a FIX computer-to-computer interface (CTCI).

This package is heavily based on the Java source code provided by Interactive Brokers for their API and closely replicates its behavior with a few minor exceptions. The end result is a pure Python package that (hopefully) provides seamless access to the full range of IB services.

Brief module/class overview

  • core/reader.py. The lowest-level module in the API. In Java, an EReader class is used to handle the low-level socket communications. That is partially replaced by this module which operates off of process-safe queues. The message_listener() method works as a dispatcher that receives information via a socket queue and translates the raw socket data into a method name and parameters which are placed in an output queue.
  • core/network_handler.py. Handles communicating with the broker over a socket, but leaves the interpretation of the socket messages to the reader module. This class makes use of processes to get around the concurrency limitations of threads with Python's GIL. For communication, queues are used to pass messages between the different processes. There are three processes:
  • Outgoing request listener. Handles client --> broker communication.
  • Incoming data listener. Handles broker --> client communication.
  • Incoming message handler. Deserializes the socket data stream for incoming communications.
  • core/client_socket.py. Python implementation of the API presented by the EClientSocket class in Java. This is the user-facing class that is used as "the API".
  • data/.... Data objects such as ticks, orders, etc.

Changes from the native IB API

  • Contract and ContractDetails are merged into a single Contract class.
  • Order and OrderState are merged into a single Order class.
  • Tick class adds midpoint() and spread() methods.
  • Execution class adds a milliseconds attribute.

To do

Due to the size of the API and the fact that I'm not trading everything that it offers, I've only implemented enough to support common operations that would be necessary in the equity and foreign exchange markets. There's still a fair amount left to do.

  • Improve inline documentation.
  • Implement the following methods in the ClientSocket class:
  • cancel_calculate_implied_volatility()
  • calculate_option_price()
  • calculate_implied_volatility()
  • cancel_calculate_option_price()
  • cancel_fundamental_data()
  • cancel_mkt_depth()
  • cancel_news_bulletins()
  • cancel_real_time_bars()
  • cancel_scanner_subscription()
  • exercise_options()
  • replace_fa()
  • req_fundamental_data()
  • req_market_data_type()
  • req_mkt_depth()
  • req_news_bulletins()
  • req_real_time_bars()
  • req_scanner_parameters()
  • req_scanner_subscription()
  • request_fa()
  • Add support to ClientSocket.place_order() for bag_type, under_comp, and algo_strategy.
  • Add support to ClientSocket.req_historical_data() for bag_type.
  • Add support to ClientSocket.req_market_data() for bag_type and under_type.

See also

About

Interactive Brokers API (IB API) native Python port

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages