Skip to content

API Reference parrot_tools.ibkr.risk

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.ibkr.risk

View source

Pre-trade risk management for IBKR agent-driven trading.

Implements configurable guardrails that intercept order operations before they reach the backend. All monetary comparisons use Decimal arithmetic.

Alias OrderRequest

Re-exported from parrot_tools.ibkr.models.OrderRequest.

Alias Position

Re-exported from parrot_tools.ibkr.models.Position.

Class RiskCheckResult

Result of a risk check.

Fields:

Field Type Default Description
passed bool Whether the check passed.
reason Optional[str] Explanation when the check fails.
check_name str Name of the check that produced this result.

Alias RiskConfig

Re-exported from parrot_tools.ibkr.models.RiskConfig.

Class RiskManager

Pre-trade risk management for IBKR orders.

Runs configurable guardrails against incoming orders and returns the first failure or an all-pass result. Tracks daily P&L for loss-limit enforcement.

Parameter Type Default Description
config RiskConfig Risk configuration with thresholds.
confirmation_callback Optional[Callable[[OrderRequest], Awaitable[bool]]] None Optional async callback invoked before order execution. Must return True to approve.

Method RiskManager.validate_order

Run all risk checks on an order.

Checks are executed in order; the first failure is returned immediately. If all pass, the optional confirmation callback is invoked last.

validate_order(order: OrderRequest, current_positions: Optional[list[Position]] = None, current_price: Optional[Decimal] = None) -> RiskCheckResult

Parameter Type Default Description
order OrderRequest The order to validate.
current_positions Optional[list[Position]] None Current portfolio positions (for position limit check).
current_price Optional[Decimal] None Current market price of the instrument.

Returns: RiskCheckResult — RiskCheckResult indicating pass or first failure.

Method RiskManager.update_pnl

Update daily P&L tracking.

update_pnl(realized: Decimal = Decimal('0'), unrealized: Decimal = Decimal('0')) -> None

Parameter Type Default Description
realized Decimal Decimal('0') Realized P&L delta to add.
unrealized Decimal Decimal('0') New unrealized P&L snapshot (replaces previous).

Method RiskManager.reset_daily_pnl

Reset daily P&L counters (call at start of trading day).

reset_daily_pnl() -> None

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally