sgmarket api analytics RATES helper
This repo is meant to make it easy for clients (and employees) to tap SG Research APIs.
This is a work in progress and subject to change.
In particular only one endpointa of the Rates V1 API is covered.
The usual way to expose an API is to make a swagger available and also a GUI, typically a web page.
These have the following drawbacks:
To fill the gap, we introduce the Jupyter notebook as an API consumption tool (It as many other uses).
The associated Python package used here has a very simple interface, but can be arbitrarily modified for (and by) an advanced user. It has the same display capabilities as a web page (being one itself). Most importantly is is written in Python so can be evolved by a business user (as opposed to web front end which is invariably delegated to specialist developpers).
This repo contains:
Here, the notebook is a convenient and versatile interface to
From terminal:
# download and install package from pypi.org
pip install sgmarkets_api_analytics_rates
# launch notebook
jupyter notebook
Create a notebook or run the demo notebook and modify it to your own use case.
Read the demo notebook.
The key steps are the following.
The package contains the corresponding API swagger url and contact info:
from sgmarkets_api_analytics_rates as rates.endpoint import endpoint as ep
# info about ROTB
See the user guide in the sgmarkets-api-auth repo
Select it from the list of those available in the package. At that time only v1_curves_price is available, but other are in the pipe.
from sgmarkets_api_analytics_rates.endpoint import endpoint as ep
# Examples
ep = ep.v1_curves_price
Each end point comes with a Request
object.
# For all endpoints
rq = ep.request()
And fill the object with the necessary data.
This part is specific to the endpoint selected.
See the demo notebook for examples.
IMPORTANT:
You should make sure the request will not overload the server. If not the API call may time out.
To this effect theRequest
object will display information, warnings and recommendations.
You can call the API directly from the Request
object.
# For all endpoints
# a is an Api object (see 3.2)
res = rq.call_api(a)
The returned object is a Response
object associated to this endpoint.
For those endpoints which return a large amount of data, slicing the result is usually the best/only way to exploit the results.
Then use the associated Slice
results down to a 1-D or 2-D or 3-D dataframe.
# example - see demo notebook for the context
dic_req_fix = {'date': pd.Timestamp('2016-11-11')}
s1 = ep.slice(res, x='expiry', y='tenor', dic_req_fix=dic_req_fix, value='value')