11 MARKETSUSDG10 S GRIDNEXT FILL 00:10
//03_ Docs

TRADING

//01_ POSITIONS

A position is isolated, discrete and immutable. Its margin backs that position alone, so the most it can lose is its own margin. Margin and leverage are fixed when it opens: you cannot add margin, remove margin or close part of it. If you want more exposure, open a second position. If you want less, close this one and open a smaller one.

SIZE
size  = margin x leverage            (notional, in USDG)
entry = the fill price of the open request

A $100 margin at 10x is a $1,000 position. A 1% move in your favour is a $10 gain before settlement; a 1% move against you is a $10 loss.

//02_ LIMITS

LIMITVALUENOTE
Leverage2x to the market maxwhole numbers only; 100x crypto, 50x equities
Minimum margin$1per position
Maximum notional$100,000margin x leverage, per position
Open interest cap$250,000per market and per side, total notional
Pending closeoneper position
Close sizefulla close always closes the whole position

The notional limit sets the largest margin at each leverage: $50,000 at 2x, $10,000 at 10x, $2,000 at 50x and $1,000 at 100x. The open interest cap counts the notional of every open position on one side of a market; an open that would push it past $250,000 is refused. These are the launch values; the owner can change them within the bounds listed in admin powers.

//03_ REQUEST, THEN FILL

Every open and every close happens in two steps, so that no trade can fill at a price its sender could already see.

  1. 01
    Request. You call requestOpen or requestClose. The contract records the block time and computes the fill time: the first 10 s grid point strictly after it. For an open, the margin moves from available to locked.
  2. 02
    Fill. After the fill time, anyone calls execute with the RedStone price signed for exactly that timestamp. The keeper does it about 2 s after the grid point. The open becomes a position at that price, or the close is settled at it.
FILL TIME
fillTs = (floor(requestTime x 1000 / 10000) + 1) x 10000      (milliseconds)

request at 14:30:03  ->  fills at the price of 14:30:10
request at 14:30:10  ->  fills at the price of 14:30:20   (strictly after)

The fill time is at most 10 s after the block that records your request, and the keeper submits the execution a few seconds later. The app shows a countdown to the fill time of every pending request.

//04_ CHECKS

When you request an open, the contract checks the leverage, the minimum margin, the maximum notional, the open interest cap, your available balance, that the market is not retired, that new opens are not paused and, for an equity, that the session is open. A request that fails is refused on the spot.

At execution the market checks run again: retired market, paused opens, leverage, margin, notional and open interest. An open that fails one of them at its fill time is cancelled and its margin is returned to available; it does not revert and it costs you nothing but gas. The equity session is checked only when the request is made: a request sent at 15:59:55 fills at 16:00:00 and executes normally after the close.

//05_ CLOSING

requestClose closes the whole position at the next grid point. A position can have one pending close at a time. While the close is pending the position stays open and can still be liquidated; if it is, the pending close is dropped.

A close whose fill price is at or beyond the bust price settles as a liquidation: the full margin is lost. How a close is settled, win or loss, is set out step by step in wins and losses.

//06_ CANCELLING

A request cannot be cancelled before its time to live, 3,600 s after it was made. After that, any address can call cancelRequest on a request that was never executed: an open is refunded in full, a close is dropped and the position stays open. In practice this only happens if no price package exists for the fill time, or if the signed price fails a check (see the oracle).

The delay is deliberate. If a request could be withdrawn before its fill, the sender could wait to see the price and cancel the bad ones. With a fixed fill time and no early cancel, a request is a commitment.

//07_ TERMS ARE FIXED AT OPEN

Each position records the version of its market's settlement parameters at open: impact curve, profit cap and fees. It is settled under that version, whatever the owner changes later. Leverage limits, margin limits and caps apply to new requests only. The oracle settings (reference feed and band) apply to every price the contract checks, including the close of a position that is already open.

Credits: hands from Michelangelo, The Creation of Adam (detail), public domain, via Wikimedia Commons. Marks of the markets and integrations belong to their owners (sources, credits).