Skip to navigation

Receiving Error Messages

View as MarkdownOpen in Claude

Introduction

When a client application sends a message to TWS which requires a response which has an expected response (i.e. placing an order, requesting market data, subscribing to account updates, etc.), TWS will almost either always

  1. Respond with the relevant data or
  2. Send an error message to EWrapper.error().

Error messages sent by the TWS are handled by the EWrapper.error() method. The EWrapper.error() event contains the originating request Id (or the orderId in case the error was raised when placing an order), a numeric error code and a brief description. It is important to keep in mind that this function is used for true error messages as well as notifications that do not mean anything is wrong.

Non-English API Error Messages
Error messages are sent using Latin1 encoding. Non-Latin error messages are UTF-8 encoded.

Receiving Error Messages

EWrapper.error(reqId, errorTime, errorCode, errorMsg, advancedOrderRejectJson)

reqId
integerRequired

The request identifier corresponding to the most recent reqId that maintained the error stream.
This does not pertain to the orderId from placeOrder, but whatever the most recent requestId is.

errorTime
integerRequired

The Unix timestamp of when the error took place.

errorCode
integerRequired

The Unix timestamp of when the error took place.

errorMsg
stringRequired

The Unix timestamp of when the error took place.

advancedOrderRejectJson
string

The Unix timestamp of when the error took place.


def error(self, reqId: TickerId, errorTime: int, errorCode: int, errorString: str, advancedOrderRejectJson = ""):
print("Error. Id:", reqId, errorTime, "Code:", errorCode, "Msg:", errorString, "AdvancedOrderRejectJson:", advancedOrderRejectJson)