Skip to content

feat(trades): add taker trades endpoint#106

Merged
graphite-app[bot] merged 1 commit into
mainfrom
feature/rai-530-add-rest-api-endpoint-for-taker-trade-lookup
May 13, 2026
Merged

feat(trades): add taker trades endpoint#106
graphite-app[bot] merged 1 commit into
mainfrom
feature/rai-530-add-rest-api-endpoint-for-taker-trade-lookup

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented May 12, 2026

Chained PRs

Dependent PRs

  • Depends on rainlanguage/raindex#2571 for SDK getTrades taker filtering, local DB predicate pushdown, sender-time indexes, and local query tracing. This PR should not merge until that raindex PR lands and the submodule pointer is mergeable.

Summary

  • Adds GET /v1/trades/taker/{address} for paginated trades by taker address.
  • Wires the endpoint through the existing trades route module, OpenAPI registration, auth, rate limiting, tracing span propagation, and shared trades response mapping.
  • Uses the raindex SDK get_trades taker filter directly with pagination and time filtering; there is no API-side query workaround.
  • Clones the shared RaindexClient before awaiting the SDK call so the raindex provider read lock is not held during fetch/count work.
  • Adds focused tests for successful taker queries, empty results, SDK errors, auth failure, invalid address handling, and route registration.
  • Bumps the rain.orderbook submodule to the SDK commit with taker-filtered getTrades support and local DB query tracing.

Linear: RAI-530

Behavior

The new endpoint accepts the same pagination/time query parameters as the existing trade list endpoints:

GET /v1/trades/taker/{takerAddress}?page=1&pageSize=20&startTime=...&endTime=...

It returns trades whose taker/sender matches the path address and includes the shared trade list pagination metadata.

Local DB Smoke Test

After resetting the local raindex DB and waiting for /health/detailed to report Base as active and ready, the endpoint used local DB only:

local_chain_ids_count=1
subgraph_chain_ids_count=0

Measured locally against taker 0x55f3412d51bbe48255a286189848a151236c0307:

  • pageSize=3: 3 rows, totalTrades=1676, HTTP total 1.596s; SDK fetch 667ms, count 662ms, total 1343ms.
  • pageSize=50: 50 rows, totalTrades=1676, HTTP total 1.726s; SDK fetch 675ms, count 651ms, total 1477ms.

Verification

  • nix develop -c cargo check
  • nix develop -c cargo test routes::trades::get_by_taker
  • nix develop -c cargo test
  • nix develop -c cargo fmt
  • nix develop -c rainix-rs-static

rainix-rs-static passes with pre-existing dead-code warnings in src/cache.rs.


View in Codesmith
Need help on this PR? Tag @codesmith with what you need.

  • Let Codesmith autofix CI failures and bot reviews

@linear
Copy link
Copy Markdown

linear Bot commented May 12, 2026

RAI-530

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe542868-d668-4341-87f2-7c755a8fc7de

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/rai-530-add-rest-api-endpoint-for-taker-trade-lookup

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Copy link
Copy Markdown
Collaborator Author

findolor commented May 12, 2026


How to use the Graphite Merge Queue

Add the label add-to-gt-merge-queue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@findolor findolor self-assigned this May 12, 2026
findolor added a commit that referenced this pull request May 12, 2026
## Chained PRs

