-
Notifications
You must be signed in to change notification settings - Fork 1
/
query_get_order_count.go
52 lines (44 loc) · 1.3 KB
/
query_get_order_count.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package query
import (
"context"
"fmt"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/fibonacci-chain/core/x/dex/types"
"github.com/spf13/cobra"
)
func CmdGetOrderCount() *cobra.Command {
cmd := &cobra.Command{
Use: "get-order-count [contract] [price denom] [asset denom] [LONG|SHORT] [price]",
Short: "get number of orders at a price leve",
Args: cobra.ExactArgs(5),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
var direction types.PositionDirection
switch args[3] {
case "LONG":
direction = types.PositionDirection_LONG
case "SHORT":
direction = types.PositionDirection_SHORT
default:
return fmt.Errorf("unknown direction %s", args[3])
}
price := sdk.MustNewDecFromStr(args[4])
res, err := queryClient.GetOrderCount(context.Background(), &types.QueryGetOrderCountRequest{
ContractAddr: args[0],
PriceDenom: args[1],
AssetDenom: args[2],
PositionDirection: direction,
Price: &price,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}