Skip to content

Commit

Permalink
better comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaron committed Apr 23, 2024
1 parent 7460037 commit 07dd092
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions roboquant/feeds/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@


class CollectorFeed(Feed):
"""Collect events into one new event if they occur close to eachother.
"""Collect events that occur close after ech other into a single new event.
Close to eachother is defined by the timeout is seconds. If there is no new
event in the specified timeout, all previous events will be bundled together and
put on the channel.
event in the specified timeout, all the previously collected event items will
be bundled together and put on the channel as a single event.
"""

def __init__(
Expand Down
3 changes: 3 additions & 0 deletions roboquant/feeds/historic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def __init__(self):
def _add_item(self, time: datetime, item: PriceItem):
"""Add a price-item at a moment in time to this feed.
Subclasses should invoke this method to populate the historic-feed.
Items added at the same time, will be part of the same event.
So each unique time will only produce a single event.
"""

self.__modified = True
Expand Down
9 changes: 7 additions & 2 deletions roboquant/feeds/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ class LiveFeed(Feed):
"""
Abstract base class for feeds that produce live price-items. It will ensure that
events that are published are monotonic in time (so always increasing).
If a new event has a timestamp that is before or equal to the previous event, the
timstamp will be corrected so the event occurs after the previous event.
The default is to increment it by 1 microsecond over the previous event, but this is configurable.
"""

def __init__(self):
super().__init__()
self._channel = None
self._last_time = datetime.fromisoformat("1900-01-01T00:00:00+00:00")
self._min_change = timedelta(microseconds=1)
self.increment = timedelta(microseconds=1)

def play(self, channel: EventChannel):
self._channel = channel
Expand All @@ -28,7 +33,7 @@ def put(self, event: Event):
if self._channel:
try:
if event.time <= self._last_time:
event.time = self._last_time + self._min_change
event.time = self._last_time + self.increment
self._channel.put(event)
self._last_time = event.time
except ChannelClosed:
Expand Down
3 changes: 2 additions & 1 deletion roboquant/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def run(
timeframe: Optionally limit the run to events within this timeframe. The default is None
capacity: The max capacity of the used event channel. Default is 10 events.
heartbeat_timeout: Optionally, a heartbeat (is an empty event) will be generated if no other events are received
within the specified timeout in seconds. The default is None.
within the specified timeout in seconds. The default is None. This should normally only be used with live feeds since
the timestamp used for the heartbeat is the current time.
Returns:
The latest version of the account
Expand Down

0 comments on commit 07dd092

Please sign in to comment.