Class Day
Day represents a continuous period of time approximately 24 hours long. The day is aligned to the start and the end of business activities of a certain business entity or business process. For example, the day may be aligned to a trading schedule of a particular instrument on an exchange. Thus, different days may start and end at various local times depending on the related trading schedules.
The length of the day depends on the trading schedule and other circumstances. For example, it is possible that day for Monday is longer than 24 hours because it includes part of Sunday; consequently, the day for Sunday will be shorter than 24 hours to avoid overlapping with Monday. Days do not overlap with each other - rather they form consecutive chain of adjacent periods of time that cover entire time scale. The point on a border line is considered to belong to following day that starts there. Each day consists of sessions that cover entire duration of the day. If day contains at least one trading session (i.e. session within which trading activity is allowed), then the day is considered trading day. Otherwise the day is considered non-trading day (e.g. weekend or holiday). Day may contain sessions with zero duration - e.g. indices that post value once a day. Such sessions can be of any appropriate type, trading or non-trading. Day may have zero duration as well - e.g. when all time within it is transferred to other days.public class Day
- Inheritance
-
Day
- Inherited Members
Properties
DayId
Gets number of this day since January 1, 1970. (that day has identifier of 0 and previous days have negative identifiers).
public int DayId { get; }
Property Value
DayOfMonth
Gets ordinal day number in the month starting with 1 for the first day of month.
public int DayOfMonth { get; }
Property Value
DayOfWeek
Gets ordinal day number in the week starting with 1=Monday and ending with 7=Sunday.
public int DayOfWeek { get; }
Property Value
EndTime
Gets end time of this day (exclusive).
public long EndTime { get; }
Property Value
IsHoliday
Gets a value indicating whether this day is an exchange holiday. Usually there are no trading takes place on an exchange holiday.
public bool IsHoliday { get; }
Property Value
IsShortDay
Gets a value indicating whether this day is a short day. Usually trading stops earlier on a short day.
public bool IsShortDay { get; }
Property Value
IsTrading
Gets a value indicating whether trading activity is allowed within this day. Positive result assumes that day has at least one trading session.
public bool IsTrading { get; }
Property Value
MonthOfYear
Gets calendar month number in the year starting with 1=January and ending with 12=December.
public int MonthOfYear { get; }
Property Value
ResetTime
Gets reset time for this day. Reset of daily data is performed on trading days only, the result has no meaning for non-trading days.
public long ResetTime { get; }
Property Value
Schedule
Gets schedule to which this day belongs.
public Schedule Schedule { get; }
Property Value
StartTime
Gets start time of this day (inclusive).
public long StartTime { get; }
Property Value
Year
Gets calendar year - i.e. it returns 1977
for the year 1977
.
public int Year { get; }
Property Value
YearMonthDay
Gets year, month and day numbers decimally packed in the following way:
YearMonthDay = year * 10000 + month * 100 + day
public int YearMonthDay { get; }
Property Value
Examples
September 28, 1977 has value 19770928.
Methods
ContainsTime(long)
Determines whether a specified time falls within the current day.
public bool ContainsTime(long time)
Parameters
time
longThe time to check
Returns
- bool
true
if the specified time is within the start and end time of the day; otherwise,false
.
Equals(object?)
Indicates whether some other object is "equal to" this one.
public override bool Equals(object? obj)
Parameters
obj
objectThe object to compare with the current object.
Returns
- bool
true
if the specified object is equal to the current object; otherwise,false
.
GetFirstSession(SessionFilter)
Gets the first session of the day that is accepted by the specified filter, or null if no such session is found.
public Session? GetFirstSession(SessionFilter filter)
Parameters
filter
SessionFilterThe filter used to evaluate sessions.
Returns
- Session
The first session of the day that meets the filter criteria; otherwise, null.
GetHashCode()
Gets a hash code value for this object.
public override int GetHashCode()
Returns
- int
A hash code value for this object.
GetLastSession(SessionFilter)
Gets the last session of the day that is accepted by the specified filter, or null if no such session is found.
public Session? GetLastSession(SessionFilter filter)
Parameters
filter
SessionFilterThe filter used to evaluate sessions.
Returns
- Session
The last session of the day that meets the filter criteria; otherwise, null.
GetNextDay(DayFilter)
Gets the following day that is accepted by the specified filter, if such a day exists.
public Day? GetNextDay(DayFilter filter)
Parameters
filter
DayFilterThe filter used to determine the suitability of days.
Returns
- Day
The nearest following day that meets the filter criteria; otherwise,
null
if no suitable day is found within the search period of up to a year in the future.
Remarks
This method provides a convenient way to access the next day without handling the output parameter directly.
GetPrevDay(DayFilter)
Gets the previous day that is accepted by the specified filter, if such a day exists.
public Day? GetPrevDay(DayFilter filter)
Parameters
filter
DayFilterThe filter used to evaluate each day.
Returns
- Day
The nearest previous day that meets the filter criteria; otherwise,
null
if no suitable day is found within the search period of up to a year back in time.
Remarks
This method provides a convenient way to access the previous day without handling the output parameter directly.
GetSessionByTime(long)
Gets session belonging to this day that contains specified time.
public Session GetSessionByTime(long time)
Parameters
time
longThe time to search for.
Returns
- Session
The session that contains specified time.
Exceptions
- JavaException
If no such session was found within this day.
GetSessions()
Gets list of sessions that constitute this day. This method will throw JavaException if specified time falls outside of valid date range from 0001-01-02 to 9999-12-30. The list is ordered according to natural order of sessions - how they occur one after another.
public IEnumerable<Session> GetSessions()
Returns
- IEnumerable<Session>
The list of sessions.
ToString()
Returns string representation of this object.
public override string ToString()
Returns
- string
The string representation.
TryGetFirstSession(SessionFilter, out Session)
Attempts to find the first session belonging to this day accepted by specified filter. This method does not cross the day boundary.
public bool TryGetFirstSession(SessionFilter filter, out Session session)
Parameters
filter
SessionFilterThe filter used to evaluate sessions.
session
SessionThe first session that is accepted by the filter.
Returns
- bool
true
if a session meeting the filter criteria is found within the day; otherwise,false
.
Examples
To find the first trading session of any type:
bool found = TryGetFirstSession(SessionFilter.TRADING, out Session session);
To find the first regular trading session:
bool found = TryGetFirstSession(SessionFilter.REGULAR, out Session session);
TryGetLastSession(SessionFilter, out Session)
Attempts to find the last session belonging to this day accepted by specified filter. This method does not cross the day boundary.
public bool TryGetLastSession(SessionFilter filter, out Session session)
Parameters
filter
SessionFilterThe filter used to evaluate sessions.
session
SessionThe first session that is accepted by the filter.
Returns
- bool
true
if a session meeting the filter criteria is found within the day; otherwise,false
.
Examples
To find last trading session of any type use this code:
bool found = TryGetLastSession(SessionFilter.TRADING, out Session session);
To find last regular trading session use this code:
bool found = TryGetLastSession(SessionFilter.REGULAR, out Session session);
TryGetNextDay(DayFilter, out Day)
Attempts to find the following day accepted by specified filter. This method looks for appropriate day up to a year in the future.
public bool TryGetNextDay(DayFilter filter, out Day day)
Parameters
filter
DayFilterThe filter used to evaluate each day.
day
DayThe nearest following day that is accepted by the filter.
Returns
- bool
true if a suitable day is found; otherwise, false.
TryGetPrevDay(DayFilter, out Day)
Attempts to find the previous day accepted by specified filter. This method looks for appropriate day up to a year back in time.
public bool TryGetPrevDay(DayFilter filter, out Day day)
Parameters
filter
DayFilterThe filter used to evaluate each day.
day
DayThe nearest previous day that is accepted by the filter.
Returns
- bool
true if a suitable day is found; otherwise, false.