question

Upvotes
Accepted
21 1 2 4

TRTH V2 Rest API modify template

I am using a customized template from TimeAndSizes through the GUI, which I manually selected all the fields. However, it seems the field names have been changed from the soap version, is that intended? My question is if there a way for me to modify my template directly through API on certain fields AND inheriting all others? For example, I would like to change the template to use a different query range only, and do not want to change anything else. How should I do this?

tick-history-rest-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@jsi-data,

Thank you for your participation in the forum.

Is the reply below satisfactory in resolving your query? If yes please click the 'Accept' text next to the reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

-AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.
Thanks,
AHS

Upvotes
Accepted
13.7k 26 8 12

@jsi-data

You can update a template using the API, with a PUT call to this endpoint (adapt it depending on the report template type, and use your own report template ID):

https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/TickHistoryIntradaySummariesReportTemplates('0x05b70f51783b3016')

This call is documented in the REST API Reference Tree.

Note: the PUT request body must contain all the data for the new template contents, i.e. you cannot change just one item, you must re-specify the whole contents. The update does not have a "delta" mode, so whatever you pass through is considered to be the new content of the template.

The easiest way to do that would be to retrieve the report template first using the API, then change whatever needs to be changed, and then use the PUT call to update it.

An example is available in the C# example application (explained in the Quick Start), under Report Template Examples - Update. It shows how this is done in C# and pure HTTP.

Note this example uses a DSS report template which you might not be entitled to as a TRTH customer, so just in case you cannot run it I include the appropriate screenshots for the HTTP calls below (you can see the C# code even if you cannot run it).

The first one is for the GetByName (to retrieve the report template by name):

The second one is the update:


getbyname.png (90.6 KiB)
update.png (86.7 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
21 1 2 4

Thanks for the info. I have an issue doing that though, in Python. Even if I just send over the template definition I got over the GET request, I got error from underlying Python Request library.

requests.exceptions.ConnectionError: ('Connection aborted.', BadStatusLine("''",))

It looks as if there is some limitations on how much data I could send out as in the requests. Here is from my experiment:

r = self.getTemplateById(source_template_id)
template_body = {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.TickHistoryTimeAndSalesReportTemplate",
"ShowColumnHeaders": False,
"Name": template_name,
"Headers": [],
"Trailers": [],
"ContentFields": r['ContentFields'][0:20],
"Condition": {
"MessageTimeStampIn": "GmtUtc",
"ApplyCorrectionsAndCancellations": False,
"ReportDateRangeType": "Range",
"QueryStartDate": "2016-09-29T15:15:00.000Z",
"QueryEndDate": "2016-09-29T15:45:00.000Z"
}
}

So I get template definition from an existing TimeAndSale template, and then store the boy in dictionary r, and in the new dictionary I am going to send out the the REST API, I just copy the field definition from the existing template, if I copy the first 20 fields, I can create the new template, and I can see the result in the DSS GUI. However, if I copy more fields, the connection error just shows up. My original template has all the fields included.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
13.7k 26 8 12

@jsi-data

I just tried this in Postman:

1) Create a report template with 5 fields:

URL: https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/TickHistoryTimeAndSalesReportTemplates

POST request body:

{
  "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.TickHistoryTimeAndSalesReportTemplate",
  "ShowColumnHeaders": false,
  "Name": "myTandSTemplateName",
  "Headers": [],
  "Trailers": [],
  "ContentFields": [
    {      "FieldName": "Quote - Ask Price"    },
    {      "FieldName": "Quote - Ask Size"    },
    {      "FieldName": "Quote - Bid Price"    },
    {      "FieldName": "Quote - Bid Size"    },
    {      "FieldName": "Quote - Exchange Time"    }
  ],
    "Condition": {
      "MessageTimeStampIn": "GmtUtc",
      "ApplyCorrectionsAndCancellations": false,
      "ReportDateRangeType": "Range",
      "QueryStartDate": "2016-09-29T15:15:00.000Z",
      "QueryEndDate": "2016-09-29T15:45:00.000Z"
    }
}

2) GET the report template by name:

URL: https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/ReportTemplateGetByName(Name='myTandSTemplateName')

