Index | Recent Threads | Who's Online | Search

Posts: 127    Pages: 13    1 2 3 4 5 6 7 8 9 10 Next
Last Post
New Thread
This topic has been viewed 3185 times and has 126 replies
InspectorSector
Python code for calling 123 API

P123 staff -

I am attempting to run the Portfolio123 API using Python running in Google Colaboratory. I have successfully imported the P123 code, but now I am stuck because there is no meaningful example or documentation provided. The sample code provided is:

Sample code:
```python
import p123api
try:
client = p123api.Client(api_id='your api id', api_key='your api key')
print(client.screen_run({'screen': {'type': 'stock', 'universe': 'nasdaq100'}, 'asOfDt': '2020-05-12'}))
except p123api.ClientException as e:
print(e)
```

Can you provide a REAL example for running a ranking system on a specific date for specific stocks (or stock universe). I have gone as far as I can guessing as to what the parameters might be. You guys have gone to the effort of creating this. So can you please go the last mile?

Thank you

Nov 17, 2020 8:39:33 PM       
valmarv
Re: Python code for calling 123 API

The API documentation (supported endpoints and parameters) can be found here:
https://api.portfolio123.com:8443/docs/index.html

As for the Python client you can get the supported operations via code completion on the "client" object in any decent IDE. They generally follow the naming convention of the endpoints:
- /data -> client.data
- /data/universe -> client.data_universe
- /rank -> client.rank_update
- /rank/performance -> client.rank_perf
- /rank/ranks -> client.rank_ranks
- /screen/run -> client.screen_run
- /screen/backtest -> client.screen_run
- /screen/rolling-backtest -> client.screen_rolling_backtest
- /universe -> client.universe_update

Marius Valeanu
Portfolio123 Staff

Nov 18, 2020 4:42:52 AM       
Edit 1 times, last edit by valmarv at Nov 18, 2020 4:43:20 AM
InspectorSector
Re: Python code for calling 123 API

valmarv - OK - please point me to a "decent IDE" for Google Colaboratory and how to perform "code completion" using such IDE. As far as I can tell there isn't enough information in the P123 documentation to make use of the client rank_ranks. A simple example call using the python client would very likely suffice to get me going. However, it seems that P123 is either unwilling to make the effort or is only interested in catering to specialized programmers with experience the this area. I am not the first to make this complaint.

Nov 18, 2020 6:39:45 AM       
Edit 1 times, last edit by InspectorSector at Nov 18, 2020 6:40:28 AM
marco
Re: Python code for calling 123 API

Steve I agree . We need examples in the documentation that actually work with all the possible values for each parameter. Did you download the samples files for the DataMiner ? they should give you better idea and what to put for the parameters . Parameter names are not exactly the same but should be obvious. I've been pushing the programmers to be more supportive of non programmers.

For now see the sample folder in

https://www.dropbox.com/sh/08lu93jqio254m2/AAB8f3zelalF3DOE0yEJfvaCa?dl=0

Portfolio123 Staff.

Nov 18, 2020 7:19:03 AM       
InspectorSector
Re: Python code for calling 123 API

I have looked at Dataminer, and I have gone through the python-importable file and and can't find anywhere the parameter definitions that I need to make a simple ranking system output using python and the client provided. It would probably take 30 seconds from someone at P123 to generate a simple working example that I could use and modify for my project. The alternative is for me to flounder until I give up.

Thanks
Steve

Nov 18, 2020 7:49:15 AM       
valmarv
Re: Python code for calling 123 API

Here's a simple rank ranks call:
```python
import p123api
try:
client = p123api.Client(api_id='your api id', api_key='your api key')
print(client.ranks({'rankingSystem': 264499, 'asOfDt': '2015-04-21', 'universe': 'nasdaq100'}))
except p123api.ClientException as e:
print(e)
```

Full list of supported parameters can be found here (under Request Body > Schema):
https://api.portfolio123.com:8443/docs/index.html#/Rank/_ranks

Marius Valeanu
Portfolio123 Staff

Nov 18, 2020 8:21:58 AM       
Edit 1 times, last edit by valmarv at Nov 18, 2020 8:22:26 AM
marco
Re: Python code for calling 123 API

Steve see image for parameter definition

Attachment Capture.PNG (62291 bytes) (Download count: 112)


Portfolio123 Staff.

Nov 18, 2020 9:17:18 AM       
InspectorSector
Re: Python code for calling 123 API

Thank you Valmarv! When I looked through the python module I realized that you are an exceptional programmer. Just keep in mind that you are working with hacks like myself that need to shown the obvious.

Nov 18, 2020 9:38:47 AM       
marco
Re: Python code for calling 123 API

We will be adding sample code too for each API operation

Portfolio123 Staff.

Nov 18, 2020 9:40:59 AM       
marco
Re: Python code for calling 123 API

Steve, what you are trying to do is supported in the DataMiner. Just curious, why not use the DataMiner?

Portfolio123 Staff.

Nov 18, 2020 10:08:50 AM       
Posts: 127    Pages: 13    1 2 3 4 5 6 7 8 9 10 Next
 Last Post