Exemple #1
0
        /// <summary>
        /// Create an API Class with the specified credentials
        /// </summary>
        /// <param name="uid">User id</param>
        /// <param name="token">Token string</param>
        /// <returns>API class for placing calls</returns>
        private IApi CreateApiAccessor(int uid, string token)
        {
            var api = new Api.Api();

            api.Initialize(uid, token);
            return(api);
        }
Exemple #2
0
        public void ApiWillAuthenticate_ValidCredentials_Successfully()
        {
            var api = new Api.Api();

            api.Initialize(_testAccount, _testToken, _dataFolder);
            Assert.IsTrue(api.Connected);
        }
Exemple #3
0
        /// <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;
            }
        }
Exemple #4
0
        public bool Fetch(Symbol symbol, DateTime date, Resolution resolution, TickType tickType)
        {
            Log.Trace(
                string.Format(
                    "Attempting to get data from QuantConnect.com's data library for symbol({0}), resolution({1}) and date({2}).",
                    symbol.ID, resolution, date.Date.ToShortDateString()));

            var api = new Api.Api();

            api.Initialize(_uid, _token, _dataPath);

            var download = api.DownloadData(symbol, resolution, date);

            if (download)
            {
                Log.Trace(
                    string.Format(
                        "Successfully retrieved data for symbol({0}), resolution({1}) and date({2}).",
                        symbol.ID, resolution, date.Date.ToShortDateString()));
                return(true);
            }


            Log.Error(
                string.Format(
                    "Unable to remotely retrieve data for symbol({0}), resolution({1}) and date({2}). Please make sure you have the necessary data in your online QuantConnect data library.",
                    symbol.ID, resolution, date.Date.ToShortDateString()));
            return(false);
        }
Exemple #5
0
        public void ApiWillAuthenticate_InvalidCredentials_Unsuccessfully()
        {
            var api = new Api.Api();

            api.Initialize(_testAccount, "", _dataFolder);
            Assert.IsFalse(api.Connected);
        }
Exemple #6
0
        public void Setup()
        {
            _testAccount = Config.GetInt("job-user-id", 1);
            _testToken   = Config.Get("api-access-token", "ec87b337ac970da4cbea648f24f1c851");
            _dataFolder  = Config.Get("data-folder");

            _api = new Api.Api();
            _api.Initialize(_testAccount, _testToken, _dataFolder);
        }
Exemple #7
0
        public void Setup()
        {
            _testAccount      = Config.GetInt("job-user-id");
            _testToken        = Config.Get("api-access-token");
            _testOrganization = Config.Get("job-organization-id", "EnterOrgHere"); //This org must be your preferred org
            _dataFolder       = Config.Get("data-folder");

            _api = new Api.Api();
            _api.Initialize(_testAccount, _testToken, _dataFolder);
        }
Exemple #8
0
        public void Setup()
        {
            TestAccount      = Config.GetInt("job-user-id", 1);
            TestToken        = Config.Get("api-access-token", "EnterTokenHere");
            TestOrganization = Config.Get("job-organization-id", "EnterOrgHere");
            DataFolder       = Config.Get("data-folder");

            ApiClient = new Api.Api();
            ApiClient.Initialize(TestAccount, TestToken, DataFolder);
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
0
 /// <summary>
 /// Authenticate API
 /// </summary>
 /// <param name="credentials">User id and access token to authenticate the API</param>
 /// <returns>true if successfully authenticated API, false otherwise</returns>
 public bool Login(Credentials credentials)
 {
     VSActivityLog.Info("Authenticating QuantConnect API");
     try
     {
         var api = new Api.Api();
         api.Initialize(int.Parse(credentials.UserId), credentials.AccessToken, Globals.DataFolder);
         if (api.Connected)
         {
             _api = api;
             return(true);
         }
     }
     catch (FormatException)
     {
         VSActivityLog.Error("User id is not a valid number");
     }
     return(false);
 }
        /// <summary>
        /// Authenticate API
        /// </summary>
        /// <param name="credentials">User id and access token to authenticate the API</param>
        /// <returns>true if successfully authenticated API, false otherwise</returns>
        public async System.Threading.Tasks.Task <bool> Login(Credentials credentials)
        {
            VSActivityLog.Info("Authenticating QuantConnect API");
            try
            {
                var api = new Api.Api();
                api.Initialize(int.Parse(credentials.UserId), credentials.AccessToken, Globals.DataFolder);
                var apiConnected = await System.Threading.Tasks.Task.Run(() => api.Connected);

                if (apiConnected)
                {
                    _api = api;
                    return(true);
                }
            }
            catch (Exception exception)
            {
                VsUtils.ShowErrorMessageBox(ServiceProvider.GlobalProvider,
                                            "QuantConnect Exception", exception.ToString());
            }
            return(false);
        }
 /// <summary>
 /// Authenticate API
 /// </summary>
 /// <param name="userId">User id to authenticate the API</param>
 /// <param name="accessToken">Access token to authenticate the API</param>
 /// <returns>true if successfully authenticated API, false otherwise</returns>
 public bool LogIn(Credentials credentials, string dataFolderPath)
 {
     _log.Info($"Authenticating QuantConnect API with data folder {dataFolderPath}");
     try
     {
         var api = new Api.Api();
         api.Initialize(int.Parse(credentials.UserId), credentials.AccessToken, dataFolderPath);
         if (api.Connected)
         {
             _api = api;
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (FormatException)
     {
         // User id is not a number
         return(false);
     }
 }
Exemple #14
0
 public void Setup()
 {
     _api = new Api.Api();
     _api.Initialize(_testAccount, _testToken, _dataFolder);
 }
Exemple #15
0
        public void NullDataFolder()
        {
            var api = new Api.Api();

            Assert.DoesNotThrow(() => api.Initialize(TestAccount, "", null));
        }
 /// <summary>
 /// Constructor that initializes Api Connection
 /// </summary>
 public ApiDataQueueHandler()
 {
     _api = new Api.Api();
     _api.Initialize(Config.GetInt("job-user-id", 0), Config.Get("api-access-token", ""), Config.Get("data-folder"));
 }
        /// <summary>
        /// Initialize a new instance of the <see cref="ApiDataProvider"/>
        /// </summary>
        public ApiDataProvider()
        {
            _api = new Api.Api();

            _api.Initialize(_uid, _token, _dataPath);
        }
 /// <summary>
 /// Constructor that initializes Api Connection
 /// </summary>
 public ApiDataQueueHandler()
 {
     _api = new Api.Api();
     _api.Initialize(Config.GetInt("job-user-id", 0), Config.Get("api-access-token", ""), Config.Get("data-folder"));
 }
Exemple #19
0
 public void Setup()
 {
     _api = new Api.Api();
     _api.Initialize(_testAccount, _testToken, _dataFolder);
 }
Exemple #20
0
 /// <summary>
 /// Create an API Class with the specified credentials
 /// </summary>
 /// <param name="uid">User id</param>
 /// <param name="token">Token string</param>
 /// <returns>API class for placing calls</returns>
 private IApi CreateApiAccessor(int uid, string token)
 {
     var api = new Api.Api();
     api.Initialize(uid, token);
     return api;
 }