PA Engine API

Overview

Through the PA Engine API, request analytics for multi-asset class performance, attribution, and risk, including the flexibility of choosing your portfolio, benchmark, return period, and more.

API Definition

swagger_file_format

API Documentation

SDK Library

Code Snippet

Building and running a calculation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Api;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Client;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Model;

namespace FactSet.AnalyticsAPI.PAEngineAPI.v1.Examples
{
    class Program
    {
        private static Configuration configuration;

        private static Configuration GetConfiguration()
        {
            if (configuration != null)
            {
                return configuration;
            }

            configuration = new Configuration
            {
                BasePath = "https://api.factset.com",
                Username = "<username-serial>",
                Password = "<apiKey>"
            };

            return configuration;
        }

        static void Main(string[] args)
        {
            var componentsApi = new ComponentsApi(GetConfiguration());

            // PA_DOCUMENTS:DEFAULT is default document available to all users.
            ApiResponse<Dictionary<string, ComponentListEntity>> componentGetAllResponse =
                componentsApi.GetAllWithHttpInfo("PA_DOCUMENTS:DEFAULT");
            var componentId = componentGetAllResponse.Data.First().Key;

            var account = "BENCH:SP50";
            var benchmark = "BENCH:R.1000";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            CalculationParameters inputBody = new CalculationParameters(componentId, account, benchmark);
            var calculationsApi = new CalculationsApi(GetConfiguration());
            var createrCalculationResponse = calculationsApi.CreateWithHttpInfo(inputBody);

            if (createrCalculationResponse.StatusCode != 202)
            {
                LogError(createrCalculationResponse);
                return;
            }

            // Parse the the Location header for calculation Id
            createrCalculationResponse.Headers.TryGetValue("Location", out string location);
            if (string.IsNullOrWhiteSpace(location))
            {
                LogError(createrCalculationResponse);
                return;
            }

            var splits = location.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var calculationId = splits.Last();
            ApiResponse<object> getCalculationStatus = null;
            while (getCalculationStatus == null || getCalculationStatus.StatusCode == 202)
            {
                getCalculationStatus = calculationsApi.GetStatusByIdWithHttpInfo(calculationId);
                if (getCalculationStatus.StatusCode != 202)
                {
                    continue;
                }

                if (getCalculationStatus.Headers.ContainsKey("Cache-Control"))
                {
                    Console.WriteLine("Progress: " + getCalculationStatus.Headers["X-Factset-Api-Pickup-Progress"]);

                    var ageValue = getCalculationStatus.Headers["Cache-Control"];
                    if (string.IsNullOrWhiteSpace(ageValue))
                    {
                        Console.WriteLine("Sleeping for 2 seconds");
                        // Sleep for atleast 2 seconds.
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        int age = int.Parse(ageValue.Replace("max-age=", ""));
                        Console.WriteLine($"Sleeping for {age} seconds");
                        Thread.Sleep(age * 1000);
                    }
                }
            }

            if (getCalculationStatus.StatusCode != 201)
            {
                LogError(getCalculationStatus);
                return;
            }

            var getCalculationResult = calculationsApi.GetResultByIdWithHttpInfo(calculationId);
            if (getCalculationResult.StatusCode != 200)
            {
                Console.WriteLine("Error!!!");
                Console.WriteLine("Status Code: " + getCalculationResult.StatusCode);
                Console.WriteLine("Request Key: " + getCalculationResult.Headers["X-Factset-Api-Request-Key"]);
                return;
            }

            var package = getCalculationResult.Data;
            Console.WriteLine(package.ToString());
            Console.ReadKey();
        }

        private static void LogError(ApiResponse<object> response)
        {
            Console.WriteLine("Error!!!");
            Console.WriteLine("Status Code: " + response.StatusCode);
            Console.WriteLine("Request Key: " + response.Headers["X-Factset-Api-Request-Key"]);
        }
    }
}

 

package examples;

import java.util.List;
import java.util.Map;

import com.factset.protobuf.stach.PackageProto.Package;

import factset.analyticsapi.paengineapi.v1.ApiClient;
import factset.analyticsapi.paengineapi.v1.ApiException;
import factset.analyticsapi.paengineapi.v1.ApiResponse;
import factset.analyticsapi.paengineapi.v1.api.CalculationsApi;
import factset.analyticsapi.paengineapi.v1.api.ComponentsApi;
import factset.analyticsapi.paengineapi.v1.models.*;

