SDK
Python SDK
Models

Pydantic Models

Overview

The SnipeRoute SDK uses Pydantic v2 models for type-safe request/response handling. All models provide:

  • Automatic validation
  • Type coercion
  • JSON serialization/deserialization
  • IDE auto-completion

Trade Intent Models

TradeIntentRequest

Model for creating a Trade Intent.

from sniperoute.models import TradeIntentRequest, OrderSide, OrderType, TimeInForce
from decimal import Decimal
 
intent = TradeIntentRequest(
    intent_id="trade_001",
    symbol="AAPL",
    side=OrderSide.BUY,
    quantity=Decimal("10"),
    order_type=OrderType.MARKET,
    broker_id="my_broker"
)

Fields:

FieldTypeRequiredDescription
intent_idstrYesUnique identifier (idempotency key)
symbolstrYesTrading symbol (e.g., "AAPL")
sideOrderSideYesOrderSide.BUY or OrderSide.SELL
quantityDecimalYesNumber of shares/units
order_typeOrderTypeYesSee OrderType
broker_idstrYesConnected broker account ID
limit_priceDecimal | NoneConditionalRequired for limit orders
stop_priceDecimal | NoneConditionalRequired for stop orders
time_in_forceTimeInForce | NoneNoDefault: TimeInForce.DAY
extended_hoursboolNoDefault: False

TradeIntentResponse

Model returned when creating or querying a Trade Intent.

response = await client.create_intent(intent)
 
print(f"ID: {response.id}")
print(f"Intent ID: {response.intent_id}")
print(f"Status: {response.status}")
print(f"Symbol: {response.symbol}")

Fields:

FieldTypeDescription
idstr (UUID)Internal Trade Intent UUID
intent_idstrYour external identifier
symbolstrTrading symbol
sideOrderSideOrder side
quantityDecimalNumber of shares/units
order_typeOrderTypeOrder type
limit_priceDecimal | NoneLimit price (if applicable)
stop_priceDecimal | NoneStop price (if applicable)
time_in_forceTimeInForceTime in force
extended_hoursboolExtended hours enabled
statusIntentStatusCurrent status
broker_idstrBroker account ID
orderslist[Order]List of broker orders
errorErrorDetail | NoneError details (if failed)
created_atdatetimeCreation timestamp
updated_atdatetimeLast update timestamp

Order Models

Order

Model representing a broker order.

for order in response.orders:
    print(f"Broker Order ID: {order.broker_order_id}")
    print(f"Status: {order.status}")

Fields:

FieldTypeDescription
idstr (UUID)Internal order UUID
broker_order_idstrBroker's order ID
statusOrderStatusOrder status
fillslist[Fill]List of fills
created_atdatetimeCreation timestamp
updated_atdatetimeLast update timestamp

Fill

Model representing an order fill.

for fill in order.fills:
    print(f"Filled: {fill.quantity} @ ${fill.price}")
    print(f"Time: {fill.filled_at}")

Fields:

FieldTypeDescription
quantityDecimalShares filled
priceDecimalFill price
filled_atdatetimeFill timestamp

Enums

OrderSide

from sniperoute.models import OrderSide
 
# Buy order
side = OrderSide.BUY
 
# Sell order
side = OrderSide.SELL

Values:

  • OrderSide.BUY - Buy order
  • OrderSide.SELL - Sell order

OrderType

from sniperoute.models import OrderType
 
# Market order
order_type = OrderType.MARKET
 
# Limit order
order_type = OrderType.LIMIT
 
# Stop order
order_type = OrderType.STOP
 
# Stop-limit order
order_type = OrderType.STOP_LIMIT

Values:

  • OrderType.MARKET - Market order
  • OrderType.LIMIT - Limit order
  • OrderType.STOP - Stop order
  • OrderType.STOP_LIMIT - Stop-limit order

TimeInForce

from sniperoute.models import TimeInForce
 
# Day order (default)
tif = TimeInForce.DAY
 
# Good-till-canceled
tif = TimeInForce.GTC
 
# Immediate-or-cancel
tif = TimeInForce.IOC
 
# Fill-or-kill
tif = TimeInForce.FOK

Values:

  • TimeInForce.DAY - Valid until end of trading day
  • TimeInForce.GTC - Good-till-canceled
  • TimeInForce.IOC - Immediate-or-cancel
  • TimeInForce.FOK - Fill-or-kill

IntentStatus

from sniperoute.models import IntentStatus
 
if response.status == IntentStatus.FILLED:
    print("Order filled!")

Values:

  • IntentStatus.PENDING - Order pending
  • IntentStatus.FILLED - Order fully filled
  • IntentStatus.PARTIALLY_FILLED - Order partially filled
  • IntentStatus.CANCELED - Order canceled
  • IntentStatus.REJECTED - Broker rejected
  • IntentStatus.FAILED - Routing/validation failed

OrderStatus

from sniperoute.models import OrderStatus
 
for order in response.orders:
    if order.status == OrderStatus.FILLED:
        print("Order filled!")

Values:

  • OrderStatus.PENDING - Order pending
  • OrderStatus.FILLED - Order fully filled
  • OrderStatus.PARTIALLY_FILLED - Order partially filled
  • OrderStatus.CANCELED - Order canceled
  • OrderStatus.REJECTED - Broker rejected

Error Models

ErrorDetail

Model for error information.

if response.error:
    print(f"Error code: {response.error.code}")
    print(f"Message: {response.error.message}")

Fields:

FieldTypeDescription
codestrError code
messagestrError message

Validation

Automatic Validation

Pydantic automatically validates all fields:

from sniperoute.models import TradeIntentRequest, OrderSide, OrderType
from decimal import Decimal
 
# This will raise ValidationError
intent = TradeIntentRequest(
    intent_id="trade_001",
    symbol="AAPL",
    side="invalid_side",  # Invalid enum value
    quantity=Decimal("10"),
    order_type=OrderType.MARKET,
    broker_id="my_broker"
)

Manual Validation

from pydantic import ValidationError
 
try:
    intent = TradeIntentRequest(...)
except ValidationError as e:
    print(e.errors())

JSON Serialization

To JSON

# Convert to dict
intent_dict = intent.model_dump()
 
# Convert to JSON string
import json
intent_json = json.dumps(intent.model_dump(), default=str)

From JSON

import json
from sniperoute.models import TradeIntentResponse
 
# Parse JSON
data = json.loads(response_json)
 
# Create model
response = TradeIntentResponse(**data)

Type Hints

All models have full type hints for IDE support:

from sniperoute.models import TradeIntentRequest
from decimal import Decimal
 
def create_market_order(
    symbol: str,
    quantity: Decimal,
    broker_id: str
) -> TradeIntentRequest:
    return TradeIntentRequest(
        intent_id=f"order_{symbol}",
        symbol=symbol,
        side=OrderSide.BUY,
        quantity=quantity,
        order_type=OrderType.MARKET,
        broker_id=broker_id
    )
 
# IDE will auto-complete fields
intent = create_market_order("AAPL", Decimal("10"), "my_broker")

Next Steps