Get started
Quick start
Read a live BTC price in ten lines of JavaScript, or in a small Rust program.
Two recipes. Each prints the BTC price as it changes.
JavaScript: through the web proxy
Works in a browser and in Node.js 22 or newer. The public proxy is wss://feeds.markoutlabs.com/v1/ws.
- Add the package. It is not on npm yet: copy
packages/oracle-jsfrom the docs repository into your project as a workspace package. - Run this:
import { OracleClient } from '@markoutlabs/oracle';
const oracle = new OracleClient({ url: 'wss://feeds.markoutlabs.com/v1/ws' });
oracle.subscribe({ prices: ['CRYPTO.BTC/USD'] });
oracle.on('price', (price) => {
if (price.status === 'halted') return; // Never act on a halted price.
console.log(price.price, '±', price.conf, price.status);
});The SDK reconnects by itself and sends the subscription again. Go on with the JavaScript SDK for books, venues, funding and history.
Rust: with the SDK
Your process connects to every node, verifies each update and takes the median. It needs a client key that governance lists; ask us for one, as Get a client key tells.
- Add the crate. It needs Rust 1.88 or newer and a C compiler.
[dependencies]
oracle-client = { git = "https://github.com/markoutlabs/oracle-node", tag = "v0.1.0" }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }- Run this, with your key file next to it:
use oracle_client::{OracleClient, Signer, Status};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let key = Signer::from_hex(std::fs::read_to_string("client.key")?.trim())?;
let mut client = OracleClient::mainnet().await?.client_key(key).build()?;
client.subscribe(&["CRYPTO.BTC/USD"]).await?;
while let Some(price) = client.next().await {
match price.status {
Status::Ok | Status::Degraded => println!("{:?} ± {:?}", price.price, price.conf),
Status::Halted => println!("halted: {:?}", price.concerns),
}
}
Ok(())
}OracleClient::mainnet() knows the mainnet registry and its trust root. Go on with the Rust SDK for the settings, the events and the other streams.
What the numbers mean
priceis the median of the node prices.confis a ± band.okmeans the nodes agree and the band is small.degradedmeans the price is usable but the band is doing real work: size your risk from it.haltedmeans too few nodes report. There is no price. Wait for the next update.
Decimals and times are strings in JSON, because a JavaScript number cannot hold a nanosecond timestamp or 12 decimal places. Keep them as strings, or use a decimal library.