public class Example {
	private static ApiClient apiClient = null;

	public static void main(String[] args) throws InterruptedException {
		try {
			ComponentsApi componentsApi = new ComponentsApi(apiClientFactory());
			Map<String, ComponentListEntity> components = componentsApi.getAll("PA_DOCUMENTS:DEFAULT");
			String componentId = components.entrySet().stream().findFirst().get().getKey();
			System.out.println("ComponentID: " + componentId);

			CalculationParameters parameters = new CalculationParameters();
			parameters.componentid(componentId);
			parameters.setAccount("BENCH:SP50");
			parameters.setBenchmark("BENCH:R.2000");

			CalculationsApi calculationsApi = new CalculationsApi(apiClientFactory());
			ApiResponse<Void> calculationResult = (new CalculationsApi(apiClientFactory()))
					.createWithHttpInfo(parameters);

			Map<String, List<String>> headers = calculationResult.getHeaders();
			String locationToPoll = headers.get("Location").get(0);
			String[] splits = locationToPoll.split("/");
			String requestId = splits[splits.length - 1];

			ApiResponse<Void> calculationPollResponse = calculationsApi.getStatusByIdWithHttpInfo(requestId);

			while (calculationPollResponse.getStatusCode() == 202) {
				List<String> progress = calculationPollResponse.getHeaders().get("X-Factset-Api-Pickup-Progress");
				if (progress != null) {
					System.out.println("Progress: " + progress.get(0));
				}

				List<String> cacheControl = calculationPollResponse.getHeaders().get("Cache-Control");
				if (cacheControl != null) {
					int maxAge = Integer.parseInt(cacheControl.get(0).replaceAll("max-age=", ""));
					System.out.println("Sleeping for: " + maxAge + " seconds");
					Thread.sleep(maxAge * 1000);
				} else {
					System.out.println("Sleeping for: 2 seconds");
					Thread.sleep(2 * 1000);
				}

				calculationPollResponse = calculationsApi.getStatusByIdWithHttpInfo(requestId);
			}

			if (calculationPollResponse.getStatusCode() != 201) {
				System.err.println("Error!!!");
				System.err.println("X-DataDirect-Request-Key: "
						+ calculationPollResponse.getHeaders().get("X-DataDirect-Request-Key").get(0));
				return;
			}

			ApiResponse<Package> calculationResultResponse = calculationsApi.getResultByIdWithHttpInfo(requestId);
			System.out.println(calculationResultResponse.getData());

		} catch (ApiException e) {
			System.err.println("ResponseBody: " + e.getResponseBody());
			System.err.println(
					"X-DataDirect-Request-Key: " + e.getResponseHeaders().get("X-DataDirect-Request-Key").get(0));
			e.printStackTrace();
		}
	}

	private static ApiClient apiClientFactory() {
		if (apiClient != null) {
			return apiClient;
		}

		apiClient = new ApiClient();
		apiClient.setBasePath("https://api.factset.com");
		apiClient.setUsername("<username-serial>"); // username-serial combination
		apiClient.setPassword("<apiKey>"); // api key

		apiClient.setVerifyingSsl(false);

		return apiClient;
	}
}

 

from fds.analyticsapi.paengineapi.v1.configuration import Configuration
from fds.analyticsapi.paengineapi.v1.api_client import ApiClient
from fds.analyticsapi.paengineapi.v1.api.components_api import ComponentsApi
from fds.analyticsapi.paengineapi.v1.models.component_entity import ComponentEntity
from fds.analyticsapi.paengineapi.v1.api.calculations_api import CalculationsApi
from fds.analyticsapi.paengineapi.v1.models.calculation_parameters import CalculationParameters
from fds.analyticsapi.paengineapi.v1.models.outstanding_calculation import OutstandingCalculation
from fds.protobuf.stach.Package_pb2 import Package
import time

config = Configuration()
config.host = "https://api.factset.com"
config.username = "<username-serial>"
config.password = "<apiKey>"
config.verify_ssl = False

api_client = ApiClient(config)

