Session-Aware Equity Feed
Using Pyth to build a session-aware data feed.
Requirements
Bun: Install Bun for package management and building.
Rust: Install Rust for development and building.
WASM: Install the
wasm32-wasip1target withrustup target add wasm32-wasip1for WASM compilation.Alternatively, use the devcontainer for a pre-configured environment.
A SEDA FAST developer key. Visit the Developer Page here and access a 7 day trial.
If you need more than 7 days for your trial key, please reach out to our team on Discord for an extended free trial.
Getting started
Clone and checkout the seda-starter-kit repository:
git clone https://github.com/sedaprotocol/seda-starter-kit.git sesssion-aware-feed; cd sesssion-aware-feedBun install:
bun installCopy and populate the .env file's MNEMONIC .
cp .env.example .envIf you need a SEDA mnemonic this can most easily be achieved by downloading Keplr wallet. You can then claim Testnet SEDA tokens at the SEDA faucet
Building your session-aware equities price feed
Session awareness
Publicly listed equities typically follow three regular trading session, between 4:00am ET - 8:00pm ET. With SEDA developer can access the Blue Ocean ADS overnight trading session provided exclusively in partnership with Pyth. The full 24/7 trading sessions are as follows:
Pre-market
04:00am-09:30am
Regular hours
9:30am-04:00pm
Post-market
04:00pm-08:00pm
Overnight
08:00pm-04:00am+1
Key Points for Weekend Pricing:
Friday there is no overnight trading session
Saturday there is no trading session
Sunday overnight session provided by Blue Ocean ADS begins at 8pm
Pyth aggregates pricing data across all institutional-grade regulated exchanges for equities. With SEDA you can combine all pricing sessions into one clean end-point for consumption.
Getting started
Start by navigating to the src/execution_phase.rs file. The execution phase contains the main computational component of your FAST feed. This phase dictates how data is fetched and aggregated. The src/tally_phase.rs is more important for feeds that require onchain delivery via SEDA Core or that need to be backwards compatible with a SEDA Core feed.
For this feed we will take individual feeds, such as the Pre-market and Regular-market hours to create a unified endpoint to query the latest available price. The program automatically determines what session should be active and queries and returns the data correlated to this session.
We will start by defining our inputs. Since we will be using Pyth Core as a data source for this feed. We need to know what Pyth Asset ID we want to fetch. Navigate to https://insights.pyth.network/price-feeds and pick a feed. We are going with NVDA:USD which correlates to Asset IDs:
Pre-market
0x61c4ca5b9731a79e285a01e24432d57d89f0ecdd4cd7828196ca8992d5eafef6Regular hours
0xb1073854ed24cbc755dc527418f52b7d271f6cc967bbf8d8129112b18860a593
Defining your inputs & outputs
As inputs we require the two trading sessions, in chronological order.
As output we expect the latest in-session price of the two selected sessions. We also want to know which session's data is currently being returned, and if the market is currently in-session, if not the price is stale.
We then parse the expected inputs in the execution_phase function and replace the rest of the code with placeholders.
The code will look something like this:
We continue by adding two dependencies to our Cargo.toml, chrono and chrono-tz:
Cargo.toml :
Now we create a new file in /src called sessions.rs . We will write our session determination logic in there.
sessions.rs:
Add mod sessions.rs; to main.rs .
We then call the get_current_session function from execution_phase.rs :
We now want to fetch data for the correct, latest session. We can use the same fetch_pyth function we used in our previous example. Create the src/fetch_pyth.rs file:
Add mod fetch_pyth.rs; to main.rs .
Now fetch the price for the correct session and return it as PriceFeedResponse:
Almost finish! Just implement the simple tally_phase.rs , similar as what we did with the crypto data feed example:
We can now deploy the feed and start querying it:
Which should result in something like:
tx
65CBFC700883A870E24216F86434F1C0534AFBE1E67CCEB4952B1EE5255C81EC
oracleProgramId
8cf7808cdb5d16e9fb328007968b31727f8e67ac3c83b655aa61c4ccd4077125
You can then query the fast oracle by calling:
Last updated
Was this helpful?

