How to use the flumine.config 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_simulated.py View on Github external
def test_bool(self):
        self.assertFalse(self.simulated)
        from flumine import config

        config.simulated = True
        self.assertTrue(self.simulated)
github liampauling / flumine / flumine / worker.py View on Github external
def _get_cleared_orders(flumine, betting_client, market_id: str) -> bool:
    from_record = 0
    while True:
        try:
            cleared_orders = betting_client.betting.list_cleared_orders(
                bet_status="SETTLED",
                from_record=from_record,
                market_ids=[market_id],
                customer_strategy_refs=[config.hostname],
            )
        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))
github liampauling / flumine / flumine / baseflumine.py View on Github external
def __enter__(self):
        logger.info("Starting flumine", extra=self.info)
        # add execution to clients
        self.client.add_execution(self)
        # simulated
        if self.BACKTEST:
            config.simulated = True
        else:
            config.simulated = False
        # login
        self.client.login()
        self.client.update_account_details()
        # add default and start all workers
        self._add_default_workers()
        for w in self._workers:
            w.start()
        # start logging controls
        for c in self._logging_controls:
            c.start()
        # start strategies
        self.strategies.start()
        # start streams
        self.streams.start()

        self._running = True
github liampauling / flumine / flumine / baseflumine.py View on Github external
def __enter__(self):
        logger.info("Starting flumine", extra=self.info)
        # add execution to clients
        self.client.add_execution(self)
        # simulated
        if self.BACKTEST:
            config.simulated = True
        else:
            config.simulated = False
        # login
        self.client.login()
        self.client.update_account_details()
        # add default and start all workers
        self._add_default_workers()
        for w in self._workers:
            w.start()
        # start logging controls
        for c in self._logging_controls:
            c.start()
        # start strategies
        self.strategies.start()
        # start streams
        self.streams.start()
github liampauling / flumine / flumine / utils.py View on Github external
) -> None:
    try:
        strategy_process_market_book(market, market_book)
    except FlumineException as e:
        logger.error(
            "FlumineException %s in strategy_process_market_book %s %s"
            % (e, strategy_process_market_book, market.market_id),
            exc_info=True,
        )
    except Exception as e:
        logger.critical(
            "Unknown error %s in strategy_process_market_book %s %s"
            % (e, strategy_process_market_book, market.market_id),
            exc_info=True,
        )
        if config.raise_errors:
            raise
github liampauling / flumine / flumine / order / orderpackage.py View on Github external
client,
        market_id: str,
        orders: list,
        package_type: OrderPackageType,
        market,
        async_: bool = False,
    ):
        super(BaseOrderPackage, self).__init__(None)
        self.id = uuid.uuid1()
        self.client = client
        self.market_id = market_id
        self._orders = orders
        self.package_type = package_type
        self.market = market
        self.async_ = async_
        self.customer_strategy_ref = config.hostname
        self.processed = False  # used for simulated execution
github liampauling / flumine / flumine / worker.py View on Github external
def _get_cleared_market(flumine, betting_client, market_id: str) -> bool:
    try:
        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 / utils.py View on Github external
) -> bool:
    try:
        return strategy_check_market(market, market_book)
    except FlumineException as e:
        logger.error(
            "FlumineException %s in strategy_check_market %s %s"
            % (e, strategy_check_market, market.market_id),
            exc_info=True,
        )
    except Exception as e:
        logger.critical(
            "Unknown error %s in strategy_check_market %s %s"
            % (e, strategy_check_market, market.market_id),
            exc_info=True,
        )
        if config.raise_errors:
            raise
    return False
github liampauling / flumine / flumine / streams / orderstream.py View on Github external
def run(self) -> None:
        logger.info("Starting OrderStream")

        if not self._output_thread.is_alive():
            logger.info("Starting output_thread {0}".format(self._output_thread))
            self._output_thread.start()

        self._stream = self.betting_client.streaming.create_stream(
            unique_id=self.stream_id, listener=self._listener
        )
        try:
            self.stream_id = self._stream.subscribe_to_orders(
                order_filter=filters.streaming_order_filter(
                    customer_strategy_refs=[config.hostname],
                    partition_matched_by_strategy_ref=True,
                    include_overall_position=False,
                ),
                conflate_ms=self.conflate_ms,
            )
            self._stream.start()
        except BetfairError:
            logger.error("OrderStream run error", exc_info=True)
            raise
        except Exception:
            logger.critical("OrderStream run error", exc_info=True)
            raise
        logger.info("Stopped OrderStream {0}".format(self.stream_id))