derivitec.core.client.DerivitecClient.add_request¶
- classmethod DerivitecClient.add_request(request_name, request_class, response_attribute=None)¶
Add a request to the client.
- Parameters:
request_name (str) – The request (function) name.
request_class (type) – The request class
response_attribute (str) – The response attribute (optional).
Code
Suppose we expect a market data request of type MyRequest to return a market data response of type MyResponse. We construct the two as follows.
>>> class MyRequest(MarketDataType): ... __slots__ = ("Parameter",) ... def __init__(self, parameter): ... self.Parameter = parameter ... end_point = "api/MarketData/MyRequestEndPoint"
>>> class MyResponse(MarketDataType, ApiBaseResponseMixin): ... __slots__ = ("Attribute",) + ApiBaseResponseMixin.__slots__
Then to make it available on the client add it. We want the Attribute member of the response to be returned by the client as we add this information in the key word argument response_attribute.
>>> ClientBase.add_request('my_request', MyRequest, response_attribute='Attribute')
We can now call this method on the client.
>>> conn.client.my_request(parameter)