Beispiel #1
0
        /// <summary>
        /// Retrieves data to be used in an algorithm.
        /// If file does not exist, an attempt is made to download them from the api
        /// </summary>
        /// <param name="key">File path representing where the data requested</param>
        /// <returns>A <see cref="Stream"/> of the data requested</returns>
        public override Stream Fetch(string key)
        {
            return(DownloadOnce(key, s =>
            {
                // Verify we have enough credit to handle this
                var pricePath = _api.FormatPathForDataRequest(key);
                var price = _dataPrices.GetPrice(pricePath);

                // No price found
                if (price == -1)
                {
                    throw new ArgumentException($"ApiDataProvider.Fetch(): No price found for {pricePath}");
                }

                if (_purchaseLimit < price)
                {
                    throw new ArgumentException($"ApiDataProvider.Fetch(): Cost {price} for {pricePath} data exceeds remaining purchase limit: {_purchaseLimit}");
                }

                if (DownloadData(key))
                {
                    // Update our purchase limit.
                    _purchaseLimit -= price;
                }
            }));
        }
Beispiel #2
0
        public void FormattingPathForDataRequestsAreCorrect(string dataFolder, string dataToDownload)
        {
            var api = new Api.Api();

            api.Initialize(TestAccount, TestToken, dataFolder);

            var path = Path.Combine(dataFolder, dataToDownload);

            var result = api.FormatPathForDataRequest(path);

            Assert.AreEqual(dataToDownload.Replace("\\", "/", StringComparison.InvariantCulture), result);
        }
Beispiel #3
0
        public void FormattingPathForDataRequestsAreCorrect(string dataFolder)
        {
            var api = new Api.Api();

            api.Initialize(TestAccount, TestToken, dataFolder);

            var dataToDownload = "forex/oanda/daily/eurusd.zip";
            var path           = Path.Combine(dataFolder, dataToDownload);

            var result = api.FormatPathForDataRequest(path);

            Assert.AreEqual(dataToDownload, result);
        }