componentsApi = ComponentsApi(api_client)
component_api_get_result = componentsApi.get_all_with_http_info(documentname="PA_DOCUMENTS:DEFAULT")
componentId = list(component_api_get_result[0].keys())[0]
print("Component ID: " + componentId)

calculation_params = CalculationParameters(componentId, "BENCH:SP50", "BENCH:R.2000")
calculationsApi = CalculationsApi(api_client)
calculation_api_post_result =  calculationsApi.create_with_http_info(parameters=calculation_params)

if(calculation_api_post_result[1] != 202):
    print(calculation_api_post_result[2].get('x-factset-api-request-key'))
    quit()

statusLocation = calculation_api_post_result[2].get('Location')
splits = statusLocation.split('/')
calculationId = splits[-1]
print("Calculation Id: " + calculationId)

calculation_status_result = calculationsApi.get_status_by_id_with_http_info(calculationId)
while calculation_status_result[1] == 202:
    progress = calculation_status_result[2].get('X-Factset-Api-Pickup-Progress')
    if(progress != None):
        print("Progress: " + progress)
    ageValue = calculation_status_result[2].get('Cache-Control')
    if(ageValue != None):
        maxAge = ageValue.replace("max-age=", "")
        print('Sleeping: ' + maxAge)
        time.sleep(int(maxAge))
    calculation_status_result = calculationsApi.get_status_by_id_with_http_info(calculationId)

if(calculation_status_result[1] != 201):
    print(calculation_api_post_result[2].get('x-factset-api-request-key'))
    quit()

calculation_api_result = calculationsApi.get_result_by_id_with_http_info(calculationId)

if(calculation_api_result[1] != 200):
    print(calculation_api_result[2].get('x-factset-api-request-key'))
    quit()

print(calculation_api_result[0])

 

Building and running a calculation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Api;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Client;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Model;

namespace FactSet.AnalyticsAPI.PAEngineAPI.v1.Examples
{
    class Program
    {
        private static Configuration configuration;

        private static Configuration GetConfiguration()
        {
            if (configuration != null)
            {
                return configuration;
            }

            configuration = new Configuration
            {
                BasePath = "https://api.factset.com",
                Username = "<username-serial>",
                Password = "<apiKey>"
            };

            return configuration;
        }

        static void Main(string[] args)
        {
            var componentsApi = new ComponentsApi(GetConfiguration());

            // PA_DOCUMENTS:DEFAULT is default document available to all users.
            ApiResponse<Dictionary<string, ComponentListEntity>> componentGetAllResponse =
                componentsApi.GetAllWithHttpInfo("PA_DOCUMENTS:DEFAULT");
            var componentId = componentGetAllResponse.Data.First().Key;

            var account = "BENCH:SP50";
            var benchmark = "BENCH:R.1000";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            CalculationParameters inputBody = new CalculationParameters(componentId, account, benchmark);
            var calculationsApi = new CalculationsApi(GetConfiguration());
            var createrCalculationResponse = calculationsApi.CreateWithHttpInfo(inputBody);

            if (createrCalculationResponse.StatusCode != 202)
            {
                LogError(createrCalculationResponse);
                return;
            }

            // Parse the the Location header for calculation Id
            createrCalculationResponse.Headers.TryGetValue("Location", out string location);
            if (string.IsNullOrWhiteSpace(location))
            {
                LogError(createrCalculationResponse);
                return;
            }

            var splits = location.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var calculationId = splits.Last();
            ApiResponse<object> getCalculationStatus = null;
            while (getCalculationStatus == null || getCalculationStatus.StatusCode == 202)
            {
                getCalculationStatus = calculationsApi.GetStatusByIdWithHttpInfo(calculationId);
                if (getCalculationStatus.StatusCode != 202)
                {
                    continue;
                }

                if (getCalculationStatus.Headers.ContainsKey("Cache-Control"))
                {
                    Console.WriteLine("Progress: " + getCalculationStatus.Headers["X-Factset-Api-Pickup-Progress"]);

                    var ageValue = getCalculationStatus.Headers["Cache-Control"];
                    if (string.IsNullOrWhiteSpace(ageValue))
                    {
                        Console.WriteLine("Sleeping for 2 seconds");
                        // Sleep for atleast 2 seconds.
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        int age = int.Parse(ageValue.Replace("max-age=", ""));
                        Console.WriteLine($"Sleeping for {age} seconds");
                        Thread.Sleep(age * 1000);
                    }
                }
            }

            if (getCalculationStatus.StatusCode != 201)
            {
                LogError(getCalculationStatus);
                return;
            }

            var getCalculationResult = calculationsApi.GetResultByIdWithHttpInfo(calculationId);
            if (getCalculationResult.StatusCode != 200)
            {
                Console.WriteLine("Error!!!");
                Console.WriteLine("Status Code: " + getCalculationResult.StatusCode);
                Console.WriteLine("Request Key: " + getCalculationResult.Headers["X-Factset-Api-Request-Key"]);
                return;
            }

            var package = getCalculationResult.Data;
            Console.WriteLine(package.ToString());
            Console.ReadKey();
        }

