OpenFIGI API Examples

repository·main·Indexed 42 days ago

https://github.com/openfigi/api-examples

A collection of code examples in multiple programming languages—including C# (.NET 8.0), Java, JavaScript (Node.js v22.11.0), Python 3.12, Swift 6.0, Bash, and PowerShell—demonstrating how to interact with the OpenFIGI API to retrieve Financial Instrument Global Identifiers (FIGIs) for securities.

Tokens
2.4K
Snippets
12
Records
13
Agent score
54%

What's inside OpenFIGI

  1. Overview of OpenFIGI API Examples

    main
    This repository provides simple, language-specific examples demonstrating how to obtain FIGIs (Financial Instrument Global Identifiers) for securities using the OpenFIGI API. It serves as a reference for developers looking to integrate OpenFIGI capabilities into their applications using various programming languages such as Java, JavaScript, and Python.
  2. Run the OpenFIGI Python3 example locally

    main

    To run the example script on your local machine, ensure you have Python 3.12 installed. The script is designed to run without any external libraries and has been tested with Python 3.12.7.

    If you have an API key, you can export it as an environment variable before running the script to authenticate your requests.

    # Optional: Export your API key
    export OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    python3 example.py
  3. Run OpenFIGI shell examples using Bash and curl

    main

    To run the OpenFIGI shell examples in a Bash environment, ensure you have bash and curl installed. You can optionally export your API key to an environment variable named OPENFIGI_API_KEY before execution.

    # Optional: Export your API key
    export OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    
    ./curl.sh
    # OR
    bash ./curl.sh
  4. Run the OpenFIGI Swift example using Docker

    main

    If you prefer using Docker, you can build and run the example in a containerized environment. This requires Docker to be installed on your system.

    To run without an API key:

    1. Build the image with the tag openfigi-swift.
    2. Run the container, mounting the current directory to /OpenFIGI inside the container.

    To run with an API key, pass the OPENFIGI_API_KEY environment variable using the -e flag.

    # Build the image
    docker build --tag 'openfigi-swift' .
    
    # Run without API key
    docker run --rm -it --volume ./:/OpenFIGI 'openfigi-swift' swift example.swift
    
    # Run with API key
    docker run --rm -it --volume ./:/OpenFIGI -e OPENFIGI_API_KEY=<YOUR_KEY_HERE> 'openfigi-swift' swift example.swift
  5. Run the OpenFIGI Java example using Docker

    main

    If you prefer using Docker, ensure Docker is installed. You can build the image and run the example by mounting the current directory to the container. You can provide your API key via an environment variable during the docker run command.

    # Build the image
    docker build --tag 'openfigi-java' .
    
    # Run without API key
    docker run --rm -it --entrypoint java --volume ./:/OpenFIGI 'openfigi-java' ./example.java
    
    # Run with API key
    docker run -e OPENFIGI_API_KEY=<YOUR_KEY_HERE> --rm -it --entrypoint java --volume ./:/OpenFIGI 'openfigi-java' ./example.java
  6. Run OpenFIGI Javascript example using Docker

    main

    If you prefer to use a containerized environment, you can build and run the example using Docker.

    Prerequisites

    • Docker must be installed on your system.

    Execution Steps

    1. Build the image: Tag the image as openfigi-js.
    2. Run the container: Use the --entrypoint flag to execute the script and mount the current directory to /OpenFIGI inside the container.
    3. Using an API Key: To pass your API key to the container, use the -e flag to set the OPENFIGI_API_KEY environment variable.
    # Build the image
    docker build --tag 'openfigi-js' .
    
    # Run without API key
    docker run --rm -it --entrypoint ./example.mjs --volume ./:/OpenFIGI 'openfigi-js'
    
    # Run with API key
    docker run --rm -it --entrypoint ./example.mjs --volume ./:/OpenFIGI 'openfigi-js' -e OPENFIGI_API_KEY=<YOUR_KEY_HERE>
  7. Run the OpenFIGI Python3 example using Docker

    main

    If you prefer using Docker, you can build and run the example in a containerized environment. This requires Docker to be installed.

    1. Build the image with the tag openfigi-python.
    2. Run the container, mounting the current directory to /OpenFIGI inside the container.
    3. To use an API key, pass it using the -e flag to set the OPENFIGI_API_KEY environment variable.
    # Build the image
    docker build --tag 'openfigi-python' .
    
    # Run without API key
    docker run --rm -it --entrypoint ./example.py --volume ./:/OpenFIGI 'openfigi-python'
    
    # Run with API key
    docker run --rm -it --entrypoint ./example.py --volume ./:/OpenFIGI 'openfigi-python' -e OPENFIGI_API_KEY=<YOUR_KEY_HERE>
  8. Run the OpenFIGI Swift example locally

    main

    To run the Swift example locally, ensure you have Swift 6.0 installed. The script is designed to run without external dependencies and has been tested with Swift 6.0.3 on Ubuntu 24.04.1 LTS.

    If you have an API key, you can export it as an environment variable before running the script to authenticate your requests.

    # Optional: Export your API key
    export OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    swift example.swift
  9. Run OpenFIGI shell examples using PowerShell

    main

    To run the OpenFIGI shell examples in a PowerShell environment, ensure powershell is installed. You can optionally export your API key to an environment variable named OPENFIGI_API_KEY before execution.

    # Optional: Export your API key
    export OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    
    ./example-powershell.ps1
    # OR
    pwsh ./example-powershell.ps1
  10. Run OpenFIGI Javascript example with Node.js

    main

    This example script is designed to run in a Node.js environment without requiring any external libraries. It has been tested with Node.js v22.11.0.

    Prerequisites

    • node must be installed on your system.

    Execution Steps

    1. Set your API Key (Optional): To use your own credentials, export the OPENFIGI_API_KEY environment variable.
    2. Run the script: Execute the script using node example.mjs or ./example.mjs.
    # Optional: Export your API key
    export OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    
    # Run the script
    ./example.mjs
    # OR
    node example.mjs
  11. Run the OpenFIGI API C# example using Docker

    main

    If you prefer using Docker, you can build and run the example in a containerized environment.

    Prerequisites

    • Docker installed

    Execution Steps

    1. Build the Docker image:
      docker build --tag 'openfigi-dotnet' .
    2. Run the container. You must mount the current directory to /OpenFIGI inside the container to provide the script context.

    Without an API Key:

    docker run --rm -it --entrypoint ./example.csx --volume ./:/OpenFIGI 'openfigi-dotnet'

    With an API Key: Pass your key using the -e flag:

    docker run --rm -it --entrypoint ./example.csx --volume ./:/OpenFIGI 'openfigi-dotnet' -e OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    docker build --tag 'openfigi-dotnet' .
    
    docker run --rm -it --entrypoint ./example.csx --volume ./:/OpenFIGI 'openfigi-dotnet'
    
    # OR: If you have acquired an API Key
    docker run --rm -it --entrypoint ./example.csx --volume ./:/OpenFIGI 'openfigi-dotnet' -e OPENFIGI_API_KEY=<YOUR_KEY_HERE>
  12. Run the OpenFIGI Java example locally

    main

    To run the Java example on your local machine, ensure you have jdk installed. The script is designed to be built by JDK and run on the JVM without external libraries. While this example uses no external dependencies, it is recommended that end users use a JSON library for serializing requests and deserializing responses in their own implementations.

    # Optional: Export your API key
    export OPENFIGI_API_KEY=<YOUR_KEY_HERE>
    
    java ./example.java