コード例 #1
0
        public void TestSaveHistoricalDataEmptyFolder()
        {
            var fn = string.Empty;

            _hist = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
            _hist.OnQuoteSaved += (object sender, string exch, string filename) =>
            {
                fn = filename;
            };

            var starttime = _timenow - 10000 * _interval;
            var q         = CreateQuote(starttime, 700);
            var r         = _hist.Save(q);

            Assert.IsTrue(r);

            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 0));

            starttime = q.LastTime + _interval;
            q         = CreateQuote(starttime, 700);
            r         = _hist.Save(q);
            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 0));

            starttime = q.LastTime - 100 * _interval;
            q         = CreateQuote(starttime, 700);
            r         = _hist.Save(q);
            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 1));
            q = QuoteBasicExension.LoadFile(fn);
            Assert.IsTrue(q.Count == 599);
        }
コード例 #2
0
        public void TestLoadHistoricalDataWithQuote()
        {
            _hist     = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
            _lasttime = _timenow - 10000 * _interval;

            //download 700 bars and save to first file
            var r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            var quote = _hist.Load(_symbol, _interval, 0, 1000);

            Assert.IsTrue(quote != null && quote.Count == 700);

            //download 700 bars and save to first file
            r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            quote = _hist.Load(_symbol, _interval, 0, 1000);
            Assert.IsTrue(quote != null && quote.Count == 1000);

            //download 700 bars and save to 2nd file
            r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            quote = _hist.Load(_symbol, _interval, 0, 1000);
            Assert.IsTrue(quote != null && quote.Count == 700);

            //download 700 bars and save to 2nd file
            r     = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            quote = _hist.Load(_symbol, _interval, 0, 1000);
            Assert.IsTrue(quote != null && quote.Count == 1000);
        }
コード例 #3
0
        public void TestLoadHistoricalDataNoQuote()
        {
            _hist = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);

            //since no quote in folder, null returned
            var quote = _hist.Load(_symbol, _interval, 0, 1000);

            Assert.IsTrue(quote == null);
        }
コード例 #4
0
        public void Initialize()
        {
            if (Directory.Exists(_folder))
            {
                Directory.Delete(_folder, true);
            }
            Directory.CreateDirectory(_folder);

            _timenow = DateTime.UtcNow.GetUnixTimeFromUTC() / _interval * _interval;

            _moqDownload.Setup(d => d.Exchange).Returns(_exchange);
            _moqDownload.Setup(d => d.Download(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>())).Returns <string, int, int>((s, i, t) =>
            {
                //if (_count == 0)
                //    _lasttime = _timenow - _startInterval * _interval;
                if (_count < 0)
                {
                    return(Task.FromResult <IQuoteBasicBase>(null));
                }
                else
                {
                    ++_count;

                    //create quote file and save to folder
                    var q1 = new QuoteBasicBase(_symbol, _interval);
                    var ts = _lasttime + _interval;
                    for (int j = 0; j < 700; j++)
                    {
                        q1.AddUpdate(ts + j * _interval, 0, 0, 0, 0, 0);
                    }
                    _lasttime = q1.LastTime;

                    return(Task.FromResult <IQuoteBasicBase>(q1));
                }
            });



            _hist = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
        }
コード例 #5
0
        public void TestUpdateHistoricalDataWithExistingQuoteFilesDownloadSuccess()
        {
            //create quote file and save to folder
            var filename = this.GetQuoteFileName(_symbol, _interval, 0);
            var q        = new QuoteBasicBase(_symbol, _interval) as IQuoteBasicBase;
            var ts1      = _timenow - 10000 * _interval;

            for (int j = 0; j < 700; j++)
            {
                q.AddUpdate(ts1 + j * _interval, 0, 0, 0, 0, 0);
            }
            q.SaveToFile(filename);

            _lasttime = q.LastTime + _interval;
            _hist     = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
            var fn = string.Empty;

            _hist.OnQuoteSaved += (object sender, string exch, string file) => fn = file;

            //append to the existing quote file
            var r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;

            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 0));
            q = q.LoadFile(fn);
            Assert.IsTrue(q.Count == 1400);

            //since the number is larger than maxNumbars, a new file is created
            r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 1));
            q = q.LoadFile(fn);
            Assert.IsTrue(q.Count == 700);

            r = _hist.Update(_moqDownload.Object, _symbol, _interval).Result;
            Assert.IsTrue(r);
            Assert.IsTrue(fn == this.GetQuoteFileName(_symbol, _interval, 1));
            q = q.LoadFile(fn);
            Assert.IsTrue(q.Count == 1400);
        }
コード例 #6
0
 public void TestSaveHistoricalDataNull()
 {
     _hist = new QuoteBasicFileStore(_exchange, _folder, _numBarsInFile);
 }