예제 #1
0
        /// <summary>
        /// Handles error messages from IB
        /// </summary>
        private void HandleError(object sender, IB.ErrorEventArgs e)
        {
            Log.Trace(string.Format("InteractiveBrokersBrokerage.HandleError(): Order: {0} ErrorCode: {1} - {2}", e.TickerId, e.ErrorCode, e.ErrorMsg));

            // figure out the message type based on our code collections below
            var brokerageMessageType = BrokerageMessageType.Information;

            if (ErrorCodes.Contains((int)e.ErrorCode))
            {
                brokerageMessageType = BrokerageMessageType.Error;
            }
            else if (WarningCodes.Contains((int)e.ErrorCode))
            {
                brokerageMessageType = BrokerageMessageType.Warning;
            }

            if (InvalidatingCodes.Contains((int)e.ErrorCode))
            {
                Log.Trace(string.Format("InteractiveBrokersBrokerage.HandleError.InvalidateOrder(): Order: {0} ErrorCode: {1} - {2}", e.TickerId, e.ErrorCode, e.ErrorMsg));

                // invalidate the order
                var order      = _orderMapping.GetOrderByBrokerageId(e.TickerId);
                var orderEvent = new OrderEvent(order)
                {
                    Status = OrderStatus.Invalid
                };
                OnOrderEvent(orderEvent);
            }

            OnMessage(new BrokerageMessageEvent(brokerageMessageType, (int)e.ErrorCode, e.ErrorMsg));
        }
예제 #2
0
 void client_Error(object sender, Krs.Ats.IBNet.ErrorEventArgs e)
 {
     logger.Error(" TWS Message TickerId={0} ErrorCode={1} MSG:{2}", e.TickerId, e.ErrorCode, e.ErrorMsg);
     //if (e.ErrorCode.ToString() == "1100" || e.ErrorCode.ToString() == "1300") // see http://www.interactivebrokers.com/php/apiguide/interoperability/socket_client_c++/errors.htm
     //{
     //    logger.Error(" Requesting reconnect...");
     //    reconnectRequested = true;
     //}
 }
예제 #3
0
        /// <summary>
        /// Handles error messages from IB
        /// </summary>
        private void HandleError(object sender, IB.ErrorEventArgs e)
        {
            // https://www.interactivebrokers.com/en/software/api/apiguide/tables/api_message_codes.htm

            // rewrite these messages to be single lined
            e.ErrorMsg = e.ErrorMsg.Replace("\r\n", ". ").Replace("\r", ". ").Replace("\n", ". ");
            Log.Trace(string.Format("InteractiveBrokersBrokerage.HandleError(): Order: {0} ErrorCode: {1} - {2}", e.TickerId, e.ErrorCode, e.ErrorMsg));

            // figure out the message type based on our code collections below
            var brokerageMessageType = BrokerageMessageType.Information;

            if (ErrorCodes.Contains((int)e.ErrorCode))
            {
                brokerageMessageType = BrokerageMessageType.Error;
            }
            else if (WarningCodes.Contains((int)e.ErrorCode))
            {
                brokerageMessageType = BrokerageMessageType.Warning;
            }

            // code 1100 is a connection failure, we'll wait a minute before exploding gracefully
            if ((int)e.ErrorCode == 1100 && !_disconnected1100Fired)
            {
                _disconnected1100Fired = true;
                // wait a minute and see if we've been reconnected
                Task.Delay(TimeSpan.FromMinutes(1)).ContinueWith(task =>
                {
                    if (_disconnected1100Fired)
                    {
                        OnMessage(new BrokerageMessageEvent(BrokerageMessageType.Error, -1, "Connection with Interactive Brokers lost. " +
                                                            "This could be because of internet connectivity issues or a log in from another location."
                                                            ));
                    }
                });
            }
            else if ((int)e.ErrorCode == 1102)
            {
                _disconnected1100Fired = false;
            }

            if (InvalidatingCodes.Contains((int)e.ErrorCode))
            {
                Log.Trace(string.Format("InteractiveBrokersBrokerage.HandleError.InvalidateOrder(): Order: {0} ErrorCode: {1} - {2}", e.TickerId, e.ErrorCode, e.ErrorMsg));

                // invalidate the order
                var order      = _orderMapping.GetOrderByBrokerageId(e.TickerId);
                var orderEvent = new OrderEvent(order)
                {
                    Status = OrderStatus.Invalid
                };
                OnOrderEvent(orderEvent);
            }

            OnMessage(new BrokerageMessageEvent(brokerageMessageType, (int)e.ErrorCode, e.ErrorMsg));
        }
