How to use the flumine.events.events function in flumine

To help you get started, we’ve selected a few flumine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github liampauling / flumine / tests / test_flumine.py View on Github external
mock__process_end_flumine,
        mock__process_current_orders,
        mock__process_order_package,
        mock__process_close_market,
    ):
        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.StrategyResetEvent(None),
            events.CustomEvent(None),
            events.NewDayEvent(None),
            events.EventType.TERMINATOR,
        ]
        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])
github liampauling / flumine / tests / test_flumine.py View on Github external
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_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.StrategyResetEvent(None),
            events.CustomEvent(None),
            events.NewDayEvent(None),
            events.EventType.TERMINATOR,
        ]
        for i in mock_events:
            self.flumine.handler_queue.put(i)
        self.flumine.run()
github liampauling / flumine / flumine / worker.py View on Github external
"RUNNER_DESCRIPTION",
                    "RUNNER_METADATA",
                    "MARKET_START_TIME",
                    "MARKET_DESCRIPTION",
                ],
            )
        except BetfairError as e:
            logger.error(
                "poll_market_catalogue error",
                exc_info=True,
                extra={"trading_function": "list_market_catalogue", "response": e},
            )
            continue

        if market_catalogues:
            flumine.handler_queue.put(events.MarketCatalogueEvent(market_catalogues))
github liampauling / flumine / flumine / worker.py View on Github external
except BetfairError as e:
            logger.error(
                "poll_cleared_orders error",
                extra={"trading_function": "list_cleared_orders", "response": e},
                exc_info=True,
            )
            return False

        logger.info(
            "{0}: {1} cleared orders found, more available: {2}".format(
                market_id, len(cleared_orders.orders), cleared_orders.more_available
            )
        )
        cleared_orders.market_id = market_id
        flumine.handler_queue.put(events.ClearedOrdersEvent(cleared_orders))
        flumine.log_control(events.ClearedOrdersEvent(cleared_orders))

        from_record += len(cleared_orders.orders)
        if not cleared_orders.more_available:
            break
    return True
github liampauling / flumine / flumine / markets / market.py View on Github external
def place_order(self, order, execute: bool = True) -> None:
        order.place(self.market_book.publish_time)
        if order.id not in self.blotter:
            self.blotter[order.id] = order
            if order.trade.market_notes is None:
                order.trade.update_market_notes(self)
            self.flumine.log_control(events.TradeEvent(order.trade))  # todo dupes?
        else:
            return  # retry attempt so ignore?
        if execute:  # handles replaceOrder
            self.blotter.pending_place.append(order)
github liampauling / flumine / flumine / baseflumine.py View on Github external
def add_strategy(self, strategy: BaseStrategy, client: BaseClient = None) -> None:
        logger.info("Adding strategy {0}".format(strategy))
        _client = client or self.client
        self.streams(strategy)  # create required streams
        self.strategies(strategy, _client)  # store in strategies
        self.log_control(events.StrategyEvent(strategy))
github liampauling / flumine / flumine / worker.py View on Github external
cleared_markets = betting_client.betting.list_cleared_orders(
            bet_status="SETTLED",
            market_ids=[market_id],
            customer_strategy_refs=[config.hostname],
            group_by="MARKET",
        )
    except BetfairError as e:
        logger.error(
            "_get_cleared_markets error",
            extra={"trading_function": "list_cleared_orders", "response": e},
            exc_info=True,
        )
        return False

    if cleared_markets.orders:
        flumine.handler_queue.put(events.ClearedMarketsEvent(cleared_markets))
        flumine.log_control(events.ClearedMarketsEvent(cleared_markets))
        return True
    else:
        return False
github liampauling / flumine / flumine / baseflumine.py View on Github external
def __exit__(self, *args):
        # shutdown streams
        self.streams.stop()
        # shutdown thread pools
        self.simulated_execution.shutdown()
        self.betfair_execution.shutdown()
        # shutdown logging controls
        self.log_control(events.TerminationEvent(None))
        for c in self._logging_controls:
            if c.is_alive():
                c.join()
        # logout
        self.client.logout()
        self._running = False
        logger.info("Exiting flumine", extra=self.info)
github liampauling / flumine / flumine / worker.py View on Github external
bet_status="SETTLED",
            market_ids=[market_id],
            customer_strategy_refs=[config.hostname],
            group_by="MARKET",
        )
    except BetfairError as e:
        logger.error(
            "_get_cleared_markets error",
            extra={"trading_function": "list_cleared_orders", "response": e},
            exc_info=True,
        )
        return False

    if cleared_markets.orders:
        flumine.handler_queue.put(events.ClearedMarketsEvent(cleared_markets))
        flumine.log_control(events.ClearedMarketsEvent(cleared_markets))
        return True
    else:
        return False