<\/a><\/p>\nS <\/span>= <\/span>Param<\/span>( <\/span>"Example Error Msg"<\/span>, <\/span>0<\/span>, <\/span>0<\/span>, <\/span>10<\/span>, <\/span>1 <\/span>);\rswitch ( <\/span>S <\/span>)\r{\rcase <\/span>0<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"ID=15071. Error 135. Can't find order with id =:15071"<\/span>;\r break;\rcase <\/span>1<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"ID=2094, Error 103, Duplicate ORder id"<\/span>;\r break;\rcase <\/span>2<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"ID=-1, Error 1102, Connectivity between IB AND TWS Has been restored - data MAintained"<\/span>;\r break;\rcase <\/span>3<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"ID=-1, Error 2100, New account data requested"<\/span>;\r break;\rcase <\/span>4<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"ID=-1, Error 1100, Connectivity between IB AND TWS has been lost"<\/span>;\r break;\rcase <\/span>5<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"Connection established OK, Next Order Id=2080"<\/span>;\r break;\rcase <\/span>6<\/span>:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>"ID=6125. Error 202. Order Canceled - reason:"<\/span>;\r break;\rdefault:\r <\/span>TWSLastErrorMsg <\/span>= <\/span>""<\/span>;\r break;\r}\r\rfunction <\/span>GetErrorCode<\/span>( <\/span>TWSLastErrorMsg <\/span>)\r{\r <\/span>p <\/span>= <\/span>StrFind<\/span>( <\/span>TWSLastErrorMsg<\/span>, <\/span>" Error " <\/span>);\r <\/span>ErrStr <\/span>= <\/span>StrMid<\/span>( <\/span>TWSLastErrorMsg<\/span>, <\/span>p <\/span>+ <\/span>6<\/span>, <\/span>4 <\/span>);\r <\/span>ErrNum <\/span>= <\/span>StrToNum<\/span>( <\/span>ErrStr <\/span>);\r <\/span>ErrStr <\/span>= <\/span>NumToStr<\/span>( <\/span>ErrNum<\/span>, <\/span>1.0<\/span>, <\/span>False <\/span>);\r return <\/span>ErrStr<\/span>;\r}\r\rfunction <\/span>ExtractErrorID<\/span>( <\/span>TWSLastErrorMsg <\/span>)\r{\r <\/span>p <\/span>= <\/span>StrFind<\/span>( <\/span>TWSLastErrorMsg<\/span>, <\/span>"ID=" <\/span>);\r <\/span>IDStr <\/span>= <\/span>StrMid<\/span>( <\/span>TWSLastErrorMsg<\/span>, <\/span>p <\/span>+ <\/span>2<\/span>, <\/span>5 <\/span>);\r <\/span>IDNum <\/span>= <\/span>StrToNum<\/span>( <\/span>IDStr <\/span>);\r <\/span>IDStr <\/span>= <\/span>NumToStr<\/span>( <\/span>IDNum<\/span>, <\/span>1.0<\/span>, <\/span>False <\/span>);\r return <\/span>IDStr<\/span>;\r}\r\r<\/span>TWSErrorCode <\/span>= <\/span>GetErrorCode<\/span>( <\/span>TWSLastErrorMsg <\/span>);\r<\/span>TWSErrorOrderID <\/span>= <\/span>ExtractErrorID<\/span>( <\/span>TWSLastErrorMsg <\/span>);\r<\/span>Title <\/span>= <\/span>"\\n" <\/span>+\r <\/span>"Extracting OrderIDs and Error codes from TWS Error Messages" <\/span>+ <\/span>"\\n" <\/span>+\r <\/span>"Example Error Msg: " <\/span>+ <\/span>TWSLastErrorMsg <\/span>+ <\/span>"\\n" <\/span>+\r <\/span>" Error Code: " <\/span>+ <\/span>TWSErrorCode <\/span>+ <\/span>"\\n" <\/span>+\r <\/span>" TWS Error OrderID: " <\/span>+ <\/span>TWSErrorOrderID<\/span>;<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"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\u2019t have to be live with IB to test it. I suggest that you inspect the IB list of error messages, copy the errors […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[70],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1722"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1722"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1722\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1722"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}