Skip to content

Commit

Permalink
price for placeLimitOrder CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jcompagni10 committed Apr 12, 2024
1 parent 367cb06 commit 75f62ad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
7 changes: 7 additions & 0 deletions x/dex/client/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const (
FlagMaxAmountOut = "max-amount-out"
FlagIncludePoolData = "include-pool-data"
FlagCalcWithdraw = "calc-withdraw"
FlagPrice = "price"
)

func FlagSetMaxAmountOut() *flag.FlagSet {
Expand All @@ -14,6 +15,12 @@ func FlagSetMaxAmountOut() *flag.FlagSet {
return fs
}

func FlagSetPrice() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.String(FlagPrice, "", "Sell price for limit order")
return fs
}

func FlagSetIncludePoolData() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
fs.Bool(FlagIncludePoolData, false, "Include pool data with response")
Expand Down
26 changes: 21 additions & 5 deletions x/dex/client/cli/tx_place_limit_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
math_utils "github.com/neutron-org/neutron/v3/utils/math"
"github.com/spf13/cobra"

"github.com/neutron-org/neutron/v3/x/dex/types"
Expand All @@ -18,7 +19,7 @@ import (
func CmdPlaceLimitOrder() *cobra.Command {
cmd := &cobra.Command{
//nolint:lll
Use: "place-limit-order [receiver] [token-in] [token-out] [tick-index] [amount-in] ?[order-type] ?[expirationTime] ?(--max-amout-out)",
Use: "place-limit-order [receiver] [token-in] [token-out] [tick-index] [amount-in] ?[order-type] ?[expirationTime] ?(--max-amout-out) ?(--price)",
Short: "Broadcast message PlaceLimitOrder",
Example: "place-limit-order alice tokenA tokenB [-10] tokenA 50 GOOD_TIL_TIME '01/02/2006 15:04:05' --max-amount-out 20 --from alice",
Args: cobra.RangeArgs(5, 7),
Expand Down Expand Up @@ -65,16 +66,29 @@ func CmdPlaceLimitOrder() *cobra.Command {
if err != nil {
return err
}
var maxAmountOutIntP *math.Int

var maxAmountOutInt math.Int
if maxAmountOutArg != "" {
maxAmountOutInt, ok := math.NewIntFromString(maxAmountOutArg)
maxAmountOutInt, ok = math.NewIntFromString(maxAmountOutArg)
if !ok {
return sdkerrors.Wrapf(
types.ErrIntOverflowTx,
"Integer overflow for max-amount-out",
)
}
maxAmountOutIntP = &maxAmountOutInt
}

priceArg, err := cmd.Flags().GetString(FlagPrice)
if err != nil {
return err
}

var priceDec math_utils.PrecDec
if maxAmountOutArg != "" {
priceDec, err = math_utils.NewPrecDecFromStr(priceArg)
if err != nil {
return err
}
}

clientCtx, err := client.GetClientTxContext(cmd)
Expand All @@ -91,7 +105,8 @@ func CmdPlaceLimitOrder() *cobra.Command {
amountInInt,
orderType,
goodTil,
maxAmountOutIntP,
&maxAmountOutInt,
&priceDec,
)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
Expand All @@ -100,6 +115,7 @@ func CmdPlaceLimitOrder() *cobra.Command {

flags.AddTxFlagsToCmd(cmd)
cmd.Flags().AddFlagSet(FlagSetMaxAmountOut())
cmd.Flags().AddFlagSet(FlagSetPrice())

return cmd
}

0 comments on commit 75f62ad

Please sign in to comment.