How to get real time IB data Market Feed

134 views
Skip to first unread message

Brian Sherman

unread,
May 12, 2013, 10:09:21 PM5/12/13
to tbg-quant...@googlegroups.com
Hi,

My TBG-Quant Strategy now connects to IB, but I dont think I'm successfully getting data.

Because its the weekend I created a test strategy to just get realtime EUR data and see if it triggers the onEvent method.

If I use the IB Java Test Client I am able to get EUR data.  I press the Req Mkt Data Button and then in the Contract Sub Panel I fill in Symbol = EUR, security type = CASH, Exchange = IDEALPRO, and Currency = USD.  I then hit OK and I gte real time data displaying in the Market and Historical Data Window.

Now if I go to my Strategy I create a Security with the same values, and when I run the STrategy it connects to IB but I do not get the onEvent method to trigger.

 securityEUR.setSymbol(new Symbol("EUR")); // Online Mode, fetches data from www.thebonnotgang.com
 securityEUR.setSecurityType(SecurityType.CASH);
 securityEUR.setExchange("IDEALPRO");
 securityEUR.setCurrency(Currency.USD);


My output is: 

run:
ERROR| 12-May-2013 21:53:32,698 EDT|  | tbg-Quant.properties not found in ClassPath, loading default settings (inMemoryDB). 
Server Version:67
TWS Time at connection:20130512 21:53:22 EST

The Class code is below for your reference.  Am I doing something wrong?  Thanks for your help.

-Brian


public class EURStrategyTest extends TradingSystem implements IStrategy {

    /**
     * Sets Account
     */
    private final IBAccount account = new IBAccount();

    {
        account.setAccountID("Paper Account");
        account.setAccountCurrency(Currency.USD);
    }
    private final InteractiveBrokersAdapter interactiveBrokersAdapter = new InteractiveBrokersAdapter();

    {
        // settings for IB Gateway/TWS Connection
        interactiveBrokersAdapter.setTWS_PORT(7496); // TWS Client
        //interactiveBrokersAdapter.setTWS_PORT(4001); // IBGateway 
        interactiveBrokersAdapter.setTWS_HOST("127.0.0.1");
    }
    private final IBroker broker = new IBBroker(account, interactiveBrokersAdapter);
    /**
     * Sets the marketDataFeeder
     */
    private final IBMarketDataFeed marketDataFeed = new IBMarketDataFeed(interactiveBrokersAdapter);

    {
        marketDataFeed.setDebug(true);
        marketDataFeed.connectToMarketFeed();
    }
    /**
     * Setting the report service, by default prints report to the output.
     */
    private final IReportService reportService = new TextReportService();
    
    /**
     * Sets the VXX security
     */
    private final Security securityEUR = new Security();
    {
        securityEUR.setSymbol(new Symbol("EUR")); // Online Mode, fetches data from www.thebonnotgang.com
        securityEUR.setSecurityType(SecurityType.CASH);
        securityEUR.setExchange("IDEALPRO");
        securityEUR.setCurrency(Currency.USD);
    }

    /**
     * Sets the System and services
     */
    public EURStrategyTest() {
        setTradingSystemName("EUR Strategy");
        setBroker(broker);
        setMarketDataFeed(marketDataFeed);
        setReportService(reportService);
        this.subscribeSecurity(securityEUR);
        setReportService(reportService);
    }

    @Override
    public void onStart() {
        log.info("START");
    }

    @Override
    public void onStop() {
        log.info("STOP");
    }

    @Override
    public void onEvent(Object event) {
        log.info("onEvent(): "+event.toString());
    }

    @Override
    public void onError(Messages msg) {
        log.error(msg.toString());
    }

    /**
     * Start it up!
     */
    public static void main(String[] args) {
        new EURStrategyTest().start();
    }
}

Sfl

unread,
May 13, 2013, 5:20:06 PM5/13/13
to tbg-quant...@googlegroups.com
Hello,

Let me know if you can gets the quotes with this settings:

        securityEUR.setSymbol(new Symbol("XOM")); 
        securityEUR.setSecurityType(SecurityType.STK);
        securityEUR.setExchange("SMART");
        securityEUR.setCurrency(Currency.USD);

thank you

Sfl

unread,
May 15, 2013, 4:18:15 AM5/15/13
to tbg-quant...@googlegroups.com
Hi Brian,

I found out the issue. It is related to the forex market only using InteractiveBrokers. IB does not compute the lastPrice, this is the reason why you do not get any quotes.
Bid and Ask are not streamed too because we are checking the lastPrice before pushing to CEP engine.

We already fixed the issue but not committed on GitHub master, we would like to discuss about what to do:

- Compute the lastPrice like the midpoint of Ask/Bid ( which is the lastPrice you see on InteractiveBrokers TWS )
Or
- Pushing Ask/Bid and remove the check about lastPrice > 0, this means that lastprice will be always zero and you will have to work on Bid/Ask

Personally I prefer pushing to CEP only positive values for lastPrice, since you have the chance to work on Bid/Ask anyway. 
Streaming zero values can be misunderstood.
We want to discuss about this before pushing to GitHub, it would not take a while.

You are welcomed to comment :-)

thank you
Alberto

Sfl

unread,
May 18, 2013, 3:59:31 PM5/18/13
to tbg-quant...@googlegroups.com
Hello Brian

We pushed the fix in the GitHub master.
I also create two examples showing Forex & Futures: 



Hope this helps, let me know if you need help and thank you for your email that let us discover this bug.
bye

Brian Sherman

unread,
May 20, 2013, 11:03:44 AM5/20/13
to tbg-quant...@googlegroups.com
Hi Alberto,

Thanks for your responses.  Sorry I did not reply sooner as I did not have time to investigate.  I did have a chance to try the XOM ticker and I think I may have an issue on my end with regard to Market Data Subscriptions.  Im not able to get XOM data, only a delayed market feed.  This happens in TWS itself.  I'll have to sort that out with IB.

I'm glad you guys found the issue with Forex and Futures.  I think your solution makes sense and should work just fine.  

And thank you for the quick response once again.

-Brian
Reply all
Reply to author
Forward
0 new messages