<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.spiretrading.com/index.php?action=history&amp;feed=atom&amp;title=Order_Execution_Server</id>
	<title>Order Execution Server - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.spiretrading.com/index.php?action=history&amp;feed=atom&amp;title=Order_Execution_Server"/>
	<link rel="alternate" type="text/html" href="https://wiki.spiretrading.com/index.php?title=Order_Execution_Server&amp;action=history"/>
	<updated>2026-05-28T23:02:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.1</generator>
	<entry>
		<id>https://wiki.spiretrading.com/index.php?title=Order_Execution_Server&amp;diff=141&amp;oldid=prev</id>
		<title>Kamal: Created page with &quot;The Order Execution Server receives order submissions from clients, routes them to appropriate execution venues or brokers, and tracks the lifecycle of each order from submiss...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.spiretrading.com/index.php?title=Order_Execution_Server&amp;diff=141&amp;oldid=prev"/>
		<updated>2026-05-27T20:10:32Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The Order Execution Server receives order submissions from clients, routes them to appropriate execution venues or brokers, and tracks the lifecycle of each order from submiss...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The Order Execution Server receives order submissions from clients, routes them to appropriate execution venues or brokers, and tracks the lifecycle of each order from submission through completion. It publishes execution reports to subscribed clients, enforces compliance rules and risk parameters, and maintains a persistent record of all order activity. By centralizing order routing and monitoring, the server ensures consistent application of trading controls while providing real-time visibility into order status across the system.&lt;br /&gt;
&lt;br /&gt;
The Order Execution Server integrates with the [[Service Locator]] for authentication, the [[Compliance Server]] for rule validation, the [[Risk Server]] for position and loss monitoring, the [[Administration Server]] for risk parameters, the [[Market Data Server]] for pricing and board lot checks, the [[Uid Server]] for unique order identifiers, and a MySQL database (with optional replication) to persist order records and execution reports.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The Order Execution Server is configured via a YAML file with three top-level sections: &amp;lt;code&amp;gt;server&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;service_locator&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;data_store&amp;lt;/code&amp;gt;. An optional &amp;lt;code&amp;gt;session_start_time&amp;lt;/code&amp;gt; field may also be specified. Below is the structure of the configuration file with example values:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
server:&lt;br /&gt;
  # Primary network interface and port the Order Execution Server binds to.&lt;br /&gt;
  interface: &amp;quot;0.0.0.0:20700&amp;quot;&lt;br /&gt;
  # List of addresses the server is reachable at (for registration with Service Locator).&lt;br /&gt;
  # Typically includes both public-facing and local addresses.&lt;br /&gt;
  addresses: [&amp;quot;198.51.100.5:20700&amp;quot;, &amp;quot;10.0.0.5:20700&amp;quot;]&lt;br /&gt;
&lt;br /&gt;
service_locator:&lt;br /&gt;
  # The address of the Service Locator (host:port).&lt;br /&gt;
  address: &amp;quot;10.0.0.5:20000&amp;quot;&lt;br /&gt;
  # The account username used by the Order Execution Server to authenticate with the Service Locator.&lt;br /&gt;
  username: order_execution_server&lt;br /&gt;
  # The password for the Order Execution Server's Service Locator account.&lt;br /&gt;
  password: [REQUIRED]&lt;br /&gt;
&lt;br /&gt;
# Data store supports replication: provide either a single MySQL endpoint&lt;br /&gt;
# or a list of endpoints to replicate writes across.&lt;br /&gt;
data_store:&lt;br /&gt;
  # The address of the MySQL server.&lt;br /&gt;
  address: &amp;quot;127.0.0.1:3306&amp;quot;&lt;br /&gt;
  # The username used to authenticate with MySQL.&lt;br /&gt;
  username: spireadmin&lt;br /&gt;
  # The password for the MySQL user.&lt;br /&gt;
  password: [REQUIRED]&lt;br /&gt;
  # The name of the database schema where data is stored.&lt;br /&gt;
  schema: spire&lt;br /&gt;
&lt;br /&gt;
# Optional start time of the trading session (default: +infinity, meaning no session boundary).&lt;br /&gt;
session_start_time: &amp;quot;2026-01-01 09:30:00&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &amp;lt;code&amp;gt;setup.py&amp;lt;/code&amp;gt; script is provided to generate the final &amp;lt;code&amp;gt;config.yml&amp;lt;/code&amp;gt; from the &amp;lt;code&amp;gt;config.default.yml&amp;lt;/code&amp;gt; template. Usage:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  --local 0.0.0.0                 # Local interface (default: auto-detected IP)&lt;br /&gt;
  --world 198.51.100.5            # Global/public interface (optional)&lt;br /&gt;
  --address 10.0.0.5:20000        # Service Locator address (default: local_interface:20000)&lt;br /&gt;
  --password [REQUIRED]           # Service password for authentication&lt;br /&gt;
  --mysql_address 127.0.0.1:3306  # MySQL server address&lt;br /&gt;
  --mysql_username spireadmin     # MySQL username&lt;br /&gt;
  --mysql_password secretpw       # MySQL password (default: --password if omitted)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Order Submission ==&lt;br /&gt;
