Skip to content

Improve order endpoint trade lookup#109

Merged
graphite-app[bot] merged 1 commit into
mainfrom
feature/order-endpoint-batch-trade-query
May 26, 2026
Merged

Improve order endpoint trade lookup#109
graphite-app[bot] merged 1 commit into
mainfrom
feature/order-endpoint-batch-trade-query

Conversation

@findolor
Copy link
Copy Markdown
Collaborator

@findolor findolor commented May 18, 2026

Dependent PR

Stacked on #108, feature/rai-581-preview-api-infrastructure.

Linear

Part of RAI-580.

Motivation

GET /v1/order/{order_hash} was the biggest confirmed endpoint latency issue in the benchmark pass. The production path was observed around 30-40s for a real order hash, which made the endpoint unsuitable for normal interactive use.

Solution

  • Replace the order endpoint's trade lookup from order.get_trades_list(...) to client.get_trades_by_order_hashes(...).
  • Keep the response shape unchanged by selecting the requested order hash's grouped trades from the batch result.
  • Leave broader SDK and SQL changes out of this PR; this is the safe checkpoint for the confirmed endpoint win.

Benchmark Notes

Order hash used:

0x55c8f34ab380147ee98450e145f32c5dda080a4c6c9ad45206267048a3b475bf

Observed before this change:

  • Production API: roughly 30-40s for the order endpoint.
  • Old order.get_trades_list(...) path against a ready local DB: roughly 10-11s.

Observed with this change against the current production registry bootstrap DB:

  • Warm local runs mostly landed around 1.5-2.0s.
  • Earlier local runs were around 1.6-1.8s after the DB was ready.
  • The same response returned 72 trades.

Follow-up investigation showed direct SQLite trade SQL itself is fast, so remaining latency is likely SDK enrichment work rather than missing indexes:

  • order.get_quotes(...)
  • dotrain/metaboard source hydration during order lookup
  • object hydration, formatting, and response serialization

Checks

  • nix develop -c cargo fmt
  • nix develop -c rainix-rs-static

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

  • Let Codesmith autofix CI failures and bot reviews

Summary by CodeRabbit

  • Refactor
    • Improved backend trade data retrieval mechanism for orders, enhancing system reliability and query performance.

Review Change Stack

@findolor findolor self-assigned this May 18, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 18, 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: f85e4711-0dba-45b3-a484-bd6dcbc850df

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
📝 Walkthrough

Walkthrough

The PR refactors the order trades endpoint to fetch trades by order hashes through the RaindexClient instead of directly from the RaindexOrder object. Import statements are updated to include new filter and type definitions, and the lookup logic is reworked to query trades and locate the matching order hash entry.

Changes

Order Trades Query Refactoring

Layer / File(s) Summary
Order trades lookup refactoring
src/routes/order/mod.rs
Imports are updated to include GetTradesByOrderHashesFilters, OrderHashes, and RaindexTrade. The get_order_trades method is refactored to call RaindexClient::get_trades_by_order_hashes(...) with a GetTradesByOrderHashesFilters and TimeFilter::default(), then selects the matching order hash from the returned trades; returns an empty vector if no match is found.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • ST0x-Technology/st0x.rest.api#34: Both PRs modify the get_order_trades implementation in OrderDataSource; this PR refactors it to use RaindexClient::get_trades_by_order_hashes(...) for the same endpoint added in #34.

Suggested reviewers

  • hardyjosh
  • 0xgleb
  • JuaniRios

Poem

🐰 A twisty tail of trades untold,
Now queries dance through hashes bold,
No more direct, but client-wise,
Order flows through filter's eyes!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Improve order endpoint trade lookup' directly describes the main change: replacing the trade lookup mechanism from order.get_trades_list() to client.get_trades_by_order_hashes() to address latency issues in the GET /v1/order/{order_hash} endpoint.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/order-endpoint-batch-trade-query

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 18, 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.

