private static T[] CreateCandles <T>(FakeOandaContext.FakeOandaInstrument inst, TimeSpan interval, int count, DateTime?start, DateTime?end, bool includeFirst, Func <DateTime, FakeOandaContext.FakeOandaPrice, FakeOandaContext.FakeOandaPrice, FakeOandaContext.FakeOandaPrice, FakeOandaContext.FakeOandaPrice, int, T> factory)
        {
            var i      = 0;
            var result = new T[count];

            for (var d = includeFirst ? start.Value : start.Value + interval; d <= end.Value; d += interval)
            {
                var open  = inst.CurrentPrice(d);
                var close = inst.CurrentPrice(d + interval);

                FakeOandaContext.FakeOandaPrice high;
                FakeOandaContext.FakeOandaPrice low;
                if (open.Ask > close.Ask)
                {
                    high = open;
                    low  = close;
                }
                else
                {
                    high = close;
                    low  = open;
                }

                result[i++] = factory(d, open, high, low, close, (d.Hour + 120) * 200);
            }

            return(result);
        }
        public static FakeOandaContext.FakeOandaPrice CurrentPrice(this FakeOandaContext.FakeOandaInstrument instrument, DateTime time)
        {
            var diff = ((decimal)Math.Cos(2 * Math.PI * (time.Hour / 12.0))) * instrument.BaseAsk * 0.01m;
            var ask  = instrument.BaseAsk + diff;
            var bid  = instrument.BaseBid + diff;
            var exp  = (int)Math.Abs(Math.Log10(instrument.Precision));

            return(new FakeOandaContext.FakeOandaPrice(instrument.Instrument, time, Math.Round(ask, exp), Math.Round(bid, exp)));
        }