I kicked stated my first auto trading with IB paper a/c. I found that I was not getting market data until I restarted the TWS. how can I monitor the following conenctions via api and alert myself if needed.
Your error() callback function will be called with an error code and error message whenever a connection is broken or reestablished. Examples: 12:55:59 ErrorCode=2103 ErrorMsg=Market data farm connection is broken:afarm 12:56:01 ErrorCode=2103 ErrorMsg=Market data farm connection is broken:jfarm 12:56:01 ErrorCode=2104 ErrorMsg=Market data farm connection is OK:afarm 12:56:10 ErrorCode=2104 ErrorMsg=Market data farm connection is OK:jfarm
Simple, via api, request time from server (=heartbeat) and report responses to hipchat via api, hipchat runs even on your mobile and is free of charge for individuals.
You can continually request the server's time, as described above by @dumpdapump Or you can continuously request market data for an instrument which trades almost always, such as the USD/EUR exchange rate. Once you don't receive data any more you might have lost connection. And take appropriate action.