Response body:

{
  "@odata.context": "https://hosted.datascopeapi.reuters.com/RestApi/v1/$metadata#ReportTemplates/ThomsonReuters.Dss.Api.Extractions.ReportTemplates.TickHistoryTimeAndSalesReportTemplate/$entity",
  "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.TickHistoryTimeAndSalesReportTemplate",
  "ReportTemplateId": "0x05b7f905044b3036",
  "ShowColumnHeaders": true,
  "CompressionType": "GZip",
  "CreateDate": "2017-05-15T09:43:08.100Z",
  "LastChangedDate": "2017-05-15T09:43:08.100Z",
  "Name": "myTandSTemplateName",
  "OutputFormat": "CommaSeparatedValues",
  "ReportFieldCount": 5,
  "Delimiter": "None",
  "DeliveryType": "None",
  "Destination": "",
  "TemplateTypeCode": "THT",
  "Headers": [],
  "Trailers": [],
  "ContentFields": [
    {
      "FieldName": "Quote - Ask Price",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Ask Size",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Bid Price",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Bid Size",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Exchange Time",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldTextFormat",
        "Capitalization": "None"
      }
    }
  ],
  "Condition": {
    "SortBy": "SingleByRic",
    "MessageTimeStampIn": "GmtUtc",
    "ApplyCorrectionsAndCancellations": false,
    "ReportDateRangeType": "Range",
    "QueryStartDate": "2016-09-29T15:15:00.000Z",
    "QueryEndDate": "2016-09-29T15:45:00.000Z",
    "Preview": "None",
    "ExtractBy": "Ric",
    "DisplaySourceRIC": false
  }
}

3) Add 45 fields to the report:

URL: https://hosted.datascopeapi.reuters.com/RestApi/v1/Extractions/TickHistoryTimeAndSalesReportTemplates('0x05b7f905044b3036')

POST request body:

