-
Notifications
You must be signed in to change notification settings - Fork 1
Domain Types
Eugene Palchukovsky edited this page Mar 12, 2026
·
1 revision
Pit uses domain-specific value types so that quantities, prices, fees, P&L, cash flow, and identifiers are not mixed accidentally.
| Concept | Meaning | Rust | Python |
|---|---|---|---|
| Asset | Asset or currency identifier such as AAPL or USD
|
openpit::param::Asset |
openpit.param.Asset |
| Side | Trade direction: buy or sell | openpit::param::Side |
openpit.param.Side |
| PositionSide | Hedge-mode leg: long or short | openpit::param::PositionSide |
openpit.param.PositionSide |
| Quantity | Requested or filled size in instrument units | openpit::param::Quantity |
openpit.param.Quantity |
| Price | Signed per-unit price | openpit::param::Price |
openpit.param.Price |
| PnL | Realized profit or loss in the settlement asset | openpit::param::Pnl |
openpit.param.Pnl |
| Fee | Fee paid or rebate received in the settlement asset | openpit::param::Fee |
openpit.param.Fee |
| Volume | Absolute monetary size, usually order notional | openpit::param::Volume |
openpit.param.Volume |
| CashFlow | Signed cash movement | openpit::param::CashFlow |
openpit.param.CashFlow |
| PositionSize | Signed exposure size | openpit::param::PositionSize |
openpit.param.PositionSize |
| Leverage | Per-order leverage multiplier | openpit::param::Leverage |
openpit.param.Leverage and openpit.Leverage
|
| FillType | Execution-event classification such as trade or liquidation | openpit::param::FillType |
Not exposed |
| PositionEffect | Position action reported by the venue: open or close | openpit::param::PositionEffect |
Not exposed |
| Type | Positive | Negative |
|---|---|---|
Pnl |
Profit | Loss |
Fee |
Fee paid | Rebate received |
CashFlow |
Inflow | Outflow |
PositionSize |
Long | Short |
Quantity and Volume can never be negative.
Orders use a single trade_amount field with context defined by its type
where the target technology supports that shape. Otherwise, integrations may
expose two separate fields/arguments (quantity and volume) with equivalent
semantics.
-
trade_amountasQuantity: run the order by instrument amount -
trade_amountasVolume: run the order by settlement notional -
Pricepresent: treat it as the worst execution price allowed -
Priceabsent: treat the order as market-price execution
This means:
- If a
Priceis provided, the engine must evaluate risk using that price as the worst possible price for the order. - It does not matter whether the order is expressed as quantity-based or
volume-based
trade_amount— wherever a price is required for risk evaluation, the provided price must be treated as the worst-case price. - If
Priceis not provided, the engine must obtain the current market price to evaluate the risk. - If a market price cannot be obtained, the risk check must fail with an error indicating insufficient data to evaluate risk.
| Property | Value |
|---|---|
| Minimum | 1x |
| Maximum | 3000x |
| Step | 0.1x |
Rust behavior:
- Checked arithmetic returns
Result<_, openpit::param::Error> - Rounded constructors accept an explicit
RoundingStrategy -
Price::calculate_volume(quantity)andQuantity::calculate_volume(price)compute absolute notional as|price| × quantity
Python behavior:
- The public wrappers validate inputs and expose canonical string values through
.value - Invalid inputs raise
ValueError -
ParamKindandRoundingStrategyare exposed as stable string constants
Rust exposes:
openpit::param::ParamKindopenpit::param::RoundingStrategyopenpit::param::Error
Python exposes:
openpit.param.ParamKindopenpit.param.RoundingStrategy
The Python wrappers do not expose the Rust arithmetic error enum directly.
Rust
use openpit::param::{Asset, Pnl, Price, Quantity};
let asset = Asset::new("AAPL").expect("asset code must be valid");
let quantity = Quantity::from_str("10.5").expect("quantity must be valid");
let price = Price::from_str("185").expect("price must be valid");
let pnl = Pnl::from_str("-12.5").expect("pnl must be valid");
assert_eq!(asset.as_ref(), "AAPL");
assert_eq!(quantity.to_string(), "10.5");
assert_eq!(price.to_string(), "185");
assert_eq!(pnl.to_string(), "-12.5");Python
import openpit
asset = openpit.param.Asset("AAPL")
quantity = openpit.param.Quantity("10.5")
price = openpit.param.Price(185)
pnl = openpit.param.Pnl(-12.5)
assert asset.value == "AAPL"
assert quantity.value == "10.5"
assert price.value == "185"
assert pnl.value == "-12.5"Rust
use openpit::param::{PositionSide, Side};
assert_eq!(Side::Buy.opposite(), Side::Sell);
assert_eq!(Side::Sell.sign(), -1);
assert_eq!(PositionSide::Long.opposite(), PositionSide::Short);Python
import openpit
side = openpit.param.Side.BUY
position_side = openpit.param.PositionSide.LONG
assert side.opposite().value == "sell"
assert side.sign() == 1
assert position_side.opposite().value == "short"Rust
use openpit::param::Leverage;
let from_multiplier = Leverage::from_u16(100).expect("valid leverage");
let from_float = Leverage::from_f64(100.5).expect("valid leverage");
assert_eq!(from_multiplier.value(), 100.0);
assert_eq!(from_float.value(), 100.5);Python
import openpit
from_multiplier = openpit.param.Leverage.from_u16(100)
from_float = openpit.param.Leverage.from_f64(100.5)
assert from_multiplier.value == 100.0
assert from_float.value == 100.5- Policies: Value types used by built-in and custom policies
- Architecture: Public integration model