        private static void LogError(ApiResponse<object> response)
        {
            Console.WriteLine("Error!!!");
            Console.WriteLine("Status Code: " + response.StatusCode);
            Console.WriteLine("Request Key: " + response.Headers["X-Factset-Api-Request-Key"]);
        }
    }
}

 

package examples;

import java.util.List;
import java.util.Map;

import com.factset.protobuf.stach.PackageProto.Package;

import factset.analyticsapi.paengineapi.v1.ApiClient;
import factset.analyticsapi.paengineapi.v1.ApiException;
import factset.analyticsapi.paengineapi.v1.ApiResponse;
import factset.analyticsapi.paengineapi.v1.api.CalculationsApi;
import factset.analyticsapi.paengineapi.v1.api.ComponentsApi;
import factset.analyticsapi.paengineapi.v1.models.*;

public class Example {
	private static ApiClient apiClient = null;

	public static void main(String[] args) throws InterruptedException {
		try {
			ComponentsApi componentsApi = new ComponentsApi(apiClientFactory());
			Map<String, ComponentListEntity> components = componentsApi.getAll("PA_DOCUMENTS:DEFAULT");
			String componentId = components.entrySet().stream().findFirst().get().getKey();
			System.out.println("ComponentID: " + componentId);

			CalculationParameters parameters = new CalculationParameters();
			parameters.componentid(componentId);
			parameters.setAccount("BENCH:SP50");
			parameters.setBenchmark("BENCH:R.2000");

			CalculationsApi calculationsApi = new CalculationsApi(apiClientFactory());
			ApiResponse<Void> calculationResult = (new CalculationsApi(apiClientFactory()))
					.createWithHttpInfo(parameters);

			Map<String, List<String>> headers = calculationResult.getHeaders();
			String locationToPoll = headers.get("Location").get(0);
			String[] splits = locationToPoll.split("/");
			String requestId = splits[splits.length - 1];

			ApiResponse<Void> calculationPollResponse = calculationsApi.getStatusByIdWithHttpInfo(requestId);

			while (calculationPollResponse.getStatusCode() == 202) {
				List<String> progress = calculationPollResponse.getHeaders().get("X-Factset-Api-Pickup-Progress");
				if (progress != null) {
					System.out.println("Progress: " + progress.get(0));
				}

				List<String> cacheControl = calculationPollResponse.getHeaders().get("Cache-Control");
				if (cacheControl != null) {
					int maxAge = Integer.parseInt(cacheControl.get(0).replaceAll("max-age=", ""));
					System.out.println("Sleeping for: " + maxAge + " seconds");
					Thread.sleep(maxAge * 1000);
				} else {
					System.out.println("Sleeping for: 2 seconds");
					Thread.sleep(2 * 1000);
				}

				calculationPollResponse = calculationsApi.getStatusByIdWithHttpInfo(requestId);
			}

			if (calculationPollResponse.getStatusCode() != 201) {
				System.err.println("Error!!!");
				System.err.println("X-DataDirect-Request-Key: "
						+ calculationPollResponse.getHeaders().get("X-DataDirect-Request-Key").get(0));
				return;
			}

			ApiResponse<Package> calculationResultResponse = calculationsApi.getResultByIdWithHttpInfo(requestId);
			System.out.println(calculationResultResponse.getData());

		} catch (ApiException e) {
			System.err.println("ResponseBody: " + e.getResponseBody());
			System.err.println(
					"X-DataDirect-Request-Key: " + e.getResponseHeaders().get("X-DataDirect-Request-Key").get(0));
			e.printStackTrace();
		}
	}

