C#
Here is a small example of making a GetQuoteSnap request for a couple symbols and pulling the symbol and last price from the result.
using System;
using System.Net;
using System.Threading.Tasks;
using System.Xml.Linq;
class Program
{
static void Main(string[] args)
{
string username = "username";
string password = "password";
// The symbols to request in an array
string[] symbols = { "@C@1", "@C@2" };
// Join the array into a comma-separated string
string joinedSymbols = string.Join(",", symbols);
// Insert the credentials and symbols into the URL
string url = String.Format("https://pxweb.dtn.com/PXWebSvc/PXServiceWeb.svc/GetQuoteSnap?UserID={0}&Password={1}&Type=P&Symbol={2}&SymbolLimit=&PageToken=&Market=&Vendor=&Format=", username, password, joinedSymbols);
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Make an HTTP GET request to the URL
using (var client = new WebClient())
{
try
{
string xmlResponse = client.DownloadString(url);
// Parse the XML response
XDocument doc = XDocument.Parse(xmlResponse);
// Find all Quote elements and print their TickerSymbol attributes
var quotes = doc.Descendants("Quote");
foreach (var quote in quotes)
{
string tickerSymbol = quote.Attribute("TickerSymbol").Value;
string last = quote.Element("Last").Value;
Console.WriteLine(String.Format("{0} : {1}", tickerSymbol, last));
}
}
catch (WebException e)
{
Console.WriteLine(String.Format("Error: {0}", e.Message));
}
catch (Exception e)
{
Console.WriteLine(String.Format("An error occurred: {0}", e.Message));
}
}
}
}