/// <summary>
        /// Creates a new <see cref="IBrokerage"/> instance
        /// </summary>
        /// <param name="job">The job packet to create the brokerage for</param>
        /// <param name="algorithm">The algorithm instance</param>
        /// <returns>A new brokerage instance</returns>
        public override IBrokerage CreateBrokerage(LiveNodePacket job, IAlgorithm algorithm)
        {
            var errors = new List <string>();

            // read values from the brokerage data
            var keyId       = Read <string>(job.BrokerageData, "alpaca-key-id", errors);
            var secretKey   = Read <string>(job.BrokerageData, "alpaca-secret-key", errors);
            var tradingMode = Read <string>(job.BrokerageData, "alpaca-trading-mode", errors);

            if (errors.Count != 0)
            {
                // if we had errors then we can't create the instance
                throw new Exception(string.Join(System.Environment.NewLine, errors));
            }

            tradingMode = tradingMode.ToLower();
            if (!tradingMode.Equals("live") && !tradingMode.Equals("paper"))
            {
                // if the trading mode is invalid, do not proceed further
                throw new Exception("Available trading mode: paper/live");
            }

            var brokerage = new AlpacaBrokerage(algorithm.Transactions, algorithm.Portfolio, keyId, secretKey, tradingMode);

            Composer.Instance.AddPart <IDataQueueHandler>(brokerage);

            return(brokerage);
        }
示例#2
0
        /// <summary>
        /// Creates a new <see cref="IBrokerage"/> instance
        /// </summary>
        /// <param name="job">The job packet to create the brokerage for</param>
        /// <param name="algorithm">The algorithm instance</param>
        /// <returns>A new brokerage instance</returns>
        public override IBrokerage CreateBrokerage(LiveNodePacket job, IAlgorithm algorithm)
        {
            var errors = new List <string>();

            // read values from the brokerage data
            var keyId       = Read <string>(job.BrokerageData, "alpaca-key-id", errors);
            var secretKey   = Read <string>(job.BrokerageData, "alpaca-secret-key", errors);
            var tradingMode = Read <string>(job.BrokerageData, "alpaca-trading-mode", errors);

            if (errors.Count != 0)
            {
                // if we had errors then we can't create the instance
                throw new Exception(string.Join(Environment.NewLine, errors));
            }

            tradingMode = tradingMode.ToLowerInvariant();
            if (!tradingMode.Equals("live") && !tradingMode.Equals("paper"))
            {
                // if the trading mode is invalid, do not proceed further
                throw new Exception("Available trading mode: paper/live");
            }

            var handlesMarketData = job.DataQueueHandler.EndsWith("AlpacaBrokerage");

            var brokerage = new AlpacaBrokerage(algorithm.Transactions,
                                                algorithm.Portfolio,
                                                keyId,
                                                secretKey,
                                                tradingMode,
                                                handlesMarketData,
                                                Composer.Instance.GetExportedValueByTypeName <IDataAggregator>(Config.Get("data-aggregator", "QuantConnect.Lean.Engine.DataFeeds.AggregationManager")));

            Composer.Instance.AddPart <IDataQueueHandler>(brokerage);

            return(brokerage);
        }