예제 #4
0
        void tws_Error(object sender, Krs.Ats.IBNet.ErrorEventArgs e)
        {
            if (tick_list.ContainsKey(e.TickerId))
            {
                TickData t = tick_list[e.TickerId];
                t.error_code = e.ErrorCode;
                t.ready_event.Set();
            }
            else if (cont_list.ContainsKey(e.TickerId))
            {
                ContData c = cont_list[e.TickerId];
                c.error_code = e.ErrorCode;
                c.ready_event.Set();
            }
            else if (e.ErrorCode == ErrorMessage.NotConnected)
            {
                Connect = false;
            }
            else if (e.ErrorMsg.Contains("max rate"))
            {
                Thread.Sleep(1000 + tws_backoff_time);
            }
            else if (e.ErrorMsg.StartsWith("Max number of tickers has been reached"))
            {
                if (!tws_err_max_tickers_reached)
                {
                    MessageBox.Show("Max number of tickers has been reached.\nPlease reduce number of parallel tickers in plug-in configuration, or number of active tickers in TWS.    ", "Interactive Brokers Plug-In - TWS Error Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    tws_err_max_tickers_reached = true;
                }
            }
            else if (e.ErrorMsg.StartsWith("Connectivity between IB and TWS has been lost"))
            {
                MessageBox.Show("Connectivity between IB and TWS has been lost.    ", "Interactive Brokers Plug-In - TWS Error Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Connect = false;
            }
            else if (e.ErrorMsg.StartsWith("Market data farm connection is OK") ||
                     e.ErrorMsg.StartsWith("Can't find EId with tickerId") ||
                     e.ErrorMsg.StartsWith("No historical data query found for ticker id") ||
                     e.ErrorMsg.StartsWith("AlreadyConnected"))
            {
                // ignore
            }
#if DEBUG
            else
            {
                MessageBox.Show(e.ErrorMsg, "TWS Client Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
#endif
        }
예제 #5
0
        /// <summary>
        /// Handles error messages from IB
        /// </summary>
        private void HandleError(object sender, IB.ErrorEventArgs e)
        {
            // if greater than zero error generated from order or ticker
            var message = string.Format("InteractiveBrokersBrokerage.HandleError(): {0} - {1}", e.TickerId, e.ErrorMsg);

            if (e.TickerId > 0)
            {
                Log.Error(message);
            }
            else
            {
                Log.Trace(message);
            }

            OnError(new InteractiveBrokersException(e.ErrorCode, e.TickerId, e.ErrorMsg));
        }
 private void _client_Error(object sender, ErrorEventArgs e)
 {
     if (e.ErrorMsg == "No security definition has been found for the request")
         Dispatcher.Invoke(() => StatusLabel.Content = e.ErrorMsg);
     else
         Dispatcher.Invoke(() => _logger.Log(NLog.LogLevel.Error, string.Format("{0} - {1}", e.ErrorCode, e.ErrorMsg)));
 }
예제 #7
0
파일: Program.cs 프로젝트: cadoogi/IBNet
 static void client_Error(object sender, ErrorEventArgs e)
 {
     Console.WriteLine("Error: "+ e.ErrorMsg);
 }
예제 #8
0
파일: TWSUtils.cs 프로젝트: ychaim/qdms
 public static ErrorArgs ConvertErrorArguments(ErrorEventArgs args)
 {
     return new ErrorArgs((int)args.ErrorCode, args.ErrorMsg);
 }
예제 #9
0
 private void _client_BatchAddingError(object sender, ErrorEventArgs e)
 {
     if (e.ErrorMsg == "No security definition has been found for the request")
     {
         SendNextRequestInBatch();
     }
 }
예제 #10
0
 private void client_Error(object sender, Krs.Ats.IBNet.ErrorEventArgs e)
 {
     log.Notice("Status: " + e.ErrorMsg);
 }
예제 #11
0
 //called if accured tws error
 static void ClientError(object sender, ErrorEventArgs e)
 {
     Logger.WriteToLog(DateTime.Now, string.Format("ClientManager.client_Error(): {0}", e.ErrorMsg), Program.UserId);
     Console.WriteLine(e.ErrorMsg);
 }
예제 #12
0
        void client_Error(object sender, ErrorEventArgs e)
        {
            lock (_lockObject)
            {
                try
                {
                    string errorText = "Error! id=" + e.TickerId + " errorCode=" + e.ErrorCode + "\r\n" + e.ErrorMsg;

                    int errorCode = (int)e.ErrorCode;

                    if (errorCode == 165)
                    {
                        return;
                    }

                    //if (errorCode == 2106 && _histRetrieval != null && !_histRetrieval.ReceivedData)
                    //{
                    //    System.Diagnostics.Trace.WriteLine("Historical data available.  Resending historical data request...");
                    //    _histRetrieval.SendRequest();
                    //}

                    if (errorCode == 2107 && _histRetrieval != null && _histRetrieval.bPaused)
                    {
                        //	Resume historical data collection
                        System.Diagnostics.Trace.WriteLine("Historical data available.  Resuming data collection...");
                        _histRetrieval.bPaused = false;
                        _histRetrieval.SendRequest();
                    }

                    RightEdge.Common.BrokerOrder order;
                    if (openOrders.TryGetValue(e.TickerId.ToString(), out order))
                    {
                        string message = string.Format("IB error/warning code {0}: {1}", errorCode, e.ErrorMsg);
                        bool bError = true;

                        if (errorCode >= 2100 && errorCode <= 3000)
                        {
                            //	Error code 2109 can happen often and is apparently just noise.
                            //	The error text for error 2109 is: Order Event Warning: Attribute “Outside Regular Trading Hours” is ignored based on the order type and destination. PlaceOrder is now processed
                            if (errorCode != 2109)
                            {
                                //	It's probably just a warning, and the order may continue
                                Console.WriteLine("IB Warning code " + errorCode + " for order ID " + e.TickerId + ": " + e.ErrorMsg);
                            }
                            bError = false;
                        }
                        else if (errorCode == 404)
                        {
                            //	404: Shares for this order are not immediately available for short sale. The order will be held while we attempt to locate the shares.
                            bError = false;
                        }
                        else if (errorCode == 399)
                        {
                            //	Order Message:\nWarning: your order will not be placed at the exchange until 2010-04-22 09:30:00 US/Eastern
                            if (e.ErrorMsg.StartsWith("Order Message:\nWarning: your order will not be placed at the exchange until"))
                            {
                                bError = false;
                            }
                        }

                        //string message = string.Format("Error code {0}: {1}", errorCode, e.ErrorMsg);

                        // error code 202 is a cancelled order ... we want to know about these!
                        if (errorCode == 202)
                        {
                            order.OrderState = BrokerOrderState.Cancelled;
                        }
                        else if (bError)
                        {
                            order.OrderState = BrokerOrderState.Rejected;
                        }
                        OrderUpdatedDelegate tmp = OrderUpdated;
                        if (tmp != null)
                        {
                            tmp(order, null, message);
                        }
                        return;
                    }

                    System.Diagnostics.Trace.WriteLine(errorText);

                    if (errorCode == 1100)		//	Connectivity has been lost
                    {
                        _watching = false;
                        _connected = false;
                        errorText = "Disconnected: " + errorText;
                    }
                    else if (errorCode == 1102)
                    {
                        _hadError1102 = true;
                        TimeSpan diff = DateTime.Now.Subtract(_waitHandleTime);
                        Trace.WriteLine("Time from waithandle set to errorCode 1102: " + diff.ToString());
                        int b = 0;
                    }

                    if (errorCode < 2000 && errorCode != 202)
                    {
                        if (_histRetrieval != null)
                        {
                            //	Currently retrieving historical data
                            if (errorCode == 162 && e.ErrorMsg.Contains("Historical data request pacing violation"))
                            {
                                _histRetrieval.bPaused = true;
                                System.Diagnostics.Trace.WriteLine("Historical data pacing violation.  Waiting for data to become available...");
                                _histRetrieval.waitEvent.Set();
                                //	Need to wait for this:
                                //	Error! id=-1 errorCode=2107
                                //	HMDS data farm connection is inactive but should be available upon demand.:ushmds2a
                            }
                            else if ((errorCode == 321 && e.ErrorMsg.Contains("Historical data queries on this contract requesting any data earlier than")) ||
                                    (errorCode == 162 && e.ErrorMsg.Contains("query returned no data")))
                            {
                                //	Error code 321
                                //	Error validating request:-'qb' : cause - Historical data queries on this contract requesting any data earlier than one year back from now which is 20060218 12:34:47 EST are rejected.  Your query would have run from 20060214 00:00:00 EST to 20060221 00:00:00 EST.

                                //	Error! id=34 errorCode=162
                                //	Historical Market Data Service error message:HMDS query returned no data: ESU8@GLOBEX Trades

                                //	We will not treat this as an error.  We will simply return the data that we could get.

                                _histRetrieval.Done = true;
                                _histRetrieval.waitEvent.Set();
                            }
                            else
                            {

                                System.Diagnostics.Trace.WriteLine("Error ended historical data retrieval: " + errorText);
                                lastError = errorText;
                                hadError = true;
                                _histRetrieval.waitEvent.Set();
                            }
                        }
                        else
                        {
                            lastError = errorText;
                            hadError = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    RightEdge.Common.Internal.TraceHelper.DumpExceptionToTrace(ex);
                }
            }
        }
예제 #13
0
파일: Instrument.cs 프로젝트: ajmal017/HAC
 private void S_OnError(Object sender, Krs.Ats.IBNet.ErrorEventArgs e)
 {
     //MessageBox.Show( e.ErrorMsg );
 }