Skip to main content

Overview

The MarketMakerStrategy implements an automated market-making strategy with:
  • Multi-level quote generation
  • Inventory-based price skewing
  • Position limit management
  • Quote lifecycle tracking
  • Configurable spread and refresh intervals
This strategy continuously provides liquidity by placing limit orders on both sides of the market.

MarketMakerConfig

Configuration Parameters

base_spread_ticks

The base spread between bid and ask quotes, measured in ticks. Default: 2 Example:

inventory_skew_factor

Controls how much to skew quotes based on current inventory position. Range: 0.0 to 1.0. Default: 0.5 Behavior:
  • Positive inventory (long) → Lower bids, higher asks (encourage selling)
  • Negative inventory (short) → Higher bids, lower asks (encourage buying)
  • Factor of 0.0 → No skew
  • Factor of 1.0 → Maximum skew
Formula:

max_inventory

Maximum absolute position size allowed. Strategy stops quoting on a side when this limit is reached. Default: 50 Example:

order_size

Quantity of contracts for each quote order. Default: 5

num_levels

Number of price levels to quote on each side of the market. Default: 3 Example:

min_edge_ticks

Minimum edge required before placing quotes (currently not actively used in implementation). Default: 1

cancel_distance_ticks

Distance from the best bid/offer at which to cancel stale orders. Default: 10 file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:229-252

tick_size

Raw price units per tick. Default: 25

refresh_interval_ns

How often to refresh quotes, in nanoseconds. Default: 100_000_000 (100ms)

Default Configuration

QuoteManager

Manages the lifecycle of active quote orders.

Methods

new

Creates a new quote manager.

next_order_id

Generates the next unique order ID.

on_order_submit

Records a submitted order and marks it as pending acknowledgment.

on_order_ack

Removes the order from pending acknowledgments.

on_order_reject

Removes a rejected order from tracking.

on_fill

Updates remaining quantity after a fill. Removes the order if fully filled. file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:108-122

on_cancel

Removes a cancelled order from tracking.

Quantity Tracking

Returns total outstanding quantity on bids or asks.

Order Lists

Returns all active order IDs for bids or asks.

MarketMakerStrategy

Constructor

new

Creates a new market-making strategy. Parameters:
  • name: Strategy identifier
  • instrument_id: ID of the instrument to trade
  • config: Market maker configuration
  • tick_value: Value of one tick for P&L calculation
Example:

Core Methods

calculate_quotes

Calculates bid and ask prices with inventory skew applied. file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:197-222 Algorithm:
  1. Calculate inventory ratio: position / max_inventory
  2. Calculate skew in ticks: inv_ratio * skew_factor * base_spread
  3. Apply skew to bid/ask prices around mid
Example:

should_refresh_quotes

Checks if enough time has passed since the last quote update.

generate_quotes

Generates new quote orders across multiple levels. file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:255-322 Process:
  1. Check if mid price is available
  2. Check position limits (stop quoting if at max)
  3. Calculate skewed bid/ask prices
  4. Generate orders for each level
  5. Record orders in quote manager
  6. Update last quote time

generate_cancels

Identifies orders that are too far from the best bid/offer and should be cancelled.

Accessor Methods

quotes

Returns a reference to the quote manager.

config

Returns the strategy configuration.

fair_value

Returns the current fair value estimate (mid price).

Strategy Implementation

The MarketMakerStrategy implements the Strategy trait:

on_market_data

file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:348-366 Called when market data updates:
  1. Updates base strategy (P&L, position)
  2. Checks if strategy is ready
  3. Checks if quotes need refreshing
  4. Generates new quotes if refresh interval elapsed

on_fill

file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:368-371 Handles fill events:
  1. Updates position and P&L via base strategy
  2. Updates remaining quantity in quote manager

on_order_ack, on_order_reject, on_order_cancel

file:///home/daytona/workspace/source/crates/nano-strategy/src/market_maker.rs:373-384 Forward order lifecycle events to the quote manager.

Complete Example

Inventory Management

The strategy implements inventory risk management through:
  1. Position Limits: Stops quoting when max_inventory is reached
  2. Price Skewing: Adjusts quotes to encourage inventory reduction
  3. Symmetric Limits: Applies limits to both long and short positions
Example Scenario:

Performance Considerations

  • Quote refresh is throttled by refresh_interval_ns
  • Old quotes beyond cancel_distance_ticks are cancelled
  • All order tracking uses efficient HashMap lookups
  • Position checks prevent over-trading

See Also