-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add price api #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add price api #636
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5130d28
add stub
Kaladin13 41ca614
fill article
Kaladin13 24738e8
Merge branch 'main' into price-api
Kaladin13 eab08e2
real time and fixes
Kaladin13 a60a900
add example
Kaladin13 c1eac84
Merge remote-tracking branch 'origin/price-api' into price-api
Kaladin13 fe5134b
Merge branch 'main' into price-api
Kaladin13 f8bc1a0
Update ecosystem/rpc/price.mdx
anton-trunov 34702dd
Update ecosystem/rpc/price.mdx
anton-trunov 2edef2d
Update ecosystem/rpc/price.mdx
anton-trunov 57cb27d
Update ecosystem/rpc/price.mdx
anton-trunov 91ef82f
Merge branch 'main' into price-api
anton-trunov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,7 +244,8 @@ | |
} | ||
} | ||
] | ||
} | ||
}, | ||
"ecosystem/rpc/price" | ||
] | ||
}, | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: "Jetton prices API" | ||
--- | ||
|
||
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](https://www.coinbase.com/learn/advanced-trading/what-is-an-automated-market-maker-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. | ||
|
||
## Off-chain API | ||
|
||
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: | ||
|
||
- [dTon](https://docs.dton.io/about-pnl) | ||
- [CoinGecko](https://www.coingecko.com/en/api/ton) | ||
- [Dyor.io](https://dyor.io/tonapi) | ||
|
||
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](https://docs.coingecko.com/websocket). | ||
|
||
## On-chain API | ||
|
||
Currently it is not possible to retrieve **historical** jetton prices on-chain - since TON contracts [are limited by storage](/guidebook/from-ethereum#limited-contract-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](https://dedust.io) DEX it is possible to retrieve pool information on-chain using an internal message with the following [TL-B](/language/TL-B/overview) schema: | ||
|
||
```tlb | ||
provide_pool_state#6e24728d query_id:uint64 include_assets:Bool = InMsgBody; | ||
|
||
take_pool_state#bddd4954 query_id:uint64 reserve0:Coins reserve1:Coins total_supply:Coins | ||
assets:(Maybe ^[ asset0:Asset asset1:Asset ]) = InMsgBody; | ||
``` | ||
|
||
Here is a smart contract snippet in [Tolk](/language/tolk) illustrating how you can send the 'provide' message: | ||
|
||
```tolk | ||
struct (0x6e24728d) ProvideDeDustPool { | ||
queryId: uint64 | ||
doIncludeAssets: bool | ||
} | ||
|
||
fun main() { | ||
val requestDeDustPoolInfoMsg = createMessage({ | ||
body: ProvideDeDustPool { queryId: 1, doIncludeAssets: true }, | ||
bounce: true, | ||
dest: dedustPoolAddress, | ||
value: 0, | ||
}); | ||
|
||
requestDeDustPoolInfoMsg.send(SEND_MODE_CARRY_ALL_REMAINING_MESSAGE_VALUE); | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.