Developers

Vault conversion rate

Get the best exchange rate the gateway accepts now for a vault investment or redemption that converts currency.

On this page

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.

SDKclient.vault_conversion_rate(...)
HTTPPOST https://trades.testnet.grvt.io/full/v1/vault_conversion_rate, or /lite/v1/vault_conversion_rate for lite names (the SDKs' default)
WebSocketmethod v1/vault_conversion_rate on wss://trades.testnet.grvt.io/ws/full, or /ws/lite for lite names
AuthSession required (Authentication)
RetriesRead: the SDKs retry retryable errors (rules)
Contract idvault.vault_conversion_rate (RPCVaultConversionRateV1)

Request

Body type ApiVaultConversionRateRequest. Fields the server fills are left out.

  • from_currencylite name fcstringrequired#
    The currency converted from.
  • to_currencylite name tcstringrequired#
    The currency converted into.
  • from_num_tokenslite name fnstringoptionaldefault 0#
    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).

  • from_currencylite name fcstringrequired#
    The currency converted from.
  • to_currencylite name tcstringrequired#
    The currency converted into.
  • exchange_ratelite name erstringrequired#
    The highest rate accepted now, toCurrency per unit of fromCurrency, floored to 9 decimal places. It is 1 when both currencies are the same.
  • spot_ratelite name srstringrequired#
    The current spot rate from the latest oracle prices, 9 decimal places.
  • fee_rate_centi_beepslite name frinteger (uint32)required#
    The conversion fee configured for the pair, in centibeeps (1 = 0.0001%).
  • window_secondslite name wsinteger (uint32)required#
    The length of the window the rate is the highest of, in seconds.
  • valid_untillite name vustring (int64 unix ns)required#
    When the price sample the rate comes from leaves the window, in unix nanoseconds. Show a validity no longer than this.
  • event_timelite name etstring (int64 unix ns)required#
    The time of the newest oracle price the rate uses, in unix nanoseconds.
  • from_num_tokenslite name fnstringoptional#
    The amount of fromCurrency the request named, if any.
  • to_num_tokenslite name tnstringoptional#
    What fromNumTokens converts into at exchangeRate, floored to toCurrency decimals. Omitted without fromNumTokens.

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"
}
EOF

With 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
Build request
esc

↑ ↓ move↵ open⇧↵ open .mdTry an error code like 2002

Keyboard shortcuts

⌘ K
Search the docs
/
Search
l
Next code language (Python → TypeScript → Go → Rust → curl → WebSocket)
j / k
Next / previous page
t
Light / dark theme
?
This help
Esc
Close dialogs and drawers