Add BarChart supplemental feed
This commit is contained in:
@@ -165,47 +165,15 @@ namespace MarketData.Helper
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdatePricesBigCharts]End, total took {0}(ms)",profiler.End()));
|
||||
}
|
||||
}
|
||||
public bool UpdatePricesYahooSweep(DateTime? startDate=null) // get prices from Yahoo
|
||||
{
|
||||
Profiler profiler=new Profiler();
|
||||
try
|
||||
{
|
||||
symbols=PricingDA.GetSymbols();
|
||||
currentIndex=0;
|
||||
if(null==startDate) startDate=DateTime.Now;
|
||||
while(true)
|
||||
{
|
||||
List<String> queueSymbols=GetQueueSymbols();
|
||||
if(null==queueSymbols||0==queueSymbols.Count) break;
|
||||
ManualResetEvent[] resetEvents=new ManualResetEvent[queueSymbols.Count];
|
||||
for(int eventIndex=0;eventIndex<resetEvents.Length;eventIndex++)
|
||||
{
|
||||
resetEvents[eventIndex]=new ManualResetEvent(false);
|
||||
}
|
||||
for(int index=0;index<queueSymbols.Count;index++)
|
||||
{
|
||||
PricingThreadHelper pricingThreadHelper=new PricingThreadHelper(queueSymbols[index],startDate.Value,resetEvents[index]);
|
||||
ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesYahooSweep,pricingThreadHelper);
|
||||
try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;}
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesYahooSweep, waiting for queued items to complete.");
|
||||
WaitHandle.WaitAll(resetEvents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdatePricesYahooSweep]End, total took {0}(ms)",profiler.End()));
|
||||
}
|
||||
}
|
||||
public bool UpdatePricesAsOfSymbol(String symbol,DateTime asOf) // get prices from BigCharts
|
||||
|
||||
public bool UpdatePricesYahooSweep(DateTime? startDate = null) // get prices from Yahoo
|
||||
{
|
||||
Profiler profiler=new Profiler();
|
||||
Profiler profiler = new Profiler();
|
||||
try
|
||||
{
|
||||
symbols=new List<String>();
|
||||
symbols.Add(symbol);
|
||||
currentIndex=0;
|
||||
symbols = PricingDA.GetSymbols();
|
||||
currentIndex = 0;
|
||||
if (null == startDate) startDate = DateTime.Now;
|
||||
while (true)
|
||||
{
|
||||
List<String> queueSymbols = GetQueueSymbols();
|
||||
@@ -217,19 +185,92 @@ namespace MarketData.Helper
|
||||
}
|
||||
for (int index = 0; index < queueSymbols.Count; index++)
|
||||
{
|
||||
PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], resetEvents[index],asOf);
|
||||
ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesAsOf, pricingThreadHelper);
|
||||
try{Thread.Sleep(WaitBetweenRequests);}catch(Exception){;}
|
||||
PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], startDate.Value, resetEvents[index]);
|
||||
ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesYahooSweep, pricingThreadHelper);
|
||||
try { Thread.Sleep(WaitBetweenRequests); } catch (Exception) {; }
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"UpdatePricesAsOfSymbol, waiting for queued items to complete.");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "UpdatePricesYahooSweep, waiting for queued items to complete.");
|
||||
WaitHandle.WaitAll(resetEvents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("[UpdatePricesAsOfSymbol]End, total took {0}(ms)",profiler.End()));
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("[UpdatePricesYahooSweep]End, total took {0}(ms)", profiler.End()));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UpdatePricesBarChartSweep - This feed will retrieve latest price. It will not use a date
|
||||
/// </summary>
|
||||
/// <param name="startDate"></param>
|
||||
/// <returns></returns>
|
||||
public bool UpdatePricesBarChartSweep(DateTime? startDate = null) // get prices from BarCharts
|
||||
{
|
||||
Profiler profiler = new Profiler();
|
||||
try
|
||||
{
|
||||
symbols = PricingDA.GetSymbols();
|
||||
if (null == startDate) startDate = DateTime.Now;
|
||||
currentIndex = 0;
|
||||
while (true)
|
||||
{
|
||||
List<String> queueSymbols = GetQueueSymbols();
|
||||
if (null == queueSymbols || 0 == queueSymbols.Count) break;
|
||||
ManualResetEvent[] resetEvents = new ManualResetEvent[queueSymbols.Count];
|
||||
for (int eventIndex = 0; eventIndex < resetEvents.Length; eventIndex++)
|
||||
{
|
||||
resetEvents[eventIndex] = new ManualResetEvent(false);
|
||||
}
|
||||
for (int index = 0; index < queueSymbols.Count; index++)
|
||||
{
|
||||
PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], startDate.Value, resetEvents[index]);
|
||||
ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesBarChartSweep, pricingThreadHelper);
|
||||
try { Thread.Sleep(WaitBetweenRequests); } catch (Exception) {; }
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "UpdatePricesBarChartSweep, waiting for queued items to complete.");
|
||||
WaitHandle.WaitAll(resetEvents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("[UpdatePricesBarChartSweep]End, total took {0}(ms)", profiler.End()));
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdatePricesAsOfSymbol(String symbol, DateTime asOf) // get prices from BigCharts
|
||||
{
|
||||
Profiler profiler = new Profiler();
|
||||
try
|
||||
{
|
||||
symbols = new List<String>();
|
||||
symbols.Add(symbol);
|
||||
currentIndex = 0;
|
||||
while (true)
|
||||
{
|
||||
List<String> queueSymbols = GetQueueSymbols();
|
||||
if (null == queueSymbols || 0 == queueSymbols.Count) break;
|
||||
ManualResetEvent[] resetEvents = new ManualResetEvent[queueSymbols.Count];
|
||||
for (int eventIndex = 0; eventIndex < resetEvents.Length; eventIndex++)
|
||||
{
|
||||
resetEvents[eventIndex] = new ManualResetEvent(false);
|
||||
}
|
||||
for (int index = 0; index < queueSymbols.Count; index++)
|
||||
{
|
||||
PricingThreadHelper pricingThreadHelper = new PricingThreadHelper(queueSymbols[index], resetEvents[index], asOf);
|
||||
ThreadPool.QueueUserWorkItem(ThreadPoolCallbackUpdatePricesAsOf, pricingThreadHelper);
|
||||
try { Thread.Sleep(WaitBetweenRequests); } catch (Exception) {; }
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "UpdatePricesAsOfSymbol, waiting for queued items to complete.");
|
||||
WaitHandle.WaitAll(resetEvents);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
finally
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("[UpdatePricesAsOfSymbol]End, total took {0}(ms)", profiler.End()));
|
||||
}
|
||||
}
|
||||
public bool UpdatePriceAsOfSymbolYahoo(String symbol,DateTime asOf) // get prices from Yahoo
|
||||
{
|
||||
@@ -492,19 +533,33 @@ namespace MarketData.Helper
|
||||
{
|
||||
pricingThreadHelper.ResetEvent.Set();
|
||||
}
|
||||
}
|
||||
public void ThreadPoolCallbackUpdatePricesBarChartSweep(Object pricingThreadHelperContext)
|
||||
{
|
||||
PricingThreadHelper pricingThreadHelper=(PricingThreadHelper)pricingThreadHelperContext;
|
||||
try
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (BarChart), Thread {0} started for {1}...",Thread.CurrentThread.ManagedThreadId,pricingThreadHelper.Symbol));
|
||||
UpdatePriceBarChartSweep(pricingThreadHelper.Symbol,pricingThreadHelper.PricingDate);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price (BarChart), Thread {0} ended for {1}",Thread.CurrentThread.ManagedThreadId,pricingThreadHelper.Symbol));
|
||||
}
|
||||
finally
|
||||
{
|
||||
pricingThreadHelper.ResetEvent.Set();
|
||||
}
|
||||
}
|
||||
public void ThreadPoolCallbackUpdatePricesAsOf(Object pricingThreadHelperContext)
|
||||
{
|
||||
PricingThreadHelper pricingThreadHelper = (PricingThreadHelper)pricingThreadHelperContext;
|
||||
PricingThreadHelper pricingThreadHelper = (PricingThreadHelper)pricingThreadHelperContext;
|
||||
try
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price, Thread {0} started for {1}...", Thread.CurrentThread.ManagedThreadId, pricingThreadHelper.Symbol));
|
||||
UpdatePriceAsOfEx(pricingThreadHelper.Symbol,pricingThreadHelper.StartDate.Value);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Load price, Thread {0} ended for {1}", Thread.CurrentThread.ManagedThreadId, pricingThreadHelper.Symbol));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Load price, Thread {0} started for {1}...", Thread.CurrentThread.ManagedThreadId, pricingThreadHelper.Symbol));
|
||||
UpdatePriceAsOfEx(pricingThreadHelper.Symbol, pricingThreadHelper.StartDate.Value);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Load price, Thread {0} ended for {1}", Thread.CurrentThread.ManagedThreadId, pricingThreadHelper.Symbol));
|
||||
}
|
||||
finally
|
||||
{
|
||||
pricingThreadHelper.ResetEvent.Set();
|
||||
pricingThreadHelper.ResetEvent.Set();
|
||||
}
|
||||
}
|
||||
public void ThreadPoolCallbackGetMissingPrice(Object pricingThreadHelperContext)
|
||||
@@ -733,7 +788,7 @@ namespace MarketData.Helper
|
||||
price=MarketDataHelper.GetDailyPrice(symbol,pricingDate);
|
||||
if(null==price)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"No price (UpdatePriceYahoo) for '"+symbol+"'");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"No price (UpdatePriceYahooSweep) for '"+symbol+"'");
|
||||
return;
|
||||
}
|
||||
else if(!price.IsValid)
|
||||
@@ -752,35 +807,86 @@ namespace MarketData.Helper
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Exception {0}",exception.ToString()));
|
||||
}
|
||||
}
|
||||
public static void UpdatePriceAsOfEx(String symbol,DateTime asOf)
|
||||
/// <summary>
|
||||
/// This feed is intended to supplement BigCharts and Yahoo feed.
|
||||
/// It should run in the UPDATEDAILY2 chain after Yahoo during the nightly price capture.
|
||||
/// It will only retrieve price for the current date AND it expects us to have a price for the previous business date.
|
||||
/// In other words it will not fill pricing gaps, it will only add "tonights" price to an already established pricing history
|
||||
/// </summary>
|
||||
/// <param name="symbol"></param>
|
||||
/// <param name="pricingDate"></param>
|
||||
public static void UpdatePriceBarChartSweep(String symbol, DateTime pricingDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
DateTime prevBusinessDay = dateGenerator.FindPrevBusinessDay(pricingDate);
|
||||
Price price = PricingDA.GetPrice(symbol); // retrieve the latest price for this symbol
|
||||
if (null == price) // we don't have a price for the symbol so return
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (price.Date.Date.Equals(pricingDate.Date))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, $"Already have latest price for {symbol} on {price.Date.ToShortDateString()}");
|
||||
return;
|
||||
}
|
||||
if (!prevBusinessDay.Date.Equals(price.Date.Date))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, $"Expected a date of {prevBusinessDay.ToShortDateString()} for {symbol} but found {price.Date.ToShortDateString()}");
|
||||
return;
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,$"Latest price for {symbol} is {price.Date.Date.ToShortDateString()}");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("UpdatePriceBarChartSweep: Requesting latest price for {0} ", symbol));
|
||||
price = MarketDataHelper.GetLatestPriceBarChart(symbol);
|
||||
if (null == price)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "(UpdatePriceBarChartSweep) No price for '" + symbol + "'");
|
||||
return;
|
||||
}
|
||||
else if (!price.IsValid)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "(UpdatePriceBarChartSweep) Invalid price for '" + symbol + "'");
|
||||
return;
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("(UpdatePriceBarChartSweep) Inserting price {0}...", price.ToString()));
|
||||
PricingDA.InsertPrice(price);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("(UpdatePriceBarChartSweep) Exception {0}", exception.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdatePriceAsOfEx(String symbol, DateTime asOf)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime latestDate = PricingDA.GetLatestDate(symbol);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Latest pricing date for {0} is {1}",symbol,latestDate.ToShortDateString()));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Latest pricing date for {0} is {1}", symbol, latestDate.ToShortDateString()));
|
||||
if (latestDate.Equals(asOf))
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"Already have price for '" + symbol + "' on "+Utility.DateTimeToStringMMHDDHYYYY(asOf));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "Already have price for '" + symbol + "' on " + Utility.DateTimeToStringMMHDDHYYYY(asOf));
|
||||
return;
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Retrieving price for {0} on {1} from BigCharts",symbol,asOf.ToShortDateString()));
|
||||
Price price = MarketDataHelper.GetPriceAsOf(symbol,asOf);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Retrieving price for {0} on {1} from BigCharts", symbol, asOf.ToShortDateString()));
|
||||
Price price = MarketDataHelper.GetPriceAsOf(symbol, asOf);
|
||||
if (null == price)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Error retrieving price for {0} on {1}",symbol,asOf.ToShortDateString()));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Error retrieving price for {0} on {1}", symbol, asOf.ToShortDateString()));
|
||||
return;
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,Price.Header);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,price.ToString());
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("Inserting price {0}...",price.ToString()));
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, Price.Header);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, price.ToString());
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, String.Format("Inserting price {0}...", price.ToString()));
|
||||
PricingDA.InsertPrice(price);
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,"");
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, "");
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
MDTrace.WriteLine(LogLevel.DEBUG,exception.ToString());
|
||||
MDTrace.WriteLine(LogLevel.DEBUG, exception.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadPricesSymbolEx(String symbol,DateTime pricingDate)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user