We can fetch real time intraday data from google(1min) finanace.
Following is the procedure for geeting the data.
Following is the Url for getting the realtime backfill data which most of the trading softwares are using as a source for realtime datafeed
q= stock symbol on Google finance
x= exchange symbol
i= interval (in secs)
p= no of period(here 5d denotes 5 days of data)
year -- > 5Y
month --> 5M
Minute --> 5m
f= parameters (day, close, open, high,low& Volume)
df= difference (cpct is may be in % change )
auto =1,
ts = time start… if you cut the last 4 digits…the rest gives the start day in seconds
you can choose your own set of value depending upon your need.
The following link gives the 1 min Realtime data for Nifty
Using the above procdure we can make any formats(1min,5min, 15min,hourly) of real time data and can be use as a backfill
to feed charting softwares like Amibroker, Metastock, Ninja Trader etc
Following is the C# code for make the above URL.
public enum Interval { OneMin = 60, FiveMin = 300, OneDay = 3600 }
/// <summary>
/// Returns a URI to invoke the getPrices method.
/// </summary>
public string getGetPricesUri(string StockExchange,string Symbol,Interval interval, string period)
{
if (String.IsNullOrEmpty(period))
throw new ArgumentException("No 'period'.");
string formatURI = BASE_URL + "?q={0}{1}&i={2}&p={3}&f=d,c,h,l,o,v";
string exchangeString = string.Empty;
if (!String.IsNullOrEmpty(StockExchange))
{
exchangeString = "&x=" + StockExchange;
}
int _interval = 3600;
switch (interval)
{
case Interval.OneDay:
_interval = 3600;
break;
case Interval.OneMin:
_interval = 60;
break;
case Interval.FiveMin:
_interval = 300;
break;
}
return String.Format(formatURI, Symbol, exchangeString, _interval, period);
}
/// <summary>
/// Method invoked by getGetPricesUriForRecentData().
/// </summary>
public string getPeriod(DateTime startDate, DateTime endDate)
{
if (endDate.Date < startDate.Date)
{
throw new ArgumentException("The ending date can't be lower than the starting date.");
}
if (endDate.Year > startDate.Year)
{ //More than a year.
return (endDate.Year - startDate.Year + 1) + "Y";
}
TimeSpan span = endDate - startDate;
if (span.Days > 50)
{ //Return months.
return ((span.Days % 25) + 1) + "M";
}
else if(span.TotalHours > 20)
{ //Return days.
return (span.Days + 1) + "d"; //+1 because, depending on the hour, no data might be retrieved (1d is for today).
}
else
{ //Return days.
return (span.Minutes + 1) + "m"; //+1 because, depending on the hour, no data might be retrieved (1d is for today).
}
}
// call the function
getGetPricesUri("NSE","NSEI", Interval.OneMin,getPeriod(DateTime.Now.AddDays(-15), DateTime.Now));