betcode-org / flumine

flūmine - Betting trading framework
MIT License
176 stars 60 forks source link

Transactions to all fail or all validate as a group #542

Open jsphon opened 2 years ago

jsphon commented 2 years ago

When placing multiple orders within a single trade, it would be nice if it was possible to make Flumine reject all the orders if any of them fail to validate. I am currently using this hacky code to achieve the desired result:


  with market.transaction() as t:
                            all_valid = all(
                                t._validate_controls(order, OrderPackageType.PLACE)
                                for order in entry_trade.orders
                            )
                            if all_valid:
                                if runner_context.live_trade_count+len(entry_trade.orders)<self.max_live_trade_count:
                                    for order in entry_trade.orders:
                                        t.place_order(order)
                                else:
                                    logger.error('This would invalidate the max trade count')
liampauling commented 2 years ago

The problem here is that it is easy to add some logic to check a list of orders against the controls but I assume you also went to check them against themselves ie. two orders to be placed A & B:

To do this A has to be 'placed' and added to the blotter but then violated along with B if there is an issue. Trying to think of a clean way of doing this.

jsphon commented 2 years ago

Could it help if all back orders for a selection were bunched together, and then all lay orders bunched together?The worst case scenarios would occur when all backs are matched with zero lays matched. Or vice versa.On 7 Jan 2022 8:04 am, Liam @.***> wrote: The problem here is that it is easy to add some logic to check a list of orders against the controls but I assume you also went to check them against themselves ie. two orders to be placed A & B: Does placing order A result in order B violating To do this A has to be 'placed' and added to the blotter but then violated along with B if there is an issue. Trying to think of a clean way of doing this.

—Reply to this email directly, view it on GitHub, or unsubscribe.Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you authored the thread.Message ID: @.***>

jsphon commented 2 years ago

I've attempted to address this with:

https://github.com/betcode-org/flumine/pull/590