Documentation · Guides
Read a price
Read a Stock Token's band, the market session and any trading halt from the chain, and tell a price from no price.
Every Stock Token has a band on chain: a low edge, a centre and a high edge, with a state that says how far to trust it. In this guide you read the band of TSLA, the session it follows and the halt that can stop it, from code or over HTTP. You need no wallet and no ether.
Before you start#
- A chain's registry,
deployments/46630.jsonin the repository. The SDKs compile in no address. - An SDK, installed as in the quickstart, or
curl. - The testnet RPC
https://rpc.testnet.chain.robinhood.com, or the public indexerhttps://indexer-production-f5dc.up.railway.app.
The examples below reuse the client and deployments the quickstart builds.
1. Read the band#
import { band } from '@tapehouse/sdk'
const { state, live, mid, halfBps, low, high } = await band.quote(client, deployments, 'TSLA')| Field | Meaning |
|---|---|
state | 0 halted, 1 degraded, 2 closed, 3 open |
live | How many price legs are live |
mid | The band's centre, USD with 8 decimals |
halfBps | The half-width, in basis points |
low, high | The band's edges, USD with 8 decimals |
All fields are zero while the band is halted. The margin accounts value a Stock Token at low, and a short position is margined at high. The band explains how the width is set.
2. Read the session#
The band's state follows two clocks: Chainlink's 24/5 session and NYSE's regular hours.
const { state, nyse, nyseNext, changeMs, boundaryMs } = await band.session(client, deployments)state is 0 when the session is not known, 1 closed and 2 open. changeMs and boundaryMs are milliseconds. The session says what happens to the band at each boundary.
3. Read the halt#
A halt stops the band from pricing an asset. Three things cause one: a halt signed by Tapehouse's halt signer, a pause of the Stock Token's oracle by its issuer, and a multiplier change that Chainlink has not yet confirmed.
const { signedHalt, until, issuedAt, oraclePaused } = await band.halt(client, deployments, 'TSLA')4. Read the price as a Chainlink feed#
Each asset has a BandFeed that serves the band's low side as Chainlink's latestRoundData, so a contract that already reads Chainlink can read the band.
const round = await band.latestRound(client, deployments, 'TSLA')
const whole = await band.latestBand(client, deployments, 'TSLA')The round's answer is the band's low edge, and its round ID and updatedAt are the block time.
What to expect#
- Closed, degraded and halted bands are valid answers. A reader that needs a price checks
statefirst: a halted band has no price, and a degraded one has a wider band. - While the market is closed the band has a price only while someone writes a fresh RedStone package to it, which anyone may do. A band nobody has written to for two minutes can have no live leg.
- Pin a read to a block when you compare several: the TypeScript functions take
{ blockNumber }as their last argument, the Go ones a*bind.CallOptswithBlockNumber, the Rust calls.block(...), and the HTTP view ablockquery parameter.
Errors you may hit#
| Error | Cause |
|---|---|
The registry has no .bandFeeds.<asset> | The registry names no BandFeed for that asset. Check deployments/<chainId>.json. |
Error::Argument in Rust, an error from ToBytes32 in Go | An asset name longer than 32 bytes. |
NoAnswer(symbol) | A BandFeed's latestRoundData or a Morpho oracle read a band with no price. See the Morpho oracle guide. |
Next#
- The band and the session.
- Open an account to borrow against what you read.
- The Morpho oracle guide, if a lending market prices a Stock Token by its band.