
gTrade · Acts onchain
Places an order on gTrade, Gains Network's perpetuals exchange, to go long or short one of its pairs with a collateral it lists, at a chosen leverage. The diamond's openTrade records the order on the trader's book and pulls the collateral. A market order asks for the price stated and accepts a fill within the slippage of it; a limit order opens once the price reaches the trigger and a stop order once it moves through it. The take profit and stop loss are prices, zero for none. The program reads the index the diamond lists the collateral token at when it runs. gTrade refuses an order below the pair's minimum collateral, outside its leverage bounds, with a price impact too high for the leverage, or with a take profit or stop loss on the wrong side of the price. gTrade fills a market order asynchronously: the program's transaction places it and escrows its collateral, and the oracle network answers in a later block with the price the trade opens at, opening it only within the slippage of the price asked for and returning the collateral otherwise. The order exists as a pending order until then; the trade exists only once the answer lands. 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 open a position when a condition is met, coiling the collateral from a swap or a withdrawal, and pair it with the trade and counter reads to act once the trade exists.
On other protocols · 1