Implementation:Nautechsystems Nautilus trader TestInstrumentProvider Factory
| Field | Value |
|---|---|
| Sources | GitHub: test_kit/providers.py, NautilusTrader Documentation |
| Domains | Financial Instruments, Test Fixtures, Backtesting Setup |
| Last Updated | 2026-02-10 12:00 GMT |
Overview
Concrete factory for pre-configured financial instrument objects provided by NautilusTrader's test kit.
Description
The TestInstrumentProvider class is a static factory that produces fully specified instrument objects for use in backtesting, unit testing, and development. Each static method returns a single instrument with all metadata fields (price precision, size precision, tick increments, lot sizes, fees, margin rates, and notional limits) pre-populated with values that match real exchange specifications. The class covers a broad range of instrument types including cryptocurrency spot pairs, perpetual swaps, futures contracts, equities, FX currency pairs, CFDs, options, betting instruments, and synthetic instruments. This eliminates the need for developers to manually construct instrument objects or connect to live exchange APIs during testing.
Usage
Import and call TestInstrumentProvider static methods whenever you need realistic instrument definitions for:
- Unit and integration tests that require instrument metadata.
- Backtesting configuration where instrument definitions are needed before loading market data.
- Strategy prototyping where correct precision and fee parameters matter for P&L accuracy.
- Example notebooks and documentation code samples.
Code Reference
Source Location
| Item | Value |
|---|---|
| File | nautilus_trader/test_kit/providers.py
|
| Lines | L86-917 |
| Class | TestInstrumentProvider
|
Key Method Signatures
class TestInstrumentProvider:
@staticmethod
def btcusdt_binance() -> CurrencyPair: ...
@staticmethod
def ethusdt_binance() -> CurrencyPair: ...
@staticmethod
def btcusdt_perp_binance() -> CryptoPerpetual: ...
@staticmethod
def ethusdt_perp_binance() -> CryptoPerpetual: ...
@staticmethod
def default_fx_ccy(symbol: str, venue: Venue | None = None) -> CurrencyPair: ...
@staticmethod
def equity(symbol: str = "AAPL", venue: str = "XNAS") -> Equity: ...
@staticmethod
def es_future(expiry_year: int, expiry_month: int, venue: Venue | None = None) -> FuturesContract: ...
@staticmethod
def aapl_option() -> OptionContract: ...
@staticmethod
def synthetic_instrument() -> SyntheticInstrument: ...
@staticmethod
def betting_instrument(venue: str | None = None) -> BettingInstrument: ...
Import
from nautilus_trader.test_kit.providers import TestInstrumentProvider
I/O Contract
Inputs
| Method | Parameter | Type | Description |
|---|---|---|---|
btcusdt_binance() |
(none) | -- | Returns pre-configured BTC/USDT Binance spot pair |
ethusdt_binance() |
(none) | -- | Returns pre-configured ETH/USDT Binance spot pair |
default_fx_ccy() |
symbol |
str |
Currency pair symbol string (6-7 chars, e.g. "EURUSD") |
default_fx_ccy() |
venue |
Venue ¦ None |
Optional venue; defaults to Venue("SIM") |
equity() |
symbol |
str |
Ticker symbol; defaults to "AAPL" |
equity() |
venue |
str |
Venue name; defaults to "XNAS" |
es_future() |
expiry_year |
int |
Contract expiry year |
es_future() |
expiry_month |
int |
Contract expiry month |
Outputs
| Method | Return Type | Description |
|---|---|---|
btcusdt_binance() |
CurrencyPair |
BTC/USDT with price_precision=2, size_precision=6, maker/taker fee 0.1% |
ethusdt_binance() |
CurrencyPair |
ETH/USDT with price_precision=2, size_precision=5, maker/taker fee 0.01% |
btcusdt_perp_binance() |
CryptoPerpetual |
BTCUSDT-PERP with margin_init=5%, margin_maint=2.5% |
default_fx_ccy() |
CurrencyPair |
FX pair with JPY=3dp or other=5dp, lot_size=1000, margin=3% |
equity() |
Equity |
Equity with price_precision=2, lot_size=100, ISIN="US0378331005" |
es_future() |
FuturesContract |
E-mini S&P 500 future with price_increment=0.25 |
aapl_option() |
OptionContract |
AAPL CALL option with strike=149.00, multiplier=100 |
Usage Examples
Creating a Crypto Spot Instrument
from nautilus_trader.test_kit.providers import TestInstrumentProvider
# Get a fully specified BTC/USDT instrument for Binance
instrument = TestInstrumentProvider.btcusdt_binance()
print(instrument.id) # BTCUSDT.BINANCE
print(instrument.price_precision) # 2
print(instrument.size_precision) # 6
print(instrument.maker_fee) # 0.001
print(instrument.min_notional) # 10.00000000 USDT
Creating an FX Currency Pair
from nautilus_trader.test_kit.providers import TestInstrumentProvider
# Generate a default EUR/USD instrument for the SIM venue
eurusd = TestInstrumentProvider.default_fx_ccy("EURUSD")
print(eurusd.id) # EURUSD.SIM
print(eurusd.price_precision) # 5
print(eurusd.lot_size) # 1000
# Generate a JPY pair (uses 3-decimal pricing)
usdjpy = TestInstrumentProvider.default_fx_ccy("USDJPY")
print(usdjpy.price_precision) # 3
Creating an Equity Instrument
from nautilus_trader.test_kit.providers import TestInstrumentProvider
# Default AAPL equity
aapl = TestInstrumentProvider.equity()
print(aapl.id) # AAPL.XNAS
print(aapl.lot_size) # 100
# Custom equity
msft = TestInstrumentProvider.equity(symbol="MSFT", venue="XNAS")
print(msft.id) # MSFT.XNAS
Using Instruments in Backtest Configuration
from nautilus_trader.test_kit.providers import TestInstrumentProvider
from nautilus_trader.backtest.engine import BacktestEngine
engine = BacktestEngine()
# Add instruments to the engine
btcusdt = TestInstrumentProvider.btcusdt_binance()
engine.add_instrument(btcusdt)
ethusdt = TestInstrumentProvider.ethusdt_binance()
engine.add_instrument(ethusdt)