FUTU HK Help Center-Catch exceptions to improve your strategies
English
Back
Open Account
Clear
All
Quotes
News
Learn
Help
All
HK
US
CN
SG
AU
JP
CA
MY
All
News
Announcements
Reports
No matches yet
Operations too frequent. Please try again later.
Please check network settings and try again Refresh Refresh
Loading
History record
    Latest News
      Quotes More
      News More
      Learn More
      Help More
      Loading
      News More
      Announcements More
      Reports More

      Catch exceptions to improve your strategies

      How to catch error code exceptions

      When exceptions occur during the calling of algo functions, an APIException is thrown. This exception contains an err_code attribute that provides specific error code information corresponding to different error scenarios.

      Error Code

      Scenario

      ExceedReqLimit

      Requests too frequent

      ReqTimeout

      Request to the interface timed out

      NoQuoteRight

      No permission to access quotes

      InvalidArgument

      Invalid parameter (parameter validation failed)

      ReqFailed

      Interface request failed

      NoDataAvailable

      No data (returned data is NA)

      EmptySymbol

      The parameter symbol is empty

      Unknow

      Unknown error

      To strengthen your strategy, you can catch error codes at critical points in the strategy and execute custom handling procedures.

      Example: To improve the reliability of order placements, consider using a custom-coded card that attempts to resubmit the order until it succeeds in the event of an initial failure.

      while True:
          try:
              place_limit(symbol=self.trigger_symbol 1, price=2, qty=100, side=OrderSide.BUY, time_in_force=TimeInForce.DAY)
              break  # Order placed successfully. Exit the loop.
          except APIException as ex:
              print('Order placement failed. Retry in 2 seconds.')
              time.sleep(2)
              continue  # Order placement failed. Retry.

      Any images provided are not current and any securities or inputs shown are for illustrative purposes only and are not recommendations.

       

      How to use a Custom-Coded Card vs Global Exception Settings

      Using a custom-coded card for exception handling overrides the global exception settings.

      Example 1: Passive exception catching

      Use a standard card without custom coding to catch exception error codes. Make sure to change the default settings:

      • Set Exception Settings to Skip the Current Round

      Any images provided are not current and any securities or inputs shown are for illustrative purposes only and are not recommendations.

      When the strategy runs and reaches the No Retry on Order Failure card, it will follow the exception settings and skip this round if the order placement fails. Therefore, the Mark as Complete card will not be executed. The No Retry on Order Failure card will run again when the next signal triggers the strategy.

      Example 2: Active exception catching

      Use a custom-coded card to actively catch exception error codes and retry submitting the order until it is successful. Make sure to change the default settings:

      • Set Exception Settings to Skip the Current Round

      Any images provided are not current and any securities or inputs shown are for illustrative purposes only and are not recommendations.

      When the strategy runs and reaches the Retry Order Placement on Exception card, you assume the first attempt to place an order fails.

      According to the steps shown in the image, when an error code is detected, the system will keep trying to resubmit the order until it succeeds. Afterward, the Mark as Complete card will be run next.

      Custom-coded cards designed to catch error code exceptions will capture any exceptions first. Once an exception is caught by the card, the global exception settings will not be triggered.

      This presentation is for informational and educational use only and is not a recommendation or endorsement of any particular investment or investment strategy. Investment information provided in this content is general in nature, strictly for illustrative purposes, and may not be appropriate for all investors. It is provided without respect to individual investors’ financial sophistication, financial situation, investment objectives, investing time horizon, or risk tolerance. You should consider the appropriateness of this information having regard to your relevant personal circumstances before making any investment decisions. Past investment performance does not indicate or guarantee future success. Returns will vary, and all investments carry risks, including loss of principal. Our platform makes no representation or warranty as to its adequacy, completeness, accuracy or timeliness for any particular purpose of the above content.

      Market Insights

      Market Hot Picks Market Hot Picks
      Unlock Now

      Discussing

      關稅風暴暫離高壓區!市場能否迎來反彈?
      當地時間4月22日,美國總統特朗普公開承認美國目前對中國出口商品的關稅過高,預計稅率將大幅降低;美國財政部長貝森特也表示中美雙方關稅戰將很快降溫。4月25日,特朗普表示將爲不同國家設定「公平的」關稅稅率。特朗普此次對華關稅態度的轉變,能否平息市場恐慌情緒?關稅拉鋸戰最終結局如何? Show More