Home / Trading Apps / Consuming data: comparing FTP and web services…

Consuming data: comparing FTP and web services…

At Xignite we consume data through a wide variety of formats, such as FTP and web services, and we run tens of thousands of checks against our own services. Let’s look at the differences in consuming data through FTP and web services.

When consuming data through FTP you have to:

  1. Log into the FTP site.
  2. Navigate to the appropriate location.
  3. Download the correct file.

Let’s take a look at Microsoft’s own documentation for those first 3 steps:

// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
request.Method = WebRequestMethods.Ftp.DownloadFile;

// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
    
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());

Console.WriteLine("Download Complete, status 0", response.StatusDescription);
    
reader.Close();
response.Close();  

http://msdn.microsoft.com/en-us/library/ms229711%28v=vs.110%29.aspx

But there is still a 4th step: you have parse that data to be able to pick what you want out of it. Here’s a quick example from StackOverflow:

public static List<string> SplitCSV(string line)

    if (string.IsNullOrEmpty(line))
        throw new ArgumentException();

    List<string> result = new List<string>();

    bool inQuote = false;
    StringBuilder val = new StringBuilder();

    // parse line
    foreach (var t in line.Split(','))
    
        int count = t.Count(c => c == '"');

        if (count > 2 && !inQuote)
        
            inQuote = true;
            val.Append(t);
            val.Append(',');
            continue;
        

        if (count > 2 && inQuote)
        
            inQuote = false;
            val.Append(t);
            result.Add(val.ToString());
            continue;
        

        if (count == 2 && !inQuote)
        
            result.Add(t);
            continue;
        

        if (count == 2 && inQuote)
        
            val.Append(t);
            val.Append(',');
            continue;
        
    

    // remove quotation
    for (int i = 0; i < result.Count; i++)
    
        string t = result[i];
        result[i] = t.Substring(1, t.Length - 2);
    

    return result;

http://stackoverflow.com/questions/316649/csv-parsing

Of course, you’d have to write more code to piece the two together. You’d have to loop over the above for every line in the file, then pick out the data you want- so it would take even more code than the above just to extract a price.

However, the point of this post isn’t walking through all the details of consuming data over FTP. So let’s turn our attention to consuming data through web services. To use web services, I just have to initialize a few objects and issue a call:

//declare and initialize variables
RemoteGlobalQuotes.XigniteGlobalQuotes GlobalQuotesService = new RemoteGlobalQuotes.XigniteGlobalQuotes();
RemoteGlobalQuotes.Header GlobalQuotesHeader = new RemoteGlobalQuotes.Header();
RemoteGlobalQuotes.GlobalQuote Result = null;

GlobalQuotesHeader.Username = "Your token here";
GlobalQuotesService.HeaderValue = GlobalQuotesHeader;

//...then just one line to call the service to get a quote for Jack in the Box
Result = GlobalQuotesService.GetGlobalDelayedQuote("JACK", RemoteGlobalQuotes.IdentifierTypes.Symbol);

//You don't have to parse, that's done for you so just display the last price
Console.WriteLine(string.Format("Current delayed price for JACK is 0", Result.Last));

The above is significantly less code than FTP, yet does even more such as packaging the result into native C# objects that I can use directly in my code.

Even if you aren’t a developer you can see from the above that your company’s developers are going to be spending significant more time pulling data through FTP as opposed to a web service. To me it has always been a no-brainer: why spend your time on consuming data through legacy delivery systems such as FTP instead of using an easy to consume mechanism such as web services? If getting data is easy, you’re free to spend more time doing what matters to your business: building the application.

Disclaimer: to keep the examples concise, error handling has been omitted. That is something you’d want to include in production code.

To test drive our market data APIs and experience for yourself how easy they are to integrate into your applications, request a free trial.


Source link


About admin

Check Also

01Oct2014-AWSOutageOnPingdom.png

AWS Issue…

On October 1, 2014 at 3:31 AM Pacific time I was awoken for a series ...

Leave a Reply

Your email address will not be published. Required fields are marked *

NFL Jerseys 2019