API question - Strategy

First, Happy New Year! Hope you all have a successful 2023.

For those with experience using the API, can someone guide me through the sequence of steps to run “Strategy”, here:

https://api.portfolio123.com/docs/index.html#/Strategy/_details

I figured the steps are:

  1. Try It Out
  2. Access Token (API ID or Key? I tried each. Other?)
  3. Strategy ID
  4. Execute

I get an error message when I do this. What am I missing?

Thanks.

Hi Mm,

Should be as simple as:

client = p123api.Client(api_id='<insert your own>', api_key='<insert your own>')
your_simulation = client.strategy(strategy_id=<insert your own strategy id>)

Best,

Victor

Thanks - but maybe I’m missing something again. That logic makes sense but the page I’m working with here on P123 (https://api.portfolio123.com/docs/index.html#/Strategy/_details) seems to require entering pre-defined values into Token and ID fields, not coding or a data string. Where would I enter that string or statement? Or how do I do this using just the Strategy inputs on that API page? Thanks.

Hi Mm,

The code I gave above would be used in Python using IDE software of choice like Visual Studio Code or Spyder.

I think you are looking for a way to call the API through your browser. I’m not sure if that is possible even though that would be an easy and handy way of using the API. The code described here might be a good starting point though: Single factor testing tool developed using the API - #6 by danparquette. It uses Google Cobab to execute the code in Python. That way at least you don’t have to download an IDE.

Hope this doesn’t sound too confusing and perhaps there is a more user friendly way of using the API that I am not currently aware of.

Best,

Victor

Thank you. Good info.

Below are the steps if you want to use the Try It Out functionality in the API documentation tool (Swagger).

Go to the section for the /auth endpoint:
https://api.portfolio123.com:8443/docs/index.html#/Authenticate/_authenticate
Click Try it Out.
Enter your API id and key in the apiid and apiKey fields. They will have 0 and string by default.
image
Click Execute. If there were no errors, the access token will be in the code 200 section. Copy the access token from the response body.
Go to The Strategy endpoint and click Try it Out.
Paste in the Access Token into the token field.
Enter the strategy id of the strategy in the Id field. This id is found at the end of the URL while on the site and on that page for the Strategy.
Click Execute

Thanks. Yes I’ve tried this approach but I get an error message when I attempt to execute the /auth endpoint. Do I need to Create Key, ie create a new key each time on the Dataminer/API page? If not then I’m not sure why I’m getting that error message.

You do not need to create a new key. The only time you would need to create a new key would be for security reasons.

Try closing the browser, reopen it and try the process again. If you still get an error from /auth, please provide the error message.

Thanks for the info. I am getting the same error now with my id. I’ll ask the developer to look at it.

Please do not share your api key with others. This include screenshots. Anybody with the id and key can use them to run scripts using the api credits from your account. Please go to the Dataminer & API page in account settings and delete the key with id 196 and then create a new one.

1 Like

Done and deleted post.

Please try using https://api.portfolio123.com/docs/index.html instead of the link I gave above which had the :8443 in it - that was an old URL.

That works! Thanks.