Compliance Server

From Spire Trading Inc.
Revision as of 20:03, 27 May 2026 by Kamal (talk | contribs) (Created page with "The Compliance Server manages compliance rules and monitors rule violations for trading accounts. It maintains a repository of compliance rule definitions organized by directo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Compliance Server manages compliance rules and monitors rule violations for trading accounts. It maintains a repository of compliance rule definitions organized by directory entry, tracks rule states (active, passive, or deleted), and records violation events. By centralizing compliance rule administration and violation tracking, the server enforces consistent regulatory and risk management policies across the trading platform.

The Compliance Server integrates with the Service Locator for authentication and permission verification, the Administration Server to validate administrator privileges, and a MySQL database to persist compliance rules and violation records.

Configuration

The Compliance Server is configured via a YAML file with three top-level sections: server, service_locator, and data_store. Below is the structure of the configuration file with example values:

server:
  # Primary network interface and port the Compliance Server binds to.
  interface: "0.0.0.0:21900"
  # List of addresses the server is reachable at (for registration with Service Locator).
  # Typically includes both public-facing and local addresses.
  addresses: ["198.51.100.5:21900", "10.0.0.5:21900"]

service_locator:
  # The address of the Service Locator (host:port).
  address: "10.0.0.5:20000"
  # The account username used by the Compliance Server to authenticate with the Service Locator.
  username: compliance_server
  # The password for the Compliance Server's Service Locator account.
  password: [REQUIRED]

data_store:
  # The address of the MySQL server.
  address: "127.0.0.1:3306"
  # The username used to authenticate with MySQL.
  username: spireadmin
  # The password for the MySQL user.
  password: [REQUIRED]
  # The name of the database schema where data is stored.
  schema: spire

A setup.py script is provided to generate the final config.yml from the config.default.yml template. Usage:

  --local 0.0.0.0                 # Local interface (default: auto-detected IP)
  --world 198.51.100.5            # Global/public interface (optional)
  --address 10.0.0.5:20000        # Service Locator address (default: local_interface:20000)
  --password [REQUIRED]           # Service password for authentication
  --mysql_address 127.0.0.1:3306  # MySQL server address
  --mysql_username spireadmin     # MySQL username
  --mysql_password secretpw       # MySQL password (default: --password if omitted)

Capabilities

The Compliance Server provides the following capabilities:

Rule Management

Compliance rules are organized by directory entry (accounts or groups) and consist of:

  • A compliance rule schema defining the rule logic
  • Parameters configuring the rule's behavior
  • A state indicating whether the rule is active, passive, or deleted

Administrators can create, update, and delete compliance rules. Rule changes are immediately propagated to subscribed clients for real-time enforcement.

Rule Loading and Subscription

Clients can:

  • Load existing compliance rules for a specific directory entry
  • Subscribe to receive real-time updates when rules are added, modified, or deleted

Subscriptions enable clients to maintain synchronized views of active compliance rules without polling.

Violation Reporting

Administrators can report compliance rule violations, which are:

  • Persisted to the database for audit purposes
  • Associated with the specific account and rule involved
  • Timestamped using an NTP-synchronized time client

Management

The Compliance Server is controlled using three operational scripts: start.sh, stop.sh, and check.sh.

start.sh

  • Exits immediately if the server is already running.
  • Creates a logs/ directory if necessary.
  • Moves any existing srv_*.log files into logs/.
  • Starts the ComplianceServer process in the background.
  • Reads network interfaces from config.yml and waits until the server is listening on at least one configured address.

This ensures the server is fully initialized before the script exits.

stop.sh

  • Sends SIGINT to request a graceful shutdown.
  • Waits for termination using exponential backoff (up to 300 seconds).
  • Sends SIGKILL if the server fails to stop cleanly.
  • Appends a forced-termination message to the most recent log file (if applicable).

This guarantees consistent shutdown behavior across normal and exceptional conditions.

check.sh

The check.sh script verifies whether the server is currently running by inspecting the PID recorded in pid.lock and testing whether the associated process exists.

Logging

Upon startup, older log files are moved into the logs/ directory.