Sessions and Session
Sessions allow you to run code at specific times of the day.
A session is a time period between two datetime.time objects specified in utc.
Attributes:
| Name |
Type |
Description |
Default |
| start |
datetime.time |
The start time of the session. |
None |
| end |
datetime.time |
The end time of the session. |
None |
| on_start |
str |
The action to take when the session starts. Default is None. |
None |
| on_end |
str |
The action to take when the session ends. Default is None. |
None |
| custom_start |
Callable |
A custom function to call when the session starts. Default is None. |
None |
| custom_end |
Callable |
A custom function to call when the session ends. Default is None. |
None |
Methods:
| Name |
Description |
| begin |
Call the action specified in on_start or custom_start. |
| close |
Call the action specified in on_end or custom_end. |
| action |
Used by begin and close to call the action specified. |
| delta |
Get the timedelta of a datetime.time object. |
| until |
Get the seconds until the session starts from the current time. |
__init__
Create a session.
Arguments:
| Name |
Type |
Description |
Default |
| start |
int | datetime.time |
The start time of the session in UTC. |
None |
| end |
int | datetime.time |
The end time of the session in UTC. |
None |
| on_start |
Literal['close_all', 'close_win', 'close_loss', 'custom_start'] |
The action to take when the session starts. Default is None. |
None |
| on_end |
Literal['close_all', 'close_win', 'close_loss', 'custom_end'] |
The action to take when the session ends. Default is None. |
None |
| custom_start |
Callable |
A custom function to call when the session starts. Default is None. |
None |
| custom_end |
Callable |
A custom function to call when the session ends. Default is None. |
None |
begin
Call the action specified in on_start or custom_start.
close
Call the action specified in on_end or custom_end.
action
Used by begin and close to call the action specified.
Arguments:
| Name |
Type |
Description |
Default |
| action |
Literal['close_all', 'close_win', 'close_loss', 'custom_start', 'custom_end'] |
The action to take. |
None |
delta
Get the timedelta of a datetime.time object.
Arguments:
| Name |
Type |
Description |
Default |
| obj |
datetime.time |
A datetime.time object. |
None |
Returns:
| Type |
Description |
| timedelta |
A timedelta object. |
until
Get the seconds until the session starts from the current time.
Returns:
| Type |
Description |
| int |
The seconds until the session starts. |
Sessions
Sessions allow you to run code at specific times of the day. It is a collection of Session objects.
Sessions are sorted by start time. The sessions object is an asynchronous context manager.
Attributes:
| Name |
Type |
Description |
Default |
| sessions |
list[Session] |
A list of Session objects. |
[] |
| current_session |
Session |
The current session. |
None |
Methods:
| Name |
Description |
| add |
Add a Session object to the sessions list. |
| remove |
Remove a Session object from the sessions list. |
| find |
Find a session that contains a datetime.time object. |
| find_next |
Find the next session that contains a datetime.time object. |
| check |
Check if the current session has started and if not, wait until it starts. |
__init__
Create a Sessions object.
Arguments:
| Name |
Type |
Description |
Default |
| sessions |
tuple[Session] |
A tuple of Session objects. |
None |
find
Find a session that contains a datetime.time object.
Arguments:
| Name |
Type |
Description |
Default |
| obj |
datetime.time |
A datetime.time object. |
None |
Returns:
| Type |
Description |
| Session |
A Session object or None if not found. |
find_next
Find the next session that contains a datetime.time object.
Arguments:
| Name |
Type |
Description |
Default |
| obj |
datetime.time |
A datetime.time object. |
None |
Returns:
| Type |
Description |
| Session |
A Session object. |
check
Check if the current session has started and if not, wait until it starts.