Vault conversion rate
Get the best exchange rate the gateway accepts now for a vault investment or redemption that converts currency.
On this page
Write a small program that calls `vault.vault_conversion_rate` on Grvt {environment} {using}.
Target environment: {environment} (chain ID {chainId}). Recorded signing cases keep their original environment.
{executionGuidance}
Read this first: {origin}/bundle/reference/rpc/vault_conversion_rate.md (~55 KB, plain Markdown: this page plus the AGENTS.md rules, Authentication and sessions, Errors and retries, Python SDK, Environments).
Fetch other pages from the index at {origin}/llms.txt only as you need them. {origin}/downloads/contract.json is a machine-readable contract for tools, not for reading.
Rules: follow AGENTS.md; do not send requests without the user asking you to; read credentials from environment variables; never retry writes automatically; show me the code and how to run it. URLs and generated code samples on this page: Testnet (chain ID 326). Other code on this page doesn't change: it stays on testnet until you switch it in your code. Tutorials, signing cases and live tools always use testnet.
Sign this rate as exchange_rate: any rate at or below it passes while the quote is valid.
| SDK | client. |
|---|---|
| HTTP | POST https:/, or / for lite names (the SDKs' default) |
| WebSocket | method v1/ on wss:/, or /ws/lite for lite names |
| Auth | Session required (Authentication) |
| Retries | Read: the SDKs retry retryable errors (rules) |
| Contract id | vault. (RPCVaultConversionRateV1) |
Request
Body type ApiVaultConversionRateRequest. Fields the server fills are left out.
- The currency converted from.
- The currency converted into.
- Optional amount of
fromCurrency. When set, the response estimates what it converts into.
Response
Body type ApiVaultConversionRateResponse (the same object is the JSON-RPC result over WebSocket).
- The currency converted from.
- The currency converted into.
- The highest rate accepted now,
toCurrencyper unit offromCurrency, floored to 9 decimal places. It is 1 when both currencies are the same. - The current spot rate from the latest oracle prices, 9 decimal places.
- The conversion fee configured for the pair, in centibeeps (1 = 0.0001%).
- The length of the window the rate is the highest of, in seconds.
- When the price sample the rate comes from leaves the window, in unix nanoseconds. Show a validity no longer than this.
- The time of the newest oracle price the rate uses, in unix nanoseconds.
- The amount of
fromCurrencythe request named, if any. - What
fromNumTokensconverts into atexchangeRate, floored totoCurrencydecimals. Omitted withoutfromNumTokens.
Errors
Errors come back as {"code", "message", "status"} (lite {"c", "m", "s"}) with the HTTP status. Codes this call can return (all error codes):
7019VaultConversionPriceStale400- A price this conversion needs is stale or not available yet. Please try again later.
7801CurrencyNotConvertible400- This currency is not enabled for stable coin convert.
7802PriceOutOfConvertBand400- The index price of one of the currencies is outside the permitted convert band. Please try again later.
7805InexactConversion400- This amount cannot be converted exactly between the two currencies’ decimals. Please adjust the amount.
Plus 8 errors any call can return
1000Unauthorized401- You need to authenticate prior to using this functionality
1001Forbidden403- You are not authorized to access this functionality
1002InternalServer500- Internal Server Error
1003InvalidRequest400- Request could not be processed due to malformed syntax
1006RateLimit429retryable- You have surpassed the allocated rate limit for your tier
1007UnsupportedCurrency404- The currency you are requesting for is not currently supported
1008IPNotWhitelisted401- Your IP has not been whitelisted for access
1009APIEndpointTemporarilyDeactivated503retryable- We are temporarily deactivating this API endpoint, please try again later
Example
Example code
import os
from grvt import Grvt
with Grvt(
env=os.environ.get("GRVT_ENV", "testnet"),
api_key=os.environ["GRVT_API_KEY"],
) as client:
resp = client.vault_conversion_rate(
from_currency="USDT",
to_currency="USDC",
)
print(resp)
Raw HTTP (set GRVT_DOMAIN, see Environments; GRVT_COOKIE and GRVT_ACCOUNT_ID come from login):
With full field names:
curl -sS "https://trades.testnet.grvt.io/full/v1/vault_conversion_rate" \
-H "Content-Type: application/json" \
-H "Cookie: gravity=$GRVT_COOKIE" \
-H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \
--data @- <<EOF
{
"from_currency": "USDT",
"to_currency": "USDC"
}
EOFWith lite field names:
curl -sS "https://trades.testnet.grvt.io/lite/v1/vault_conversion_rate" \
-H "Content-Type: application/json" \
-H "Cookie: gravity=$GRVT_COOKIE" \
-H "X-Grvt-Account-Id: $GRVT_ACCOUNT_ID" \
--data @- <<EOF
{
"fc": "USDT",
"tc": "USDC"
}
EOF