/// <summary> /// Initialize a new instance of the <see cref="ApiDataProvider"/> /// </summary> public ApiDataProvider() { _api = new Api.Api(); _unsupportedSecurityType = new HashSet <SecurityType> { SecurityType.Future, SecurityType.FutureOption, SecurityType.Index, SecurityType.IndexOption }; _api.Initialize(_uid, _token, _dataPath); // If we have no value for organization get account preferred if (string.IsNullOrEmpty(_organizationId)) { var account = _api.ReadAccount(); _organizationId = account?.OrganizationId; Log.Trace($"ApiDataProvider(): Will use organization Id '{_organizationId}'."); } // Read in data prices and organization details _dataPrices = _api.ReadDataPrices(_organizationId); var organization = _api.ReadOrganization(_organizationId); // Determine if the user is subscribed to map and factor files (Data product Id 37) if (organization.Products.Where(x => x.Type == ProductType.Data).Any(x => x.Items.Any(x => x.Id == 37))) { _subscribedToEquityMapAndFactorFiles = true; } // Verify user has agreed to data provider agreements if (organization.DataAgreement.Signed) { //Log Agreement Highlights Log.Trace("ApiDataProvider(): Data Terms of Use has been signed. \r\n" + $" Find full agreement at: {_dataPrices.AgreementUrl} \r\n" + "==========================================================================\r\n" + $"CLI API Access Agreement: On {organization.DataAgreement.SignedTime:d} You Agreed:\r\n" + " - Display or distribution of data obtained through CLI API Access is not permitted. \r\n" + " - Data and Third Party Data obtained via CLI API Access can only be used for individual or internal employee's use.\r\n" + " - Data is provided in LEAN format can not be manipulated for transmission or use in other applications. \r\n" + " - QuantConnect is not liable for the quality of data received and is not responsible for trading losses. \r\n" + "=========================================================================="); Thread.Sleep(TimeSpan.FromSeconds(3)); } else { // Log URL to go accept terms throw new InvalidOperationException($"ApiDataProvider(): Must agree to terms at {_dataPrices.AgreementUrl}, before using the ApiDataProvider"); } // Verify we have the balance to maintain our purchase limit, if not adjust it to meet our balance var balance = organization.Credit.Balance; if (balance < _purchaseLimit) { if (_purchaseLimit != decimal.MaxValue) { Log.Error("ApiDataProvider(): Purchase limit is greater than balance." + $" Setting purchase limit to balance : {balance}"); } _purchaseLimit = balance; } }
public void GetPrices(string filePath) { if (_pricesCache == null) { _pricesCache = ApiClient.ReadDataPrices(TestOrganization); } // Make sure we actually have these prices for the test to work Assert.IsTrue(_pricesCache.Success); // Get the price int price = _pricesCache.GetPrice(filePath); Assert.IsTrue(price != 0); }
public void DataPriceRegex(string dataFile, string matchingRegex) { var setPrice = 10; var dataList = new DataPricesList { Prices = new List <PriceEntry>() { new PriceEntry() { Price = setPrice, RawRegEx = matchingRegex } } }; int price = dataList.GetPrice(dataFile); Assert.AreEqual(setPrice, price); }