Using the Flex Web Service

The Flex Web Service lets you access your pre-configured flex queries via HTTPS protocol without logging into Account Management. This feature lets you write automated client software in your preferred language, which can request previously defined Flex queries in real-time.

 

To use the Flex Web Service

  1. Click Report Management in the left pane, then click Delivery Settings.

  2. Click the Flex Webservice link.

    flexWebserviceDeliveryActivate.jpg
  3. Activate the Flex Web Service by clicking the Click Here to Activate link.

    The page refreshes, indicating a status of ACTIVE for the Flex Web Service, and lets you generate a confirmation number, which you will need to initiate Flex requests and retrieve Flex reports.

  4. flexWebserviceDelivery.jpg

     

  5. Generate a new token:

  1. In the Should Expire After list, select the amount of time before the token expires. The token is valid for a 6 hour period by default.

  2. In the Valid For IP Address field, enter an IP address to restrict the token to that IP address. If you leave this field blank, there will be no IP address restrictions.

  3. Click Generate New Token.

    The page refreshes, updating the Current Token Details section with information about your newly-generated token. When you generate a new token, you invalidate the current token.

  4. Initiate an automated Flex Web Service request:

  1. Make sure you have the following information:

    Your current token (displayed in the Current Token Details section of the page)
    The Flex Query ID generated when you created the Flex query.

  2. Type the following URL in your browser’s Address field:

    https://www.interactivebrokers.com/Universal/servlet/FlexStatementService.SendRequest?t=<TOKEN>&q=<QUERY_ID>

    Where <TOKEN> is your current token and <QUERY_ID> is the Flex Query ID.

  3. You will receive an XML response from IB containing the following information:

    Reference Code - If the request was successful, the XML response will contain a numeric reference code. This code will be used to retrieve the generated Flex query. If the request was unsuccessful you will get back “INVALID REQUEST” (without the quoted) as the code.

    Response URL - This is the URL to be used to retrieve the Flex report.

    Here is a sample XML response:

    sampleXMLresponse.jpg
  4. Retrieve the Flex data:

  1. Be sure that you have your current token number, and the reference code you received as part of the response to your initial request.

  2. Type the following URL in your browser’s Address field:

    https://www.interactivebrokers.com/Universal/servlet/FlexStatement
    Service.GetStatement?q=<REFERENCE_CODE>&t=<TOKEN>&v=
    <SERVICE_VERSION>

    Where:
    <REFERENCE_CODE> is the code you received as part of the response when you placed the request
    <TOKEN> is your current token and
    <SERVICE_VERSION> is set to 2 for activity Flex or trade confirmation Flex, or 1 or left blank for legacy Flex.

You will receive the Flex data as the response if the request was successful. Otherwise, you will receive a XML based response informing you that the request was invalid.

For more information...

         Statements and Reports - FlexWeb Service