-
Notifications
You must be signed in to change notification settings - Fork 25
3. Margin Trading
The collateralized margin trading protocol allows users to trade leveraged long or short Forex pairs such as EURUSD, commodities such as XAUUSD, stocks such as APPL, and crypto-assets such as BTC-USD.
There is no order book, each trade initiated by the trader is instantaneously executed by the chosen liquidity pool. Future versions will allow trades split across multiple pools for the best price/risk, and currently, you can only trade with one pool at a time. Liquidity pools will enjoy earning spreads of each trade, but the catch is that they need to hedge the positions somehow and comply with a set of risk parameters set out by the protocol to safeguard the interests of all traders. Read more here.
The guide below will illustrate the following functionalities
- Check available margin liquidity pools
- Check Check Pool Balance & Risks
- Check pricing
- Deposit balance into the chosen liquidity pool
- Open Position, Close Position
- Check trader profits/losses and risks
Query chain state
baseLiquidityPoolsForMargin.nextPoolId(): LiquidityPoolId
to check available pools.
Query chain state marginLiquidityPools.tradingPairOptions(TradingPair)
to check available pairs
Query chain state marginLiquidityPools.poolTradingPairOptions(LiquidityPoolId, TradingPair)
to check available leverage
Query chain state marginProtocol.balances(LiquidityPoolId)
to check balance.
To see the current Equity to Net Position Ratio (ENP) & Equity to Longest Leg Ratio (ELL), you can use RPC call:
curl -H 'Content-Type: application/json' --data \
'{ \
"jsonrpc":"2.0", \
"method":"margin_poolState", \
"params":[<POOL_ID>], "id":1 \
}' \
<ENDPOINT_URL>
Replace <POOL_ID>
and <ENDPOINT_URL>
with valid data.
Read more on Liquidity Pool risk profiles here.
Use RPC
oracle.getAllValues()
for up-to-date oracle pricing.
Each liquidity pool would employ varied bid and ask spread for given margin trading pairs.
Query chain state marginLiquidityPools.liquidityPoolOptions(LiquidityPoolId, TradingPair)
to check spreads.
bidPrice = price - bidSpread
askPrice = price + askSpread
Before trading, you will need to deposit a certain amount of USD into a pool. You can also withdraw the free balance (the amount that has yet to be used as margins) at any time.
Use
marginProtocol.openPosition(pool_id, pair, leverage, leveraged_amount, price)
to open a leveraged position.
Note the price
for a long position is the maximum price you can accept, while for a short position is the minimum you can accept.
Use
marginProtocol.closePosition(position_id, price)
to close a leveraged position.
Note that the price
for a long position is the minimum price you can accept, while for a short position is the maximum you can accept.
To obtain the trader's risk profile you call:
curl -H 'Content-Type: application/json' \
--data '{ \
"jsonrpc":"2.0", \
"method":"margin_traderState", \
"params":["<TRADER_ADDRESS>", 0], "id":1 \
}' \
<ENDPOINT_URL>
Replace <TRADER_ADDRESS>
and <ENDPOINT_URL>
with valid data.
More details here on trader's risk profile.
Navigate to the Margin Trading
page. You need to deposit some balance before trading, as it will be served as margins.
The main page displays all liquidity pools available, future versions will abstract away the complexity and only show an aggregated view. But this version allows users to manually choose and trade with a particular liquidity provider based on their preference e.g. spread, risk profile etc.
- Click on
Fast Buy/Sell
button - Click on
Deposit
button to deposit USD (ticker: aUSD powered by Acala Dollar)
From the main Margin Trading
page
- Click on
Fast Buy/Sell
button - Choose leverage e.g. x10
- Enter leveraged amount e.g. 100 aUSD. Note that this is the leveraged amount, the margin required for opening this position (say for x10 leverage) would be 10 aUSD
- Then go
Buy/Long
orSell/Short
Click on a trading pair of interest e.g. fEURUSD
to go into the advanced trading page.
Be aware of your risk profile e.g. your margin level will need to be above Margin Call Threshold
, otherwise no new positions are allowed. If your margin level falls below the Stop Out Threshold
, then force closure will happen.
Pool Risk Profile
To understand a liquidity pool's risk profile, read more here.
Trader Risk Profile
To understand a trader's risk profile, read more here.