Introduction
As a subscriber to one or more of Sensa Investments’ product you will be granted access to the Sensa Investments API (application programming interface). While you will of course also receive trade instructions via email and have access to current investment recommendations via your account dashboard the API gives you more flexibility to access current position data for each of our products. You can use your favourite programming language to make HTTP requests to the API and use the response data in your trading scripts.
API Key / Token
In order to access the Sensa Investments API you will need a personalised API key/token which you will pass along when making requests to the API in order to authenticate your access level.
Your personal API code can be requested via your account dashboard by clicking the ‘Request API Access’ button under ‘Account Actions’ or by clicking this link: request API access. You will be asked to input your password and the API key/token will be provided to you. Please store it somewhere safe as we will not be able to retrieve or restore it. (However should you lose it you can request a new key via this web-page). The key will expire after 1 year at which point you should submit a new request.
Example API key/token:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvc2Vuc2FpbnZlc3RtZW50cy5jb20iLCJpYXQiOjE1OTgwMjQ1NTQsIm5iZiI6MTU5ODAyNDU1NCwiZXhwIjoxNjI5NTYwNTU0LCJkYXRhIjp7InVzZXIiOnsiaWQiOjF9fX0.PYcQSSUbs3XbBUPmueHBU30KQre2BJkWcm6shypc8v
How to Access the API
Once you have requested and received your API key/token you will be able to make HTTP requests to the Sensa Investments API in order to receive the current position of the product in question.
You should be able to use any HTTP requests script for your specific programming language. At Sensa Investments we primarily use Python. Below we have included a simple Python script utilising the excellent Requests library. Simply copy (or download) this script and insert the product name and your API key/token as indicated.
import requests
from requests.exceptions import HTTPError
BASE_URL = "https://sensainvestments.com/wp-json/api/v1/"
request_type = 'get_position'
product_name = # INSERT PRODUCT NAME ('sensa_500_a', 'sensa_500_b' or 'sensa_500_c')
API_key = # INSERT YOUR API KEY / TOKEN
headers = {
"Connection": "keep-alive",
"Authorization": "Bearer " + API_key
}
URL = BASE_URL + request_type + "/" + product_name
try:
response = requests.get(URL, headers=headers)
response.raise_for_status()
# Print response
print("Response")
print(response.json())
except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')
except Exception as err:
print(f'Other error occurred: {err}')
API Response
The API response will be a JSON object (example included below) and you can thus easily access object properties for use in your trading script.
{
"product_name": "sensa_500_c",
"option_contract": {
"conId": 437354554,
"right": "P",
"strike": 3155,
"symbol": "SPX",
"secType": "OPT",
"currency": "USD",
"exchange": "CBOE",
"multiplier": "100",
"localSymbol": "SPXW 200904P03155000",
"tradingClass": "SPXW",
"lastTradeDateOrContractMonth": "20200904"
},
"time_stamp": "2020-08-20T16:00:25.419492+00:00",
"bid": "8.4",
"bid_size": "218",
"ask": "8.6",
"ask_size": "183",
"underlying_price": "3389.35",
"bidGreeks": {
"vega": 1.146558645128052,
"delta": -0.09369952707104734,
"gamma": 0.00092088955601933,
"theta": -1.0046723402189373,
"optPrice": 8.399999618530273,
"impliedVol": 0.265115244991731,
"pvDividend": 3.1446779363850914
},
"askGreeks": {
"vega": 1.158808671431826,
"delta": -0.0950596496555679,
"gamma": 0.0009247761685710984,
"theta": -1.0219628517739248,
"optPrice": 8.600000381469727,
"impliedVol": 0.26682166077481295,
"pvDividend": 3.1446779363850914
},
"collateral_requirement": 98248.95756454692
}
Further Developments
We are always looking to further improve our product offering including our API. More functionalities are already in development but please do reach out to us should you have any suggestions or requests that you would like to see included in our API.
0 Comments