The source data feed is free for personal, academic and educational use. To connect to the Realtime Trains API, you will need access credentials - see here for further information.
First, add the following keys to your web.config or app.config, using the credentials supplied by RTT.
<add key="Api.Username" value="YOUR-API-USERNAME" />
<add key="Api.Password" value="YOUR-API-PASSWORD" />
<add key="Api.Url" value="https://api.rtt.io/api/v1/" />
Now instantiate a new client object:
var rttClient = new RealtimeTrainsClient();
You can now search for arrivals, departures, or get detailed information on a specific service. For example, to get all arrivals and departures in the near future between Leeds and London Kings Cross, in both directions:
var rttClient = new RealtimeTrainsClient();
var arrivals = rttClient.GetDepartures("KGX", "LDS");
var departures = rttClient.GetDepartures("LDS", "KGX");
For more information, see the Realtime Trains Location Listing documentation.
Once you have results, you can get further detailed information using the service unique Id, and a call to the GetService() method:
var service = rttClient.GetService(serviceUid, new DateFilter(date.Year, date.Month, date.Day));
Note that 'service Unique IDs' are only unique to a particular day, so you must also pass in the date to this call. For more information, see the Realtime Trains Service Information documentation.
TheTrain.rocks is a web app that uses this Nuget package to allow searching for UK train services, and will reveal the platform numbers before they are announced on the station information boards.