コード例 #1
0
        /// <summary>
        /// Creates a new IBrokerage instance and set ups the environment for the brokerage
        /// </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 datas
            var useTws                = Config.GetBool("ib-use-tws");
            var port                  = Config.GetInt("ib-port", 4001);
            var host                  = Config.Get("ib-host", "127.0.0.1");
            var twsDirectory          = Config.Get("ib-tws-dir", "C:\\Jts");
            var ibControllerDirectory = Config.Get("ib-controller-dir", "C:\\IBController");

            var account          = Read <string>(job.BrokerageData, "ib-account", errors);
            var userID           = Read <string>(job.BrokerageData, "ib-user-name", errors);
            var password         = Read <string>(job.BrokerageData, "ib-password", errors);
            var agentDescription = Read <AgentDescription>(job.BrokerageData, "ib-agent-description", errors);

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

            // launch the IB gateway
            InteractiveBrokersGatewayRunner.Start(ibControllerDirectory, twsDirectory, userID, password, useTws);

            var ib = new InteractiveBrokersBrokerage(algorithm.Transactions, algorithm.Portfolio, account, host, port, agentDescription);

            Composer.Instance.AddPart <IDataQueueHandler>(ib);
            return(ib);
        }
コード例 #2
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// Stops the InteractiveBrokersGatewayRunner
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public override void Dispose()
 {
     InteractiveBrokersGatewayRunner.Stop();
 }