Timeout errors and too many requests for instrument pricing analytics
Hey. I am calling the instrument pricing analytics serivce, specifically: https://api.refinitiv.com/data/quantitative-analytics/v1/financial-contracts
import refinitiv.dataplatform as rdp
...
endpoint = rdp.Endpoint(session, 'https://api.refinitiv.com/data/quantitative-analytics/v1/financial-contracts')
req = get_request_body(swap_name, currency, legs, valuation_date, forward_starting_date, tenor=tenor)
rsp = endpoint.send_request(method = rdp.Endpoint.RequestMethod.POST, body_parameters = req)
This works okay mostly but I get two different errors when trying to run this across several dates:
- ReadTimeout <- just fails with no more information.
- Too many requests <- fails seemingly because I issue too many requests.
I tried inserting some "sleep" commands but still get the same error. I am certainly issuing many requests, but does anyone know the policy so I can throttle this, if that is the case.
And, how can I avoid the "timeout" error? I don't care if it takes a long time to respond; I can happily just execute my code overnight if needed.
Best Answer
-
Via configuration, you should be able to override the default timeout. Is it possible for you to provide some details about your request so we can attempt to replicate and determine if changing the default timeout can help?
Note: I can see you are using an older version of the library. I would suggest you update your code to a newer version. You can see how to use it via examples. The design of the newer library is similar to the one you are using so the effort to change should be minimal.
0
Answers
-
Hey.
I reviewed your example link and updated to using the newer library:
import refinitiv.data as rd
rd.open_session()The code is like this:
from typing import List
# Refinitiv throws an error when we issue too many requests. So sleep some...
import time
def swap_valuation(currency, swap_name, leg_function, fixed_rate_pct, floating_spread_bps, valuation_date, forward_starting_date, tenor):
time.sleep(1)
legs = leg_function(fixed_rate_pct=fixed_rate_pct, floating_spread_bps=floating_spread_bps)
req = get_request_body(swap_name, currency, legs, valuation_date, forward_starting_date, tenor=tenor)
request_definition = rd.delivery.endpoint_request.Definition(
url = ipa_url,
method = rd.delivery.endpoint_request.RequestMethod.POST,
body_parameters = req
)
response = request_definition.get_data()
if not 'headers' in response.data.raw:
display(response.data.raw)
raise Exception('Refinitiv error...')
else:
value = get_value(response)
return valueAs you can see, I try to "sleep" to not get limited and thrown out...
The request body is like this:
from typing import List
def get_request_body(
instr_tag:str,
currency:str,
legs,
valuation_date: pd.Timestamp,
start_date: pd.Timestamp,
tenor:str=None,
flds:List[str]=None):
'''
:param instr_tag str: Custom name of the instrument.
:param currency str: The currency.
:param legs: Fixed and floating leg definitions.
:param valuation_date: The date at which to value the swap.
:param start_date: The start date of the swap, e.g. T+2, T+1M or T-1M or similar.
:param tenor str: Tenor string, e.g. 5Y.
:param flds List[str]: Fields to retrieve in the response (optional).
'''
tenor = tenor or '5Y'
flds = flds or [
'InstrumentTag',
'LegTag',
'Direction',
'MarketValueInDealCcy',
'CleanMarketValueInDealCcy',
'DirtyPricePercent',
'FixedRatePercent',
'SpreadBp',
'PV01Bp',
'PV01AmountInDealCcy',
'DiscountCurveNamne',
'ForwardCurveName',
'ErrorCode',
'ErrorMessage']
return {
'fields': flds,
'universe': [{
'instrumentType': 'Swap',
'instrumentDefinition': {
'instrumentTag': instr_tag,
'startDate': start_date.strftime('%Y-%m-%d'),
'tenor': tenor,
'legs': legs
}
}],
'pricingParameters': {
'valuationDate': valuation_date.strftime('%Y-%m-%d')
},
'outputs': ['Data', 'Headers'],
}And so this is just a valuation of a plain vanilla forward starting swap.
I loop over a couple of swaps and value them each day from say 2014 through 2020. So in all, that becomes many requests.
I have seen that there is a json configuration file that can be used to increase timeouts. However, I can't find any example. I found this: Example.DataLibrary.Python/refinitiv-data.config.json at main · Refinitiv-API-Samples/Example.DataLibrary.Python (github.com)
Can you provide me a link to documentation on the config options here?
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