In this article we will discuss different ways to retrieve Jettons historical prices on Decentralized Exchanges, DEXes.Each swap operation, either between native asset (Toncoin) and jetton or between two distinct jettons, has its price - fixed exchange rate of one asset to another. This price is calculated by the internal DEX math algorithm, called AMM. Some services require information about previous swaps on the blockchain to use it in their internal business logic or to simply show statistics to users.
The most often use case for price API is to fetch jetton info on the web2 backend and use aggregated data inside the service. There are several historical jetton prices providers in TON:
You can find detailed information about API usage technical details in provider docs.There is no established solution for real-time jetton swap market data, however one can explore CoinGecko websocket API.
Currently it is not possible to retrieve historical jetton prices on-chain - since TON contracts are limited by storage it is quite hard to implement such API fully on-chain. However it is possible to retrieve current prices via Request-Response pattern on some DEXes, refer to specific service documentation to learn more about it.For example, on the DeDust DEX it is possible to retrieve pool information on-chain using an internal message with the following TL-B schema: