示例#1
0
        public void LiveBitfinexTest()
        {
            var key       = Config.Get("bitfinex-api-key");
            var secretKey = Config.Get("bitfinex-api-secret");

            // Create default algorithm settings
            var settings = new BitfinexLiveAlgorithmSettings(key, secretKey);

            var file = new ProjectFile
            {
                Name = "Main.cs",
                Code = File.ReadAllText("../../../Algorithm.CSharp/BasicTemplateAlgorithm.cs")
            };

            RunLiveAlgorithm(settings, file);
        }
示例#2
0
        public void LiveAlgorithmSettings_CanBeCreated_Successfully()
        {
            string user     = "";
            string password = "";
            BrokerageEnvironment environment = BrokerageEnvironment.Paper;
            string account   = "";
            string key       = "";
            string secretKey = "";

            // Oanda Custom Variables
            string accessToken      = "";
            var    dateIssuedString = "20160920";

            // Tradier Custom Variables
            string dateIssued   = "";
            string refreshToken = "";
            string lifetime     = "";

            // Create and test settings for each brokerage
            foreach (BrokerageName brokerageName in Enum.GetValues(typeof(BrokerageName)))
            {
                BaseLiveAlgorithmSettings settings = null;

                switch (brokerageName)
                {
                case BrokerageName.Default:
                    user     = Config.Get("default-username");
                    password = Config.Get("default-password");
                    settings = new DefaultLiveAlgorithmSettings(user, password, environment, account);

                    Assert.IsTrue(settings.Id == BrokerageName.Default.ToString());
                    break;

                case BrokerageName.FxcmBrokerage:
                    user     = Config.Get("fxcm-user-name");
                    password = Config.Get("fxcm-password");
                    settings = new FXCMLiveAlgorithmSettings(user, password, environment, account);

                    Assert.IsTrue(settings.Id == BrokerageName.FxcmBrokerage.ToString());
                    break;

                case BrokerageName.InteractiveBrokersBrokerage:
                    user     = Config.Get("ib-user-name");
                    password = Config.Get("ib-password");
                    account  = Config.Get("ib-account");
                    settings = new InteractiveBrokersLiveAlgorithmSettings(user, password, account);

                    Assert.IsTrue(settings.Id == BrokerageName.InteractiveBrokersBrokerage.ToString());
                    break;

                case BrokerageName.OandaBrokerage:
                    accessToken = Config.Get("oanda-access-token");
                    account     = Config.Get("oanda-account-id");

                    settings = new OandaLiveAlgorithmSettings(accessToken, environment, account);
                    Assert.IsTrue(settings.Id == BrokerageName.OandaBrokerage.ToString());
                    break;

                case BrokerageName.TradierBrokerage:
                    dateIssued   = Config.Get("tradier-issued-at");
                    refreshToken = Config.Get("tradier-refresh-token");
                    account      = Config.Get("tradier-account-id");

                    settings = new TradierLiveAlgorithmSettings(refreshToken, dateIssued, refreshToken, account);
                    break;

                case BrokerageName.Bitfinex:
                    key       = Config.Get("bitfinex-api-key");
                    secretKey = Config.Get("bitfinex-api-secret");

                    settings = new BitfinexLiveAlgorithmSettings(key, secretKey);
                    break;

                case BrokerageName.GDAX:
                    key       = Config.Get("gdax-api-key");
                    secretKey = Config.Get("gdax-api-secret");
                    var passphrase = Config.Get("gdax-api-passphrase");

                    settings = new GDAXLiveAlgorithmSettings(key, secretKey, passphrase);
                    break;

                case BrokerageName.AlphaStreams:
                    // No live algorithm settings
                    settings = new BaseLiveAlgorithmSettings();
                    break;

                case BrokerageName.Binance:
                    // No live algorithm settings
                    settings = new BaseLiveAlgorithmSettings();
                    break;

                default:
                    throw new Exception($"Settings have not been implemented for this brokerage: {brokerageName}");
                }

                // Tests common to all brokerage configuration classes
                Assert.IsTrue(settings != null);
                Assert.IsTrue(settings.Password == password);
                Assert.IsTrue(settings.User == user);

                // Oanda specific settings
                if (brokerageName == BrokerageName.OandaBrokerage)
                {
                    var oandaSetting = settings as OandaLiveAlgorithmSettings;

                    Assert.IsTrue(oandaSetting.AccessToken == accessToken);
                }

                // Tradier specific settings
                if (brokerageName == BrokerageName.TradierBrokerage)
                {
                    var tradierLiveAlogrithmSettings = settings as TradierLiveAlgorithmSettings;

                    Assert.IsTrue(tradierLiveAlogrithmSettings.DateIssued == dateIssued);
                    Assert.IsTrue(tradierLiveAlogrithmSettings.RefreshToken == refreshToken);
                    Assert.IsTrue(settings.Environment == BrokerageEnvironment.Live);
                }

                // reset variables
                user        = "";
                password    = "";
                environment = BrokerageEnvironment.Paper;
                account     = "";
            }
        }