Skip to content

Commit

Permalink
Better error code handling (#52)
Browse files Browse the repository at this point in the history
* Automatically populate missing error codes.

* Automatically populate missing error codes.

* Resolves #49.  Error code 2157.

* Formatting update.

* Formatting update.

* Handle 10190.
Resolves #48.
  • Loading branch information
chipkent authored May 11, 2022
1 parent 8c2e81d commit fa88995
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/deephaven_ib/_internal/error_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ def load_error_codes() -> Tuple[Dict[int, str], Dict[int, str]]:
504: "Not connected",
502: "Couldn't connect to TWS. Confirm that 'Enable ActiveX and Socket EClients' is enabled and connection port is the same as 'Socket Port' on the TWS 'Edit->Global Configuration...->API->Settings' menu. Live Trading ports: TWS: 7496; IB Gateway: 4001. Simulated Trading ports for new installations of version 954.1 or newer: TWS: 7497; IB Gateway: 4002",
2113: "The order size for Bonds (Bills) is entered as a nominal par value of the order, and must be a multiple",
2157: "Sec-def data farm connection is broken:secdefil",
10089: "Requested market data requires additional subscription for API.See link in 'Market Data Connections' dialog for more details.",
10168: "Requested market data is not subscribed.Delayed market data is not enabled.",
10172: "Failed to request news article: No data available",
10187: "Failed to request historical ticks",
10189: "Failed to request tick-by-tick data",
10190: "Maxnumber of tick-by-tick requests has been reached.",
}

for k, v in overrides.items():
Expand Down
6 changes: 6 additions & 0 deletions src/deephaven_ib/_tws/tws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ def error(self, reqId: TickerId, errorCode: int, errorString: str):
if reqId == 2147483647:
reqId = None

if errorCode not in _error_code_message_map:
msg = f"Unmapped error code. Please file an issue at https://github.com/deephaven-examples/deephaven-ib/issues:\n\terrorCode='{errorCode}'\n\terrorString='{errorString}'\n\tThis only impacts the error message you see and will not impact the execution of your program."
logging.error(msg)
_error_code_message_map[errorCode] = errorString
_error_code_note_map[errorCode] = ""

self._table_writers["errors"].write_row(
[reqId, errorCode, map_values(errorCode, _error_code_message_map), errorString,
map_values(errorCode, _error_code_note_map)])
Expand Down

0 comments on commit fa88995

Please sign in to comment.