Skip to content

Commit

Permalink
Merge pull request #274 from liampauling/task/269-latency-warning
Browse files Browse the repository at this point in the history
  • Loading branch information
liampauling committed Sep 14, 2020
2 parents 36ee4cc + 68752b2 commit 81ddf83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions flumine/baseflumine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import queue
import logging
import threading
Expand Down Expand Up @@ -113,6 +114,19 @@ def _add_default_workers(self) -> None:
def _process_market_books(self, event: events.MarketBookEvent) -> None:
for market_book in event.event:
market_id = market_book.market_id

# check latency
latency = time.time() - (market_book.publish_time_epoch / 1e3)
if latency > 2:
logger.warning(
"High latency between current time and MarketBook publish time",
extra={
"market_id": market_id,
"latency": latency,
"pt": market_book.publish_time,
},
)

if market_book.status == "CLOSED":
self.handler_queue.put(events.CloseMarketEvent(market_book))
continue
Expand Down
2 changes: 1 addition & 1 deletion tests/test_baseflumine.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test__add_default_workers(self):

def test__process_market_books(self):
mock_event = mock.Mock()
mock_market_book = mock.Mock()
mock_market_book = mock.Mock(publish_time_epoch=123)
mock_market_book.runners = []
mock_event.event = [mock_market_book]
self.base_flumine._process_market_books(mock_event)
Expand Down

0 comments on commit 81ddf83

Please sign in to comment.