Browse Source

broker: sqnum request

master
Denis Tereshkin 2 years ago
parent
commit
46067f1303
  1. 3
      src/ATrade/Broker/Client.hs
  2. 3
      src/ATrade/Broker/Server.hs

3
src/ATrade/Broker/Client.hs

@ -113,7 +113,7 @@ brokerClientThread socketIdentity ctx ep cmd comp killMv secParams logger = fina @@ -113,7 +113,7 @@ brokerClientThread socketIdentity ctx ep cmd comp killMv secParams logger = fina
log Debug "Broker.Client" "Connected"
isTimeout <- newIORef False
whileM_ (andM [isNothing <$> tryReadMVar killMv, (== False) <$> readIORef isTimeout]) $ do
whileM_ (andM [isNothing <$> tryReadMVar killMv, not <$> readIORef isTimeout]) $ do
(request, resp) <- takeMVar cmd
send sock [] (BL.toStrict $ encode request)
incomingMessage <- timeout 5000000 $ receive sock
@ -159,6 +159,7 @@ notificationThread clientIdentity callbacks ctx ep idCounter cmdVar killMv secPa @@ -159,6 +159,7 @@ notificationThread clientIdentity callbacks ctx ep idCounter cmdVar killMv secPa
initialSqnum <- requestCurrentSqnum cmdVar idCounter clientIdentity
log Debug "Broker.Client" $ "Got current sqnum: " <> (T.pack . show) initialSqnum
notifSqnumRef <- newIORef initialSqnum
whileM_ (isNothing <$> tryReadMVar killMv) $ do
evs <- poll 5000 [Sock sock [In] Nothing]

3
src/ATrade/Broker/Server.hs

@ -208,7 +208,7 @@ brokerServerThread state logger = finally brokerServerThread' cleanup @@ -208,7 +208,7 @@ brokerServerThread state logger = finally brokerServerThread' cleanup
unless (null . L.head $ events) $ do
msg <- receiveMulti sock
case msg of
[peerId, _, payload] ->
[peerId, _, payload] -> do
case eitherDecode . BL.fromStrict $ payload of
Right request -> do
let sqnum = requestSqnum request
@ -266,6 +266,7 @@ brokerServerThread state logger = finally brokerServerThread' cleanup @@ -266,6 +266,7 @@ brokerServerThread state logger = finally brokerServerThread' cleanup
log Warning "Broker.Server" $ "Unknown account: " <> (orderAccountId order)
return $ ResponseError "Unknown account"
RequestCancelOrder sqnum clientIdentity localOrderId -> do
log Debug "Broker.Server" $ "Request: cancel order:" <> (T.pack . show) request
m <- orderToBroker <$> readIORef state
bm <- orderMap <$> readIORef state
let fullOrderId = FullOrderId clientIdentity localOrderId

Loading…
Cancel
Save