Skip to main content

Module instrument_cache

Module instrument_cache 

Source
Expand description

Thread-safe instrument cache for dYdX adapter.

This module provides a centralized cache for instrument data that is shared between HTTP client, WebSocket client, and execution client via Arc.

§Design

dYdX uses different identifiers in different contexts:

  • InstrumentId (“BTC-USD-PERP.DYDX”): Nautilus internal identifier (primary key)
  • Market ticker (“BTC-USD”): Used in public WebSocket channels
  • clob_pair_id (0, 1, 2…): Used in blockchain transactions and order messages

This cache provides O(1) lookups by any of these identifiers through internal indices. Using InstrumentId as the primary key provides better type safety and eliminates redundant conversions.

§Thread Safety

All operations use DashMap for lock-free concurrent access. The cache can be safely shared across multiple async tasks via Arc<InstrumentCache>.

Structs§

InstrumentCache
Thread-safe instrument cache with multiple lookup indices.