nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: image-rs/image-tiff
Pull request #138 (2021-05-28 13:52:00)

Fix division by zero issue with malformed file
I wasn't sure of the best place to put the test data (since it was found through fuzzing, but not through `afl`), so I left it in the code for now, I'm fine with moving it to wherever else it should be.

This isn't the only bug I found through fuzzing, but I figure it's better to not lump 5 bugfixes into one PR.


Patch:
diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs
index 173c4d5..368d8fc 100644
--- a/src/decoder/mod.rs
+++ b/src/decoder/mod.rs
@@ -1309,6 +1309,14 @@ impl<R: Read + Seek> Decoder<R> {
             let tile_width = usize::try_from(self.get_tag_u32(Tag::TileWidth)?)?;
             let tile_length = usize::try_from(self.get_tag_u32(Tag::TileLength)?)?;
 
+            if tile_width == 0 {
+                return Err(TiffFormatError::InvalidTagValueType(Tag::TileWidth).into());
+            }
+
+            if tile_length == 0 {
+                return Err(TiffFormatError::InvalidTagValueType(Tag::TileLength).into());
+            }
+
             let tiles_across = (usize::try_from(self.width)? + tile_width - 1) / tile_width;
             let tiles_down = (usize::try_from(self.height)? + tile_length - 1) / tile_length;
 


Test patch:
diff --git a/tests/decode_images.rs b/tests/decode_images.rs
index 863b23f..58ffc4a 100644
--- a/tests/decode_images.rs
+++ b/tests/decode_images.rs
@@ -284,3 +284,26 @@ fn test_tiled_incremental() {
         }
     }
 }
+
+#[test]
+fn test_div_zero() {
+    use tiff::tags;
+    use tiff::{TiffError, TiffFormatError};
+
+    let image = [
+        73, 73, 42, 0, 8, 0, 0, 0, 8, 0, 0, 1, 4, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 40, 1, 0, 0,
+        0, 158, 0, 0, 251, 3, 1, 3, 0, 1, 0, 0, 0, 1, 0, 0, 39, 6, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+        17, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 0, 1, 0, 0, 0, 158, 0, 0, 251, 67, 1, 3, 0,
+        1, 0, 0, 0, 40, 0, 0, 0, 66, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 178, 178, 178, 178,
+        178, 178, 178,
+    ];
+
+    let mut decoder = tiff::decoder::Decoder::new(std::io::Cursor::new(&image)).unwrap();
+
+    let err = decoder.read_image().unwrap_err();
+
+    match err {
+        TiffError::FormatError(TiffFormatError::InvalidTagValueType(tags::Tag::TileWidth)) => {}
+        unexpected => panic!("Unexpected error {}", unexpected),
+    }
+}
Repository: image-rs/image-tiff
Pull request #190 (2022-11-16 16:35:51)

Added support for the YCbCr PhotometricInterpretation
I added support for the YCbCr PhotometricInterpretation. 
This works fine for my use case. 
I am not sure if this is all there was to do to get this working or whether I missed something.


Patch:
diff --git a/src/decoder/image.rs b/src/decoder/image.rs
index c5c884f..e3ea624 100644
--- a/src/decoder/image.rs
+++ b/src/decoder/image.rs
@@ -314,6 +314,15 @@ impl Image {
                     ),
                 )),
             },