	private static ApiClient apiClientFactory() {
		if (apiClient != null) {
			return apiClient;
		}

		apiClient = new ApiClient();
		apiClient.setBasePath("https://api.factset.com");
		apiClient.setUsername("<username-serial>"); // username-serial combination
		apiClient.setPassword("<apiKey>"); // api key

		apiClient.setVerifyingSsl(false);

		return apiClient;
	}
}

 

from fds.analyticsapi.paengineapi.v1.configuration import Configuration
from fds.analyticsapi.paengineapi.v1.api_client import ApiClient
from fds.analyticsapi.paengineapi.v1.api.components_api import ComponentsApi
from fds.analyticsapi.paengineapi.v1.models.component_entity import ComponentEntity
from fds.analyticsapi.paengineapi.v1.api.calculations_api import CalculationsApi
from fds.analyticsapi.paengineapi.v1.models.calculation_parameters import CalculationParameters
from fds.analyticsapi.paengineapi.v1.models.outstanding_calculation import OutstandingCalculation
from fds.protobuf.stach.Package_pb2 import Package
import time

config = Configuration()
config.host = "https://api.factset.com"
config.username = "<username-serial>"
config.password = "<apiKey>"
config.verify_ssl = False

api_client = ApiClient(config)

componentsApi = ComponentsApi(api_client)
component_api_get_result = componentsApi.get_all_with_http_info(documentname="PA_DOCUMENTS:DEFAULT")
componentId = list(component_api_get_result[0].keys())[0]
print("Component ID: " + componentId)

calculation_params = CalculationParameters(componentId, "BENCH:SP50", "BENCH:R.2000")
calculationsApi = CalculationsApi(api_client)
calculation_api_post_result =  calculationsApi.create_with_http_info(parameters=calculation_params)

if(calculation_api_post_result[1] != 202):
    print(calculation_api_post_result[2].get('x-factset-api-request-key'))
    quit()

statusLocation = calculation_api_post_result[2].get('Location')
splits = statusLocation.split('/')
calculationId = splits[-1]
print("Calculation Id: " + calculationId)

calculation_status_result = calculationsApi.get_status_by_id_with_http_info(calculationId)
while calculation_status_result[1] == 202:
    progress = calculation_status_result[2].get('X-Factset-Api-Pickup-Progress')
    if(progress != None):
        print("Progress: " + progress)
    ageValue = calculation_status_result[2].get('Cache-Control')
    if(ageValue != None):
        maxAge = ageValue.replace("max-age=", "")
        print('Sleeping: ' + maxAge)
        time.sleep(int(maxAge))
    calculation_status_result = calculationsApi.get_status_by_id_with_http_info(calculationId)

if(calculation_status_result[1] != 201):
    print(calculation_api_post_result[2].get('x-factset-api-request-key'))
    quit()

calculation_api_result = calculationsApi.get_result_by_id_with_http_info(calculationId)

if(calculation_api_result[1] != 200):
    print(calculation_api_result[2].get('x-factset-api-request-key'))
    quit()

print(calculation_api_result[0])

 

Building and running a calculation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Api;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Client;
using FactSet.AnalyticsAPI.PAEngineAPI.v1.Model;

namespace FactSet.AnalyticsAPI.PAEngineAPI.v1.Examples
{
    class Program
    {
        private static Configuration configuration;

        private static Configuration GetConfiguration()
        {
            if (configuration != null)
            {
                return configuration;
            }

            configuration = new Configuration
            {
                BasePath = "https://api.factset.com",
                Username = "<username-serial>",
                Password = "<apiKey>"
            };

            return configuration;
        }

