本文整理汇总了C#中OpenQuant.API.Bar.IsSessionOpenBar方法的典型用法代码示例。如果您正苦于以下问题:C# Bar.IsSessionOpenBar方法的具体用法?C# Bar.IsSessionOpenBar怎么用?C# Bar.IsSessionOpenBar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQuant.API.Bar
的用法示例。
在下文中一共展示了Bar.IsSessionOpenBar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReloadDailyData
/*
protected void ReloadDailyData()
{
DateTime start = DateTime.Now;
DailyBarSeries = GetHistoricalBars("IB", Instrument, DateTime.Now.AddDays(-60), DateTime.Now, PeriodConstants.PERIOD_DAILY);
DateTime end = DateTime.Now;
LoggingUtility.WriteDebug(LoggingConfig, string.Format("Took {0}ms to retrieve data from IB for daily data", end.Subtract(start).TotalMilliseconds));
start = DateTime.Now;
foreach (Bar currentBar in DailyBarSeries)
{
Bars.Add(currentBar);
if (PersistHistoricalData)
DataManager.Add(Instrument, currentBar);
}
end = DateTime.Now;
LoggingUtility.WriteVerbose(LoggingConfig, string.Format("Took {0}ms to load data into memory for daily data", end.Subtract(start).TotalMilliseconds));
}*/
protected Bar GetPreviousBar(Bar bar, int period)
{
Bar retVal = null;
BarSeries barsToUse = null;
bool isSessionOpenBar = bar.IsSessionOpenBar(Instrument.Type);
bool isDailyPeriod = period == PeriodConstants.PERIOD_DAILY;
if (isDailyPeriod)
return GetPreviousDayBar();
barsToUse = MinutelyBarSeries;
if (barsToUse.Count > 0)
{
int idx = 0;
bool found = false;
while (!found && idx <= barsToUse.Count - 1)
{
Bar prevBar = barsToUse.Ago(idx);
if ((prevBar.EndTime <= bar.BeginTime) && prevBar.IsWithinRegularTradingHours(Instrument.Type))
{
if (isSessionOpenBar || isDailyPeriod)
{
found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 1;
if (!found && DateTime.Now.IsPastRegularTradingHours(Instrument.Type))
found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 0;
}
else
{
found = true;
}
}
if (found)
retVal = prevBar;
else
idx++;
}
}
if (retVal == null)
throw new ApplicationException(string.Format("Count not retreive a period {0} bar to {1}. If it is due to exchange holidays - then set the 'DaysToGoBackForMinutelyData' parameter to fetch more data.", period, bar));
LoggingUtility.WriteInfo(LoggingConfig, string.Format("Previous closing bar was {0}", retVal));
return retVal;
}
示例2: GetPreviousBar
/// <summary>
///
/// </summary>
/// <param name="bar"></param>
/// <returns></returns>
protected Bar GetPreviousBar(Instrument instrument, Bar bar, int period)
{
Bar retVal = null;
BarSeries barsToUse = null;
string instId = instrument.ToIdentifier();
Dictionary<string, BarSeries> dictionaryToUse = null;
bool isSessionOpenBar = bar.IsSessionOpenBar(Instrument.Type);
bool isDailyPeriod = period == PeriodConstants.PERIOD_DAILY;
if (isDailyPeriod) // || isSessionOpenBar
dictionaryToUse = dailyBarSeriesDictionary;
else
dictionaryToUse = minutelyBarSeriesDictionary;
barsToUse = dictionaryToUse[instId];
if (barsToUse.Count > 0)
{
int idx = 0;
bool found = false;
while (!found && idx <= barsToUse.Count - 1)
{
Bar prevBar = barsToUse.Ago(idx);
if ((prevBar.EndTime <= bar.BeginTime) && prevBar.IsWithinRegularTradingHours(Instrument.Type))
{
if (isSessionOpenBar || isDailyPeriod)
{
found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 1;
if (!found && DateTime.Now.IsPastRegularTradingHours(Instrument.Type))
found = DateTime.Today.Subtract(prevBar.BeginTime.Date).TotalDays >= 0;
}
else
{
found = true;
}
}
if (found)
retVal = prevBar;
else
idx++;
}
}
if (retVal == null)
throw new ApplicationException(string.Format("Count not retreive a period {0} bar to {1}", period, bar));
LoggingUtility.WriteDebug(LoggingConfig, string.Format("Previous closing bar was {0}", retVal));
return retVal;
}