def raw_market_updates_instruments( market="1.166811431", runner1="60424", runner2="237478", currency="GBP" ): updates = BetfairTestStubs.raw_market_updates( market=market, runner1=runner1, runner2=runner2 ) market_def = updates[0]["mc"][0] instruments = make_instruments(market_def, currency) return instruments
async def test_make_instruments(self): # Arrange list_market_catalogue_data = { m["marketId"]: m for m in BetfairResponses.betting_list_market_catalogue()["result"] if m["eventType"]["name"] == "Basketball" } # Act instruments = [ instrument for metadata in list_market_catalogue_data.values() for instrument in make_instruments(metadata, currency="GBP") ] # Assert assert len(instruments) == 30412
def historical_instrument_provider_loader(instrument_provider, line): from nautilus_trader.adapters.betfair.providers import make_instruments if instrument_provider is None: return data = orjson.loads(line) # Find instruments in data for mc in data.get("mc", []): if "marketDefinition" in mc: market_def = {**mc["marketDefinition"], **{"marketId": mc["id"]}} instruments = make_instruments(market_definition=market_def, currency="GBP") instrument_provider.add_bulk(instruments) # By this point we should always have some instruments loaded from historical data if not instrument_provider.list_all(): # TODO - Need to add historical search raise Exception("No instruments found")
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
def test_market_bsp(self): # Setup update = BetfairStreaming.mcm_BSP() provider = self.client.instrument_provider() for mc in update[0]["mc"]: market_def = {**mc["marketDefinition"], "marketId": mc["id"]} instruments = make_instruments(market_definition=market_def, currency="GBP") provider.add_bulk(instruments) for update in update: self.client._on_market_update(update) result = Counter([type(event).__name__ for event in self.messages]) expected = { "TradeTick": 95, "BSPOrderBookDelta": 30, "InstrumentStatusUpdate": 9, "OrderBookSnapshot": 8, "OrderBookDeltas": 2, } assert result == expected
def raw_market_updates_instruments(): updates = BetfairTestStubs.raw_market_updates() market_def = updates[0]["mc"][0] instruments = make_instruments(market_def, "AUD") return instruments
def test_load_instruments(market_metadata): instruments = [ instrument for metadata in market_metadata.values() for instrument in make_instruments(metadata, currency="GBP") ] assert len(instruments) == 172535