Skip to main content
Mobula pair data API allows you to fetch real-time and historical price data for any on-chain pair. You can use this data to feed Trading View charting library.
Live Demo: See charts in action on mtt.gg - try any token or pair page!Full Source Code: The complete TradingView implementation is open-source at github.com/MobulaFi/MTT

What you’ll need

  1. Access to trading view codebase repo (need manual approval from Trading View)
  2. An API key from the Dashboard (only for production use, you can use the API without an API key in development mode)
  3. A react app (or any other framework) to display the chart

Open Source Reference Implementation

Before diving into the code, check out the production-ready implementation in the MTT (Mobula Trader Terminal) codebase: Live Examples:

Walkthrough

1

Identify your asset

Pick your asset symbol, name or address. If it is a symbol/name, make sure to check case sensitivity and to respect the asset name as listed on Mobula curated token list (explorable here). If it is an address, make sure to check the blockchain supported (check here for the full list) and to respect the blockchain ID format.You can also use pair address directly (if using asset, we will route to the largest liquidity pool for this asset).
2

Setup Chart Component

Let’s first setup the main chart component - you must host the trading view lib files inside the public folder of your app, in our example, we host them at static/charting_library.Here’s a simplified version. For the full production implementation with theme support, loading states, and tool persistence, see the MTT chart component.
3

Setup the Datafeed with Token & Pair Support

The datafeed handles both token-based and pair-based charts. This is the key difference in the MTT implementation:
  • Token mode (isPair: false): Uses asset parameter to route to the highest liquidity pool
  • Pair mode (isPair: true): Uses address parameter for a specific pool
4

Fetch Historical Data (getBars)

The getBars function fetches historical OHLCV data. The key is handling both token and pair modes:
5

Subscribe to Real-Time OHLCV Stream

The MTT implementation uses Mobula’s WebSocket ohlcv stream for real-time candle updates:
6

Resolution Normalization

The MTT datafeed supports sub-second resolutions. Here’s the normalization function:

Token Page vs Pair Page

The MTT terminal has two types of pages that use charts differently:

Token Page (/token/[blockchain]/[address])

Uses the asset mode which automatically routes to the highest liquidity pool:

Pair Page (/pair/[blockchain]/[address])

Uses the pair mode for a specific pool/pair:

Supported Resolutions

The MTT implementation supports these resolutions:

Full Example: Complete Datafeed

For the complete production-ready datafeed with all edge cases handled, see: src/components/charts/datafeed.tsx Key features in the production implementation:
  • Request deduplication with pendingRequests map
  • Last bar caching for smooth real-time updates
  • First candle gap handling (fills gaps between last historical bar and first streaming candle)
  • Proper subscription cleanup
  • Support for both token and pair modes

Need help?

Can’t find what you’re looking for? Reach out to us, response times < 1h.

Support

Telegram

Support

Slack

Support

Discord

Need help?

Email