0

I finally got reqMktData() to work! Unfortunately, it just gave me the price $5.54 for the stock SHLD. That is the close of Thursday. and right now it's Saturday... I would think it should give me the closing price of Friday... and even the most recent after hours closing price.

So it seems that it's a day off? I wonder if this is because of the weekend?

I'm not sure. Here is my code snippet for the tickPrice() function (basically just printing things out):

void PosixTestClient::tickPrice( TickerId tickerId, TickType field, double price, int canAutoExecute) {
    printf( "Tick Price. Ticker Id: %ld, Field: %d, Price: %g, CanAutoEx: %ld \n",
            tickerId, (int)field, price, canAutoExecute);
}

And here is my code for the reqMktData() function:

void PosixTestClient::getHData(){
    Contract contract;
    contract.symbol = "SHLD";
    contract.secType = "STK";
    contract.exchange = "SMART";
    contract.currency = "USD";

    TagValueListSPtr mktDataOptions( new TagValueList);


    m_pClient->reqMktData(1,contract,"",false, mktDataOptions);


}
rikkitikkitumbo
  • 954
  • 3
  • 17
  • 38
  • If you're using the demo account, it doesn't send valid data. If it's a real account, I dunno. – brian Feb 12 '17 at 01:20
  • even if I'm paying for real market data in the demo acct? – rikkitikkitumbo Feb 12 '17 at 02:47
  • You can't get real data in the demo account, notice the login doesn't use your name or password. If you have a real account with data then use it. You can set up a paper trading account and share the data subscription. – brian Feb 12 '17 at 02:52
  • ok yeah... that's what I've done. I just compared the 'live' account with the 'paper' account and I'm getting the same result. As far as I know, there's no way to set times on the data you are getting with reqMktData()...it just returns the most current stream of data... so I don't think it's a wrong argument that's getting passed – rikkitikkitumbo Feb 12 '17 at 03:03
  • The live and paper acct share the same data. All I can suggest is wait for the market to open or play with the frozen data setting. https://interactivebrokers.github.io/tws-api/market_data_type.html#gsc.tab=0 – brian Feb 12 '17 at 03:10
  • damn, didn't work, but thanks for the link... it seems so odd that it would be exactly one day off. I've tried it for many different stocks too... always the same thing – rikkitikkitumbo Feb 12 '17 at 03:47

1 Answers1

1

With reqMktData you receive all data you need in the paper and the live account. Check if your settings are right with getting real time data in the TWS for the account you want to connect to the API.

Then look at the messages received by the handler. There are lots of different fields. I didn't find anything helpful in the documentation, too. But I streamed all message data and tested the fields:

  • field = 9 -> last close price (most of the time from yesterday)
  • field = 4 -> realtime market data (like displayed in the TWS beneath the symbol)

I hope I can help you and I can send you sample code if you need some.

TravelTrader
  • 398
  • 4
  • 15
  • I am calling the function reqMktData, but it does not send any response back. Does it take too much time to return the result, or there is any problem in my call? i am new to IB API, may you please tell me the process. I am working in .Net Core 2.1. – Aneeq Azam Khan Nov 16 '18 at 14:12
  • Did you include a `sleep` command? It's important because _it takes some time_ (not much) to get the server response. – TravelTrader Nov 18 '18 at 08:54