{
  "@odata.context": "https://hosted.datascopeapi.reuters.com/RestApi/v1/$metadata#ReportTemplates/ThomsonReuters.Dss.Api.Extractions.ReportTemplates.TickHistoryTimeAndSalesReportTemplate/$entity",
  "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.TickHistoryTimeAndSalesReportTemplate",
  "ReportTemplateId": "0x05b7f905044b3036",
  "ShowColumnHeaders": true,
  "CompressionType": "GZip",
  "CreateDate": "2017-05-15T09:43:08.100Z",
  "LastChangedDate": "2017-05-15T09:43:08.100Z",
  "Name": "myTandSTemplateName",
  "OutputFormat": "CommaSeparatedValues",
  "ReportFieldCount": 5,
  "Delimiter": "None",
  "DeliveryType": "None",
  "Destination": "",
  "TemplateTypeCode": "THT",
  "Headers": [],
  "Trailers": [],
  "ContentFields": [
    {      "FieldName": "Auction - Exchange Time"    },
    {      "FieldName": "Auction - Price"    },
    {      "FieldName": "Auction - Qualifiers"    },
    {      "FieldName": "Auction - Volume"    },
    {      "FieldName": "Correction - Accumulated Volume"    },
    {      "FieldName": "Correction - Ask Price"    },
    {      "FieldName": "Correction - Bid Price"    },
    {      "FieldName": "Correction - Buyer ID"    },
    {      "FieldName": "Correction - Exchange Time"    },
    {      "FieldName": "Correction - Exchange/Contributor ID"    },
    {      "FieldName": "Correction - Ask Price"    },
    {      "FieldName": "Correction - Bid Price"    },
    {      "FieldName": "Correction - Buyer ID"    },
    {      "FieldName": "Correction - Exchange Time"    },
    {      "FieldName": "Correction - Exchange/Contributor ID"    },
    {      "FieldName": "Correction - Market VWAP"    },
    {      "FieldName": "Correction - Orderbook VWAP"    },
    {      "FieldName": "Correction - Original Accumulated Volume"    },
    {      "FieldName": "Correction - Original Buyer ID"    },
    {      "FieldName": "Correction - Original Date"    },
    {      "FieldName": "Correction - Original Exchange Time"    },
    {      "FieldName": "Correction - Original Price"    },
    {      "FieldName": "Correction - Original Primary Activity"    },
    {      "FieldName": "Correction - Original RIC of Last Eligible Trade"    },
    {      "FieldName": "Correction - Original Seller ID"    },
    {      "FieldName": "Correction - Original Sequence Number"    },
    {      "FieldName": "Correction - Original Trade Sequence Number"    },
    {      "FieldName": "Correction - Original Unique Trade Identification"    },
    {      "FieldName": "Correction - Original Volume"    },
    {      "FieldName": "Correction - Original Yield"    },
    {      "FieldName": "Correction - PE Ratio"    },
    {      "FieldName": "Correction - Price"    },
    {      "FieldName": "Correction - Primary Activity"    },
    {      "FieldName": "Correction - Qualifiers"    },
    {      "FieldName": "Correction - RIC of Last Eligible Trade"    },
    {      "FieldName": "Correction - Seller ID"    },
    {      "FieldName": "Correction - Sequence Number"    },
    {      "FieldName": "Correction - Trade Sequence Number"    },
    {      "FieldName": "Correction - Volume"    },
    {      "FieldName": "Correction - Yield"    },
    {      "FieldName": "Domain"    },
    {      "FieldName": "History End"    },
    {      "FieldName": "History Start"    },
    {      "FieldName": "Instrument ID"    },
    {      "FieldName": "Instrument ID Type"    },
    {
      "FieldName": "Quote - Ask Price",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Ask Size",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Bid Price",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Bid Size",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldNumberFormat",
        "DecimalPlaces": 9,
        "DecimalSeparator": "Period",
        "IntegerPlaces": 18,
        "UseLeadingZero": false,
        "NegativeSignPosition": "Before",
        "ThousandSeparator": "Comma",
        "UseThousandSeparator": true,
        "UseTrailingZero": false
      }
    },
    {
      "FieldName": "Quote - Exchange Time",
      "Justification": "Center",
      "Label": "",
      "WidthStyle": "VariableWidth",
      "Format": {
        "@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ReportTemplates.ContentFieldTextFormat",
        "Capitalization": "None"
      }
    }
  ],
  "Condition": {
    "SortBy": "SingleByRic",
    "MessageTimeStampIn": "GmtUtc",
    "ApplyCorrectionsAndCancellations": false,
    "ReportDateRangeType": "Range",
    "QueryStartDate": "2016-09-29T15:15:00.000Z",
    "QueryEndDate": "2016-09-29T15:45:00.000Z",
    "Preview": "None",
    "ExtractBy": "Ric",
    "DisplaySourceRIC": false
  }
}

HTTP status response was 204, report template was successfully updated and contained 50 fields, so I don't believe the issue is due to a limitation in the size of the request, at least not from an API point of view.

Did you use the exact same workflow ?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
21 1 2 4

If works in postman. Even if I includes all the ~350 fields. I got connection error when I was using Python request library. Here I copy the postman GET result into a Python hash, and then use the API to create the template, got Connection Reset Error.

However, if I reduced the fields in the python hash, the same code ran just fine.

// template in the python hash copied from postman output

template_body = tb.CreateTimeAndSaleReportTemplate1
...

// modify the template

template_body["Condition"]["QueryStartDate"] = query_start
template_body["Condition"]["QueryEndDate"] = query_end

// sending the http POST request

headers = self._buildRequestHeader()
self._buildRequest("POST",
RestUri.TimeAndSalesReportTemplate,
headers, body = template_body)

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
21 1 2 4

It looks the "Format" string is the culprit here. I directly send the full template output to the API, and I got various complains on "Malformated requests", pointing to the fields in the "Format". I eventually removed the "Format" for all fields. And the update requests just worked fine with all the Quote and Trade Fields, ~350.

I should mentioned that I also skipped using the session objects in this case, instead, I send a post request directly.

requests.post(RestUri.TimeAndSalesReportTemplate, headers=headers,
proxies=Requester.PROXIES, auth=("xxxx","xxxx"),
json=json.loads(json.dumps(template_body)))

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.