Class Session
Session represents a continuous period of time during which apply same rules regarding trading activity. For example,
regular trading session
is a period of time consisting of one day of business activities
in a financial market, from the opening bell to the closing bell, when regular trading occurs.
Sessions can be either trading or non-trading, with different sets of rules and reasons to exist.
Sessions 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 session that starts there.
Each session completely fits inside a certain day. 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.
public class Session
- Inheritance
-
Session
- Inherited Members
Properties
Day
Gets day to which this session belongs.
public Day Day { get; }
Property Value
EndTime
Gets end time of this session (exclusive). For normal sessions the end time is greater than the start time, for empty sessions they are equal.
public long EndTime { get; }
Property Value
IsEmpty
Gets a value indicating whether this session has zero duration. Empty sessions can be used for indices that post value once a day or for convenience. Such sessions can be of any appropriate type, trading or non-trading.
public bool IsEmpty { get; }
Property Value
IsTrading
Gets a value indicating whether trading activity is allowed within this session. Some sessions may have zero duration - e.g. indices that post value once a day. Such sessions can be of any appropriate type, trading or non-trading.
public bool IsTrading { get; }
Property Value
StartTime
Gets start time of this session (inclusive). For normal sessions the start time is less than the end time, for empty sessions they are equal.
public long StartTime { get; }
Property Value
Type
Gets type of this session.
public SessionType Type { get; }
Property Value
Methods
ContainsTime(long)
Determines whether a specified time belongs to this session.
public bool ContainsTime(long time)
Parameters
time
longThe time to check
Returns
- bool
true
if the specified time is belongs to this session; 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
.
GetHashCode()
Gets a hash code value for this object.
public override int GetHashCode()
Returns
- int
A hash code value for this object.
GetNextSession(SessionFilter)
Retrieves the following session that is accepted by the specified filter, if such a session exists.
public Session? GetNextSession(SessionFilter filter)
Parameters
filter
SessionFilterThe filter used to determine the suitability of sessions.
Returns
- Session
The nearest following session that meets the filter criteria; otherwise,
null
if no suitable session is found within the search period of up to a year in the future.
GetPrevSession(SessionFilter)
Gets the previous session that is accepted by the specified filter, if such a session exists.
public Session? GetPrevSession(SessionFilter filter)
Parameters
filter
SessionFilterThe filter used to determine the suitability of sessions.
Returns
- Session
The nearest previous session that meets the filter criteria; otherwise,
null
if no suitable session is found within the search period of up to a year back in time.
ToString()
Returns string representation of this object.
public override string ToString()
Returns
- string
The string representation.
TryGetNextSession(SessionFilter, out Session)
Attempts to find the following session accepted by specified filter. This method may cross the day boundary and return appropriate session from following days - up to a year in the future.
public bool TryGetNextSession(SessionFilter filter, out Session session)
Parameters
filter
SessionFilterThe filter used to evaluate sessions.
session
SessionThe nearest following session that is accepted by the filter.
Returns
- bool
true
if a session meeting the filter criteria is found; otherwise,false
.
Examples
To find following trading session of any type use this code:
bool found = TryGetNextSession(SessionFilter.TRADING, out Session session);
To find following regular trading session use this code:
bool found = TryGetNextSession(SessionFilter.REGULAR, out Session session);
TryGetPrevSession(SessionFilter, out Session)
Attempts to find the previous session accepted by specified filter. This method may cross the day boundary and return appropriate session from previous days - up to a year back in time.
public bool TryGetPrevSession(SessionFilter filter, out Session session)
Parameters
filter
SessionFilterThe filter used to evaluate sessions.
session
SessionThe nearest previous session that is accepted by the filter.
Returns
- bool
true
if a session meeting the filter criteria is found; otherwise,false
.
Examples
To find previous trading session of any type use this code:
bool found = TryGetPrevSession(SessionFilter.TRADING, out Session session);
To find previous regular trading session use this code:
bool found = TryGetPrevSession(SessionFilter.REGULAR, out Session session);