
gTrade · Acts onchain
Asks gTrade to shrink an open trade at the market: by an amount of its collateral at its leverage, which closes that part of the position, or by an amount of its leverage on the same collateral. The diamond's decreasePositionSize takes exactly one of the two, the other zero, and refuses a decrease that leaves less collateral than the pair's minimum fee or a leverage below the pair's floor. The oracle network answers in a later block, and the trader is paid the part closed with its share of the profit or loss, less fees. gTrade keys every book on its trader. A program on a Plug account apart from its wallet acts on the wallet's own book: the Plug account calls the diamond's delegatedTradingAction naming the wallet, which runs the call as the wallet, so collateral is pulled from and proceeds are paid to the wallet and every trade stays the wallet's. The wallet's one standing grant is setTradingDelegate naming its Plug account, sent with its approvals before the first program that needs it; a wallet that is its own socket trades as itself. Reach for it to take part of a position off as a target is reached, or to de-risk a trade when a condition turns.