Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new InteractiveBrokersBrokerage from the specified values
        /// </summary>
        /// <param name="orderMapping">An instance of IOrderIDMapping used to fetch Order objects by brokerage ID</param>
        /// <param name="account">The Interactive Brokers account name</param>
        /// <param name="host">host name or IP address of the machine where TWS is running. Leave blank to connect to the local host.</param>
        /// <param name="port">must match the port specified in TWS on the Configure&gt;API&gt;Socket Port field.</param>
        /// <param name="agentDescription">Used for Rule 80A describes the type of trader.</param>
        public InteractiveBrokersBrokerage(IOrderIDMapping orderMapping, string account, string host, int port, IB.AgentDescription agentDescription = IB.AgentDescription.Individual)
            : base("Interactive Brokers Brokerage")
        {
            _orderMapping     = orderMapping;
            _account          = account;
            _host             = host;
            _port             = port;
            _clientID         = IncrementClientID();
            _agentDescription = agentDescription;
            _client           = new IB.IBClient();

            // set up event handlers
            _client.UpdatePortfolio    += HandlePortfolioUpdates;
            _client.OrderStatus        += HandleOrderStatusUpdates;
            _client.UpdateAccountValue += HandleUpdateAccountValue;
            _client.Error += HandleError;

            // we need to wait until we receive the next valid id from the server
            _client.NextValidId += (sender, e) =>
            {
                // only grab this id when we initialize, and we'll manually increment it here to avoid threading issues
                if (_nextValidID == 0)
                {
                    _nextValidID = e.OrderId;
                    _waitForNextValidID.Set();
                }
                Log.Trace("InteractiveBrokersBrokerage.HandleNextValidID(): " + e.OrderId);
            };
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates a new InteractiveBrokeragBrokerage for the specified account
 /// </summary>
 /// <param name="orderMapping">An instance of IOrderIDMapping used to fetch Order objects by brokerage ID</param>
 /// <param name="account">The account used to connect to IB</param>
 public InteractiveBrokersBrokerage(IOrderIDMapping orderMapping, string account)
     : this(orderMapping,
            account,
            Config.Get("ib-host", "LOCALHOST"),
            Config.GetInt("ib-port", 4001),
            Config.GetValue("ib-agent-description", IB.AgentDescription.Individual)
            )
 {
 }