-- -----------------------------------------------------------------------------
-- Requests

requests :: IB ()
requests = do
  
  display "Starting"
  displayStatus
  connect
  reqConData
  reqMktData
  recvP 10
  displayStatus
  disconnect
  delay 5
  connect
  reqMktData
  recvP 10
  delay 5
  stop
  displayStatus
  display "Finished"
  
  where
  
  reqConData = requestContractData conES
  reqMktData = requestMarketData conES [] False
  displayStatus = status >>= display . show
  recvP n = replicateM_ n $ recv >>= display . show
  delay t = liftIO $ threadDelay (t*1000000)
  display = liftIO . putStrLn
  
-- -----------------------------------------------------------------------------
-- Main
requests :: IB ()
requests = do
  
  display "Starting"
  displayStatus
  connect
  reqConData
  reqMktData
  recvP 10
  displayStatus
  disconnect
  delay 5
  connect
  reqMktData
  recvP 10
  delay 5
  stop
  displayStatus
  display "Finished"
  
  where
  
  reqConData = requestContractData conES
  reqMktData = requestMarketData conES [] False
  displayStatus = status >>= display . show
  recvP n = replicateM_ n $ recv >>= display . show
  delay t = liftIO $ threadDelay (t*1000000)
  display = liftIO . putStrLn
  
-- -----------------------------------------------------------------------------
-- Main
requests = do
  
  display "Starting"
  displayStatus
  connect
  reqConData
  reqMktData
  recvP 10
  displayStatus
  disconnect
  delay 5
  connect
  reqMktData
  recvP 10
  delay 5
  stop
  displayStatus
  display "Finished"
  
  where
  
  reqConData = requestContractData conES
  reqMktData = requestMarketData conES [] False
  displayStatus = status >>= display . show
  recvP n = replicateM_ n $ recv >>= display . show
  delay t = liftIO $ threadDelay (t*1000000)
  display = liftIO . putStrLn
  
-- -----------------------------------------------------------------------------
-- Main