Core Concepts
Deterministic Routing

Deterministic Routing

Same input always produces the same output.

Overview

SnipeRoute uses deterministic routing: the same Trade Intent input always produces the same routing behavior and output. There is no randomness, no optimization, and no adaptive logic.

Deterministic routing ensures predictable, reproducible, and auditable execution behavior.

What Deterministic Means

Same Trade Intent → Same Routing Logic → Same Broker API Call

If you submit the same Trade Intent twice (with different intent_id), SnipeRoute will:

  1. Route to the same broker
  2. Send the same order parameters
  3. Use the same execution logic

The only variable is market conditions at the broker level (fills, prices, etc.) — not SnipeRoute's routing behavior.

Example: Deterministic Routing

Input (Trade Intent)

{
  "intent_id": "trade_001",
  "symbol": "AAPL",
  "side": "buy",
  "quantity": 10,
  "order_type": "limit",
  "limit_price": 175.00,
  "time_in_force": "gtc",
  "broker_id": "my_alpaca"
}

Output (Broker API Call)

{
  "symbol": "AAPL",
  "qty": 10,
  "side": "buy",
  "type": "limit",
  "limit_price": "175.00",
  "time_in_force": "gtc"
}

Deterministic Guarantee

If you submit this Trade Intent again with intent_id: "trade_002", the routing behavior will be identical:

  • Same broker adapter (my_alpaca)
  • Same API call format
  • Same validation logic
  • Same error handling
⚠️

The market outcome (fills, execution price) may differ based on market conditions, but SnipeRoute's routing behavior is always the same.

What Is NOT Deterministic

SnipeRoute does not control these variables (they depend on the broker and market):

  • Fill prices: Determined by market conditions
  • Fill timing: Determined by broker execution speed
  • Partial fills: Determined by market liquidity
  • Broker errors: Determined by broker API availability

Comparison: Deterministic vs Non-Deterministic

Deterministic System (SnipeRoute)

# Trade Intent A
intent_a = TradeIntentRequest(
    intent_id="trade_001",
    symbol="AAPL",
    side=OrderSide.BUY,
    quantity=Decimal("10"),
    order_type=OrderType.LIMIT,
    limit_price=Decimal("175.00"),
    broker_id="my_alpaca"
)
 
# Trade Intent B (same parameters, different ID)
intent_b = TradeIntentRequest(
    intent_id="trade_002",
    symbol="AAPL",
    side=OrderSide.BUY,
    quantity=Decimal("10"),
    order_type=OrderType.LIMIT,
    limit_price=Decimal("175.00"),
    broker_id="my_alpaca"
)
 
# Both route identically to Alpaca with same API call

Non-Deterministic System (NOT SnipeRoute)

Some systems might:

  • Choose different brokers based on current liquidity
  • Adjust limit price based on order book
  • Split orders differently based on time of day
  • Apply machine learning models to optimize execution

SnipeRoute does none of these. It routes exactly as specified.

Why Deterministic?

1. Auditability

You can trace every Trade Intent to a specific broker API call. No hidden optimizations.

2. Compliance

Regulators can verify that SnipeRoute does not make discretionary decisions.

3. Testing

You can test your upstream platform's logic without worrying about SnipeRoute introducing variability.

4. Debugging

If something goes wrong, you know exactly what SnipeRoute did (or should have done).

State Independence

SnipeRoute does not maintain state between Trade Intents:

  • No learning from past executions
  • No adaptive behavior based on market conditions
  • No optimization based on historical fills

Each Trade Intent is processed independently.

# Intent 1: Buy AAPL
intent_1 = TradeIntentRequest(
    intent_id="trade_001",
    symbol="AAPL",
    side=OrderSide.BUY,
    quantity=Decimal("10"),
    order_type=OrderType.MARKET,
    broker_id="my_alpaca"
)
 
# Intent 2: Buy AAPL again
intent_2 = TradeIntentRequest(
    intent_id="trade_002",
    symbol="AAPL",
    side=OrderSide.BUY,
    quantity=Decimal("10"),
    order_type=OrderType.MARKET,
    broker_id="my_alpaca"
)
 
# Intent 2 does NOT depend on Intent 1
# Each is routed independently with identical logic

Deterministic Errors

Even error handling is deterministic:

{
  "intent_id": "trade_001",
  "symbol": "AAPL",
  "side": "buy",
  "quantity": 10,
  "order_type": "limit"
  // Missing limit_price
}

Response (always the same):

{
  "detail": "limit_price is required for limit orders"
}

If you submit this Trade Intent again, you'll get the exact same error with the exact same message.

Testing Determinism

You can verify deterministic routing by submitting the same Trade Intent multiple times:

import asyncio
from sniperoute import SnipeRouteClient
from sniperoute.models import TradeIntentRequest, OrderSide, OrderType
from decimal import Decimal
 
async def test_determinism():
    client = SnipeRouteClient()
 
    # Create same Trade Intent with different IDs
    for i in range(3):
        intent = TradeIntentRequest(
            intent_id=f"test_{i}",
            symbol="AAPL",
            side=OrderSide.BUY,
            quantity=Decimal("10"),
            order_type=OrderType.LIMIT,
            limit_price=Decimal("175.00"),
            broker_id="my_alpaca"
        )
 
        response = await client.create_intent(intent)
        print(f"Intent {i}: {response.status}")
 
        # All three will route identically
        # Only intent_id and timestamps will differ
 
asyncio.run(test_determinism())

Next Steps