Tickety, Tickety Tick

TickerTo develop and back-test trading algos its essential to have great gobs of historical data on hand, almost always at the tick level.  More often than not this data comes from your broker—OANDAAlpariDukasCopy, and Integral (TrueFX), to name a popular few—whether through commercial platforms like MT4 or proprietary APIs.  Alternately, one can use a generic downloader like Birt’s Tick Data Suite.

Over the years I’ve worked with more than a dozen brokers and other data providers so you think I’d have a handle on this stuff by now, but nothing could be further from the truth.  No, its an ever changing and messy landscape.   Continue reading

Cancel That

Cancellation in a multi-threaded Console App can be surprisingly difficult, even though I’ve done it dozens (hundreds?!?) of times before.  As any programmer can tell you, there are the “Things you know” and “Things you merely think you know.”  In programming, fiddly little details count.

I won’t go into the trade-offs between using Tasks or Parallel.For[Each] or TPL DataFlow, but suffice it to say that the later is both the most useful and easiest to get right.  Enjoy…

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;

namespace CancelDemo
   class Program
      static void Main(string[] args)
         Console.WriteLine("Press any key to cancel...");

         var cts = new CancellationTokenSource();

         var client = new HttpClient();

            var fetcher = new ActionBlock<string>(
               async url =>
                  await client.GetAsync(url, cts.Token);

                  Console.WriteLine($"FETCHED {url}");
               new ExecutionDataflowBlockOptions()
                  CancellationToken = cts.Token,
                  MaxDegreeOfParallelism = Environment.ProcessorCount

            urls.ForEach(url => fetcher.Post(url));


            var readKey = new TaskFactory(cts.Token).StartNew(() =>
               while (!Console.KeyAvailable)



            Task.WaitAny(new Task[] { fetcher.Completion, readKey });
         catch (OperationCanceledException)
         catch (Exception error)

            Console.WriteLine("Error: " + error.Message);

         Console.Write("Press any key to terminate...");


      private static List<string> urls = new List<string>()