This commit is contained in:
@@ -5366,32 +5366,89 @@ namespace MarketData.Helper
|
|||||||
return price;
|
return price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static Prices GetDailyPrices(String symbol, DateTime startDate, DateTime endDate)
|
||||||
|
// {
|
||||||
|
// HttpNetResponse httpNetResponse=null;
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if(symbol==null)return null;
|
||||||
|
// CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
|
||||||
|
// if(null!=companyProfile && companyProfile.FreezePricing)
|
||||||
|
// {
|
||||||
|
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// startDate=startDate.Date;
|
||||||
|
// endDate=endDate.Date;
|
||||||
|
// if(startDate>endDate)
|
||||||
|
// {
|
||||||
|
// DateTime tempDate=startDate;
|
||||||
|
// startDate=endDate;
|
||||||
|
// endDate=tempDate;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[MarketDataHelper:GetDailyPrices]{0} start:{1} end:{2}",symbol,Utility.DateTimeToStringMMHDDHYYYY(startDate),Utility.DateTimeToStringMMHDDHYYYY(endDate)));
|
||||||
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
// String strRequest;
|
||||||
|
// Prices prices=null;
|
||||||
|
// sb.Append("https://query1.finance.yahoo.com/v7/finance/chart/").Append(symbol).Append("?period1=").Append(Utility.DateToUnixDate(startDate)).Append("&period2=").Append(Utility.DateToUnixDate(endDate)).Append("&interval=1d&events=history");
|
||||||
|
// strRequest=sb.ToString();
|
||||||
|
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Query:{0}",strRequest));
|
||||||
|
// WebProxy webProxy=HttpNetRequest.GetProxy("GetDailyPrices");
|
||||||
|
// CookieCollection cookieCollection=new CookieCollection();
|
||||||
|
// httpNetResponse=HttpNetRequest.GetRequestNoEncodingV3B(strRequest,cookieCollection,webProxy);
|
||||||
|
// if(!httpNetResponse.Success) return null;
|
||||||
|
// JObject json=JObject.Parse(httpNetResponse.ResponseString);
|
||||||
|
// prices=GetPricesFromJSONString(json,symbol);
|
||||||
|
// return prices;
|
||||||
|
// }
|
||||||
|
// catch(Exception exception)
|
||||||
|
// {
|
||||||
|
// MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception:{0}",exception.ToString()));
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
// finally
|
||||||
|
// {
|
||||||
|
// if(null!=httpNetResponse)httpNetResponse.Dispose();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public static Prices GetDailyPrices(String symbol, DateTime startDate, DateTime endDate)
|
public static Prices GetDailyPrices(String symbol, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
HttpNetResponse httpNetResponse=null;
|
HttpNetResponse httpNetResponse=null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if(symbol==null)return null;
|
if(symbol==null)return null;
|
||||||
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
|
CompanyProfile companyProfile=CompanyProfileDA.GetCompanyProfile(symbol);
|
||||||
if(null!=companyProfile && companyProfile.FreezePricing)
|
if(null!=companyProfile && companyProfile.FreezePricing)
|
||||||
{
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
startDate=startDate.Date;
|
|
||||||
endDate=endDate.Date;
|
|
||||||
if(startDate>endDate)
|
|
||||||
{
|
{
|
||||||
DateTime tempDate=startDate;
|
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Pricing for {0} is frozen.",symbol));
|
||||||
startDate=endDate;
|
return null;
|
||||||
endDate=tempDate;
|
}
|
||||||
|
DateTime period1 = startDate.Date;
|
||||||
|
DateTime period2 = endDate.Date;
|
||||||
|
|
||||||
|
if(period1>period2)
|
||||||
|
{
|
||||||
|
DateTime tempDate=period1;
|
||||||
|
period1=period2;
|
||||||
|
period2=tempDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[MarketDataHelper:GetDailyPrices]{0} start:{1} end:{2}",symbol,Utility.DateTimeToStringMMHDDHYYYY(startDate),Utility.DateTimeToStringMMHDDHYYYY(endDate)));
|
if(period1.Equals(period2))
|
||||||
|
{
|
||||||
|
DateGenerator dateGenerator=new DateGenerator();
|
||||||
|
period1 = dateGenerator.FindPrevBusinessDay(period2);
|
||||||
|
}
|
||||||
|
|
||||||
|
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[MarketDataHelper:GetDailyPrices]{0} start:{1} end:{2}",symbol,Utility.DateTimeToStringMMHDDHYYYY(period1),Utility.DateTimeToStringMMHDDHYYYY(period2)));
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String strRequest;
|
String strRequest;
|
||||||
Prices prices=null;
|
Prices prices=null;
|
||||||
sb.Append("https://query1.finance.yahoo.com/v7/finance/chart/").Append(symbol).Append("?period1=").Append(Utility.DateToUnixDate(startDate)).Append("&period2=").Append(Utility.DateToUnixDate(endDate)).Append("&interval=1d&events=history");
|
|
||||||
|
sb.Append("https://query1.finance.yahoo.com/v7/finance/chart/").Append(symbol).Append("?period1=").Append(Utility.DateToUnixDate(period1)).Append("&period2=").Append(Utility.DateToUnixDate(period2)).Append("&interval=1d&events=history");
|
||||||
|
|
||||||
strRequest=sb.ToString();
|
strRequest=sb.ToString();
|
||||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Query:{0}",strRequest));
|
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Query:{0}",strRequest));
|
||||||
WebProxy webProxy=HttpNetRequest.GetProxy("GetDailyPrices");
|
WebProxy webProxy=HttpNetRequest.GetProxy("GetDailyPrices");
|
||||||
@@ -5400,6 +5457,10 @@ namespace MarketData.Helper
|
|||||||
if(!httpNetResponse.Success) return null;
|
if(!httpNetResponse.Success) return null;
|
||||||
JObject json=JObject.Parse(httpNetResponse.ResponseString);
|
JObject json=JObject.Parse(httpNetResponse.ResponseString);
|
||||||
prices=GetPricesFromJSONString(json,symbol);
|
prices=GetPricesFromJSONString(json,symbol);
|
||||||
|
if(startDate.Date.Equals(endDate.Date))
|
||||||
|
{
|
||||||
|
prices = new Prices(prices.Where(x => x.Date.Date.Equals(startDate.Date)).ToList());
|
||||||
|
}
|
||||||
return prices;
|
return prices;
|
||||||
}
|
}
|
||||||
catch(Exception exception)
|
catch(Exception exception)
|
||||||
@@ -5412,6 +5473,7 @@ namespace MarketData.Helper
|
|||||||
if(null!=httpNetResponse)httpNetResponse.Dispose();
|
if(null!=httpNetResponse)httpNetResponse.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Prices GetPricesFromJSONString(JObject json,String symbol)
|
private static Prices GetPricesFromJSONString(JObject json,String symbol)
|
||||||
{
|
{
|
||||||
Prices prices=new Prices();
|
Prices prices=new Prices();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -254,51 +255,116 @@ namespace MarketData.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static double ParseValue(String strText)
|
||||||
|
// {
|
||||||
|
// double value = double.NaN;
|
||||||
|
// double multiplier = 1.00;
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if (null == strText || 0 == strText.Length) return double.NaN;
|
||||||
|
// strText = strText.Trim();
|
||||||
|
// if (strText.StartsWith("--")) return double.NaN;
|
||||||
|
// if (strText.Equals("N/A")) return double.NaN;
|
||||||
|
// strText = strText.Replace("%", "");
|
||||||
|
// strText = strText.Replace("$", "");
|
||||||
|
// if (strText.Contains("("))
|
||||||
|
// {
|
||||||
|
// strText = strText.Replace("(", "");
|
||||||
|
// strText = strText.Replace(")", "");
|
||||||
|
// multiplier = -1.00;
|
||||||
|
// }
|
||||||
|
// if (strText.Equals("-")) return double.NaN;
|
||||||
|
// if (strText[strText.Length - 1].Equals('T'))
|
||||||
|
// {
|
||||||
|
// strText = strText.Replace("T", "");
|
||||||
|
// value = double.Parse(strText);
|
||||||
|
// value *= 1000000000000;
|
||||||
|
// }
|
||||||
|
// if (strText[strText.Length - 1].Equals('B'))
|
||||||
|
// {
|
||||||
|
// strText = strText.Replace("B", "");
|
||||||
|
// value = double.Parse(strText);
|
||||||
|
// value *= 1000000000;
|
||||||
|
// }
|
||||||
|
// else if (strText[strText.Length - 1].Equals('M'))
|
||||||
|
// {
|
||||||
|
// strText = strText.Replace("M", "");
|
||||||
|
// value = double.Parse(strText);
|
||||||
|
// value *= 1000000;
|
||||||
|
// }
|
||||||
|
// else if (strText[strText.Length - 1].Equals('K') || strText[strText.Length - 1].Equals('k'))
|
||||||
|
// {
|
||||||
|
// strText = strText.Replace("K", "");
|
||||||
|
// strText = strText.Replace("k", "");
|
||||||
|
// value = double.Parse(strText);
|
||||||
|
// value *= 1000;
|
||||||
|
// }
|
||||||
|
// else value = double.Parse(strText);
|
||||||
|
// value *= multiplier;
|
||||||
|
// return value;
|
||||||
|
// }
|
||||||
|
// catch (Exception)
|
||||||
|
// {
|
||||||
|
// MDTrace.WriteLine(LogLevel.DEBUG, "[ParseValue] Error parsing '" + strText + "'");
|
||||||
|
// return double.NaN;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
public static double ParseValue(String strText)
|
public static double ParseValue(String strText)
|
||||||
{
|
{
|
||||||
double value = double.NaN;
|
double value = double.NaN;
|
||||||
double multiplier = 1.00;
|
double multiplier = 1.00;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (null == strText || 0 == strText.Length) return double.NaN;
|
if (null == strText || 0 == strText.Length) return double.NaN;
|
||||||
|
|
||||||
strText = strText.Trim();
|
strText = strText.Trim();
|
||||||
|
strText = strText.Replace(",", "");
|
||||||
|
|
||||||
if (strText.StartsWith("--")) return double.NaN;
|
if (strText.StartsWith("--")) return double.NaN;
|
||||||
if (strText.Equals("N/A")) return double.NaN;
|
if (strText.Equals("N/A")) return double.NaN;
|
||||||
|
|
||||||
strText = strText.Replace("%", "");
|
strText = strText.Replace("%", "");
|
||||||
strText = strText.Replace("$", "");
|
strText = strText.Replace("$", "");
|
||||||
|
|
||||||
if (strText.Contains("("))
|
if (strText.Contains("("))
|
||||||
{
|
{
|
||||||
strText = strText.Replace("(", "");
|
strText = strText.Replace("(", "");
|
||||||
strText = strText.Replace(")", "");
|
strText = strText.Replace(")", "");
|
||||||
multiplier = -1.00;
|
multiplier = -1.00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strText.Length == 0) return double.NaN;
|
||||||
if (strText.Equals("-")) return double.NaN;
|
if (strText.Equals("-")) return double.NaN;
|
||||||
|
|
||||||
if (strText[strText.Length - 1].Equals('T'))
|
if (strText[strText.Length - 1].Equals('T'))
|
||||||
{
|
{
|
||||||
strText = strText.Replace("T", "");
|
strText = strText.Replace("T", "");
|
||||||
value = double.Parse(strText);
|
value = double.Parse(strText, CultureInfo.InvariantCulture);
|
||||||
value *= 1000000000000;
|
value *= 1000000000000;
|
||||||
}
|
}
|
||||||
if (strText[strText.Length - 1].Equals('B'))
|
else if (strText[strText.Length - 1].Equals('B'))
|
||||||
{
|
{
|
||||||
strText = strText.Replace("B", "");
|
strText = strText.Replace("B", "");
|
||||||
value = double.Parse(strText);
|
value = double.Parse(strText, CultureInfo.InvariantCulture);
|
||||||
value *= 1000000000;
|
value *= 1000000000;
|
||||||
}
|
}
|
||||||
else if (strText[strText.Length - 1].Equals('M'))
|
else if (strText[strText.Length - 1].Equals('M'))
|
||||||
{
|
{
|
||||||
strText = strText.Replace("M", "");
|
strText = strText.Replace("M", "");
|
||||||
value = double.Parse(strText);
|
value = double.Parse(strText, CultureInfo.InvariantCulture);
|
||||||
value *= 1000000;
|
value *= 1000000;
|
||||||
}
|
}
|
||||||
else if (strText[strText.Length - 1].Equals('K') || strText[strText.Length - 1].Equals('k'))
|
else if (strText[strText.Length - 1].Equals('K') || strText[strText.Length - 1].Equals('k'))
|
||||||
{
|
{
|
||||||
strText = strText.Replace("K", "");
|
strText = strText.Replace("K", "");
|
||||||
strText = strText.Replace("k", "");
|
strText = strText.Replace("k", "");
|
||||||
value = double.Parse(strText);
|
value = double.Parse(strText, CultureInfo.InvariantCulture);
|
||||||
value *= 1000;
|
value *= 1000;
|
||||||
}
|
}
|
||||||
else value = double.Parse(strText);
|
else value = double.Parse(strText, CultureInfo.InvariantCulture);
|
||||||
|
|
||||||
value *= multiplier;
|
value *= multiplier;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@@ -309,6 +375,8 @@ namespace MarketData.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static long ParseValueLong(String strText)
|
public static long ParseValueLong(String strText)
|
||||||
{
|
{
|
||||||
long value;
|
long value;
|
||||||
|
|||||||
Reference in New Issue
Block a user