Skip to content
Advertisement

Get SPY share price

I have created a demo account, and I am trying to receive delayed quotes with the following code, but it failed so far.

JavaScript

As I am working with a demo account, I have to work with delayed data, so that’s why I added self.tws.reqMarketDataType(3) (see that link). My problem is that dl.field4price return an empty list for the SPY symbol which is impossible. How could I get the SPY stock price in considering the previous code? Did I make an error?

Advertisement

Answer

I don’t know if you figured it out yet, but IB has forced an upgrade so I’m using ver 963 now. I just added what I suggested and added the delayed request to an old sample. I used Canadian stocks since I’m not subscribed but maybe that doesn’t even matter.

JavaScript

Here is part of the output, notice you can use ib’s enum type to get the name of the tick type.

Error. Id: 1101 Code: 10167 Msg: Requested market data is not subscribed. Displaying delayed market data... Tick Price. Ticker Id: 1101 tickType: DELAYED_BID Price: 97.02 Tick Price. Ticker Id: 1101 tickType: DELAYED_ASK Price: 97.02 Tick Price. Ticker Id: 1101 tickType: DELAYED_LAST Price: 0.0

It’s 9:40 am as I type this so the market is open but It’s not 15 minutes delayed yet. The DELAYED_LAST of 0.0 would need to be filtered out. I don’t think I’ve ever seen a real time last of 0.0, so beware.

I waited to 9:45 and I received

Tick Price. Ticker Id: 1101 tickType: DELAYED_LAST Price: 97.63

right on time.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement