| | |
Need Suggestion for Live Data
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2009
Posts: 9
Reputation:
Solved Threads: 1
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
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
3
#2 26 Days Ago
This should get you started:
Results in:
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Web; using System.Xml; using System.Net; using System.IO; namespace daniweb { public partial class frmStockRSS : Form { public frmStockRSS() { InitializeComponent(); } private static StockInfo GetStockInfo(string StockTicker) { if (string.IsNullOrEmpty(StockTicker)) return null; const string yhoo_url = @"http://download.finance.yahoo.com/d/quotes.csv?s={0}&f=sl1d1t1c1ohgv&e=.csv"; string url = string.Format(yhoo_url, HttpUtility.UrlEncode(StockTicker.ToUpper())); HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url); req.Method = "GET"; req.Referer = string.Empty; HttpWebResponse objResponse = (HttpWebResponse)req.GetResponse(); string resp = default(string); try { using (StreamReader sr = new StreamReader(objResponse.GetResponseStream())) { resp = sr.ReadToEnd(); sr.Close(); } } catch (HttpException) { return null; } catch (IOException) { return null; } StockInfo result = StockInfo.FromYahoo(resp); return result; } private void button1_Click(object sender, EventArgs e) { StockInfo info = GetStockInfo("GOOG"); Console.WriteLine(info.Ticker + ": " + info.LastTrade); info = GetStockInfo("YHOO"); Console.WriteLine(info.Ticker + ": " + info.LastTrade); } } public class StockInfo { private string _ticker; private decimal _lastTrade; private DateTime _tickerTime; private decimal _change; private decimal _open; private decimal _high; private decimal _low; private int _unknown; public string Ticker { get { return _ticker; } set { _ticker = value; } } public decimal LastTrade { get { return _lastTrade; } set { _lastTrade = value; } } public DateTime TickerTime { get { return _tickerTime; } set { _tickerTime = value; } } public decimal Change { get { return _change; } set { _change = value; } } public decimal Open { get { return _open; } set { _open = value; } } public decimal High { get { return _high; } set { _high = value; } } public decimal Low { get { return _low; } set { _low = value; } } public int Unknown { get { return _unknown; } set { _unknown = value; } } private StockInfo() { } public static StockInfo FromYahoo(string s) { if (string.IsNullOrEmpty(s)) return null; s = s.Replace("\"", string.Empty); string[] vals = s.Split(new char[] { ',' }, StringSplitOptions.None); if (vals.Length != 9) return null; StockInfo result = new StockInfo(); result.Ticker = vals[0]; result.LastTrade = Convert.ToDecimal(vals[1]); result.TickerTime = Convert.ToDateTime(vals[2] + " " + vals[3]); //This is very unsafe. result.Change = Convert.ToDecimal(vals[4]); result.Open = Convert.ToDecimal(vals[5]); result.High = Convert.ToDecimal(vals[6]); result.Low = Convert.ToDecimal(vals[7]); result.Unknown = Convert.ToInt32(vals[8]); //dont know what this is return result; } } }
Results in:
text Syntax (Toggle Plain Text)
GOOG: 547.96 YHOO: 15.90
![]() |
Similar Threads
- Reporting Live Online Data (Growing an Online Community)
- How to display data with the same format entered into the textarea (PHP)
- Display live data in JTextArea (Java)
- retrieving live information from other sites (PHP)
Other Threads in the C# Forum
- Previous Thread: How to display values from database into datagridview
- Next Thread: From Javascript calling a Class in CS
| Thread Tools | Search this Thread |
.net access activedirectory ado.net algorithm array barchart basic bitmap box broadcast buttons c# check checkbox client combobox contorl control conversion csharp custom database datagrid datagridview dataset datetime degrees deployment development disabled displayingopenforms draganddrop drawing editing editor encryption enum event excel file form format forms function gdi+ httpwebrequest i18n image imageprocessing index input install java label list listbox mandelbrot math mathematics mouseclick mysql operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox rows server sleep socket sql statistics stream string table text textbox thread time timer update user usercontrol validation visualstudio webbrowser windows winforms wpf xml