+            PhotometricInterpretation::YCbCr => match self.bits_per_sample[..] {
+                [y, cb, cr] if [y, y] == [cb, cr] => Ok(ColorType::YCbCr(y)),
+                _ => Err(TiffError::UnsupportedError(
+                    TiffUnsupportedError::InterpretationWithBits(
+                        self.photometric_interpretation,
+                        self.bits_per_sample.clone(),
+                    ),
+                )),
+            },
             PhotometricInterpretation::BlackIsZero | PhotometricInterpretation::WhiteIsZero
                 if self.bits_per_sample.len() == 1 =>
             {
@@ -450,6 +459,7 @@ impl Image {
             (ColorType::RGB(n), _)
             | (ColorType::RGBA(n), _)
             | (ColorType::CMYK(n), _)
+            | (ColorType::YCbCr(n), _)
             | (ColorType::Gray(n), _)
                 if usize::from(n) == buffer.byte_len() * 8 => {}
             (ColorType::Gray(n), DecodingBuffer::U8(_)) if n < 8 => match self.predictor {
diff --git a/src/encoder/colortype.rs b/src/encoder/colortype.rs
index f6c775a..1946daf 100644
--- a/src/encoder/colortype.rs
+++ b/src/encoder/colortype.rs
@@ -235,3 +235,11 @@ impl ColorType for CMYK64Float {
     const BITS_PER_SAMPLE: &'static [u16] = &[64, 64, 64, 64];
     const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::IEEEFP; 4];
 }
+
+pub struct YCbCr8;
+impl ColorType for YCbCr8 {
+    type Inner = u8;
+    const TIFF_VALUE: PhotometricInterpretation = PhotometricInterpretation::YCbCr;
+    const BITS_PER_SAMPLE: &'static [u16] = &[8, 8, 8];
+    const SAMPLE_FORMAT: &'static [SampleFormat] = &[SampleFormat::Uint; 3];
+}
diff --git a/src/lib.rs b/src/lib.rs
index b763fc0..8f23f35 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -37,4 +37,7 @@ pub enum ColorType {
 
     /// Pixel is CMYK
     CMYK(u8),
+
+    /// Pixel is YCbCr
+    YCbCr(u8),
 }


Test patch:
diff --git a/tests/encode_images.rs b/tests/encode_images.rs
index 0e5360e..57c569f 100644
--- a/tests/encode_images.rs
+++ b/tests/encode_images.rs
@@ -264,6 +264,11 @@ fn test_gray_f64_roundtrip() {
     test_f64_roundtrip::<colortype::Gray64Float>("gradient-1c-64b-float.tiff", ColorType::Gray(64));
 }
 
+#[test]
+fn test_ycbcr_u8_roundtrip() {
+    test_u8_roundtrip::<colortype::YCbCr8>("tiled-jpeg-ycbcr.tif", ColorType::YCbCr(8));
+}
+
 trait AssertDecode {
     fn assert_tag_u32(&mut self, tag: u16) -> u32;
     fn assert_tag_u32_vec(&mut self, tag: u16) -> Vec<u32>;
Repository: nuveo/prest
Pull request #106 (2017-02-16 12:41:00)

Modules structure


Patch:
diff --git a/CREATING_MODULES.md b/CREATING_MODULES.md
new file mode 100644
index 0000000..158fd57
--- /dev/null
+++ b/CREATING_MODULES.md
@@ -0,0 +1,35 @@
+
+# Creating custom modules
+
+## In order to create custom modules for pREST you need extends the router and register the custom new routes.
+
+
+## Example:
+
+
+```
+package main
+
+import (
+	"net/http"
+
+	"github.com/nuveo/prest/cmd"
+	"github.com/nuveo/prest/config"
+)
+
+func main() {
+	// Get pPREST router
+	r := config.GetRouter()
+
+	// Register custom routes
+	r.HandleFunc("/ping", Pong).Methods("GET")
+
+	// Call pREST cmd
+	cmd.Execute()
+}
+
+func Pong(w http.ResponseWriter, r *http.Request) {
+	w.Write([]byte("Pong!"))
+	return
+}
+```
\ No newline at end of file
diff --git a/cmd/root.go b/cmd/root.go
index 4e2bf23..52e0320 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -51,7 +51,8 @@ func app() {
 		n.Use(middlewares.JwtMiddleware(cfg.JWTKey))
 	}
 
-	r := mux.NewRouter()
+	r := config.GetRouter()
+
 	r.HandleFunc("/databases", controllers.GetDatabases).Methods("GET")
 	r.HandleFunc("/schemas", controllers.GetSchemas).Methods("GET")
 	r.HandleFunc("/tables", controllers.GetTables).Methods("GET")
diff --git a/config/routers.go b/config/routers.go
new file mode 100644
index 0000000..09bb3d4
--- /dev/null
+++ b/config/routers.go
@@ -0,0 +1,16 @@
+package config
+
+import "github.com/gorilla/mux"
+
+var router *mux.Router
+
+func initRouter() {
+	router = mux.NewRouter()
+}
+
+func GetRouter() *mux.Router {
+	if router == nil {
+		initRouter()
+	}
+	return router
+}


Test patch:
diff --git a/config/routers_test.go b/config/routers_test.go
new file mode 100644
index 0000000..e5c32a8
--- /dev/null
+++ b/config/routers_test.go
@@ -0,0 +1,18 @@
+package config
+
+import "testing"
+
+func TestInitRouter(t *testing.T) {
+	initRouter()
+	if router == nil {
+		t.Errorf("Router should not be nil.")
+	}
+}
+
+func TestGetRouter(t *testing.T) {
+	router = nil
+	r := GetRouter()
+	if r == nil {
+		t.Errorf("Should return a router.")
+	}
+}
Repository: liampauling/flumine
Pull request #171 (2020-05-22 16:59:11)

close market handling when market is not yet initialised


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 3f99136..22511f9 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,13 @@
 Release History
 ---------------
 
+1.5.4 (2020-05-22)
++++++++++++++++++++
+
+**Bug Fixes**
+
+- Market close bug
+
 1.5.3 (2020-05-22)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index c0859c5..9e02207 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.5.3"
+__version__ = "1.5.4"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/baseflumine.py b/flumine/baseflumine.py
index 18ac464..8dfd155 100644
--- a/flumine/baseflumine.py
+++ b/flumine/baseflumine.py
@@ -192,7 +192,14 @@ class BaseFlumine:
             self._process_market_orders(market)
 
     def _process_close_market(self, event: events.CloseMarketEvent) -> None:
-        market = self.markets.markets.get(event.event.market_id)
+        market_id = event.event.market_id
+        market = self.markets.markets.get(market_id)
+        if market is None:
+            logger.warning(
+                "Market %s not present when closing" % market_id,
+                extra={"market_id": market_id},
+            )
+            return
         market.close_market()
         market.blotter.process_closed_market(event.event)
 


Test patch:
diff --git a/tests/test_baseflumine.py b/tests/test_baseflumine.py
index 7a20eb6..4558083 100644
--- a/tests/test_baseflumine.py
+++ b/tests/test_baseflumine.py
@@ -194,6 +194,18 @@ class BaseFlumineTest(unittest.TestCase):
             self.base_flumine.cleared_market_queue.get(), mock_market.market_id
         )
 
+    def test__process_close_market_no_market(self):
+        mock_market = mock.Mock()
+        mock_market.market_book.streaming_unique_id = 2
+        mock_markets = mock.Mock()
+        mock_markets.markets = {"1.23": mock_market}
+        self.base_flumine.markets = mock_markets
+        mock_event = mock.Mock()
+        mock_market_book = mock.Mock(market_id="1.45")
+        mock_event.event = mock_market_book
+        self.base_flumine._process_close_market(mock_event)
+        mock_market.close_market.assert_not_called()
+
     def test__process_cleared_orders(self):
         mock_event = mock.Mock()
         mock_event.event.orders = []
Repository: liampauling/flumine
Pull request #209 (2020-06-08 11:12:39)

blotter live_orders bug fix


Patch:
diff --git a/flumine/markets/blotter.py b/flumine/markets/blotter.py
index 448cf8b..adf2fd3 100644
--- a/flumine/markets/blotter.py
+++ b/flumine/markets/blotter.py
@@ -72,10 +72,7 @@ class Blotter:
     @property
     def live_orders(self) -> bool:
         for order in self._orders.values():
-            if (
-                order.status == OrderStatus.EXECUTABLE
-                or order.trade.trade_complete is False
-            ):
+            if order.complete is False or order.trade.complete is False:
                 return True
         return False
 


Test patch:
diff --git a/tests/test_blotter.py b/tests/test_blotter.py
index 33a1659..1d7ec38 100644
--- a/tests/test_blotter.py
+++ b/tests/test_blotter.py
@@ -70,16 +70,14 @@ class BlotterTest(unittest.TestCase):
 
     def test_live_orders(self):
         self.assertFalse(self.blotter.live_orders)
-        mock_order = mock.Mock()
-        mock_order.status = OrderStatus.EXECUTABLE
+        mock_order = mock.Mock(complete=False)
         self.blotter._orders = {"12345": mock_order}
         self.assertTrue(self.blotter.live_orders)
 
     def test_live_orders_trade(self):
         self.assertFalse(self.blotter.live_orders)
         mock_order = mock.Mock()
-        mock_order.trade.trade_complete = False
-        mock_order.status = OrderStatus.EXECUTION_COMPLETE
+        mock_order.trade.complete = False
         self.blotter._orders = {"12345": mock_order}
         self.assertTrue(self.blotter.live_orders)
Repository: liampauling/flumine
Pull request #227 (2020-06-30 06:38:46)

mc count reduced to 25
trying to find seg fault


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 2ecbc7a..2f8362c 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,13 @@
 Release History
 ---------------
 
+1.8.1 (2020-06-30)
++++++++++++++++++++
+
+**Bug Fixes**
+
+- Reduce MC count (debugging seg fault)
+
 1.8.0 (2020-06-29)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 226b345..60cfd93 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.8.0"
+__version__ = "1.8.1"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/worker.py b/flumine/worker.py
index 150bbe7..27ee82e 100644
--- a/flumine/worker.py
+++ b/flumine/worker.py
@@ -100,11 +100,11 @@ def keep_alive(context: dict, flumine) -> None:
 def poll_market_catalogue(context: dict, flumine) -> None:
     client = flumine.client
     live_markets = list(flumine.markets.markets.keys())
-    for market_ids in chunks(live_markets, 100):
+    for market_ids in chunks(live_markets, 25):
         try:
             market_catalogues = client.betting_client.betting.list_market_catalogue(
                 filter=filters.market_filter(market_ids=market_ids),
-                max_results=100,
+                max_results=25,
                 market_projection=[
                     "COMPETITION",
                     "EVENT",


Test patch:
diff --git a/tests/test_worker.py b/tests/test_worker.py
index 1120df8..d0e42ba 100644
--- a/tests/test_worker.py
+++ b/tests/test_worker.py
@@ -95,7 +95,7 @@ class WorkersTest(unittest.TestCase):
                 "MARKET_START_TIME",
                 "MARKET_DESCRIPTION",
             ],
-            max_results=100,
+            max_results=25,
         )
         mock_flumine.handler_queue.put.assert_called_with(
             mock_events.MarketCatalogueEvent()
Repository: liampauling/flumine
Pull request #242 (2020-07-20 12:58:13)

Add middleware moved to init, Simulated needs to be the first middleware


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index aa4eb4c..8244bf7 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,13 @@
 Release History
 ---------------
 
+1.10.1 (2020-07-20)
++++++++++++++++++++
+
+**Bug Fixes**
+
+-Add middleware moved to init, Simulated needs to be the first middleware
+
 1.10.0 (2020-07-20)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 66bae86..5abb7ae 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.10.0"
+__version__ = "1.10.1"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/baseflumine.py b/flumine/baseflumine.py
index 06a5582..fc80fa4 100644
--- a/flumine/baseflumine.py
+++ b/flumine/baseflumine.py
@@ -45,6 +45,10 @@ class BaseFlumine:
         self.markets = Markets()
         self._market_middleware = []
 
+        # middleware
+        if self.BACKTEST or self.client.paper_trade:
+            self.add_market_middleware(SimulatedMiddleware())
+
         # all strategies
         self.strategies = Strategies()
 
@@ -296,9 +300,6 @@ class BaseFlumine:
             config.simulated = True
         else:
             config.simulated = False
-        # middleware
-        if self.BACKTEST or self.client.paper_trade:
-            self.add_market_middleware(SimulatedMiddleware())
         # login
         self.client.login()
         self.client.update_account_details()


Test patch:
diff --git a/tests/test_baseflumine.py b/tests/test_baseflumine.py
index c875fe5..393a976 100644
--- a/tests/test_baseflumine.py
+++ b/tests/test_baseflumine.py
@@ -18,6 +18,24 @@ class BaseFlumineTest(unittest.TestCase):
         self.assertEqual(len(self.base_flumine._trading_controls), 2)
         self.assertEqual(self.base_flumine._workers, [])
 
+    @mock.patch("flumine.baseflumine.SimulatedMiddleware")
+    @mock.patch("flumine.baseflumine.BaseFlumine.add_market_middleware")
+    def test_init_backtest(self, mock_add_market_middleware, mock_SimulatedMiddleware):
+        BaseFlumine.BACKTEST = True
+        mock_client = mock.Mock(paper_trade=False)
+        BaseFlumine(mock_client)
+        mock_add_market_middleware.assert_called_with(mock_SimulatedMiddleware())
+        BaseFlumine.BACKTEST = False
+
+    @mock.patch("flumine.baseflumine.SimulatedMiddleware")
+    @mock.patch("flumine.baseflumine.BaseFlumine.add_market_middleware")
+    def test_init_paper_trade(
+        self, mock_add_market_middleware, mock_SimulatedMiddleware
+    ):
+        mock_client = mock.Mock(paper_trade=True)
+        BaseFlumine(mock_client)
+        mock_add_market_middleware.assert_called_with(mock_SimulatedMiddleware())
+
     def test_run(self):
         with self.assertRaises(NotImplementedError):
             self.base_flumine.run()
Repository: liampauling/flumine
Pull request #308 (2020-11-02 11:24:34)

simulated bug on size remaining


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 553251c..e724902 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,13 @@
 Release History
 ---------------
 
+1.14.3 (2020-11-02)
++++++++++++++++++++
+
+**Improvements**
+
+- size reduction bug
+
 1.14.2 (2020-11-02)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 9299449..f60c1a1 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.14.2"
+__version__ = "1.14.3"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/execution/simulatedexecution.py b/flumine/execution/simulatedexecution.py
index 221aaff..c7c3b39 100644
--- a/flumine/execution/simulatedexecution.py
+++ b/flumine/execution/simulatedexecution.py
@@ -65,7 +65,7 @@ class SimulatedExecution(BaseExecution):
                     order, simulated_response, order_package.package_type
                 )
                 if simulated_response.status == "SUCCESS":
-                    if order.size_cancelled == order.size_remaining:
+                    if order.size_remaining == 0:
                         order.execution_complete()
                     else:
                         order.executable()


Test patch:
diff --git a/tests/test_execution.py b/tests/test_execution.py
index c79213c..f734e0d 100644
--- a/tests/test_execution.py
+++ b/tests/test_execution.py
@@ -886,7 +886,7 @@ class SimulatedExecutionTest(unittest.TestCase):
 
     @mock.patch("flumine.execution.simulatedexecution.SimulatedExecution._order_logger")
     def test_execute_cancel(self, mock__order_logger):
-        mock_order = mock.Mock(size_cancelled=2, size_remaining=2)
+        mock_order = mock.Mock(size_cancelled=2, size_remaining=0)
         mock_order.trade.__enter__ = mock.Mock()
         mock_order.trade.__exit__ = mock.Mock()
         mock_order_package = mock.Mock()
@@ -906,7 +906,7 @@ class SimulatedExecutionTest(unittest.TestCase):
 
     @mock.patch("flumine.execution.simulatedexecution.SimulatedExecution._order_logger")
     def test_execute_cancel_executable(self, mock__order_logger):
-        mock_order = mock.Mock(size_cancelled=2, size_remaining=3)
+        mock_order = mock.Mock(size_cancelled=2, size_remaining=2)
         mock_order.trade.__enter__ = mock.Mock()
         mock_order.trade.__exit__ = mock.Mock()
         mock_order_package = mock.Mock()
Repository: liampauling/flumine
Pull request #334 (2020-11-25 08:35:13)

Revert removal of `add_stream` (removed by accident)


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index 964adf6..c4db406 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,6 +3,13 @@
 Release History
 ---------------
 
+1.14.10 (2020-11-25)
++++++++++++++++++++
+
+**Bug Fixes**
+
+- Revert removal of `add_stream` (removed by accident)
+
 1.14.9 (2020-11-25)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 73fb43e..7b439a1 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.14.9"
+__version__ = "1.14.10"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/streams/historicalstream.py b/flumine/streams/historicalstream.py
index b962899..b5a394c 100644
--- a/flumine/streams/historicalstream.py
+++ b/flumine/streams/historicalstream.py
@@ -56,6 +56,10 @@ class HistoricListener(StreamListener):
         self.inplay = inplay
         self.seconds_to_start = seconds_to_start
 
+    def _add_stream(self, unique_id, stream_type):
+        if stream_type == "marketSubscription":
+            return Stream(self)
+
 
 class HistoricalStream(BaseStream):
 


Test patch:
diff --git a/tests/test_streams.py b/tests/test_streams.py
index 1f6dff1..7a0adf3 100644
--- a/tests/test_streams.py
+++ b/tests/test_streams.py
@@ -527,6 +527,12 @@ class TestHistoricListener(unittest.TestCase):
         self.assertTrue(self.listener.inplay)
         self.assertEqual(self.listener.seconds_to_start, 123)
 
+    @mock.patch("flumine.streams.historicalstream.Stream")
+    def test__add_stream(self, mock_stream):
+        self.assertEqual(
+            self.listener._add_stream(123, "marketSubscription"), mock_stream()
+        )
+
 
 class TestOrderStream(unittest.TestCase):
     def setUp(self) -> None:
Repository: liampauling/flumine
Pull request #434 (2021-05-16 06:40:59)

Liability param decimal place check
Check for > 2 decimal places for liability param received by order types MARKET_ON_CLOSE, LIMIT_ON_CLOSE. Addresses issue #433.


Patch:
diff --git a/HISTORY.rst b/HISTORY.rst
index d3f490a..6ffa5f6 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -3,17 +3,6 @@
 Release History
 ---------------
 
-1.18.9 (2021-05-17)
-+++++++++++++++++++
-
-**Improvements**
-
-- Notes and market notes added to order (potential race condition fix on transaction)
-
-**Bug Fixes**
-
-- #433 Liability persistence types not checked for <= 2 decimal places (@petercoles)
-
 1.18.8 (2021-05-14)
 +++++++++++++++++++
 
diff --git a/flumine/__version__.py b/flumine/__version__.py
index 1eb1d8c..2fa773b 100644
--- a/flumine/__version__.py
+++ b/flumine/__version__.py
@@ -1,6 +1,6 @@
 __title__ = "flumine"
 __description__ = "Betfair trading framework"
 __url__ = "https://github.com/liampauling/flumine"
-__version__ = "1.18.9"
+__version__ = "1.18.8"
 __author__ = "Liam Pauling"
 __license__ = "MIT"
diff --git a/flumine/controls/tradingcontrols.py b/flumine/controls/tradingcontrols.py
index 49f5be7..aef96b4 100644
--- a/flumine/controls/tradingcontrols.py
+++ b/flumine/controls/tradingcontrols.py
@@ -56,6 +56,8 @@ class OrderValidation(BaseControl):
             self._on_error(order, "Order liability is None")
         elif order.order_type.liability <= 0:
             self._on_error(order, "Order liability is less than 0")
+        elif order.order_type.liability != round(order.order_type.liability, 2):
+            self._on_error(order, "Order liability has more than 2dp")
 
     def _validate_betfair_min_size(self, order, order_type):
         client = self.flumine.client


Test patch:
diff --git a/tests/test_tradingcontrols.py b/tests/test_tradingcontrols.py
index ec7be0d..a84120d 100644
--- a/tests/test_tradingcontrols.py
+++ b/tests/test_tradingcontrols.py
@@ -173,6 +173,13 @@ class TestOrderValidation(unittest.TestCase):
         self.trading_control._validate_betfair_liability(order)
         mock_on_error.assert_called_with(order, "Order liability is less than 0")
 
+    @mock.patch("flumine.controls.tradingcontrols.OrderValidation._on_error")
+    def test__validate_betfair_liability_on_error_three(self, mock_on_error):
+        order = mock.Mock()
+        order.order_type.liability = 2.999
+        self.trading_control._validate_betfair_liability(order)
+        mock_on_error.assert_called_with(order, "Order liability has more than 2dp")
+
     @mock.patch("flumine.controls.tradingcontrols.OrderValidation._on_error")
     def test__validate_betfair_min_size_no_validation(self, mock_on_error):
         self.mock_flumine.client.min_bet_validation = False