Need Suggestion for Live Data

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2009
Posts: 9
Reputation: vksingh24 is an unknown quantity at this point 
Solved Threads: 1
vksingh24 vksingh24 is offline Offline
Newbie Poster

Need Suggestion for Live Data

 
0
  #1
26 Days Ago
Hi,

I want to write a small desktop application which will fetch Live stock price from NSE/BSE or Yahoo finance website. In order to create such application I need the guidance that how shoudl I proceed with?

The major problem I am facing is connecting a desktop application with intenet and fetching records.

Any help or guidenace is appreciated
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 3,219
Reputation: sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of sknake has much to be proud of 
Solved Threads: 573
Sponsor
sknake's Avatar
sknake sknake is offline Offline
.NET Enthusiast
 
3
  #2
26 Days Ago
This should get you started:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Web;
  10. using System.Xml;
  11. using System.Net;
  12. using System.IO;
  13.  
  14.  
  15. namespace daniweb
  16. {
  17. public partial class frmStockRSS : Form
  18. {
  19. public frmStockRSS()
  20. {
  21. InitializeComponent();
  22. }
  23.  
  24. private static StockInfo GetStockInfo(string StockTicker)
  25. {
  26. if (string.IsNullOrEmpty(StockTicker))
  27. return null;
  28.  
  29. const string yhoo_url = @"http://download.finance.yahoo.com/d/quotes.csv?s={0}&f=sl1d1t1c1ohgv&e=.csv";
  30. string url = string.Format(yhoo_url, HttpUtility.UrlEncode(StockTicker.ToUpper()));
  31. HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
  32. req.Method = "GET";
  33. req.Referer = string.Empty;
  34.  
  35. HttpWebResponse objResponse = (HttpWebResponse)req.GetResponse();
  36. string resp = default(string);
  37. try
  38. {
  39. using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
  40. {
  41. resp = sr.ReadToEnd();
  42. sr.Close();
  43. }
  44. }
  45. catch (HttpException)
  46. {
  47. return null;
  48. }
  49. catch (IOException)
  50. {
  51. return null;
  52. }
  53.  
  54. StockInfo result = StockInfo.FromYahoo(resp);
  55. return result;
  56. }
  57.  
  58. private void button1_Click(object sender, EventArgs e)
  59. {
  60. StockInfo info = GetStockInfo("GOOG");
  61. Console.WriteLine(info.Ticker + ": " + info.LastTrade);
  62. info = GetStockInfo("YHOO");
  63. Console.WriteLine(info.Ticker + ": " + info.LastTrade);
  64. }
  65. }
  66. public class StockInfo
  67. {
  68. private string _ticker;
  69. private decimal _lastTrade;
  70. private DateTime _tickerTime;
  71. private decimal _change;
  72. private decimal _open;
  73. private decimal _high;
  74. private decimal _low;
  75. private int _unknown;
  76.  
  77. public string Ticker
  78. {
  79. get { return _ticker; }
  80. set { _ticker = value; }
  81. }
  82. public decimal LastTrade
  83. {
  84. get { return _lastTrade; }
  85. set { _lastTrade = value; }
  86. }
  87. public DateTime TickerTime
  88. {
  89. get { return _tickerTime; }
  90. set { _tickerTime = value; }
  91. }
  92. public decimal Change
  93. {
  94. get { return _change; }
  95. set { _change = value; }
  96. }
  97. public decimal Open
  98. {
  99. get { return _open; }
  100. set { _open = value; }
  101. }
  102. public decimal High
  103. {
  104. get { return _high; }
  105. set { _high = value; }
  106. }
  107. public decimal Low
  108. {
  109. get { return _low; }
  110. set { _low = value; }
  111. }
  112. public int Unknown
  113. {
  114. get { return _unknown; }
  115. set { _unknown = value; }
  116. }
  117. private StockInfo()
  118. {
  119. }
  120. public static StockInfo FromYahoo(string s)
  121. {
  122. if (string.IsNullOrEmpty(s))
  123. return null;
  124. s = s.Replace("\"", string.Empty);
  125.  
  126. string[] vals = s.Split(new char[] { ',' }, StringSplitOptions.None);
  127. if (vals.Length != 9)
  128. return null;
  129.  
  130. StockInfo result = new StockInfo();
  131. result.Ticker = vals[0];
  132. result.LastTrade = Convert.ToDecimal(vals[1]);
  133. result.TickerTime = Convert.ToDateTime(vals[2] + " " + vals[3]); //This is very unsafe.
  134. result.Change = Convert.ToDecimal(vals[4]);
  135. result.Open = Convert.ToDecimal(vals[5]);
  136. result.High = Convert.ToDecimal(vals[6]);
  137. result.Low = Convert.ToDecimal(vals[7]);
  138. result.Unknown = Convert.ToInt32(vals[8]); //dont know what this is
  139.  
  140. return result;
  141. }
  142. }
  143. }

Results in:
  1. GOOG: 547.96
  2. YHOO: 15.90
Scott Knake
Custom Software Development
Apex Software, Inc.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC