Пример #1
0
 def _process(self, data: list, publish_time: int) -> None:
     for market_book in data:
         market_id = market_book["id"]
         market_book_cache = self._caches.get(market_id)
         if (
             market_book.get("img") or market_book_cache is None
         ):  # historic data does not contain img
             if "marketDefinition" not in market_book:
                 logger.error(
                     "[MarketStream: %s] Unable to add %s to cache due to marketDefinition "
                     "not being present (make sure EX_MARKET_DEF is requested)"
                     % (self.unique_id, market_id)
                 )
                 continue
             market_book_cache = MarketBookCache(
                 publish_time=publish_time, **market_book
             )
             self._caches[market_id] = market_book_cache
             logger.info(
                 "[MarketStream: %s] %s added, %s markets in cache"
                 % (self.unique_id, market_id, len(self._caches))
             )
         else:
             market_book_cache.update_cache(market_book, publish_time)
             self._updates_processed += 1
Пример #2
0
    def test_init_multiple_rc(self):
        # Initialize data with multiple rc entries for the same selection
        data = {'marketDefinition': {'runners': {}}}
        data['rc'] = [{'atb': [[1.01, 200]], 'id': 13536143}, {'atl': [[1000.0, 200]], 'id': 13536143}]

        market_book_cache = MarketBookCache(**data)

        assert len(market_book_cache.runners) == len(market_book_cache.runner_dict)
Пример #3
0
    def test_init_multiple_rc(self):
        # Initialize data with multiple rc entries for the same selection
        data = {"marketDefinition": {"runners": {}}}
        data["rc"] = [
            {"atb": [[1.01, 200]], "id": 13536143},
            {"atl": [[1000.0, 200]], "id": 13536143},
        ]

        market_book_cache = MarketBookCache(**data)

        assert len(market_book_cache.runners) == len(market_book_cache.runner_dict)
Пример #4
0
    def create_market_cache(self, market_books, publish_time):

        output_market_book = []
        for market_book in market_books:
            market_id = market_book['id']
            market_book_cache = self._market_caches.get(market_id)

            if market_book.get('img') or market_book_cache is None:  # historic data does not contain img
                market_book_cache = MarketBookCache(publish_time=publish_time, **market_book)
                self._market_caches[market_id] = market_book_cache

            market_book_cache.update_cache(market_book, publish_time)

            output_market_book.append(
                market_book_cache.create_resource(123, market_book, True)
            )

        return output_market_book
Пример #5
0
    def test_update_multiple_rc(self):
        # update data with multiple rc entries for the same selection
        data = {
            "rc": [
                {
                    "atb": [[1.01, 200]],
                    "id": 13536143
                },
                {
                    "atl": [[1000.0, 200]],
                    "id": 13536143
                },
            ]
        }

        market_book_cache = MarketBookCache("1.123", 123, True)
        market_book_cache.update_cache(data, 123)

        assert len(market_book_cache.runners) == len(
            market_book_cache.runner_dict)
Пример #6
0
    def _process(self, data: list, publish_time: int) -> bool:
        for market_book in data:
            market_id = market_book["id"]
            full_image = market_book.get("img", False)
            market_book_cache = self._caches.get(market_id)

            if (full_image or market_book_cache is
                    None):  # historic data does not contain img
                if "marketDefinition" not in market_book:
                    logger.warning(
                        "[%s: %s]: Missing marketDefinition on market %s resulting "
                        "in potential missing data in the MarketBook (make sure "
                        "EX_MARKET_DEF is requested)" %
                        (self, self.unique_id, market_id))
                market_book_cache = MarketBookCache(market_id, publish_time,
                                                    self._lightweight)
                self._caches[market_id] = market_book_cache
                logger.info(
                    "[%s: %s]: %s added, %s markets in cache" %
                    (self, self.unique_id, market_id, len(self._caches)))

            market_book_cache.update_cache(market_book, publish_time)
            self._updates_processed += 1
        return False
Пример #7
0
 def test_error(self):
     with self.assertRaises(CacheError):
         self.market_book_cache = MarketBookCache()
Пример #8
0
 def setUp(self):
     self.market_book_cache = MarketBookCache(
         **{"marketDefinition": {"runners": {}}}
     )
Пример #9
0
 def setUp(self):
     self.market_book_cache = MarketBookCache(
         **{'marketDefinition': {
             'runners': {}
         }})
Пример #10
0
 def setUp(self):
     self.market_book_cache = MarketBookCache("1.2345", 12345, True, True,
                                              False)
Пример #11
0
    def _process(self, data: list, publish_time: int) -> bool:
        active = False
        for market_book in data:
            if "id" not in market_book:
                continue
            market_id = market_book["id"]
            full_image = market_book.get("img", False)
            market_book_cache = self._caches.get(market_id)

            if (full_image or market_book_cache is
                    None):  # historic data does not contain img
                if "marketDefinition" not in market_book:
                    logger.warning(
                        "[%s: %s]: Missing marketDefinition on market %s resulting "
                        "in potential missing data in the MarketBook (make sure "
                        "EX_MARKET_DEF is requested)" %
                        (self, self.unique_id, market_id))
                market_book_cache = MarketBookCache(
                    market_id,
                    publish_time,
                    self._lightweight,
                    self._calculate_market_tv,
                    self._cumulative_runner_tv,
                )
                self._caches[market_id] = market_book_cache
                logger.info(
                    "[%s: %s]: %s added, %s markets in cache" %
                    (self, self.unique_id, market_id, len(self._caches)))

            # listener_kwargs filtering
            active = True
            if "marketDefinition" in market_book:
                _definition_status = market_book["marketDefinition"].get(
                    "status")
                _definition_in_play = market_book["marketDefinition"].get(
                    "inPlay")
                _definition_market_time = market_book["marketDefinition"].get(
                    "marketTime")
            else:
                _definition_status = market_book_cache._definition_status
                _definition_in_play = market_book_cache._definition_in_play
                _definition_market_time = market_book_cache.market_definition[
                    "marketTime"]

            # if market is not open (closed/suspended) process regardless
            if _definition_status == "OPEN":
                if self._listener.inplay:
                    if not _definition_in_play:
                        active = False
                elif self._listener.seconds_to_start:
                    _now = datetime.datetime.utcfromtimestamp(publish_time /
                                                              1e3)
                    _market_time = BaseResource.strip_datetime(
                        _definition_market_time)
                    seconds_to_start = (_market_time - _now).total_seconds()
                    if seconds_to_start > self._listener.seconds_to_start:
                        active = False
                if self._listener.inplay is False:
                    if _definition_in_play:
                        active = False
            # check if refresh required
            if active and not market_book_cache.active:
                market_book_cache.refresh_cache()

            market_book_cache.update_cache(market_book,
                                           publish_time,
                                           active=active)
            self._updates_processed += 1
        return active
Пример #12
0
 def setUp(self):
     self.market_book_cache = MarketBookCache(
         **{"marketDefinition": create_market_definition_data()})