Parsing TWS Error messages

Here is some simple code you can use to enable you to start developing your own error-parsing functions. In this example, error messages are hard-coded to facilitate code development, i.e. you don’t have to be live with IB to test it. I suggest that you inspect the IB list of error messages, copy the errors that are important to you, and add them to the hard-coded list. Since IB doesn’t list the error messages in the exact format you will receive them, you may have to place some orders with errors to see their exact format. When Applied to an Indicator, the code can be exercised by selecting the Error Message with the slider in the Param window. It will display the current error and parsing results in the Chart Title. Be sure to set Parameter properties to wrap the Title.

parsingerrors.png

Param"Example Error Msg"0010);
switch ( )
{
case 0:
    TWSLastErrorMsg "ID=15071. Error 135. Can't find order with id =:15071";
    break;
case 1:
    TWSLastErrorMsg "ID=2094, Error 103, Duplicate ORder id";
    break;
case 2:
    TWSLastErrorMsg "ID=-1, Error 1102, Connectivity between IB AND TWS Has been restored - data MAintained";
    break;
case 3:
    TWSLastErrorMsg "ID=-1, Error 2100, New account data requested";
    break;
case 4:
    TWSLastErrorMsg "ID=-1, Error 1100, Connectivity between IB AND TWS has been lost";
    break;
case 5:
    TWSLastErrorMsg "Connection established OK, Next Order Id=2080";
    break;
case 6:
    TWSLastErrorMsg "ID=6125. Error 202. Order Canceled - reason:";
    break;
default:
    TWSLastErrorMsg "";
    break;
}

function GetErrorCodeTWSLastErrorMsg )
{
    StrFindTWSLastErrorMsg" Error " );
    ErrStr StrMidTWSLastErrorMsg6);
    ErrNum    StrToNumErrStr );
    ErrStr    NumToStrErrNum1.0False );
    return ErrStr;
}

function ExtractErrorIDTWSLastErrorMsg )
{
    StrFindTWSLastErrorMsg"ID=" );
    IDStr StrMidTWSLastErrorMsg2);
    IDNum    StrToNumIDStr );
    IDStr    NumToStrIDNum1.0False );
    return IDStr;
}

TWSErrorCode GetErrorCodeTWSLastErrorMsg );
TWSErrorOrderID ExtractErrorIDTWSLastErrorMsg );
Title "\n" +
        "Extracting OrderIDs and Error codes from TWS Error Messages" "\n" +
        "Example Error Msg: " TWSLastErrorMsg "\n" +
        "        Error Code: " TWSErrorCode "\n" +
        " TWS Error OrderID: " TWSErrorOrderID;
1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 3.00 out of 5)
Loading...Loading...

Comments are closed.