sgmarket api analytics ROTB 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 a few endpoints of the Rates Option Trade Builder V1 API are 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_rotb
# 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:
import sgmarkets_api_analytics_rotb as ROTB
# info about ROTB
ROTB.info()
See the user guide in the sgmarkets-api-auth repo
Select it from the list of those available in the package.
import sgmarkets_api_analytics_rotb as ROTB
# Examples
ep = ROTB.endpoint..v1_curves
ep = ROTB.endpoint.v1_compute_strategy_components
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.
Then explore your Request
object to make sure it is properly set.
# For all endpoints
# display the structure of the object
rq.info()
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.
You can explore it starting with
# For all endpoints
# display the structure of the object
res.info()
As .csv
and .xlsx
files.
# For all endpoints
# save to disk
res.save_result(excel=True)
The Response
objects are different for each endpoint.
See the demo notebook for examples.
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='volNormal')
# display the structure of the object
s1.info()
# save to disk
s1.save()
See the user guide in the sgmarkets-api-plot repo