        static void Main(string[] args)
        {
            var componentsApi = new ComponentsApi(GetConfiguration());

            // PA_DOCUMENTS:DEFAULT is default document available to all users.
            ApiResponse<Dictionary<string, ComponentListEntity>> componentGetAllResponse =
                componentsApi.GetAllWithHttpInfo("PA_DOCUMENTS:DEFAULT");
            var componentId = componentGetAllResponse.Data.First().Key;

            var account = "BENCH:SP50";
            var benchmark = "BENCH:R.1000";

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            CalculationParameters inputBody = new CalculationParameters(componentId, account, benchmark);
            var calculationsApi = new CalculationsApi(GetConfiguration());
            var createrCalculationResponse = calculationsApi.CreateWithHttpInfo(inputBody);

            if (createrCalculationResponse.StatusCode != 202)
            {
                LogError(createrCalculationResponse);
                return;
            }

            // Parse the the Location header for calculation Id
            createrCalculationResponse.Headers.TryGetValue("Location", out string location);
            if (string.IsNullOrWhiteSpace(location))
            {
                LogError(createrCalculationResponse);
                return;
            }

            var splits = location.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            var calculationId = splits.Last();
            ApiResponse<object> getCalculationStatus = null;
            while (getCalculationStatus == null || getCalculationStatus.StatusCode == 202)
            {
                getCalculationStatus = calculationsApi.GetStatusByIdWithHttpInfo(calculationId);
                if (getCalculationStatus.StatusCode != 202)
                {
                    continue;
                }

                if (getCalculationStatus.Headers.ContainsKey("Cache-Control"))
                {
                    Console.WriteLine("Progress: " + getCalculationStatus.Headers["X-Factset-Api-Pickup-Progress"]);

                    var ageValue = getCalculationStatus.Headers["Cache-Control"];
                    if (string.IsNullOrWhiteSpace(ageValue))
                    {
                        Console.WriteLine("Sleeping for 2 seconds");
                        // Sleep for atleast 2 seconds.
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        int age = int.Parse(ageValue.Replace("max-age=", ""));
                        Console.WriteLine($"Sleeping for {age} seconds");
                        Thread.Sleep(age * 1000);
                    }
                }
            }

            if (getCalculationStatus.StatusCode != 201)
            {
                LogError(getCalculationStatus);
                return;
            }

            var getCalculationResult = calculationsApi.GetResultByIdWithHttpInfo(calculationId);
            if (getCalculationResult.StatusCode != 200)
            {
                Console.WriteLine("Error!!!");
                Console.WriteLine("Status Code: " + getCalculationResult.StatusCode);
                Console.WriteLine("Request Key: " + getCalculationResult.Headers["X-Factset-Api-Request-Key"]);
                return;
            }

            var package = getCalculationResult.Data;
            Console.WriteLine(package.ToString());
            Console.ReadKey();
        }

        private static void LogError(ApiResponse<object> response)
        {
            Console.WriteLine("Error!!!");
            Console.WriteLine("Status Code: " + response.StatusCode);
            Console.WriteLine("Request Key: " + response.Headers["X-Factset-Api-Request-Key"]);
        }
    }
}

 

package examples;

import java.util.List;
import java.util.Map;

import com.factset.protobuf.stach.PackageProto.Package;

import factset.analyticsapi.paengineapi.v1.ApiClient;
import factset.analyticsapi.paengineapi.v1.ApiException;
import factset.analyticsapi.paengineapi.v1.ApiResponse;
import factset.analyticsapi.paengineapi.v1.api.CalculationsApi;
import factset.analyticsapi.paengineapi.v1.api.ComponentsApi;
import factset.analyticsapi.paengineapi.v1.models.*;

public class Example {
	private static ApiClient apiClient = null;

