docs/concepts/instruments/cfd.md
Cfd represents a contract for difference that tracks an underlying asset without
transferring ownership of the underlying. The venue defines the quote currency,
precision, increments, limits, margins, and fees.
Examples include CFD contracts on FX, equities, indexes, and commodities.
| Field | Rust type | Python type | Required/default | Notes |
|---|---|---|---|---|
instrument_id | InstrumentId | InstrumentId | Required | Stored as id in Rust. |
raw_symbol | Symbol | Symbol | Required | Native venue symbol. |
asset_class | AssetClass | AssetClass | Required | Asset class of the underlying. |
base_currency | Option<Currency> | Currency | None | None | Base currency when the CFD tracks one. |
quote_currency | Currency | Currency | Required | Currency used to quote and value prices. |
price_precision | u8 | int | Required | Decimal places allowed for prices. |
size_precision | u8 | int | Required | Decimal places allowed for order sizes. |
price_increment | Price | Price | Required | Smallest valid price step. |
size_increment | Quantity | Quantity | Required | Smallest valid size step. |
lot_size | Option<Quantity> | Quantity | None | None | Rounded lot or board size. |
max_quantity | Option<Quantity> | Quantity | None | None | Maximum order quantity. |
min_quantity | Option<Quantity> | Quantity | None | None | Minimum order quantity. |
max_notional | Option<Money> | Money | None | None | Maximum order notional value. |
min_notional | Option<Money> | Money | None | None | Minimum order notional value. |
max_price | Option<Price> | Price | None | None | Maximum valid quote or order price. |
min_price | Option<Price> | Price | None | None | Minimum valid quote or order price. |
margin_init | Option<Decimal> | Decimal | None | 0 | Initial margin rate. |
margin_maint | Option<Decimal> | Decimal | None | 0 | Maintenance margin rate. |
maker_fee | Option<Decimal> | Decimal | None | 0 | Maker fee rate. Negative values rebate. |
taker_fee | Option<Decimal> | Decimal | None | 0 | Taker fee rate. Negative values rebate. |
tick_scheme_name | N/A | str | None | None | Registered variable tick scheme name. |
info | Option<Params> | dict | None | None | Adapter metadata. |
ts_event | UnixNanos | int | Required | Event timestamp in nanoseconds. |
ts_init | UnixNanos | int | Required | Initialization timestamp in nanoseconds. |
Note: Python constructors use instrument_id; Rust stores the same value as id.
Cfd has instrument class Cfd.use nautilus_core::UnixNanos;
use nautilus_model::{
enums::AssetClass,
identifiers::{InstrumentId, Symbol},
instruments::Cfd,
types::{Currency, Price, Quantity},
};
use rust_decimal_macros::dec;
let audusd = Cfd::new(
InstrumentId::from("AUDUSD.OANDA"),
Symbol::from("AUD/USD"),
AssetClass::FX,
Some(Currency::from("AUD")),
Currency::from("USD"),
5,
0,
Price::from("0.00001"),
Quantity::from("1"),
Some(Quantity::from("1000")),
None,
None,
None,
None,
None,
None,
Some(dec!(0.03)),
Some(dec!(0.03)),
Some(dec!(0.00002)),
Some(dec!(0.00002)),
None,
UnixNanos::default(),
UnixNanos::default(),
);
from decimal import Decimal
from nautilus_trader.model.currencies import AUD
from nautilus_trader.model.currencies import USD
from nautilus_trader.model.enums import AssetClass
from nautilus_trader.model.identifiers import InstrumentId
from nautilus_trader.model.identifiers import Symbol
from nautilus_trader.model.instruments import Cfd
from nautilus_trader.model.objects import Price
from nautilus_trader.model.objects import Quantity
audusd = Cfd(
instrument_id=InstrumentId.from_str("AUDUSD.OANDA"),
raw_symbol=Symbol("AUD/USD"),
asset_class=AssetClass.FX,
base_currency=AUD,
quote_currency=USD,
price_precision=5,
price_increment=Price.from_str("0.00001"),
size_precision=0,
size_increment=Quantity.from_int(1),
lot_size=Quantity.from_int(1000),
margin_init=Decimal("0.03"),
margin_maint=Decimal("0.03"),
maker_fee=Decimal("0.00002"),
taker_fee=Decimal("0.00002"),
ts_event=0,
ts_init=0,
)
Representative adapters that create or consume Cfd instruments include: