Page cover

Session-Aware Equity Price Feed

Using Pyth Core to build a trading session-aware equity feed deployable to SEDA Fast or SEDA Core.

Contents

Requirements

rustup target add wasm32-wasip1

Alternatively, use the devcontainerarrow-up-right for a pre-configured environment.

Additional Requirement for SEDA Fast

magnifying-glass
  • SEDA Fast requires a FAST API key for querying.

  • SEDA Core does not require a FAST API key, but instead requires submitting a Data Request onchain from a supported network or on SEDA Chain directly.

circle-info

If you need more than 7 days for your trial key, please reach out to our team on Discordarrow-up-right for an extended free trial.


Getting Started

Clone and checkout the seda-starter-kit repository:

Install dependencies:

Copy and populate the .env file's MNEMONIC:

circle-info

If you need a SEDA mnemonic this can most easily be achieved by downloading Keplr walletarrow-up-right. You can then claim Testnet SEDA tokens at the SEDA faucetarrow-up-right


Building the Session-Aware Equities Price Feed

Session Awareness

Publicly listed equities typically follow three regular trading sessions, 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:

Session name
Session timeframe (US Eastern Time)

Pre-market

04:00am-09:30am

Regular hours

9:30am-04:00pm

Post-market

04:00pm-08:00pm

Overnight

08:00pm-04:00am+1

circle-info

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.


Oracle Program Structure

Start by navigating to the src/execution_phase.rs file. The execution phase contains the main computational component of your 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.

circle-info
  • SEDA Fast: Typically runs a single executor and forwards the result.

  • SEDA Core: Multiple Overlay Nodes can execute the program, and the tally phase aggregates results.


Defining the Inputs & Outputs

We will be using Pyth Core as a data source. Navigate to https://insights.pyth.network/price-feedsarrow-up-right and pick a feed.

We are going with NVDA:USD which correlates to Asset IDs:

  • Pre-market 0x61c4ca5b9731a79e285a01e24432d57d89f0ecdd4cd7828196ca8992d5eafef6

  • Regular hours 0xb1073854ed24cbc755dc527418f52b7d271f6cc967bbf8d8129112b18860a593

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 finished! Just implement the simple tally_phase.rs , similar as what we did with the crypto data feed example:

SEDA Fast Tally Phase (Single Executor Forwarding)


SEDA Core Tally Phase (Consensus-Based Aggregation)

For SEDA Core compatibility, you can extend tally logic to:

  • Parse all reveals

  • Verify matching session

  • Select median price or most recent publish_time

  • Encode result in big-endian for EVM compatibility

Core uses multiple Overlay Nodes and aggregates execution results before returning the final output onchain.


Build & Deploy

Build:


SEDA Fast Deployment

Query:


SEDA Core Deployment

After building, you'll have the .wasm artifacts in the build directory.

These artifacts can be deployed to the SEDA network and referenced in onchain Data Requests from supported networks.

Differences between SEDA Core and Fast:

Component
SEDA Fast
SEDA Core

Execution Replication

Single executor

Multiple Overlay Nodes

Tally Behavior

Forward first reveal

Aggregated consensus (e.g. median)

Access Method

Authenticated REST API

Onchain Data Request

Encoding

JSON common

Big-endian for EVM

The Oracle Program logic remains portable between both delivery methods.

Last updated

Was this helpful?