Skip to content

Add endpoint to query historical prices in candlestick form#118

Merged
codchen merged 4 commits intomasterfrom
tony-chen-historical-prices
Jul 18, 2022
Merged

Add endpoint to query historical prices in candlestick form#118
codchen merged 4 commits intomasterfrom
tony-chen-historical-prices

Conversation

@codchen
Copy link
Collaborator

@codchen codchen commented Jul 16, 2022

Request format: /sei-protocol/seichain/dex/get_historical_prices/{contractAddr}/{priceDenom}/{assetDenom}/{periodLengthInSeconds}/{numOfPeriods}
For example, if you want to get a price bar of size 30s and you want 120 bars (for an hour), periodLengthInSeconds would be 30 and numOfPeriods would be 120.

Response format:

{
  "prices": [
    {
      "begin_timestamp": 123450,
      "end_timestamp": 123480,
      "open": 100,
      "high": 102,
      "low": 99,
      "close": 101,
      "volume": 1,
    },
    {
      "begin_timestamp": 123420,
      "end_timestamp": 123450,
      "open": 99,
      "high": 100,
      "low": 99,
      "close": 1010
      "volume": 2,
    },
    ....
  ]
}

Prices are sorted in descending order based on time (i.e. the most recent price bar is at the top). In this PR we haven't populated volume yet so this field will always be 0 for the time being.

Also changed price snapshotting to be tick-based rather than epoch-based, and extended price snapshot retention to 24 hours.

Copy link
Contributor

@LCyson LCyson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm pending a small test and comment
Also are we going to revert this change after we have an off-chain data store?


func PricePrefix(contractAddr string) []byte {
return append(KeyPrefix(PriceKey), KeyPrefix(contractAddr)...)
func PricePrefix(contractAddr string, priceDenom string, assetDenom string) []byte {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add an example for how the prefix is added in a comment, and also a test for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a comment and a test

// set open
pricePtr := 0
for i := range candlesticks {
for pricePtr < len(validPrices) && validPrices[pricePtr].SnapshotTimestampInSeconds > candlesticks[i].BeginTimestamp {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is it better to sort the validPrices in time ascending order so it can reduce some code duplication here? guess the computation is not so important as it's a query endpoint, i'm also good with changing this in a separate PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i intentionally kept open/high/low/close logic separate just to make logic clear for each. If needed I can also consolidate all four computations, but it might be less readable

@codchen codchen merged commit b38ba7b into master Jul 18, 2022
philipsu522 pushed a commit that referenced this pull request Jul 18, 2022
* Add historical price endpoint

* add tests

* linter

* key test

Co-authored-by: Tony Chen <tonychen@Tonys-MacBook-Pro.local>
alg747 pushed a commit to UXDProtocol/sei-chain that referenced this pull request Jul 20, 2022
…ocol#118)

* Add historical price endpoint

* add tests

* linter

* key test

Co-authored-by: Tony Chen <tonychen@Tonys-MacBook-Pro.local>
masih pushed a commit that referenced this pull request Sep 29, 2025
## Describe your changes and provide context
This adds the midblock interfaces and module manager functionality to
sei-cosmos


## Testing performed to validate your change
Added unit test for module manager behavior and also tested with local
sei with sei-chain changes
masih pushed a commit that referenced this pull request Sep 30, 2025
## Describe your changes and provide context
This adds the midblock interfaces and module manager functionality to
sei-cosmos


## Testing performed to validate your change
Added unit test for module manager behavior and also tested with local
sei with sei-chain changes
masih pushed a commit that referenced this pull request Oct 1, 2025
* dbsync

* snapshotting

* add CLI script

* fix

* fix

* fix

* fix

* post sync hook

* add LoadLatest abci call

* fix tests

* fixes

* fix

* change toml name

* rebase

* add unit tests

* nit

* address comments

* test parallel

* config for snapshot worker count

* make channel non-blocking

* add logs

* update default config

* OnStop

* fix race condition in tests
masih pushed a commit that referenced this pull request Oct 9, 2025
#118)

This reverts commit c35c30a, reversing
changes made to 302e86d.

## Describe your changes and provide context
- Revert surfacing errors from db layer since the rpc / keeper / store
layer hard codes a lot of handling of record not found and there needs
to be a larger refactor
- Can re introduce this error after a redesign and consideration of
impact

## Testing performed to validate your change
- Verified in unit tests and on node
@masih masih deleted the tony-chen-historical-prices branch October 31, 2025 15:53
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