Skip to content

Add get trades by owner API#2468

Open
findolor wants to merge 10 commits into2026-02-17-trades-by-tx-hashfrom
2026-02-18-trades-by-owner
Open

Add get trades by owner API#2468
findolor wants to merge 10 commits into2026-02-17-trades-by-tx-hashfrom
2026-02-18-trades-by-owner

Conversation

@findolor
Copy link
Collaborator

Chained PRs

Motivation

See issues:

The trades public API needed a way to query trades filtered by order owner address. Additionally, the existing trade query code had inline subgraph logic in the fallback path while the local DB path was cleanly abstracted into LocalDbTrades. This asymmetry made the code harder to maintain and extend.

Solution

Subgraph layer: Added SgOwnerTradesListQuery, SgOwnerTradesCountQuery types and owner_trades_list/owner_trades_count client methods for querying trades by owner address with pagination support.

Local DB layer: Added fetch_owner_trades and fetch_owner_trades_count query modules with SQL queries that join trade events with token metadata, supporting paginated lookups by owner address from SQLite.

Public API: Added get_trades_for_owner on RaindexClient returning RaindexTradesListResult (paginated trades + total count), with local DB as the primary path and subgraph fallback.

SubgraphTrades struct: Extracted inline subgraph trade logic into a SubgraphTrades struct mirroring LocalDbTrades, with get_by_tx_hash, get_by_owner, and count_by_owner methods. Refactored get_by_tx to use it for consistency.

Code organization: Co-located LocalDbTrades and SubgraphTrades in the trades/ module so both data source structs live next to the API that consumes them.

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Add SgOwnerTradesListQuery, SgOwnerTradesCountQuery types and
owner_trades_list/owner_trades_count client methods to support
querying trades filtered by order owner address.
Add fetch_owner_trades and fetch_owner_trades_count query modules
to support paginated trade lookups by owner address from the local
SQLite database.
Add SubgraphTrades struct mirroring LocalDbTrades to cleanly
abstract subgraph trade queries. Add get_trades_for_owner public
API with local DB primary path and subgraph fallback, along with
RaindexTradesListResult for paginated results.
Replace inline subgraph client calls with SubgraphTrades struct,
making the fallback path symmetric with the local DB path.
Co-locate LocalDbTrades alongside SubgraphTrades in the trades
module for better code organization. Both data source structs
now live next to the public API that consumes them.
@findolor findolor self-assigned this Feb 18, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 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.

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
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2026-02-18-trades-by-owner

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.

Pass start_timestamp/end_timestamp through to SgOwnerTradesListQuery
and SgOwnerTradesCountQuery so owner trade lookups can be filtered by
time range at the subgraph level.
Replace bare page param with PaginationParams (page + page_size) and
add TimeFilter (start/end timestamps) throughout the owner trades
query stack: local DB SQL builders, fetch wrappers, LocalDbTrades,
and SubgraphTrades.
Move PaginationParams and TimeFilter into a shared types.rs module
and add OrderbookIdentifierParams as a wasm-safe wrapper that
converts to OrderbookIdentifier. Update get_trades_for_owner to
accept OrderbookIdentifierParams instead of separate chain_id and
orderbook_address params.
Address::to_string() produces EIP-55 checksummed (mixed-case) hex
but the subgraph matches lowercase. Use format!("{:#x}", owner) to
ensure lowercase in get_by_owner and count_by_owner.
Remove duplicated cfg-gated impl blocks for PaginationParams,
TimeFilter, and OrderbookIdentifierParams by using single
wasm_bindgen impl blocks that work on both targets. Add pub new()
constructor to RaindexTradesListResult for non-wasm targets.
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

Comments