Skip to content

Commit

Permalink
[Tradeshield]: Close order (#897)
Browse files Browse the repository at this point in the history
* updates

* fix tests

* fix migration
  • Loading branch information
amityadav0 authored Nov 1, 2024
1 parent eca0a53 commit 0a5c637
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 32 deletions.
30 changes: 13 additions & 17 deletions x/tradeshield/client/cli/tx_perpetual_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (

func CmdCreatePerpetualOpenOrder() *cobra.Command {
cmd := &cobra.Command{
Use: "create-perpetual-open-order [order-type] [position] [leverage] [pool-id] [trading-asset] [collateral] [trigger-price]",
Use: "create-perpetual-open-order [position] [leverage] [pool-id] [trading-asset] [collateral] [trigger-price]",
Short: "Create a new perpetual open order",
Args: cobra.ExactArgs(7),
Args: cobra.ExactArgs(6),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -31,30 +31,28 @@ func CmdCreatePerpetualOpenOrder() *cobra.Command {
return errors.New("signer address is missing")
}

orderType := types.GetPerpetualOrderTypeFromString(args[0])
position := types.PerpetualPosition(perptypes.GetPositionFromString(args[0]))

position := types.PerpetualPosition(perptypes.GetPositionFromString(args[1]))

leverage, err := sdk.NewDecFromStr(args[2])
leverage, err := sdk.NewDecFromStr(args[1])
if err != nil {
return err
}

poolId, err := strconv.ParseUint(args[3], 10, 64)
poolId, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
}

tradingAsset := args[4]
tradingAsset := args[3]

collateral, err := sdk.ParseCoinNormalized(args[5])
collateral, err := sdk.ParseCoinNormalized(args[4])
if err != nil {
return err
}

triggerPrice := types.TriggerPrice{
TradingAssetDenom: tradingAsset,
Rate: sdk.MustNewDecFromStr(args[6]),
Rate: sdk.MustNewDecFromStr(args[5]),
}

takeProfitPriceStr, err := cmd.Flags().GetString(perpcli.FlagTakeProfitPrice)
Expand Down Expand Up @@ -89,7 +87,6 @@ func CmdCreatePerpetualOpenOrder() *cobra.Command {

msg := types.NewMsgCreatePerpetualOpenOrder(
signer.String(),
orderType,
triggerPrice,
collateral,
tradingAsset,
Expand All @@ -116,30 +113,29 @@ func CmdCreatePerpetualOpenOrder() *cobra.Command {

func CmdCreatePerpetualCloseOrder() *cobra.Command {
cmd := &cobra.Command{
Use: "create-perpetual-close-order [order-type] [trigger-price] [position-id]",
Use: "create-perpetual-close-order [trigger-price] [position-id]",
Short: "Create a new perpetual close order",
Args: cobra.ExactArgs(8),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

addr := clientCtx.GetFromAddress().String()
orderType := types.GetPerpetualOrderTypeFromString(args[0])

// trading asset will be filled by message handler
triggerPrice := types.TriggerPrice{
TradingAssetDenom: "",
Rate: sdk.MustNewDecFromStr(args[1]),
Rate: sdk.MustNewDecFromStr(args[0]),
}

positionId, err := strconv.ParseUint(args[2], 10, 64)
positionId, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgCreatePerpetualCloseOrder(addr, orderType, triggerPrice, positionId)
msg := types.NewMsgCreatePerpetualCloseOrder(addr, triggerPrice, positionId)
if err := msg.ValidateBasic(); err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion x/tradeshield/client/cli/tx_perpetual_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestCreatePerpetualOpenOrder(t *testing.T) {
fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation),
fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync),
fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin(net.Config.BondDenom, sdkmath.NewInt(10))).String()),
"limitopen", // order type
"long", // position
"10", // leverage
"1", // pool id
Expand Down
2 changes: 2 additions & 0 deletions x/tradeshield/migrations/v4_migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ func (m Migrator) V4Migration(ctx sdk.Context) error {
for _, order := range orders {
m.keeper.RemovePendingPerpetualOrder(ctx, order.OrderId)
}
m.keeper.DeleteAllPendingPerpetualOrder(ctx)
m.keeper.DeleteAllPendingSpotOrder(ctx)

return nil
}
11 changes: 0 additions & 11 deletions x/tradeshield/migrations/v5_migrator.go

This file was deleted.

2 changes: 1 addition & 1 deletion x/tradeshield/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := migrations.NewMigrator(am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 4, m.V5Migration)
err := cfg.RegisterMigration(types.ModuleName, 3, m.V4Migration)
if err != nil {
panic(err)
}
Expand Down
2 changes: 0 additions & 2 deletions x/tradeshield/types/messages_pending_perpetual_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ var _ sdk.Msg = &MsgCreatePerpetualOpenOrder{}

func NewMsgCreatePerpetualOpenOrder(
ownerAddress string,
orderType PerpetualOrderType,
triggerPrice TriggerPrice,
collateral sdk.Coin,
tradingAsset string,
Expand Down Expand Up @@ -119,7 +118,6 @@ var _ sdk.Msg = &MsgCreatePerpetualOpenOrder{}

func NewMsgCreatePerpetualCloseOrder(
ownerAddress string,
orderType PerpetualOrderType,
triggerPrice TriggerPrice,
positionId uint64,
) *MsgCreatePerpetualCloseOrder {
Expand Down

0 comments on commit 0a5c637

Please sign in to comment.