Skip to content

Pricing Engine: Implement volume-weighted pricing strategy #31

@0xDevNinja

Description

@0xDevNinja

Objective

Develop a volume-weighted pricing engine that computes a clearing price based on the weighted average of individual order prices. The engine should consider the volume of each order when calculating a uniform clearing price, providing a fairer distribution across large and small orders.

Tasks

  • Create a new module src/pricing/volume_weighted.rs that defines VolumeWeightedPricingEngine implementing the PricingEngine trait.
  • In compute_clearing_price(&[Order]) -> Option<Decimal>, calculate the weighted average of each order's implied price (buy_amount / sell_amount) using sell_amount as the weight.
  • Return None if there are fewer than two orders or if total sell volume is zero.
  • Add unit tests that verify:
    • None is returned for zero or one order.
    • The weighted average price is correct for multiple orders with varying sizes.
  • Update src/pricing/mod.rs to expose the volume_weighted module.
  • Update documentation (README or relevant docs) to describe the new pricing strategy and how to select it via CLI or config.

Acceptance Criteria

  • New module compiles without errors and is covered by tests.
  • Cargo test passes for all existing and new tests.
  • Documentation reflects the new pricing engine and usage.

Closes #? (to be filled when opening PR).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions