This project is a Go library and command-line tool for validating and generating OpenFIGI symbols.
- Validate: Checks if a symbol (or a stream of symbols from a file/stdin) adheres to the OpenFIGI format, including prefixes (
BBG/KKG), allowed characters, and the checksum. - Generate: Generates any number of valid, random OpenFIGI symbols.
The project is split into a reusable library and a simple command-line wrapper.
/
├── go.mod
├── /openfigi/ <-- The core, reusable library (package openfigi)
└── /cmd/
└── /openfigi-cli/ <-- The command-line application (package main)
-
Clone the repository:
git clone https://github.com/Gandook/openfigi-lib.git cd openfigi-lib -
Build the
openfigi-cliexecutable. This command compiles the application and places the binary in your current directory.go build ./cmd/openfigi-cli/
This will create an executable file named
openfigi-cli(oropenfigi-cli.exeon Windows).
The application has four commands: generate, genstream, validate, and valstream.
Use the generate command to create new symbols. The generated symbols are returned all at once.
Flags:
-n <number>: Number of symbols to generate (default: 1).
Example (Linux/macOS/PowerShell):
# Generate 5 unique symbols
./openfigi-cli generate -n 5Example (Windows Command Prompt):
# Generate 10 unique symbols
.\openfigi-cli.exe generate -n 10The genstream command is similar, but instead of returning all symbols at once, it returns them one at a time (as a stream). This makes it ideal for creating a large number of symbols.
Flags:
-n <number>: Number of symbols to generate (default: 1).
Example (Linux/macOS/PowerShell):
# Generate 5 unique symbols
./openfigi-cli genstream -n 5Example (Windows Command Prompt):
# Generate 10 unique symbols
.\openfigi-cli.exe genstream -n 10Use the validate command to validate a single string.
Flags:
-s <string>: The string to validate.
Example (Linux/macOS/PowerShell):
# Validate a single string
./openfigi-cli validate -s KKGW2Q0XJFQ5Use the valstream command to check existing symbols. It can read from a specified file or from standard input (stdin). Similar to genstream, it returns the results as a stream.
Example (Read from a file):
# Validate all symbols in a file
./openfigi-cli valstream path/to/your/symbols.txtExample (Read from standard input):
# Pipe input from another command (e.g., cat)
cat path/to/your/symbols.txt | ./openfigi-cli valstreamTo run the included unit tests for the library:
go test ./openfigi/