How to use the flumine.order.orderpackage.OrderPackageType.REPLACE 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_orderpackage.py View on Github external
def test_order_limit(self):
        self.assertEqual(self.order_package.order_limit(OrderPackageType.PLACE), 200)
        self.assertEqual(self.order_package.order_limit(OrderPackageType.CANCEL), 60)
        self.assertEqual(self.order_package.order_limit(OrderPackageType.UPDATE), 60)
        self.assertEqual(self.order_package.order_limit(OrderPackageType.REPLACE), 60)
github liampauling / flumine / flumine / order / orderpackage.py View on Github external
def order_limit(cls, package_type: OrderPackageType) -> int:
        if package_type == OrderPackageType.PLACE:
            return order_limits["placeOrders"]
        elif package_type == OrderPackageType.CANCEL:
            return order_limits["cancelOrders"]
        elif package_type == OrderPackageType.UPDATE:
            return order_limits["updateOrders"]
        elif package_type == OrderPackageType.REPLACE:
            return order_limits["replaceOrders"]
github liampauling / flumine / flumine / execution / simulatedexecution.py View on Github external
def handler(self, order_package: BaseOrderPackage) -> None:
        """ Only uses _thread_pool if paper_trade
        """
        if order_package.package_type == OrderPackageType.PLACE:
            func = self.execute_place
        elif order_package.package_type == OrderPackageType.CANCEL:
            func = self.execute_cancel
        elif order_package.package_type == OrderPackageType.UPDATE:
            func = self.execute_update
        elif order_package.package_type == OrderPackageType.REPLACE:
            func = self.execute_replace
        else:
            raise NotImplementedError()

        if order_package.client.paper_trade:
            self._thread_pool.submit(func, order_package, None)
        else:
            func(order_package, http_session=None)
github liampauling / flumine / flumine / controls / clientcontrols.py View on Github external
if order_package.package_type == OrderPackageType.PLACE:
            self._check_transaction_count(len(order_package))
            self.place_requests += len(order_package)
            if not self.safe:  # and order.flumine_order_type == "initial"
                for order in order_package:
                    self._on_error(
                        order,
                        "Max Order Count has been reached ({0}) for current hour".format(
                            self.transaction_count
                        ),
                    )
        elif order_package.package_type == OrderPackageType.CANCEL:
            self.cancel_requests += len(order_package)
        elif order_package.package_type == OrderPackageType.UPDATE:
            self.update_requests += len(order_package)
        elif order_package.package_type == OrderPackageType.REPLACE:
            self.replace_requests += len(order_package)
github liampauling / flumine / flumine / execution / baseexecution.py View on Github external
extra={
                "bet_id": order.bet_id,
                "order_id": order.id,
                "status": instruction_report.status,
                "error_code": instruction_report.error_code,
            },
        )
        if package_type == OrderPackageType.PLACE:
            order.responses.placed(instruction_report)
            order.bet_id = instruction_report.bet_id
            self.flumine.log_control(OrderEvent(order))
        elif package_type == OrderPackageType.CANCEL:
            order.responses.cancelled(instruction_report)
        elif package_type == OrderPackageType.UPDATE:
            order.responses.updated(instruction_report)
        elif package_type == OrderPackageType.REPLACE:
            order.responses.placed(instruction_report)
            order.bet_id = instruction_report.bet_id
            self.flumine.log_control(OrderEvent(order))
github liampauling / flumine / flumine / markets / blotter.py View on Github external
packages = []
        if self.pending_place:
            packages += self._create_packages(
                client, self.pending_place, OrderPackageType.PLACE
            )
        if self.pending_cancel:
            packages += self._create_packages(
                client, self.pending_cancel, OrderPackageType.CANCEL
            )
        if self.pending_update:
            packages += self._create_packages(
                client, self.pending_update, OrderPackageType.UPDATE
            )
        if self.pending_replace:
            packages += self._create_packages(
                client, self.pending_replace, OrderPackageType.REPLACE
            )
        if packages:
            logger.info(
                "%s order packages created" % len(packages),
                extra={"order_packages": [o.info for o in packages]},
            )
        return packages
github liampauling / flumine / flumine / controls / tradingcontrols.py View on Github external
def _validate(self, order_package):
        if order_package.package_type in (
            OrderPackageType.PLACE,
            OrderPackageType.REPLACE,  # todo potential bug?
        ):
            for order in order_package:
                strategy = order.trade.strategy

                if order.order_type.ORDER_TYPE == OrderTypes.LIMIT:
                    if order.side == "BACK":
                        exposure = order.order_type.size
                    else:
                        exposure = (order.order_type.price - 1) * order.order_type.size
                elif order.order_type.ORDER_TYPE == OrderTypes.LIMIT_ON_CLOSE:
                    exposure = order.order_type.liability  # todo correct?
                elif order.order_type.ORDER_TYPE == OrderTypes.MARKET_ON_CLOSE:
                    exposure = order.order_type.liability
                else:
                    continue
github liampauling / flumine / flumine / execution / betfairexecution.py View on Github external
instruction_report.cancel_instruction_reports.status
                        == "TIMEOUT"
                    ):
                        order.executable()

                    # process place response
                    if instruction_report.place_instruction_reports.status == "SUCCESS":
                        # create new order
                        replacement_order = order.trade.create_order_replacement(
                            order,
                            instruction_report.place_instruction_reports.instruction.limit_order.price,
                        )
                        self._order_logger(
                            replacement_order,
                            instruction_report.place_instruction_reports,
                            OrderPackageType.REPLACE,
                        )
                        # add to blotter
                        order_package.market.place_order(
                            replacement_order, execute=False
                        )
                        replacement_order.executable()
                    elif (
                        instruction_report.place_instruction_reports.status == "FAILURE"
                    ):
                        pass  # todo
                    elif (
                        instruction_report.place_instruction_reports.status == "TIMEOUT"
                    ):
                        pass  # todo