Skip to content

MPT-24264 Add the exchange pairs service - #387

Draft
jentyk wants to merge 1 commit into
mainfrom
feature/MPT-24264/add-exchange-pairs-service
Draft

MPT-24264 Add the exchange pairs service#387
jentyk wants to merge 1 commit into
mainfrom
feature/MPT-24264/add-exchange-pairs-service

Conversation

@jentyk

@jentyk jentyk commented Aug 21, 2026

Copy link
Copy Markdown
Member

🤖 AI-generated PR — Please review carefully.

Summary

/public/v1/exchange/pairs was the only exchange endpoint in the Marketplace OpenAPI spec without a service class, so currency pairs were unreachable from the client. This adds the service and registers it on the resource group.

  • New mpt_api_client/resources/exchange/pairs.py with:
    • Pair model covering the documented Pair schema attributes.
    • PairsServiceConfig (_endpoint = "/public/v1/exchange/pairs", _model_class, _collection_key = "data").
    • PairsService and AsyncPairsService.
  • pairs property registered on both Exchange and AsyncExchange.

The module follows the existing service pattern (notifications/contacts.py, accounts/modules.py); no new abstraction was introduced.

Mixin selection

Mixins were picked from what the spec actually documents for this endpoint, not from an assumed CRUD shape:

Spec operation Handled by
GET /exchange/pairs CollectionMixin / AsyncCollectionMixin
GET /exchange/pairs/{id} GetMixin / AsyncGetMixin

The collection also documents bulk POST, PUT and DELETE, all of which take a PairBulkData envelope ({"data": [Pair, ...]}) and return an envelope or a bare array. These do not match any existing mixin — CreateMixin returns a single model, and UpdateMixin/DeleteMixin operate on /{id}, which the spec does not define for PUT/DELETE here. There is no bulk-operation precedent anywhere in this client, so adding them would mean inventing a pattern. They are deliberately left out of this change; see the note below.

Streaming support for this endpoint is out of scope here and tracked in MPT-24241.

Testing

  • make check-all passes: ruff format, ruff, flake8/WPS, mypy, uv lock --check, and the full unit suite (2391 passed). pairs.py reports 100% coverage.
  • New tests/unit/resources/exchange/test_pairs.py covers mixin presence, endpoint construction, Pair field typing and optional-field absence, and mocked get / fetch_page for both sync and async.
  • tests/unit/resources/exchange/test_exchange.py gained the pairs property assertions for both Exchange and AsyncExchange.
  • Reachability verified explicitly rather than assumed: a client built via MPTClient.from_config / AsyncMPTClient.from_config resolves client.exchange.pairs to the right class, build_path() returns /public/v1/exchange/pairs, and that path was checked against the live OpenAPI spec.
  • No e2e tests in this subtask.
  • No pyproject.toml change was needed: Exchange goes from 2 to 3 methods, well under wemake's max_methods limit, and flake8 reported no WPS214.

Docs

docs/usage.md and docs/architecture.md were deliberately left untouched — this is not an omission. Neither enumerates individual services: usage.md has no service list, and the resource tree in architecture.md is group-granular with ellipses, so a new service under an existing group is already covered. Sibling work on other resource groups is in flight, and doc edits would be the only collision point.

Reported, not changed

Two things worth a reviewer's attention rather than a unilateral fix:

  1. Bulk operations are unimplemented. The spec's bulk POST/PUT/DELETE on /exchange/pairs need a bulk-capable mixin (request and response both use a data array). That is a framework addition, not a per-service one, and belongs in its own ticket.
  2. test_exchange.py uses per-service tests, not parametrized lists. Every other group test (test_accounts.py, test_catalog.py, test_billing.py, test_commerce.py, test_notifications.py) enumerates group properties with @pytest.mark.parametrize; test_exchange.py is the outlier with individual test functions. The new coverage follows the file's existing local style for consistency. Converting this file to the repo-wide parametrized convention is a reasonable tidy-up, but out of scope here.

MPT-24264

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

On-demand reviews are free for the next 24 days. After that, they cost $0.25 per reviewed file.

Or wait 48 minutes for your next included review.

View limit details

Limit details: You’ve used all 5 included reviews currently available. Your 29 included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: c41a6a64-592d-4ee9-acdc-46b9e56b5156

📥 Commits

Reviewing files that changed from the base of the PR and between 93e9552 and e0c2e00.

📒 Files selected for processing (4)
  • mpt_api_client/resources/exchange/exchange.py
  • mpt_api_client/resources/exchange/pairs.py
  • tests/unit/resources/exchange/test_exchange.py
  • tests/unit/resources/exchange/test_pairs.py

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 21, 2026

Copy link
Copy Markdown

✅ Found Jira issue key in the title: MPT-24264

Generated by 🚫 dangerJS against e0c2e00

The /public/v1/exchange/pairs collection endpoint had no service class, so
currency pairs were unreachable from both the sync and async clients. Add
PairsService and AsyncPairsService with the Pair model, and expose them as
the `pairs` property on Exchange and AsyncExchange.

Mixins follow what the OpenAPI spec documents for this endpoint: a GET
collection (CollectionMixin) and a GET by id on /pairs/{id} (GetMixin). The
collection-level bulk POST, PUT and DELETE operations take a PairBulkData
envelope and have no matching mixin or precedent in this client, so they are
left out of this change. Streaming support is tracked separately in MPT-24241.

MPT-24264

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jentyk
jentyk force-pushed the feature/MPT-24264/add-exchange-pairs-service branch from b69bf90 to e0c2e00 Compare August 27, 2026 08:32
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant