-
Notifications
You must be signed in to change notification settings - Fork 44
/
open_short.go
28 lines (21 loc) · 1.11 KB
/
open_short.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/perpetual/types"
)
func (k Keeper) OpenShort(ctx sdk.Context, poolId uint64, msg *types.MsgOpen, baseCurrency string, isBroker bool) (*types.MTP, error) {
// Determine the maximum leverage available and compute the effective leverage to be used.
maxLeverage := k.OpenShortChecker.GetMaxLeverageParam(ctx)
leverage := sdk.MinDec(msg.Leverage, maxLeverage)
// Calculate the eta value.
eta := leverage.Sub(sdk.OneDec())
// Convert the collateral amount into a decimal format.
collateralAmountDec := sdk.NewDecFromBigInt(msg.Collateral.Amount.BigInt())
// Define the assets
liabilitiesAsset := msg.TradingAsset
custodyAsset := baseCurrency
// Initialize a new Perpetual Trading Position (MTP).
mtp := types.NewMTP(msg.Creator, msg.Collateral.Denom, msg.TradingAsset, liabilitiesAsset, custodyAsset, msg.Position, leverage, msg.TakeProfitPrice, poolId)
// Call the function to process the open short logic.
return k.ProcessOpenShort(ctx, mtp, leverage, eta, collateralAmountDec, poolId, msg, baseCurrency, isBroker)
}