Back to Nautilus Trader

Currency Pair

docs/concepts/instruments/currency_pair.md

1.230.09.2 KB
Original Source

Currency Pair

CurrencyPair represents a spot or cash market quoted as BASE/QUOTE. The base currency is the asset being bought or sold, and the quote currency prices one unit of the base. Nautilus uses this type for fiat FX pairs and crypto spot pairs.

Examples include EUR/USD.SIM, BTCUSDT.BINANCE, and ETH/USD.KRAKEN.

Fields

<Tabs items={["Rust", "Python"]}> <Tab value="Rust">

FieldTypeRequired/defaultNotes
instrument_idInstrumentIdRequiredStored as id in Rust.
raw_symbolSymbolRequiredNative venue symbol.
base_currencyCurrencyRequiredAsset bought or sold.
quote_currencyCurrencyRequiredCurrency used to price the base asset.
price_precisionu8RequiredDecimal places allowed for prices.
size_precisionu8RequiredDecimal places allowed for order sizes.
price_incrementPriceRequiredSmallest valid price step.
size_incrementQuantityRequiredSmallest valid size step.
ts_eventUnixNanosRequiredEvent timestamp in nanoseconds.
ts_initUnixNanosRequiredInitialization timestamp in nanoseconds.
multiplierQuantity1Contract multiplier.
lot_sizeOption<Quantity>NoneRounded lot or board size.
max_quantityOption<Quantity>NoneMaximum order quantity.
min_quantityOption<Quantity>NoneMinimum order quantity.
max_notionalOption<Money>NoneMaximum order notional value.
min_notionalOption<Money>NoneMinimum order notional value.
max_priceOption<Price>NoneMaximum valid quote or order price.
min_priceOption<Price>NoneMinimum valid quote or order price.
margin_initOption<Decimal>0Initial margin rate.
margin_maintOption<Decimal>0Maintenance margin rate.
maker_feeOption<Decimal>0Maker fee rate. Negative values rebate.
taker_feeOption<Decimal>0Taker fee rate. Negative values rebate.
tick_schemeOption<Ustr>NoneRegistered variable tick scheme name.
infoOption<Params>NoneAdapter metadata.
</Tab> <Tab value="Python">
FieldTypeRequired/defaultNotes
instrument_idInstrumentIdRequired
raw_symbolSymbolRequiredNative venue symbol.
base_currencyCurrencyRequiredAsset bought or sold.
quote_currencyCurrencyRequiredCurrency used to price the base asset.
price_precisionintRequiredDecimal places allowed for prices.
size_precisionintRequiredDecimal places allowed for order sizes.
price_incrementPriceRequiredSmallest valid price step.
size_incrementQuantityRequiredSmallest valid size step.
ts_eventintRequiredEvent timestamp in nanoseconds.
ts_initintRequiredInitialization timestamp in nanoseconds.
multiplierQuantity1Contract multiplier.
lot_sizeQuantity | NoneNoneRounded lot or board size.
max_quantityQuantity | NoneNoneMaximum order quantity.
min_quantityQuantity | NoneNoneMinimum order quantity.
max_notionalMoney | NoneNoneMaximum order notional value.
min_notionalMoney | NoneNoneMinimum order notional value.
max_pricePrice | NoneNoneMaximum valid quote or order price.
min_pricePrice | NoneNoneMinimum valid quote or order price.
margin_initDecimal | None0Initial margin rate.
margin_maintDecimal | None0Maintenance margin rate.
maker_feeDecimal | None0Maker fee rate. Negative values rebate.
taker_feeDecimal | None0Taker fee rate. Negative values rebate.
tick_schemestr | NoneNoneRegistered variable tick scheme name.
infodict | NoneNoneAdapter metadata.
</Tab> </Tabs>

Note: Python constructors use instrument_id; Rust stores the same value as id.

Behavior

  • CurrencyPair has instrument class Spot.
  • It has no expiration, strike price, option kind, or derivative underlying field.
  • It is never inverse. The settlement currency and cost currency are the quote currency.
  • Use this type for both fiat FX pairs and crypto spot pairs.

:::warning Do not model dated futures, swaps, or options as CurrencyPair only because their symbols look like pairs. Use the specific derivative type so cost currency, settlement currency, expiration, and notional calculations match the venue. :::

Example

rust
use nautilus_core::UnixNanos;
use nautilus_model::{
    identifiers::{InstrumentId, Symbol},
    instruments::{CurrencyPair, InstrumentAny},
    types::{Currency, Money, Price, Quantity},
};
use rust_decimal_macros::dec;

let btcusdt = CurrencyPair::builder()
    .instrument_id(InstrumentId::from("BTCUSDT.BINANCE"))
    .raw_symbol(Symbol::from("BTCUSDT"))
    .base_currency(Currency::from("BTC"))
    .quote_currency(Currency::from("USDT"))
    .price_precision(2)
    .size_precision(6)
    .price_increment(Price::from("0.01"))
    .size_increment(Quantity::from("0.000001"))
    .min_quantity(Quantity::from("0.000001"))
    .min_notional(Money::from("10.00 USDT"))
    .max_price(Price::from("1000000.00"))
    .min_price(Price::from("0.01"))
    .margin_init(dec!(0.001))
    .margin_maint(dec!(0.001))
    .maker_fee(dec!(0.001))
    .taker_fee(dec!(0.001))
    .ts_event(UnixNanos::default())
    .ts_init(UnixNanos::default())
    .build()
    .unwrap();

let instrument = InstrumentAny::CurrencyPair(btcusdt);
python
from decimal import Decimal

from nautilus_trader.model import Currency
from nautilus_trader.model import CurrencyPair
from nautilus_trader.model import InstrumentId
from nautilus_trader.model import Money
from nautilus_trader.model import Price
from nautilus_trader.model import Quantity
from nautilus_trader.model import Symbol

BTC = Currency.from_str("BTC")
USDT = Currency.from_str("USDT")

btcusdt = CurrencyPair(
    instrument_id=InstrumentId.from_str("BTCUSDT.BINANCE"),
    raw_symbol=Symbol("BTCUSDT"),
    base_currency=BTC,
    quote_currency=USDT,
    price_precision=2,
    size_precision=6,
    price_increment=Price.from_str("0.01"),
    size_increment=Quantity.from_str("0.000001"),
    ts_event=0,
    ts_init=0,
    min_quantity=Quantity.from_str("0.000001"),
    min_notional=Money(10.00, USDT),
    max_price=Price.from_str("1000000.00"),
    min_price=Price.from_str("0.01"),
    margin_init=Decimal("0.001"),
    margin_maint=Decimal("0.001"),
    maker_fee=Decimal("0.001"),
    taker_fee=Decimal("0.001"),
)

Adapters

Representative adapters that create or consume CurrencyPair instruments include:

  • Data explains market data that references instruments.
  • Execution explains order checks that use instrument precision.
  • Value types explains Price, Quantity, and Money.