	public static void main(String[] args) throws InterruptedException {
		try {
			ComponentsApi componentsApi = new ComponentsApi(apiClientFactory());
			Map<String, ComponentListEntity> components = componentsApi.getAll("PA_DOCUMENTS:DEFAULT");
			String componentId = components.entrySet().stream().findFirst().get().getKey();
			System.out.println("ComponentID: " + componentId);

			CalculationParameters parameters = new CalculationParameters();
			parameters.componentid(componentId);
			parameters.setAccount("BENCH:SP50");
			parameters.setBenchmark("BENCH:R.2000");

			CalculationsApi calculationsApi = new CalculationsApi(apiClientFactory());
			ApiResponse<Void> calculationResult = (new CalculationsApi(apiClientFactory()))
					.createWithHttpInfo(parameters);

			Map<String, List<String>> headers = calculationResult.getHeaders();
			String locationToPoll = headers.get("Location").get(0);
			String[] splits = locationToPoll.split("/");
			String requestId = splits[splits.length - 1];

			ApiResponse<Void> calculationPollResponse = calculationsApi.getStatusByIdWithHttpInfo(requestId);

			while (calculationPollResponse.getStatusCode() == 202) {
				List<String> progress = calculationPollResponse.getHeaders().get("X-Factset-Api-Pickup-Progress");
				if (progress != null) {
					System.out.println("Progress: " + progress.get(0));
				}

				List<String> cacheControl = calculationPollResponse.getHeaders().get("Cache-Control");
				if (cacheControl != null) {
					int maxAge = Integer.parseInt(cacheControl.get(0).replaceAll("max-age=", ""));
					System.out.println("Sleeping for: " + maxAge + " seconds");
					Thread.sleep(maxAge * 1000);
				} else {
					System.out.println("Sleeping for: 2 seconds");
					Thread.sleep(2 * 1000);
				}

				calculationPollResponse = calculationsApi.getStatusByIdWithHttpInfo(requestId);
			}

			if (calculationPollResponse.getStatusCode() != 201) {
				System.err.println("Error!!!");
				System.err.println("X-DataDirect-Request-Key: "
						+ calculationPollResponse.getHeaders().get("X-DataDirect-Request-Key").get(0));
				return;
			}

			ApiResponse<Package> calculationResultResponse = calculationsApi.getResultByIdWithHttpInfo(requestId);
			System.out.println(calculationResultResponse.getData());

		} catch (ApiException e) {
			System.err.println("ResponseBody: " + e.getResponseBody());
			System.err.println(
					"X-DataDirect-Request-Key: " + e.getResponseHeaders().get("X-DataDirect-Request-Key").get(0));
			e.printStackTrace();
		}
	}

	private static ApiClient apiClientFactory() {
		if (apiClient != null) {
			return apiClient;
		}

		apiClient = new ApiClient();
		apiClient.setBasePath("https://api.factset.com");
		apiClient.setUsername("<username-serial>"); // username-serial combination
		apiClient.setPassword("<apiKey>"); // api key

		apiClient.setVerifyingSsl(false);

		return apiClient;
	}
}

 

from fds.analyticsapi.paengineapi.v1.configuration import Configuration
from fds.analyticsapi.paengineapi.v1.api_client import ApiClient
from fds.analyticsapi.paengineapi.v1.api.components_api import ComponentsApi
from fds.analyticsapi.paengineapi.v1.models.component_entity import ComponentEntity
from fds.analyticsapi.paengineapi.v1.api.calculations_api import CalculationsApi
from fds.analyticsapi.paengineapi.v1.models.calculation_parameters import CalculationParameters
from fds.analyticsapi.paengineapi.v1.models.outstanding_calculation import OutstandingCalculation
from fds.protobuf.stach.Package_pb2 import Package
import time

config = Configuration()
config.host = "https://api.factset.com"
config.username = "<username-serial>"
config.password = "<apiKey>"
config.verify_ssl = False

api_client = ApiClient(config)

componentsApi = ComponentsApi(api_client)
component_api_get_result = componentsApi.get_all_with_http_info(documentname="PA_DOCUMENTS:DEFAULT")
componentId = list(component_api_get_result[0].keys())[0]
print("Component ID: " + componentId)

calculation_params = CalculationParameters(componentId, "BENCH:SP50", "BENCH:R.2000")
calculationsApi = CalculationsApi(api_client)
calculation_api_post_result =  calculationsApi.create_with_http_info(parameters=calculation_params)

if(calculation_api_post_result[1] != 202):
    print(calculation_api_post_result[2].get('x-factset-api-request-key'))
    quit()

statusLocation = calculation_api_post_result[2].get('Location')
splits = statusLocation.split('/')
calculationId = splits[-1]
print("Calculation Id: " + calculationId)