&lt;br /&gt;
Before routing, each order passes through a series of submission checks:&lt;br /&gt;
&lt;br /&gt;
* '''Board Lot Check''' - Validates that order quantities conform to the security's board lot size.&lt;br /&gt;
* '''Buying Power Check''' - Ensures the account has sufficient buying power for the order, accounting for current positions and exchange rate conversions.&lt;br /&gt;
* '''Risk State Check''' - Verifies the account is in a risk state that permits new orders.&lt;br /&gt;
* '''Compliance Rule Check''' - Validates the order against all active compliance rules for the account or group.&lt;br /&gt;
&lt;br /&gt;
Orders that fail any check are immediately rejected with an appropriate error message.&lt;br /&gt;
&lt;br /&gt;
== Order Routing ==&lt;br /&gt;
&lt;br /&gt;
The server routes orders to their specified destinations based on:&lt;br /&gt;
&lt;br /&gt;
* Destination configuration (venue, broker, or internal order type like MOE)&lt;br /&gt;
* Symbol resolution against the venue and trading session&lt;br /&gt;
&lt;br /&gt;
Orders that violate compliance rules or risk limits are rejected before routing.&lt;br /&gt;
&lt;br /&gt;
== Execution Reports ==&lt;br /&gt;
&lt;br /&gt;
Clients can subscribe to receive execution reports for:&lt;br /&gt;
&lt;br /&gt;
* Specific accounts&lt;br /&gt;
* Groups of accounts&lt;br /&gt;
* Their own orders&lt;br /&gt;
&lt;br /&gt;
Subscriptions enable real-time tracking of order activity across portfolios or trading desks.&lt;br /&gt;
&lt;br /&gt;
== Order Cancellation ==&lt;br /&gt;
&lt;br /&gt;
Clients can request order cancellation. The server:&lt;br /&gt;
&lt;br /&gt;
# Validates the cancellation request against permissions and order state&lt;br /&gt;
# Forwards the cancellation to the destination&lt;br /&gt;
# Updates order state based on destination response&lt;br /&gt;
&lt;br /&gt;
=== Bulk Cancellation Utility ===&lt;br /&gt;
&lt;br /&gt;
A utility for bulk order cancellation supporting multiple use cases:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  --config config.yml              # Configuration file&lt;br /&gt;
  --region CA                      # Country code, venue, or security&lt;br /&gt;
  --connections 8                  # Parallel connections for performance&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The script supports parallel processing using multiple service connections to efficiently cancel large numbers of orders.&lt;br /&gt;
&lt;br /&gt;
== Data Store Replication ==&lt;br /&gt;
&lt;br /&gt;
The Order Execution Server supports a replicated data store, allowing order records to be written across multiple MySQL endpoints for redundancy. When multiple endpoints are configured in the &amp;lt;code&amp;gt;data_store&amp;lt;/code&amp;gt; section, writes are replicated to all configured stores while reads can be served from any available replica.&lt;br /&gt;
&lt;br /&gt;
== Management ==&lt;br /&gt;
&lt;br /&gt;
The Order Execution Server is controlled using three operational scripts: &amp;lt;code&amp;gt;start.sh&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;stop.sh&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;check.sh&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== start.sh ===&lt;br /&gt;
&lt;br /&gt;
* Exits immediately if the server is already running.&lt;br /&gt;
* Creates a &amp;lt;code&amp;gt;logs/&amp;lt;/code&amp;gt; directory if necessary.&lt;br /&gt;
* Moves any existing &amp;lt;code&amp;gt;srv_*.log&amp;lt;/code&amp;gt; files into &amp;lt;code&amp;gt;logs/&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Starts the &amp;lt;code&amp;gt;OrderExecutionServer&amp;lt;/code&amp;gt; process in the background.&lt;br /&gt;
* Reads network interfaces from &amp;lt;code&amp;gt;config.yml&amp;lt;/code&amp;gt; and waits until the server is listening on at least one configured address.&lt;br /&gt;
&lt;br /&gt;
This ensures the server is fully initialized before the script exits.&lt;br /&gt;
&lt;br /&gt;
=== stop.sh ===&lt;br /&gt;
&lt;br /&gt;
* Sends &amp;lt;code&amp;gt;SIGINT&amp;lt;/code&amp;gt; to request a graceful shutdown.&lt;br /&gt;
* Waits for termination using exponential backoff (up to 300 seconds).&lt;br /&gt;
* Sends &amp;lt;code&amp;gt;SIGKILL&amp;lt;/code&amp;gt; if the server fails to stop cleanly.&lt;br /&gt;
* Appends a forced-termination message to the most recent log file (if applicable).&lt;br /&gt;
&lt;br /&gt;
This guarantees consistent shutdown behavior across normal and exceptional conditions.&lt;br /&gt;
&lt;br /&gt;
=== check.sh ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;check.sh&amp;lt;/code&amp;gt; script verifies whether the server is currently running by inspecting the PID recorded in &amp;lt;code&amp;gt;pid.lock&amp;lt;/code&amp;gt; and testing whether the associated process exists.&lt;br /&gt;
&lt;br /&gt;
== Logging ==&lt;br /&gt;
&lt;br /&gt;
Upon startup, older log files are moved into the &amp;lt;code&amp;gt;logs/&amp;lt;/code&amp;gt; directory.&lt;/div&gt;</summary>
		<author><name>Kamal</name></author>
		
	</entry>
</feed>