Skip to content

Otto Margin Rules Endpoints

Location: backend/service_multi-repricer/app/api/v1/endpoints/otto_margin_rules.py

Purpose

Provide CRUD and lookup endpoints for margin rules used by the Otto repricer. Margin rules define min/max margin percentages and minimum-profit thresholds keyed by a buy_price threshold.

Primary fields (per rule)

  • id (int)
  • buy_price (Decimal) — threshold buy price in EUR
  • min_margin (Decimal) — minimum margin percentage
  • min_min_profit (Decimal) — minimum profit in EUR for the min margin
  • max_margin (Decimal) — maximum margin percentage
  • max_min_profit (Decimal) — minimum profit in EUR for the max margin
  • created_at, updated_at (timestamps)

Endpoints

  • GET / — List all margin rules
  • Returns rules ordered by buy_price ascending.

  • GET /find_by_buy_price/{buy_price} — Find the applicable margin rule for a given buy price

  • Path: buy_price (float)
  • Selection logic: returns the cheapest rule whose buy_price >= buy_price. If none match (price exceeds all thresholds), falls back to the highest buy_price rule.
  • Response: structured JSON with buy_price_threshold, min_margin_settings, and max_margin_settings.

  • GET /{rule_id} — Get a single rule by id

  • POST / — Create a margin rule

  • Request: MarginRuleCreate JSON (fields in Primary fields list)
  • Response: { "status": "success", "rule_id": <id> }

  • PUT /{rule_id} — Update a margin rule

  • Request: MarginRuleUpdate (partial updates allowed)
  • Response: { "status": "success", "rule_id": <id> }

  • DELETE /{rule_id} — Delete a margin rule

  • Response: { "status": "success", "rule_id": <id> }

Examples

  • Find rule by buy price (curl):
curl "http://localhost:8000/api/v1/multi/otto-margin-rules/find_by_buy_price/12.50"
  • Create a rule (curl):
curl -X POST "http://localhost:8000/api/v1/multi/otto-margin-rules/" \
  -H "Content-Type: application/json" \
  -d '{"buy_price": 10.00, "min_margin": 10.0, "min_min_profit": 2.00, "max_margin": 20.0, "max_min_profit": 3.50}'

Operational notes

  • Rules are stored in otto_margin_rules table and are ordered by buy_price.
  • The find_by_buy_price lookup returns the most appropriate rule for a given buy_price using the logic described above; callers should convert currencies/units before lookup.
  • Consider validating or restricting overlapping rules at creation time if business rules require strict, non-overlapping thresholds.

Files

  • backend/service_multi-repricer/app/api/v1/endpoints/otto_margin_rules.py

Otto Margin Rules Endpoints

Router prefix: /otto/margin_rules → full base: /api/v1/multi/otto/margin_rules

Summary: CRUD for margin rules that influence Otto repricing.

Implementation: backend/service_multi-repricer/app/api/v1/endpoints/otto_margin_rules.py


TODO: Populate detailed method table and examples.