-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CT-834] new endpoint for stateful orders #1501
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||
import { Rpc } from "../../helpers"; | ||||
import * as _m0 from "protobufjs/minimal"; | ||||
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate"; | ||||
import { QueryGetClobPairRequest, QueryClobPairResponse, QueryAllClobPairRequest, QueryClobPairAllResponse, MevNodeToNodeCalculationRequest, MevNodeToNodeCalculationResponse, QueryEquityTierLimitConfigurationRequest, QueryEquityTierLimitConfigurationResponse, QueryBlockRateLimitConfigurationRequest, QueryBlockRateLimitConfigurationResponse, QueryLiquidationsConfigurationRequest, QueryLiquidationsConfigurationResponse, StreamOrderbookUpdatesRequest, StreamOrderbookUpdatesResponse } from "./query"; | ||||
import { QueryGetClobPairRequest, QueryClobPairResponse, QueryAllClobPairRequest, QueryClobPairAllResponse, MevNodeToNodeCalculationRequest, MevNodeToNodeCalculationResponse, QueryEquityTierLimitConfigurationRequest, QueryEquityTierLimitConfigurationResponse, QueryBlockRateLimitConfigurationRequest, QueryBlockRateLimitConfigurationResponse, QueryLiquidationsConfigurationRequest, QueryLiquidationsConfigurationResponse, QueryStatefulOrderRequest, QueryStatefulOrderResponse, StreamOrderbookUpdatesRequest, StreamOrderbookUpdatesResponse } from "./query"; | ||||
/** Query defines the gRPC querier service. */ | ||||
|
||||
export interface Query { | ||||
|
@@ -22,6 +22,9 @@ export interface Query { | |||
/** Queries LiquidationsConfiguration. */ | ||||
|
||||
liquidationsConfiguration(request?: QueryLiquidationsConfigurationRequest): Promise<QueryLiquidationsConfigurationResponse>; | ||||
/** Queries the stateful order for a given order id. */ | ||||
|
||||
statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse>; | ||||
/** | ||||
* Streams orderbook updates. Updates contain orderbook data | ||||
* such as order placements, updates, and fills. | ||||
|
@@ -40,6 +43,7 @@ export class QueryClientImpl implements Query { | |||
this.equityTierLimitConfiguration = this.equityTierLimitConfiguration.bind(this); | ||||
this.blockRateLimitConfiguration = this.blockRateLimitConfiguration.bind(this); | ||||
this.liquidationsConfiguration = this.liquidationsConfiguration.bind(this); | ||||
this.statefulOrder = this.statefulOrder.bind(this); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure consistent spacing around the method binding. - this.statefulOrder = this.statefulOrder.bind(this);
+ this.statefulOrder = this.statefulOrder.bind(this); Committable suggestion
Suggested change
|
||||
this.streamOrderbookUpdates = this.streamOrderbookUpdates.bind(this); | ||||
} | ||||
|
||||
|
@@ -81,6 +85,12 @@ export class QueryClientImpl implements Query { | |||
return promise.then(data => QueryLiquidationsConfigurationResponse.decode(new _m0.Reader(data))); | ||||
} | ||||
|
||||
statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse> { | ||||
const data = QueryStatefulOrderRequest.encode(request).finish(); | ||||
const promise = this.rpc.request("dydxprotocol.clob.Query", "StatefulOrder", data); | ||||
return promise.then(data => QueryStatefulOrderResponse.decode(new _m0.Reader(data))); | ||||
} | ||||
|
||||
streamOrderbookUpdates(request: StreamOrderbookUpdatesRequest): Promise<StreamOrderbookUpdatesResponse> { | ||||
const data = StreamOrderbookUpdatesRequest.encode(request).finish(); | ||||
const promise = this.rpc.request("dydxprotocol.clob.Query", "StreamOrderbookUpdates", data); | ||||
|
@@ -116,6 +126,10 @@ export const createRpcQueryExtension = (base: QueryClient) => { | |||
return queryService.liquidationsConfiguration(request); | ||||
}, | ||||
|
||||
statefulOrder(request: QueryStatefulOrderRequest): Promise<QueryStatefulOrderResponse> { | ||||
return queryService.statefulOrder(request); | ||||
}, | ||||
|
||||
streamOrderbookUpdates(request: StreamOrderbookUpdatesRequest): Promise<StreamOrderbookUpdatesResponse> { | ||||
return queryService.streamOrderbookUpdates(request); | ||||
} | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,10 @@ service Query { | |
option (google.api.http).get = "/dydxprotocol/clob/liquidations_config"; | ||
} | ||
|
||
// Queries the stateful order for a given order id. | ||
rpc StatefulOrder(QueryStatefulOrderRequest) | ||
returns (QueryStatefulOrderResponse) {} | ||
|
||
// GRPC Streams | ||
|
||
// Streams orderbook updates. Updates contain orderbook data | ||
|
@@ -127,6 +131,25 @@ message QueryBlockRateLimitConfigurationResponse { | |
[ (gogoproto.nullable) = false ]; | ||
} | ||
|
||
// QueryStatefulOrderRequest is a request message for StatefulOrder. | ||
message QueryStatefulOrderRequest { | ||
// Order id to query. | ||
OrderId order_id = 1 [ (gogoproto.nullable) = false ]; | ||
} | ||
|
||
// QueryStatefulOrderResponse is a response message that contains the stateful | ||
// order. | ||
message QueryStatefulOrderResponse { | ||
// Stateful order placement. | ||
LongTermOrderPlacement order_placement = 1 [ (gogoproto.nullable) = false ]; | ||
|
||
// Fill amounts. | ||
uint64 fill_amount = 2; | ||
|
||
// Triggered status. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assuming this is false for regular stateful orders |
||
bool triggered = 3; | ||
} | ||
|
||
// QueryLiquidationsConfigurationRequest is a request message for | ||
// LiquidationsConfiguration. | ||
message QueryLiquidationsConfigurationRequest {} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types" | ||
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types" | ||
"github.com/spf13/cast" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func CmdQueryStatefulOrder() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "stateful-order subaccount_owner subaccount_number client_id clob_pair_id order_flags", | ||
Short: "queries a stateful order by id", | ||
Args: cobra.ExactArgs(5), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
owner := args[0] | ||
|
||
number, err := cast.ToUint32E(args[1]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clientId, err := cast.ToUint32E(args[2]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
clobPairId, err := cast.ToUint32E(args[3]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
orderFlag, err := cast.ToUint32E(args[4]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we do some check on order flag it can only be like 32 or 64 i think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to over-engineer this. non 32/64 values will just return not found |
||
if err != nil { | ||
return err | ||
} | ||
|
||
req := &types.QueryStatefulOrderRequest{ | ||
OrderId: types.OrderId{ | ||
SubaccountId: satypes.SubaccountId{ | ||
Owner: owner, | ||
Number: number, | ||
}, | ||
ClientId: clientId, | ||
ClobPairId: clobPairId, | ||
OrderFlags: orderFlag, | ||
}, | ||
} | ||
|
||
res, err := queryClient.StatefulOrder(context.Background(), req) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a period at the end of the comment for consistency.
Committable suggestion