Real-Time vs Offline Quotes
Grain offers two quoting and execution flows. Each has a separate Quote step (get a price) and Accept step (lock the trade).Real-time
Quote: The partner calls Grain’s API to get a live executable price for a specific transaction. Grain fetches a rate from a liquidity provider and returns it with an expiration window. Accept: The partner accepts the quote before it expires. The trade is executed immediately at the quoted rate. If the quote has expired, the partner must request a new one. Use real-time for lower-volume, higher-value transactions where the partner can afford an API call per transaction — e.g., a customer confirming a specific payment or hedge.Offline
Quote: The partner pre-fetches rates from Grain in bulk, then stores and applies them locally without calling Grain for every individual transaction. This avoids high API call volumes in scenarios where thousands of results need FX pricing simultaneously. Accept: When the end customer selects a specific transaction, the partner sends the accept call to Grain referencing the pre-fetched rate. Grain executes the trade based on the previously quoted price. Use offline for high-volume, display-heavy scenarios — e.g., a bedbank searching for hotels where each search result needs an FX-converted price. Calling Grain in real time for every hotel in every search would create excessive load. Instead, the partner fetches rates periodically and applies them locally.Quote Expiration
Every quote includes avalidUntilTs field — a timestamp indicating when the quote expires. After this time, the quote can no longer be accepted and the partner must request a new one.
Quote validity directly impacts pricing: a longer validity window means Grain carries more market risk while holding the price, which may result in a wider spread. Real-time quotes typically have short validity, while offline quotes may be valid for longer periods.
Fixed Side
When you request a quote you pin exactly one amount — the fixed side — and Grain derives the other from the rate. You can fix either side, or neither (deferring the amount to the Accept call).- To Amount fixed — you send
toCurrencyAmount(e.g. the listing or invoice amount you need to deliver). Grain derivesfromCurrencyAmount. - From Amount fixed — you send
fromCurrencyAmount(the amount your customer pays). Grain derivestoCurrencyAmount.
fixedSide field, so you always know which amount was specified and which was calculated.
Quote Direction
The quote is always expressed as fromCurrency per 1 toCurrency, regardless of which side you fix. Fixing either side gives the same rate — only multiply-vs-divide changes:Example
MXN → USD, quote = 20.6165. Fix To —toCurrencyAmount = 1,560 USD:
fromCurrencyAmount = 32,161.8 MXN:
Flexible Hedges
The hedges described so far lock a rate for a single exchange at maturity. Drawing part of one down earlier is a separate event with its own pricing, calculated from the forward points prevailing at the time it is taken. A flexible hedge locks one rate at creation and keeps it for every drawdown against that hedge. You can draw down as much as you like, as many times as you like, up to the hedge’s full amount, and every drawdown settles at the rate the hedge was booked at, however late in the hedge’s life you take it. This gives certainty across the whole life of the hedge rather than at a single point in it. You know what every payment out of that hedge will cost, from the day you book it.
A flexible hedge also reports its opening terms alongside its current ones. The
original* fields record the amounts, rate and due date it was booked at and never change, while the live fields show what is left to draw.