TWS API how to track hi-lo

Discussion in 'Automated Trading' started by R0bert, Apr 9, 2009.

  1. R0bert

    R0bert

    I need to track today's hi-lo for 60-100 stocks. I use ReqMktData (...) routine to get real-time quotes (bid/ask/last and including hi-lo of the day), but for some stocks TWS floods too much messages of updating bid/ask thus overloading API pipe between TWS and my program. Is there a way to receive from TWS only updating high and low prices of the day (and may be last) and omit all that bids/asks? What parameters should I use in ReqMktData for this?
     
  2. jeffweng

    jeffweng

    So far as I know, there is no way to specify the data you want to get. As long as you ReqMktData, you're gonna get all the data including bid,ask,last,hi,low. You can confirm this with IB.

    BTW, I also watched up to 100 contracts at the same time and there is no performance issue. You might need to upgrade your machine.
     
  3. R0bert

    R0bert

    Actually I have no performance issues with my machine/robots: I'm running 3 robots connected to 3 TWS and they consume 3-4% of CPU each (and 5-7% for each instance of TWS). There are definitely problems with bandwidth of API - it fires errors like "too many messages per second" or something like that.
     
  4. jeffweng

    jeffweng

    Does it exceed the maximum number of contracts you can subscribe at the same time? For me, I can only subscribe 100 contracts. Since I watch two market for one stock, I can only watch 50 stocks at the same time.
     
  5. R0bert

    R0bert

    Me too. I usually request 60-90 symbols. And when there are actively traded stocks in that requested list TWS fires the error "error_code=100, msg=Max rate of messages per second has been exceeded:50" 3 times and than stops quotes.
     
  6. jeffweng

    jeffweng

    I've never seen such a message. I think you'd better contact with IB.
     
  7. No problem (assuming you use ActiveX for interfacing, if you use C++ or Java adapt accordingly) :

    You can use the "reqMktDataEx()" sub for subscribing to a symbol data stream as you probably already did.
    [ReqMktData is obsolete in the view of IB].

    The point is that you may want to use the "snapshot" parameter which results in giving you only one set of data and then stopping.

    In your "tickprice" event callback handler you receive a parameter called "ticktype". This can have the values "bid, ask, last, high, low, close".
    Apparently you only need last (=4), high (=6) and low (=7).

    Since with the "snapshot" parameter turned on you only get a relatively small set of data (and quite fast) you can circle around many symbols (certainly much more than 100) by requesting snapshots in a round-buffer manner.

    Please take a look at
    http://www.interactivebrokers.com/php/apiUsersGuide/apiguide.htm

    Also the Yahoo-TWS-API group is quite helpful.
     
  8. R0bert

    R0bert

    Thanks a lot, I'll try to employ such trick.

    2All: Also you may vote for or comment the suggestion
    http://www.interactivebrokers.com/en/general/poll/poll.php?sid=4611
     
  9. Bob111

    Bob111

    there no problem with "bandwidth of API", don't blame IB, if don't know what a f* you are talking about..
    there is a problem with your programming skills
    because you coded it in shtty way. you keep requesting the data, instead of let it flow. you said-100 tickers-no problem. properly coded it will consume less than 5 % of your cpu.
    you create array with tickers, then -you assign data id to each ticker, then you subscribe to data. the data will flow thru tickprice\ticksize events,where you identify each stock by your dataid number and each piece of data by ticktype # below. it's very simple thing.

    id


    The ticker ID that was specified previously in the call to reqMktData()

    tickType


    Specifies the type of price. Possible values are:

    *

    1 = bid
    *

    2 = ask
    *

    4 = last
    *

    6 = high
    *

    7 = low
    *

    9 = close
     
  10. R0bert

    R0bert

    Afraid you're wrong. I make only one call of ReqMktData per contract and "let the data flow". And even with empty tickPrice/tickSize handlers (no any actions to store provided by API quotes data) API pipe gets overloaded with error mentioned here http://institutions.interactivebrokers.com/smf/index.php?action=printpage;topic=27415.0

    You can get the same problem by requesting mktdata for 15-20 actively traded symbols (say MSFT ORCL BIDU RIMM QQQQ SPY JAVA SYMC GOOG AAPL GS JPM INTC CSCO C WFC) during the first 20min after market open or in other time when market is "fast".
     
    #10     Apr 16, 2009