calculation_status_result = calculationsApi.get_status_by_id_with_http_info(calculationId)
while calculation_status_result[1] == 202:
    progress = calculation_status_result[2].get('X-Factset-Api-Pickup-Progress')
    if(progress != None):
        print("Progress: " + progress)
    ageValue = calculation_status_result[2].get('Cache-Control')
    if(ageValue != None):
        maxAge = ageValue.replace("max-age=", "")
        print('Sleeping: ' + maxAge)
        time.sleep(int(maxAge))
    calculation_status_result = calculationsApi.get_status_by_id_with_http_info(calculationId)

if(calculation_status_result[1] != 201):
    print(calculation_api_post_result[2].get('x-factset-api-request-key'))
    quit()

calculation_api_result = calculationsApi.get_result_by_id_with_http_info(calculationId)

if(calculation_api_result[1] != 200):
    print(calculation_api_result[2].get('x-factset-api-request-key'))
    quit()

print(calculation_api_result[0])

 

Change Logs

v1.3 (Released on 11/29/18)
Summary
  • New features and bug fixes
Functionality Additions
  • Added Get All Outstanding Calculations endpoint to fetch progress of all previously requested calculations [v1.3.0]
  • Added Rate Limit response headers to Run Calculation and Run Vault Calculation endpoints [v1.3.0]
  • Added support for Accept request header to all HTTP GET endpoints [v1.3.0]
Changes
  • No breaking changes
Bug Fixes
  • Fixed error reason when providing incorrect version [v1.3.0]
v1.2 (Released on 10/19/18)
Summary
  • New features and bug fixes
Functionality Additions
  • Added API Keys as an additional authentication methodology. One-Time Password (OTP) authentication will be phased out eventually [v1.2.0]
Changes
  • No breaking changes
Bug Fixes
  • Non-successful responses (HTTP status codes >= 300) will no longer fill up a user-serial’s quota [v1.2.0]
v1.1 (Released on 10/12/18)
Summary
  • New features
Functionality Additions
  • [Alpha Release] Added Calculation API for Vault data [v1.1.0]
  • [Alpha Release] Added Helper APIs to lookup Vault configuration(s) by user-serial and by Vault identifier [v1.1.0]
Changes
  • No breaking changes
Bug Fixes
  • No changes
v1 (Released on 08/30/18)
Summary
  • Moving API program out of Beta into production
  • New features and some breaking changes
Functionality Additions
  • Added the option to override groups in a PA component through Calculations API’s Run Calculation endpoint [v1.0.0]
  • Added Helper API for groups lookup [v1.0.0]
  • Added error reasons in response body for responses greater than or equal to HTTP status code 400 [v1.0.0]
  • Added API endpoint to fetch a component’s calculation settings [v1.0.0]
  • Added Api-Supported-Versions response header to describe all API versions supported by a given endpoint [v1.0.0]
Changes
  • Hostname for all endpoints has been changed from “ondemand.factset.com” to “api.factset.com” [v1.0.0]
  • Get Calculation Result Endpoint has been broken down into Get Calculation Status and Get Calculation Result endpoints [v1.0.0]
  • Run Calculation endpoint’s “documentname” property has been retired. Component identifiers will need to be fetched from ‘Fetch Component Settings’ endpoint [v1.0.0]
Bug Fixes
  • No changes
v0.2 (Retired on 11/29/18)
Summary
  • Using new JSON format (i.e., STACH format)
  • Other breaking changes
Functionality Additions
  • v0.1 JSON format has been replaced with STACH JSON format [v0.2.0]
  • Added Content-Encoding, Content-Type and Transfer-Encoding headers to CORS’ Access-Control-Expose-Headers header for all endpoints [v0.2.0]
  • Added the option to override dates and currency in a PA component through Calculations API’s Run Calculation endpoint [v0.2.2]
  • Added Helper APIs for component lookup, date translation and currency lookup [v0.2.2]
  • API version major.minor.patch will be returned in X-FactSet-Api-Version response header [v0.2.2]
Changes
  • Run Calculation endpoint’s “asofdate” property has been changed to “dates” object. “dates” object supports “startdate” and “enddate” [v0.2.0]
  • Running PA components with non-single date frequency using Run Calculation endpoint will be disallowed with HTTP status code 400 [v0.2.0]
  • Run Calculation endpoint’s “document” property has been split into “documentname” and “componentid” properties [v0.2.0]
Bug Fixes
  • Cancel Calculation endpoint returns HTTP status code 204 instead of 200 [v0.2.0]