Skip to content

Improve order endpoint trade lookup#109

Open
findolor wants to merge 1 commit into
mainfrom
feature/order-endpoint-batch-trade-query
Open

Improve order endpoint trade lookup#109
findolor wants to merge 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.

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0da373d9-8154-4e43-9bb0-00417c38baf2

📥 Commits

Reviewing files that changed from the base of the PR and between 0875f73 and f4de41e.

📒 Files selected for processing (1)
  • src/routes/order/mod.rs

📝 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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
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.

2 participants