@graphite-app graphite-app Bot changed the base branch from feature/rai-581-preview-api-infrastructure to graphite-base/109 May 20, 2026 10:41
@graphite-app graphite-app Bot force-pushed the graphite-base/109 branch from db8d0c8 to 0875f73 Compare May 20, 2026 13:37
@graphite-app graphite-app Bot force-pushed the feature/order-endpoint-batch-trade-query branch from 6ef2cb1 to b4fac6d Compare May 20, 2026 13:37
@graphite-app graphite-app Bot changed the base branch from graphite-base/109 to main May 20, 2026 13:38
@graphite-app graphite-app Bot force-pushed the feature/order-endpoint-batch-trade-query branch from b4fac6d to f4de41e Compare May 20, 2026 13:38
@findolor findolor changed the base branch from main to graphite-base/109 May 21, 2026 09:01
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch from f4de41e to 73a5ca6 Compare May 21, 2026 09:01
@findolor findolor changed the base branch from graphite-base/109 to feature/preview-api-domain May 21, 2026 09:01
@findolor findolor force-pushed the feature/preview-api-domain branch from 6580777 to dcd8d19 Compare May 21, 2026 09:06
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch 2 times, most recently from 1c569cb to e8e2ed7 Compare May 21, 2026 09:12
@findolor findolor force-pushed the feature/preview-api-domain branch 2 times, most recently from 16ce1e8 to 2f3ac5b Compare May 21, 2026 09:28
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch 2 times, most recently from 0648e86 to 2df41e9 Compare May 21, 2026 09:37
@findolor findolor force-pushed the feature/preview-api-domain branch 2 times, most recently from 388fcf9 to 0f3f104 Compare May 21, 2026 09:48
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch 2 times, most recently from bafb7ff to 8288d45 Compare May 21, 2026 09:59
@findolor findolor force-pushed the feature/preview-api-domain branch from 0f3f104 to 6d5a8da Compare May 21, 2026 09:59
@findolor findolor force-pushed the feature/preview-api-domain branch from 6d5a8da to 19a27bf Compare May 21, 2026 10:18
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch 2 times, most recently from 9d05162 to 8ca2f09 Compare May 21, 2026 10:37
@findolor findolor force-pushed the feature/preview-api-domain branch 2 times, most recently from 0c641a1 to a2d3f74 Compare May 21, 2026 10:54
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch 2 times, most recently from 511bbd2 to 9003bad Compare May 21, 2026 11:06
@findolor findolor force-pushed the feature/preview-api-domain branch 2 times, most recently from 42a41f4 to b48bc36 Compare May 21, 2026 14:00
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch from 9003bad to c6e1a8a Compare May 21, 2026 14:00
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 21, 2026

RAI-580

RAI-642

@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch from c6e1a8a to eeb2321 Compare May 22, 2026 07:15
@findolor findolor force-pushed the feature/preview-api-domain branch from b48bc36 to c2fa4be Compare May 22, 2026 07:15
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch from eeb2321 to 3bd8ca1 Compare May 22, 2026 07:22
@findolor findolor force-pushed the feature/preview-api-domain branch from c2fa4be to 256b854 Compare May 22, 2026 07:22
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch 4 times, most recently from d03ce25 to 9b39e94 Compare May 26, 2026 10:29
@findolor findolor force-pushed the feature/preview-api-domain branch from b0b84fb to d41526b Compare May 26, 2026 13:36
@findolor findolor force-pushed the feature/order-endpoint-batch-trade-query branch from 9b39e94 to 7a5bdbf Compare May 26, 2026 13:36
@graphite-app
Copy link
Copy Markdown

graphite-app Bot commented May 26, 2026

Merge activity

## Dependent PR

Stacked on #108, `feature/rai-581-preview-api-infrastructure`.

## Linear

Part of RAI-580.

## Motivation

`GET /v1/order/{order_hash}` was the biggest confirmed endpoint latency issue in the benchmark pass. The production path was observed around 30-40s for a real order hash, which made the endpoint unsuitable for normal interactive use.

## Solution

- Replace the order endpoint's trade lookup from `order.get_trades_list(...)` to `client.get_trades_by_order_hashes(...)`.
- Keep the response shape unchanged by selecting the requested order hash's grouped trades from the batch result.
- Leave broader SDK and SQL changes out of this PR; this is the safe checkpoint for the confirmed endpoint win.

## Benchmark Notes

Order hash used:

`0x55c8f34ab380147ee98450e145f32c5dda080a4c6c9ad45206267048a3b475bf`

Observed before this change:

- Production API: roughly 30-40s for the order endpoint.
- Old `order.get_trades_list(...)` path against a ready local DB: roughly 10-11s.

Observed with this change against the current production registry bootstrap DB:

- Warm local runs mostly landed around 1.5-2.0s.
- Earlier local runs were around 1.6-1.8s after the DB was ready.
- The same response returned 72 trades.

Follow-up investigation showed direct SQLite trade SQL itself is fast, so remaining latency is likely SDK enrichment work rather than missing indexes:

- `order.get_quotes(...)`
- dotrain/metaboard source hydration during order lookup
- object hydration, formatting, and response serialization

## Checks

- `nix develop -c cargo fmt`
- `nix develop -c rainix-rs-static`

<!-- codesmith:footer -->
---
<a href="https://app.blacksmith.sh/ST0x-Technology/codesmith/st0x.rest.api/pr/109"><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 -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **Refactor**
  * Improved backend trade data retrieval mechanism for orders, enhancing system reliability and query performance.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/ST0x-Technology/st0x.rest.api/pull/109?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@graphite-app graphite-app Bot force-pushed the feature/preview-api-domain branch from d41526b to 249f3f6 Compare May 26, 2026 15:03
@graphite-app graphite-app Bot force-pushed the feature/order-endpoint-batch-trade-query branch from 7a5bdbf to 0924bce Compare May 26, 2026 15:04
@graphite-app graphite-app Bot changed the base branch from feature/preview-api-domain to main May 26, 2026 15:29
@graphite-app graphite-app Bot merged commit 0924bce into main May 26, 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