IBClient

A clean and simple Scala API for Interactive Brokers

Automate your trading system with a modern, robust and easy to use API

IBClient provides great additional value on the the Interactive Brokers trading API by offering a simplified, type-safe and asynchronous layer that can be access from Scala, Python and Java.

Unlike the traditional IB Java API which is based heavily on callbacks and overrides, the IBClient API is based on modern functional programming principles and tools like reactive programming and futures, which can help tremendously decoupling your trading logic from the API and reducing code boilerplate to the minimum.

Features

pure awesomeness

  database icon
Getting historical data is a childs play

Queries for historical data couldn't be easier, your request is splitted and submitted to the broker and reassembled before delivering it back to you respecting pacing limits.

Requests are throttled automatically so pacing limits are respected. All transparent to you.

Automatic reassembly makes it very easy to get for example 1 minute bars for long periods, when available, the grunt is made for you behind the scenes, and you get the whole history as a single call.


candles
Reactive streams for market data

Receiving market data could never be easier, you get a subscription with a stream that can call your function whenever a tick is recieved. There's minimal boilerplate involved on receiving market data, just supply your "onNext" function.

Reactive streams is the dominating trend for building complex systems and services in a way that the code is easy to understand and reason about, recently pupularized by Netflix and Microsoft.


  gears
Compose asynchronous actions with futures

Actions such as contract details, getting position information etc. Are managed through the use of futures which are a powerful way to reason and manage parallel and asynchronous operations.

  robot
Robust automated systems

The design principles and tools outlined will help you create and maintain robust systems that will make a solid foundation to achieve profitability and success in your trading strategies.

Examples

check out the code

                      
val futureContractDetails = ibclient.contractDetails(stockContract)
val contractDetails = Await.result(futureContractDetails, testWaitDuration)
                      
                    
                    
// Request history between two dates                    
val startDate = new DateTime(2015, 3, 1, 15, 0).toDate
val endDate = new DateTime(2015, 3, 3, 15, 0).toDate
val futureHistory = ibclient.easyHistoricalData(stockContract, startDate, endDate, BarSize._1_min, WhatToShow.TRADES)

// Wait for the future to complete
val history = Await.result(futureHistory, Duration.Inf)

// Write it to a fil in CSV format
val csvWriter = CSVWriter.open(outFile)
history.foreach { bar ⇒
    csvWriter.writeRow(List(bar.time, bar.high, bar.low, bar.open, bar.close, bar.volume, bar.count, bar.hasGaps))
}

                    
                    
                    
// Subscribe to the EUR.USD trades
val subscription = ibclient.marketData(new CashContract("EUR", "EUR.USD"))

// Action to be executed whenever a tick is received, you could for example feed it to your system
subscription.observableTick.subscribe({ tick ⇒ log.debug(s"Got tick for eur.usd: ${tick}") })

// Do something else
[...]

// Close the subscription when done, which closes the market data line
subscription.close()

                    
                    

About

support, inquiries and price quotes

email

If you are interested in purchasing the library or need help building your trading system, you are welcome to contact me at the following email address: