Oracle documentation
Signed forex and precious-metal prices your smart contracts verify on-chain. Overview: oracle page · machine-readable: /v1/oracle/feeds, /v1/oracle/catalog.
1. How it works
- Your backend requests a signed report:
GET https://api.marketapi.app/v1/oracle/report?symbols=XAUUSD&chain_id=10(API key with theread:oraclescope; billed per signed report). - Your transaction passes the report and signature to the verifier contract, which checks the EIP-712 signature, the expiry, the chain and its circuit breaker, then stores the price.
- In the same transaction your contract reads the price with a freshness requirement. This pull pattern always uses the current price.
Prices requested through the API are also pushed on-chain automatically from time to time, but never rely on a stored price without a freshness check.
2. Networks and contracts
| Network | Chain ID | Verifier contract |
|---|---|---|
| Optimism | 10 | 0xaeF7f701acFB42267015D3F593ce17CF536Afd6B · explorer |
| Optimism Sepolia testnet | 11155420 | 0xBBf36E7Cd75494f28E02C5698EaD35fF4960a943 · explorer |
Signer address: 0x83fa2d8836525251FAd214A78A72038D0864f877. Testnets are for free testing without service guarantees.
3. Feeds
Each feed has a permanent ID: feedId = keccak256(symbol). Prices use 8 decimals.
| Symbol | feedId |
|---|---|
AUDUSD | 0x5577fa17b1be8ae0f1517fe1864ea534d6992f3721000cdb6585b11e7046d5ec |
EURGBP | 0xeaff3420d70d388655273db9b4f3000962445a6f0ea23ec1f04d843e4dbae4b0 |
EURUSD | 0x0730076c3c0f5da594eb635c5d5a22116233bdb2a9c2977279cc348b8b8ce917 |
GBPUSD | 0xd30842147b60fe333c2700bcae5eee6815b8529847955d19522858806bca8217 |
IEF | 0x309dab183458dd939568dca0d68bea45d34aa25d31fa47fc5f12030e8f227f4e |
OILCash# | 0xe21b90a237aa0663c02092eca221a0098c6c477054a61d05ecd3692f6631f6ff |
SHY | 0x78f1083af8e72ddefc2e66fad95680c38a953b3136f413c61ab40f99b72991bc |
SPY | 0xcea23e8f56b5ac447ac08d57e0808e35f468a65f29bb659b3d48934481e7c67a |
TLT | 0x4abd434857e07567d49487ccf888348e55d5cfc15498c09a9dbcba2820e40ee4 |
USDCAD | 0xa36f6cf3195abb4e93bf276660acee423f78878e6cfdbad0eab36e455afca97e |
USDCHF | 0xd85af9ebd6fec6b317a7ac07f6d6455c4fc915cc8e1cfe19471faca002582907 |
USDJPY | 0x3d6c40e9d821c10e442cb3fc6cb1c589ffd8b906e734a1ab3b3f7d213ac395d6 |
USDSGD | 0x8a1375bd16e33aff9be7037f83e076defe9df6efea6d39a51d0b08f17ac9bc6d |
XAGUSD | 0x67107df7f0e95594d9bf8ad8840bbb2ff95617123c227e10aab4d161dd6959b6 |
XAUUSD | 0xe21c86d8b6a127bfef214d88fdb0c279e55d27dd8c443733e46c8d3de3c98cd6 |
4. The signed report
EIP-712 domain: name MarketAPI Oracle, version 2, the chain ID and the verifier address. Type:
PriceReport(bytes32 feedId,int256 price,uint64 timestamp,uint64 validUntil,uint8 marketStatus,uint32 spreadBps)
- price: mid price with 8 decimals.
- timestamp: time of the price (UTC seconds); validUntil: the report expires after about a minute.
- marketStatus: 1 OPEN, 2 CLOSED (official last price, e.g. at weekends), 3 HALTED.
- spreadBps: bid-ask spread in basis points; with several brokers it also reflects how far apart they are.
The API answer contains report (ABI-encoded) and signature (65 bytes): exactly the two arguments of submit.
5. Contract functions
submit(PriceReport r, bytes sig) returns (bool): verify and store; ignored if an equal or newer price is stored.submitBatch(PriceReport[] rs, bytes[] sigs): several feeds in one transaction; invalid entries are skipped.getPrice(bytes32 feedId): latest stored price and timestamp; reverts while a feed has no price yet.getPriceNoOlderThan(bytes32 feedId, uint256 maxAge): reverts unless the market is OPEN and the price is fresh enough. Use this for trading actions.
Each feed has a circuit breaker: a jump larger than its limit pauses the feed until it is reviewed.
6. Solidity example (pull pattern)
interface IMarketApiOracle {
struct PriceReport { bytes32 feedId; int256 price; uint64 timestamp; uint64 validUntil; uint8 marketStatus; uint32 spreadBps; }
function submit(PriceReport calldata r, bytes calldata sig) external returns (bool);
function getPriceNoOlderThan(bytes32 feedId, uint256 maxAge) external view returns (int256 price, uint64 timestamp);
}
contract GoldVault {
IMarketApiOracle immutable oracle;
bytes32 constant XAUUSD = keccak256("XAUUSD");
constructor(IMarketApiOracle o) { oracle = o; }
function settle(IMarketApiOracle.PriceReport calldata r, bytes calldata sig) external {
oracle.submit(r, sig);
(int256 price, ) = oracle.getPriceNoOlderThan(XAUUSD, 60); // reverts unless OPEN and at most 60 s old
// ... use price (8 decimals)
}
}7. JavaScript example (ethers v6)
const res = await fetch("https://api.marketapi.app/v1/oracle/report?symbols=XAUUSD&chain_id=10",
{ headers: { Authorization: `Bearer ${process.env.API_KEY}` } });
const { data, refused } = await res.json();
if (!data.length) throw new Error(refused[0]?.reason); // e.g. market closed or stale
const r = data[0];
const report = ethers.AbiCoder.defaultAbiCoder().decode(
["tuple(bytes32,int256,uint64,uint64,uint8,uint32)"], r.report)[0];
await vault.settle(report, r.signature); // your contract calls oracle.submit(...)8. Refusals and errors
refusedentries list symbols that were not signed, with a reason, for example no reliable price right now (STALE) or a closed market. They are not billed.oracle_unavailable(503): the signing service is briefly unavailable; retry with back-off.- On-chain reverts:
InvalidSignature(wrong signer, chain or contract),ReportExpired,FutureTimestamp,InvalidPrice,InvalidStatus,NoPrice(feed has no price yet),FeedTripped(circuit breaker),MarketNotOpenandPriceTooOld(fromgetPriceNoOlderThan),IsPaused.
9. Best practices
- Fetch the report right before sending the transaction; reports expire after about a minute.
- Always read with
getPriceNoOlderThanand a maximum age suited to your product. - Handle CLOSED markets explicitly (weekends, holidays), for example settle at the next open.
- Test on the testnet first, then change only the contract address and chain ID.
- Keep API keys on your server, never in a web page.