- Stacked on [#106](#106) for the taker trades endpoint.
- Also follows [#105](#105) for the token trades endpoint.

## Dependent PRs

- Depends on [rainlanguage/raindex#2572](rainlanguage/raindex#2572) ([Graphite](https://app.graphite.com/github/pr/rainlanguage/raindex/2572)) for SDK `getTradesByOrderHashes` support, local DB order-hash batching, and grouped results. This PR should not merge until that raindex PR lands and the submodule pointer is mergeable.

## Summary

- Adds `POST /v1/trades/query` for batch order-hash trade lookup.
- Defines request/response DTOs for `orderHashes` input and `tradesByOrderHash` grouped output.
- Includes every requested hash in the response through the SDK grouping behavior, including hashes with no trades.
- Validates order hashes with existing API error handling and returns `400` for invalid hash input.
- Wires the route through the existing trades module, auth, rate limiting, tracing span propagation, and OpenAPI registration.
- Uses the raindex SDK batch order-hash API directly; there is no API-side query workaround.
- Reuses the shared trade list mapper for each grouped trade entry.
- Bumps the `rain.orderbook` submodule to the SDK commit with batch order-hash trade lookup support.

Linear: RAI-528

## Behavior

The new endpoint accepts a JSON body:

```json
{
  "orderHashes": [
    "0x4a051ad4567935a5a0570b3e2e77714c44405bb58e5b83e3cc484de1cee0747e"
  ],
  "startTime": 1718452800,
  "endTime": 1718539200
}
```

It returns trades grouped by requested order hash:

```json
{
  "tradesByOrderHash": [
    {
      "orderHash": "0x4a051ad4567935a5a0570b3e2e77714c44405bb58e5b83e3cc484de1cee0747e",
      "trades": []
    }
  ],
  "totalCount": 0
}
```

## Local DB Smoke Test

After clearing the local raindex DB and waiting for the Base local source to become ready, the endpoint used local DB only:

```text
local_chain_ids_count=1
subgraph_chain_ids_count=0
```

Single-order smoke test:

- Request: one real order hash plus one zero hash.
- Result: real hash returned `50` trades; zero hash returned an empty `trades` array.
- HTTP total: `0.415652s`.
- SDK local fetch: `29ms`; SDK total: `161ms`.

Heavy response stress test using the highest-trade order hashes in the local DB:

- Top 10 order hashes: `3,790` trades, `2.12 MB` response, HTTP total `11.20s`.
- Top 20 order hashes: `4,596` trades, `2.57 MB` response, HTTP total `13.50s`.
- Top 20 SQL fetch was `930ms`; full SDK grouping/materialization was `13211ms`; full API request was `13495ms`.

The heavy case is dominated by materializing, grouping, mapping, and serializing thousands of full trade objects rather than by SQL lookup.

## Notes

- The `unimplemented!()` additions are test-only mock methods required by the expanded `TradesDataSource` trait; they are not production route code.
- Empty `orderHashes` currently returns an empty grouped result, matching the SDK behavior.

## Verification

- `nix develop -c cargo fmt`
- `nix develop -c cargo check`
- `nix develop -c cargo test routes::trades::get_by_order_hashes`
- `nix develop -c cargo test`
- `nix develop -c rainix-rs-static`

`rainix-rs-static` passes with pre-existing dead-code warnings in `src/cache.rs`.
@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented May 13, 2026

Merge activity

## Chained PRs

- Stacked on [#105](#105) for the token trades endpoint.

## Dependent PRs

- Depends on [rainlanguage/raindex#2571](rainlanguage/raindex#2571) for SDK `getTrades` taker filtering, local DB predicate pushdown, sender-time indexes, and local query tracing. This PR should not merge until that raindex PR lands and the submodule pointer is mergeable.

## Summary

- Adds `GET /v1/trades/taker/{address}` for paginated trades by taker address.
- Wires the endpoint through the existing trades route module, OpenAPI registration, auth, rate limiting, tracing span propagation, and shared trades response mapping.
- Uses the raindex SDK `get_trades` taker filter directly with pagination and time filtering; there is no API-side query workaround.
- Clones the shared `RaindexClient` before awaiting the SDK call so the raindex provider read lock is not held during fetch/count work.
- Adds focused tests for successful taker queries, empty results, SDK errors, auth failure, invalid address handling, and route registration.
- Bumps the `rain.orderbook` submodule to the SDK commit with taker-filtered `getTrades` support and local DB query tracing.

Linear: RAI-530

## Behavior

The new endpoint accepts the same pagination/time query parameters as the existing trade list endpoints:

```text
GET /v1/trades/taker/{takerAddress}?page=1&pageSize=20&startTime=...&endTime=...
```

It returns trades whose taker/sender matches the path address and includes the shared trade list pagination metadata.

## Local DB Smoke Test

After resetting the local raindex DB and waiting for `/health/detailed` to report Base as active and ready, the endpoint used local DB only:

```text
local_chain_ids_count=1
subgraph_chain_ids_count=0
```

Measured locally against taker `0x55f3412d51bbe48255a286189848a151236c0307`:

- `pageSize=3`: 3 rows, `totalTrades=1676`, HTTP total `1.596s`; SDK fetch `667ms`, count `662ms`, total `1343ms`.
- `pageSize=50`: 50 rows, `totalTrades=1676`, HTTP total `1.726s`; SDK fetch `675ms`, count `651ms`, total `1477ms`.

## Verification

- `nix develop -c cargo check`
- `nix develop -c cargo test routes::trades::get_by_taker`
- `nix develop -c cargo test`
- `nix develop -c cargo fmt`
- `nix develop -c rainix-rs-static`

`rainix-rs-static` passes with pre-existing dead-code warnings in `src/cache.rs`.

<!-- codesmith:footer -->
---
<a href="https://app.blacksmith.sh/ST0x-Technology/codesmith/st0x.rest.api/pr/106"><picture><source media="(prefers-color-scheme: dark)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-in-codesmith-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://pr-comments-assets.blacksmith.sh/codesmith/view-in-codesmith-light.svg"><img alt="View in Codesmith" src="https://pr-comments-assets.blacksmith.sh/codesmith/view-in-codesmith-dark.svg"></picture></a>
<sup>Need help on this PR? Tag <code>@codesmith</code> with what you need.</sup>

- [ ] Let Codesmith autofix CI failures and bot reviews
<!-- /codesmith:footer -->
@graphite-app graphite-app Bot force-pushed the feature/rai-522-add-trades-token-endpoint branch from 500f191 to 54e38c6 Compare May 13, 2026 17:10
@graphite-app graphite-app Bot force-pushed the feature/rai-530-add-rest-api-endpoint-for-taker-trade-lookup branch from b41f9ad to 766a74c Compare May 13, 2026 17:11
graphite-app Bot pushed a commit that referenced this pull request May 13, 2026
## Chained PRs

- Stacked on [#106](#106) for the taker trades endpoint.
- Also follows [#105](#105) for the token trades endpoint.

## Dependent PRs

- Depends on [rainlanguage/raindex#2572](rainlanguage/raindex#2572) ([Graphite](https://app.graphite.com/github/pr/rainlanguage/raindex/2572)) for SDK `getTradesByOrderHashes` support, local DB order-hash batching, and grouped results. This PR should not merge until that raindex PR lands and the submodule pointer is mergeable.

## Summary

- Adds `POST /v1/trades/query` for batch order-hash trade lookup.
- Defines request/response DTOs for `orderHashes` input and `tradesByOrderHash` grouped output.
- Includes every requested hash in the response through the SDK grouping behavior, including hashes with no trades.
- Validates order hashes with existing API error handling and returns `400` for invalid hash input.
- Wires the route through the existing trades module, auth, rate limiting, tracing span propagation, and OpenAPI registration.
- Uses the raindex SDK batch order-hash API directly; there is no API-side query workaround.
- Reuses the shared trade list mapper for each grouped trade entry.
- Bumps the `rain.orderbook` submodule to the SDK commit with batch order-hash trade lookup support.

Linear: RAI-528

## Behavior

The new endpoint accepts a JSON body:

```json
{
  "orderHashes": [
    "0x4a051ad4567935a5a0570b3e2e77714c44405bb58e5b83e3cc484de1cee0747e"
  ],
  "startTime": 1718452800,
  "endTime": 1718539200
}
```

It returns trades grouped by requested order hash:

```json
{
  "tradesByOrderHash": [
    {
      "orderHash": "0x4a051ad4567935a5a0570b3e2e77714c44405bb58e5b83e3cc484de1cee0747e",
      "trades": []
    }
  ],
  "totalCount": 0
}
```

## Local DB Smoke Test

After clearing the local raindex DB and waiting for the Base local source to become ready, the endpoint used local DB only:

```text
local_chain_ids_count=1
subgraph_chain_ids_count=0
```

Single-order smoke test:

- Request: one real order hash plus one zero hash.
- Result: real hash returned `50` trades; zero hash returned an empty `trades` array.
- HTTP total: `0.415652s`.
- SDK local fetch: `29ms`; SDK total: `161ms`.

Heavy response stress test using the highest-trade order hashes in the local DB:

- Top 10 order hashes: `3,790` trades, `2.12 MB` response, HTTP total `11.20s`.
- Top 20 order hashes: `4,596` trades, `2.57 MB` response, HTTP total `13.50s`.
- Top 20 SQL fetch was `930ms`; full SDK grouping/materialization was `13211ms`; full API request was `13495ms`.

The heavy case is dominated by materializing, grouping, mapping, and serializing thousands of full trade objects rather than by SQL lookup.

## Notes

- The `unimplemented!()` additions are test-only mock methods required by the expanded `TradesDataSource` trait; they are not production route code.
- Empty `orderHashes` currently returns an empty grouped result, matching the SDK behavior.

## Verification

- `nix develop -c cargo fmt`
- `nix develop -c cargo check`
- `nix develop -c cargo test routes::trades::get_by_order_hashes`
- `nix develop -c cargo test`
- `nix develop -c rainix-rs-static`

`rainix-rs-static` passes with pre-existing dead-code warnings in `src/cache.rs`.
@graphite-app graphite-app Bot changed the base branch from feature/rai-522-add-trades-token-endpoint to main May 13, 2026 17:32
@graphite-app graphite-app Bot merged commit 766a74c into main May 13, 2026
10 checks passed
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.

3 participants