def test_market_update_runner_removed(self):
        update = BetfairStreaming.market_definition_runner_removed()

        # Setup
        market_def = update["mc"][0]["marketDefinition"]
        market_def["marketId"] = update["mc"][0]["id"]
        instruments = make_instruments(
            market_definition=update["mc"][0]["marketDefinition"],
            currency="GBP")
        self.provider.add_bulk(instruments)

        results = []
        for data in on_market_update(instrument_provider=self.provider,
                                     update=update):
            results.append(data)
        result = [r.status for r in results[:8]]
        expected = [InstrumentStatus.PRE_OPEN] * 7 + [InstrumentStatus.CLOSED]
        assert result == expected
Exemplo n.º 2
0
 def _on_market_update(self, update):
     if self._check_stream_unhealthy(update=update):
         pass
     updates = on_market_update(
         instrument_provider=self._instrument_provider,
         update=update,
     )
     if not updates:
         self._handle_no_data(update=update)
     for data in updates:
         self._log.debug(f"{data}")
         if isinstance(data, Data):
             if self._strict_handling:
                 if (hasattr(data, "instrument_id") and data.instrument_id
                         not in self._subscribed_instrument_ids):
                     # We receive data for multiple instruments within a subscription, don't emit data if we're not
                     # subscribed to this particular instrument as this will trigger a bunch of error logs
                     continue
             self._handle_data(data=data)
         elif isinstance(data, Event):
             self._log.warning(
                 f"Received event: {data}, DataEngine not yet setup to send events"
             )
Exemplo n.º 3
0
def line_parser(x, instrument_provider):
    from nautilus_trader.adapters.betfair.parsing import on_market_update

    yield from on_market_update(instrument_provider=instrument_provider, update=orjson.loads(x))