def main(): setup_logging() logging.info(sys.argv) try: stream_type = sys.argv[1] except IndexError: stream_type = 'market' logging.info('betfairlightweight version: %s' % betfairlightweight.__version__) logging.info('flumine version: %s' % __version__) if stream_type == 'race': logging.info('Creating "storageengine.s3"') storage_engine = storageengine.S3('flumine', data_type='racedata', force_update=False) logging.info('Creating "RaceRecorder"') recorder = RaceRecorder(storage_engine=storage_engine) elif stream_type == 'market': try: market_filter = json.loads(sys.argv[2]) except IndexError: logging.warning('Market Filter not provided, defaulting to GB and IE WIN racing') market_filter = {"eventTypeIds": ["7"], "countryCodes": ["GB", "IE"], "marketTypes": ["WIN"]} except json.JSONDecodeError: logging.error('Market Filter arg must be provided in json format') raise try: market_data_filter = json.loads(sys.argv[3]) except IndexError: logging.warning('Market Data Filter not provided, defaulting to None') market_data_filter = None except json.JSONDecodeError: logging.error('Market Data Filter arg must be provided in json format') market_data_filter = None logging.info('Creating "storageengine.s3"') storage_engine = storageengine.S3('flumine', data_type='marketdata') logging.info('Creating "MarketRecorder"') recorder = MarketRecorder( storage_engine=storage_engine, market_filter=market_filter, market_data_filter=market_data_filter, ) else: raise ValueError('Invalid stream_type must be "race" or "market"') flumine = Flumine( recorder=recorder, settings={'certificate_login': False} ) try: flumine.start(_async=False) except FlumineException as e: logging.critical('Major flumine error: %s' % e)
def main(s3_bucket, market_filter=None, market_data_filter=None, settings=None): setup_logging() logging.info("betfairlightweight version: %s" % betfairlightweight.__version__) logging.info("flumine version: %s" % __version__) logging.info('Creating "storageengine.s3"') storage_engine = storageengine.S3(s3_bucket) logging.info('Creating "MarketRecorder"') recorder = MarketRecorder( storage_engine=storage_engine, market_filter=market_filter, market_data_filter=market_data_filter, ) flumine = Flumine(recorder=recorder, settings=settings) try: flumine.start(async_=False) except FlumineException as e: logging.critical("Major flumine error: %s" % e)
def main(): setup_logging() logging.info(sys.argv) try: market_filter = json.loads(sys.argv[1]) except IndexError: logging.warning( 'Market Filter not provided, defaulting to GB and IE racing') market_filter = { "eventTypeIds": ["7"], "countryCodes": ["GB", "IE"], "marketTypes": ["WIN"] } except json.JSONDecodeError: logging.error('Market Filter arg must be provided in json format') raise try: market_data_filter = json.loads(sys.argv[2]) except IndexError: logging.warning('Market Data Filter not provided, defaulting to None') market_data_filter = None except json.JSONDecodeError: logging.error('Market Data Filter arg must be provided in json format') market_data_filter = None storage_engine = storageengine.S3('flumine') # storage_engine = storageengine.Local('/fluminetests') flumine = Flumine(recorder=StreamRecorder( storage_engine=storage_engine, market_filter=market_filter, market_data_filter=market_data_filter, ), ) try: flumine.start(async=False) except FlumineException: pass
def main(): setup_logging() market_filter = { "eventTypeIds": ["1"], "countryCodes": ["GB"], "marketTypes": ["MATCH_ODDS", "OVER_UNDER_25", "CORRECT_SCORE"] } storage_engine = storageengine.S3('flumine') flumine = Flumine( recorder=EPLRecorder( storage_engine=storage_engine, market_filter=market_filter, ), ) try: flumine.start(async=False) except FlumineException: pass
def setUp(self): self.mock_trading = mock.Mock() self.flumine = Flumine(self.mock_trading)
class FlumineTest(unittest.TestCase): def setUp(self): self.mock_trading = mock.Mock() self.flumine = Flumine(self.mock_trading) @mock.patch("flumine.flumine.Flumine._process_custom_event") @mock.patch("flumine.flumine.Flumine._process_cleared_orders") @mock.patch("flumine.flumine.Flumine._process_cleared_markets") @mock.patch("flumine.flumine.Flumine._process_close_market") @mock.patch("flumine.flumine.Flumine._process_order_package") @mock.patch("flumine.flumine.Flumine._process_current_orders") @mock.patch("flumine.flumine.Flumine._process_end_flumine") @mock.patch("flumine.flumine.Flumine._process_market_catalogues") @mock.patch("flumine.flumine.Flumine._process_raw_data") @mock.patch("flumine.flumine.Flumine._process_market_books") def test_run( self, mock__process_market_books, mock__process_raw_data, mock__process_market_catalogues, mock__process_end_flumine, mock__process_current_orders, mock__process_order_package, mock__process_close_market, mock__process_cleared_markets, mock__process_cleared_orders, mock__process_custom_event, ): mock_events = [ events.MarketCatalogueEvent(None), events.MarketBookEvent(None), events.RawDataEvent(None), events.CurrentOrdersEvent(None), BaseOrderPackage(None, "1.123", [], "12", None), events.ClearedMarketsEvent(None), events.ClearedOrdersEvent(None), events.CloseMarketEvent(None), events.CustomEvent(None, None), events.NewDayEvent(None), events.TerminationEvent(None), ] for i in mock_events: self.flumine.handler_queue.put(i) self.flumine.run() mock__process_market_books.assert_called_with(mock_events[1]) mock__process_raw_data.assert_called_with(mock_events[2]) mock__process_market_catalogues.assert_called_with(mock_events[0]) mock__process_end_flumine.assert_called_with() mock__process_current_orders.assert_called_with(mock_events[3]) mock__process_order_package.assert_called_with(mock_events[4]) mock__process_close_market.assert_called_with(mock_events[7]) mock__process_cleared_markets.assert_called_with(mock_events[5]) mock__process_cleared_orders.assert_called_with(mock_events[6]) mock__process_custom_event.assert_called_with(mock_events[8]) def test__add_default_workers(self): self.flumine._add_default_workers() self.assertEqual(len(self.flumine._workers), 4) def test_str(self): assert str(self.flumine) == "<Flumine>" def test_repr(self): assert repr(self.flumine) == "<Flumine>"
selection_id=runner.selection_id, handicap=runner.handicap, strategy=self, ) order = trade.create_order( side=selection["side"], order_type=LimitOrder(price=1.01, size=selection["liability"]), ) market.place_order(order) trading = betfairlightweight.APIClient("username") client = clients.BetfairClient(trading) framework = Flumine(client=client) strategy = SingleStrategy( name="back_strat_42", market_filter=streaming_market_filter( event_type_ids=["7"], country_codes=["GB", "IE"], market_types=["WIN"], ), market_data_filter=streaming_market_data_filter( fields=[ "EX_BEST_OFFERS", "EX_LTP", "EX_MARKET_DEF", ], ladder_levels=1,
for runner in market_book.runners: if runner.status == "ACTIVE": # betfair runner_name = runner_names[runner.selection_id] best_back_price = utils.get_price(runner.ex.available_to_back, 0) # betconnect selection = selections_lookup[runner_name] max_price = selection.max_price diff = (1 / max_price) - (1 / best_back_price) print(runner_name, best_back_price, max_price, round(diff, 3)) framework = Flumine() # add clients betfair_client = clients.BetfairClient( betfairlightweight.APIClient("username")) framework.add_client(betfair_client) betconnect_client = clients.BetConnectClient( betconnect.APIClient("username", "password", "apiKey", "ppURL")) framework.add_client(betconnect_client) strategy = ExampleStrategy( market_filter=streaming_market_filter(market_ids=["1.196548740"]), streaming_timeout=2, ) framework.add_strategy(strategy)
class FlumineTest(unittest.TestCase): def setUp(self): self.mock_trading = mock.Mock() self.flumine = Flumine(self.mock_trading) @mock.patch("flumine.flumine.Flumine._add_default_workers") @mock.patch("flumine.flumine.Flumine._process_custom_event") @mock.patch("flumine.flumine.Flumine._process_cleared_orders") @mock.patch("flumine.flumine.Flumine._process_cleared_markets") @mock.patch("flumine.flumine.Flumine._process_close_market") @mock.patch("flumine.flumine.Flumine._process_current_orders") @mock.patch("flumine.flumine.Flumine._process_end_flumine") @mock.patch("flumine.flumine.Flumine._process_market_catalogues") @mock.patch("flumine.flumine.Flumine._process_raw_data") @mock.patch("flumine.flumine.Flumine._process_market_books") def test_run( self, mock__process_market_books, mock__process_raw_data, mock__process_market_catalogues, mock__process_end_flumine, mock__process_current_orders, mock__process_close_market, mock__process_cleared_markets, mock__process_cleared_orders, mock__process_custom_event, mock__add_default_workers, ): mock_events = [ events.MarketCatalogueEvent(None), events.MarketBookEvent(None), events.RawDataEvent(None), events.CurrentOrdersEvent(None), events.ClearedMarketsEvent(None), events.ClearedOrdersEvent(None), events.CloseMarketEvent(None), events.CustomEvent(None, None), events.NewDayEvent(None), events.TerminationEvent(None), ] for i in mock_events: self.flumine.handler_queue.put(i) self.flumine.run() mock__process_market_books.assert_called_with(mock_events[1]) mock__process_raw_data.assert_called_with(mock_events[2]) mock__process_market_catalogues.assert_called_with(mock_events[0]) mock__process_end_flumine.assert_called_with() mock__process_current_orders.assert_called_with(mock_events[3]) mock__process_close_market.assert_called_with(mock_events[6]) mock__process_cleared_markets.assert_called_with(mock_events[4]) mock__process_cleared_orders.assert_called_with(mock_events[5]) mock__process_custom_event.assert_called_with(mock_events[7]) mock__add_default_workers.assert_called() @mock.patch("flumine.worker.BackgroundWorker") @mock.patch("flumine.Flumine.add_worker") def test__add_default_workers(self, mock_add_worker, mock_worker): self.mock_trading.betting_client.session_timeout = 1200 self.flumine._add_default_workers() self.assertEqual(len(mock_add_worker.call_args_list), 4) self.assertEqual( mock_worker.call_args_list, [ mock.call( self.flumine, function=worker.keep_alive, interval=600), mock.call( self.flumine, function=worker.poll_account_balance, interval=120, start_delay=10, ), mock.call( self.flumine, function=worker.poll_market_catalogue, interval=60, start_delay=10, ), mock.call( self.flumine, function=worker.poll_market_closure, interval=60, start_delay=10, ), ], ) def test_str(self): assert str(self.flumine) == "<Flumine>" def test_repr(self): assert repr(self.flumine) == "<Flumine>"
def setUp(self): self.mock_client = mock.Mock(EXCHANGE=ExchangeType.SIMULATED) self.flumine = Flumine(self.mock_client)
if "score" in market.context: score = market.context["score"] print( score.match_status, score.current_game, score.current_set, score.current_point, score.score.home.score, score.score.away.score, ) trading = betfairlightweight.APIClient("username") client = clients.BetfairClient(trading) framework = Flumine(client=client) strategy = ExampleStrategy( market_filter=streaming_market_filter(market_ids=["1.172415939"]), ) framework.add_strategy(strategy) framework.add_worker( BackgroundWorker( framework, poll_in_play_service, func_kwargs={"event_type_id": "2"}, interval=30, start_delay=4, )) framework.run()