3

I tried to explain this earlier, but obviously failed!

So, if you have a google finance graph open, for instance:

http://www.google.com/finance?q=INDEXNASDAQ:.IXIC

I would like to somehow use the (HttpWebRequest) object in C# so that I can grab the small data which google sends to the page to update the graph.

A friend mentioned this was JSON?

I was trying to use the following code example, but even when i set the keep alive property to 'true', it still wouldnt work:

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.keepalive.aspx#Y369

Jean
  • 721
  • 3
  • 9
  • 14

1 Answers1

0

You also need to change the example's line that sets the Connection property to Close. Comment out this line (along with keeping the keep-alive property set to true):

myHttpWebRequest2.Connection = "Close";

You do that and your example should run fine.

Regarding getting the data and using HttpWebRequest to work with it, you can do that. The data returned isn't JSON - it looks like straight text and I'm guessing Google's javascript is parsing it out. (I haven't inspected the javascript on Google Finance's page, but that's my guess.)

Using Fiddler, the response from this URL:

http://www.google.com/finance/getprices?q=.IXIC&x=INDEXNASDAQ&i=120&p=10m&f=d,c,v,o,h,l&df=cpct&auto=1&ts=1307994768643

looks like this:

EXCHANGE%3DINDEXNASDAQ
MARKET_OPEN_MINUTE=570
MARKET_CLOSE_MINUTE=960
INTERVAL=120
COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
DATA=
TIMEZONE_OFFSET=-240
a1307994120,2641.12,2641.12,2639.96,2640.01,0
1,2638.76,2642.14,2638.76,2641.13,0
2,2638.95,2640.54,2638.74,2638.79,0
3,2639.85,2640.01,2638.08,2638.95,0
4,2640.07,2640.87,2639.31,2639.88,0
5,2640.31,2640.48,2639.42,2640.08,0
6,2641.09,2641.09,2640.3,2640.31,0

A little cryptic, but you can see how the COLUMNS line lines up with the data at the bottom. Also, the f querystring parameter seems to be indicating which columns to return (d=date, c=close,v=volume,o=open,h=high,l=low).

EDIT: I should mention that the URL I used is being sent from the finance graph page to get updated data - you can see this URL being requested at regular intervals using a tool like Fiddler. The response data that I pasted above is also output by the sample application from MSDN.

But commenting out that one line in the example from MSDN and a little fiddling with Fiddler should give you the data and clues you need to parse the return that comes from that URL.

I hope this helps!

PS - my first line in my modified MSDN example looks like this:

HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create("http://www.google.com/finance/getprices?q=.IXIC&x=INDEXNASDAQ&i=120&p=10m&f=d,c,v,o,h,l&df=cpct&auto=1&ts=1307994768643");

I made a similar change to the other WebRequest call a little further down in the example...other than that, I didn't change anything else in the example.

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
  • Hi, my console window seems to close after pressing enter? I was expecting there to be a stream of that 'cryptic' data coming through? – Jean Jun 13 '11 at 20:26
  • Hit Ctrl+F5 when you run your console window...not just F5. It will close automatically when you run it just with F5. Ctrl + F5 will prompt you to press a key to close the console window. – David Hoerster Jun 14 '11 at 00:20