Add BarChart supplemental feed
This commit is contained in:
@@ -5101,9 +5101,98 @@ namespace MarketData.Helper
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetLatestPriceBarChart - This is a new feed I am implementing because I am having difficulty retrieving prices from MarketWatch(BigCharts)
|
||||
/// I am planning to use this field initially as a sweep to run after the BigCharts feed and prior to the Yahoo Sweep
|
||||
/// </summary>
|
||||
/// <param name="symbol"></param>
|
||||
/// <returns></returns>
|
||||
public static Price GetLatestPriceBarChart(String symbol)
|
||||
{
|
||||
HttpNetResponse httpNetResponse = null;
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String strRequest;
|
||||
if (null == symbol) return null;
|
||||
|
||||
sb = new StringBuilder();
|
||||
sb.Append("https://www.barchart.com/stocks/quotes/").Append(symbol).Append("/overview");
|
||||
strRequest = sb.ToString();
|
||||
WebProxy webProxy = HttpNetRequest.GetProxy("GetLatestPriceBarChart");
|
||||
httpNetResponse = HttpNetRequest.GetRequestNoEncodingV3C(strRequest, webProxy);
|
||||
if (!httpNetResponse.Success)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("GetLatestPriceBarChart: Request:{0} failed with status {1}", httpNetResponse.Request, httpNetResponse.StatusCode));
|
||||
return null;
|
||||
}
|
||||
String beginMarker = "data-ng-init='init(\"" + symbol + "\"";
|
||||
String endMarker = ">";
|
||||
String item = Utility.BetweenString(httpNetResponse.ResponseString, beginMarker, endMarker);
|
||||
if (null == item) return null;
|
||||
item = item.Replace(""", "\"");
|
||||
item = item.Replace("{", null);
|
||||
item = item.Replace("}", null);
|
||||
String[] pairs = item.Split(",");
|
||||
Dictionary<String, double> values = CreateBarChartValues(pairs);
|
||||
Price price = new Price();
|
||||
price.Symbol = symbol;
|
||||
price.Date = DateTime.Now;
|
||||
price.Source = Price.PriceSource.BarChart;
|
||||
if (values.ContainsKey("lowPrice")) price.Low = values["lowPrice"];
|
||||
if (values.ContainsKey("highPrice")) price.High = values["highPrice"];
|
||||
if (values.ContainsKey("openPrice")) price.Open = values["openPrice"];
|
||||
if (values.ContainsKey("lastPrice")) price.Close = values["lastPrice"];
|
||||
if (values.ContainsKey("volume")) price.Volume = (long)values["volume"];
|
||||
if (values.ContainsKey("prevClose")) price.PrevClose = values["prevClose"];
|
||||
else price.PrevClose = price.Close;
|
||||
price.AdjClose = price.Close;
|
||||
MarketDataHelper.CheckPrice(price);
|
||||
if (double.IsNaN(price.Open) && double.IsNaN(price.High) && double.IsNaN(price.Low) && double.IsNaN(price.Close))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("*** No closing price for {0}", price.Symbol));
|
||||
return null;
|
||||
}
|
||||
if (double.IsNaN(price.Open)) price.Open = 0.00;
|
||||
if (double.IsNaN(price.Low)) price.Low = 0.00;
|
||||
if (double.IsNaN(price.High)) price.High = 0.00;
|
||||
if (0 != price.Close && 0 == price.Open && 0 == price.High && 0 == price.Low)
|
||||
{
|
||||
price.Open = price.High = price.Low = price.Close;
|
||||
}
|
||||
return price;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, exception.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Dictionary<String, double> CreateBarChartValues(String[] pairs)
|
||||
{
|
||||
Dictionary<String, double> barChartValues = new Dictionary<String, double>();
|
||||
if (null == pairs || 0 == pairs.Length) return barChartValues;
|
||||
foreach (String item in pairs)
|
||||
{
|
||||
String[] nameValue = item.Split(":");
|
||||
if (null == nameValue || 2 != nameValue.Length) continue;
|
||||
String name = nameValue[0].Replace("\"", null);
|
||||
String value = nameValue[1].Replace("\"",null);
|
||||
double result = 0.00;
|
||||
if (barChartValues.ContainsKey(name)) continue;
|
||||
if (double.TryParse(value, out result))
|
||||
{
|
||||
barChartValues.Add(name, result);
|
||||
}
|
||||
}
|
||||
return barChartValues;
|
||||
}
|
||||
|
||||
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// ************************************************************** H I S T O R I C A L P R I C E S - B I G C H A R T S ********************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
// ************************************************************** H I S T O R I C A L P R I C E S - B I G C H A R T S ********************************************************
|
||||
// *******************************************************************************************************************************************************************************
|
||||
/// <summary>
|
||||
/// Gets historical pricing from BigCharts
|
||||
/// </summary>
|
||||
@@ -5111,24 +5200,25 @@ namespace MarketData.Helper
|
||||
/// <param name="startDate">Most recent date</param>
|
||||
/// <param name="endDate">Most historical date</param>
|
||||
/// <returns>Prices</returns>
|
||||
public static Prices GetPricesAsOf(String symbol, DateTime startDate,DateTime endDate)
|
||||
public static Prices GetPricesAsOf(String symbol, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
Prices prices=new Prices();
|
||||
Prices prices = new Prices();
|
||||
|
||||
if(null==symbol)return null;
|
||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
|
||||
if(null!=companyProfile && companyProfile.FreezePricing)
|
||||
if (null == symbol) return null;
|
||||
CompanyProfile companyProfile = CompanyProfileDA.GetCompanyProfile(symbol);
|
||||
if (null != companyProfile && companyProfile.FreezePricing)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Pricing for {0} is frozen.", symbol));
|
||||
return null;
|
||||
}
|
||||
DateGenerator dateGenerator=new DateGenerator();
|
||||
List<DateTime> dates=dateGenerator.GenerateHistoricalDates(startDate,endDate);
|
||||
for(int index=0;index<dates.Count;index++)
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
List<DateTime> dates = dateGenerator.GenerateHistoricalDates(startDate, endDate);
|
||||
for (int index = 0; index < dates.Count; index++)
|
||||
{
|
||||
DateTime currentDate=dates[index];
|
||||
Price price=GetPriceAsOf(symbol,currentDate);
|
||||
if(null==price){MDTrace.WriteLine(LogLevel.DEBUG,String.Format("No data for {0} on {1}",symbol,Utility.DateTimeToStringMMHDDHYYYY(currentDate)));continue;};
|
||||
DateTime currentDate = dates[index];
|
||||
Price price = GetPriceAsOf(symbol, currentDate);
|
||||
if (null == price) { MDTrace.WriteLine(LogLevel.DEBUG, String.Format("No data for {0} on {1}", symbol, Utility.DateTimeToStringMMHDDHYYYY(currentDate))); continue; }
|
||||
;
|
||||
prices.Add(price);
|
||||
}
|
||||
return prices;
|
||||
|
||||
Reference in New Issue
Block a user