diff --git a/libatrade.cabal b/libatrade.cabal index dbbca02..f37f4a0 100644 --- a/libatrade.cabal +++ b/libatrade.cabal @@ -15,6 +15,7 @@ cabal-version: >=1.10 library hs-source-dirs: src + ghc-options: -Wincomplete-patterns exposed-modules: ATrade.Types , ATrade.QuoteSource.Server , ATrade.Broker.Protocol @@ -37,7 +38,7 @@ library executable libatrade-exe hs-source-dirs: app main-is: Main.hs - ghc-options: -threaded -rtsopts -with-rtsopts=-N + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wincomplete-patterns build-depends: base , libatrade , pretty-hex @@ -69,7 +70,7 @@ test-suite libatrade-test , bytestring , monad-loops , uuid - ghc-options: -threaded -rtsopts -with-rtsopts=-N + ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wincomplete-patterns default-language: Haskell2010 other-modules: ArbitraryInstances , TestBrokerProtocol diff --git a/src/ATrade/Broker/Protocol.hs b/src/ATrade/Broker/Protocol.hs index c99334a..d3c226a 100644 --- a/src/ATrade/Broker/Protocol.hs +++ b/src/ATrade/Broker/Protocol.hs @@ -47,6 +47,7 @@ instance ToJSON BrokerServerRequest where data BrokerServerResponse = ResponseOrderSubmitted OrderId | ResponseOrderCancelled OrderId | ResponseNotifications [Notification] + | ResponseError T.Text deriving (Eq, Show) instance FromJSON BrokerServerResponse where @@ -59,12 +60,16 @@ instance FromJSON BrokerServerResponse where return $ ResponseOrderCancelled oid | HM.member "notifications" obj -> do notifications <- obj .: "notifications" - ResponseNotifications <$> parseJSON notifications) + ResponseNotifications <$> parseJSON notifications + | HM.member "error" obj -> do + error <- obj .: "error" + ResponseError <$> parseJSON error) instance ToJSON BrokerServerResponse where toJSON (ResponseOrderSubmitted oid) = object [ "order-id" .= oid ] toJSON (ResponseOrderCancelled oid) = object [ "order-cancelled" .= oid ] toJSON (ResponseNotifications notifications) = object [ "notifications" .= notifications ] + toJSON (ResponseError errorMessage) = object [ "error" .= errorMessage ] data Notification = OrderNotification OrderId OrderState | TradeNotification Trade deriving (Eq, Show) diff --git a/test/ArbitraryInstances.hs b/test/ArbitraryInstances.hs index d8f7a02..7d3dafb 100644 --- a/test/ArbitraryInstances.hs +++ b/test/ArbitraryInstances.hs @@ -111,8 +111,9 @@ instance Arbitrary BrokerServerRequest where instance Arbitrary BrokerServerResponse where arbitrary = do - t <- choose (1, 3) :: Gen Int + t <- choose (1, 4) :: Gen Int if | t == 1 -> ResponseOrderSubmitted <$> arbitrary | t == 2 -> ResponseOrderCancelled <$> arbitrary | t == 3 -> ResponseNotifications <$> arbitrary + | t == 4 -> ResponseError <$> arbitrary