question

leopold avatar image
2 Likes"
leopold asked ·

Screen Securities in Python

I can't figure out how to access screen_securities() in Python. In particular, what format should the logic variable follow? Can anyone give me some examples? Any examples? Can't find anything online.

logic = intrinio_sdk.SecurityScreenGroup() 

For example, this does not work:

api_response = security_api.screen_securities(logic=open_price~lte~10.50)

The SDK and API documentation is very not clear. Nothing for Python. (Link: http://help.intrinio.com/en/articles/2992244-using-the-securities-screener-with-api-v2 and https://docs.intrinio.com/documentation/screener_v2 )



python
· 1
10 |600 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

· Write an Answer
mkelly avatar image
1 Like"
mkelly answered ·

In your case, your logic variable follows the security screen group format (operator, clause(s), group(s)), an example of which is as follows:

from __future__ import print_function
import time
import intrinio_sdk
from intrinio_sdk.rest import ApiException
from pprint import pprint

intrinio_sdk.ApiClient().configuration.api_key['api_key'] = 'YOUR_API_KEY'

security_api = intrinio_sdk.SecurityApi()


clause1 = intrinio_sdk.SecurityScreenClause(field ='employees', operator = 'gt', value = 100000)
clause2 =  intrinio_sdk.SecurityScreenClause(field = 'state', operator = 'eq', value = 'California')

logic = intrinio_sdk.SecurityScreenGroup(operator ="AND", clauses =[clause1, clause2])# SecurityScreenGroup | The logic to screen with, consisting of operators, clauses, and nested groups.<br/> See <a href=\"/documentation/screener_v2\" target=\"_blank\">screener documentation</a> for details on how to construct conditions. (optional)
order_column = 'employees' # str | Results returned sorted by this column (optional)
order_direction = 'desc' # str | Sort order to use with the order_column (optional) (default to asc)
primary_only = True # bool | Return only primary securities (optional) (default to False)
page_size = 100 # int | The number of results to return. Maximum for this endpoint is 50000. (optional) (default to 100)

try:
  api_response = security_api.screen_securities(logic=logic, order_column=order_column, order_direction=order_direction, primary_only=primary_only, page_size=page_size)
  pprint(api_response)
except ApiException as e:
  print("Exception when calling SecurityApi->screen_securities: %s\r\n" % e)

In this example, the clauses set the companies returned under the restriction of locations and employee numbers. I hope that helps!

· Share
10 |600 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.