Skip to content
All library documents

Handling Order Rejections That Do Not Raise Python Exceptions

Article FMZ forum · Author: wangtaolue

Summary

The document shows a sell-order function that calls an exchange API inside a try/except block. The reported order is rejected because its limit price is below the stated minimum. The author expects the rejection to enter the exception handler, which cancels open sell orders and retries, but says that the handler is not reached.

This illustrates a useful distinction: an API can report a failed order as a return value or log message without raising a Python exception. In that case, try/except will not catch the rejection; the caller needs to inspect the API's documented return format or error behavior. The snippet does not establish how this particular exchange wrapper reports failures, so its behavior should be checked directly. The retry loop also has no visible attempt limit, which could cause repeated submissions if the failure remains unresolved.

Key ideas

  • An API rejection may be returned or logged without raising a Python exception.
  • A try/except handler runs only when an exception is raised during the protected call.
  • Check the exchange wrapper's documented error behavior and inspect the order result.
  • A retry loop should account for persistent failures and have a stopping condition.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.