mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
gctrpc/order manager: Add ModifyOrder endpoint (#724)
* gctcli: modifyorder stubs * gctcli: add ModifyOrderRequest and ModifyOrderResponse in rpc.proto * gctcli: regenerate rpc.pb.go after the addition of ModifyOrder structs * gctrpc: add ModifyOrder() and regenerate dependent files * gctcli: modifyorder command now uses newly generated ModifyOrder() RPC * exchanges/order/orders.go: use time.Time.Equal() instead of == * gctrpc: update ModifyOrderRequest and ModifyResponse and regenerate gRPC * gctcli/commands: rework modifyorder * engine: implement RPCServer.ModifyOrder * engine: commit an initial version OrderManager.Modify(), still does not update state of managed orders * engine: OrderManager.Modify now updates the inner state of managed orders, but introduces race conditions, needs fixes * engine/order_manager.go: comply with golangci-lint * gctcli: fix getOrderCommand.ArgsUsage * gctcli: fix getModifyOrderCommand args and ArgsUsage * engine: OrderManager.Modify() now correctly updates price of modified order * engine: RPCServer.ModifyOrder now uses checkParams() as advised * exchanges: (1) IBotExchange.ModifyOrder now returns a Modify struct, (2) all exchanges are updated to comply with that change * exchanges/order: Detail.UpdateOrderFromModify also updates the ID * engine/order_manager: add store.modifyExisting() and use it in OrderManager.Modify to update (on success) the state of the modified order * exchanges: Bitfinex.ModifyOrder() now returns the ID in case of an error * engine: OrdetManager.Modify() now emits an order event * exchanges/bithumb: proper order.payment_currency key * engine/order_manager: populate more Modify fields as they are needed by (some) exchanges, add comments * engine: test OrderManager.Modify() * engine: test store.modifyExisting() * engine: write a docstring for store.modifyExisting * engine: OrderManager.Modify() now also sets Modify.Price and Modify.Amount in case of zero values * engine: TestOrderManager_Modify() now verify the effects of price and/or amount set to 0 * engine: OrderManger.Modify() now uses the commsManager to let observers know of errors * engine: TestOrderManager_Modify() uses t.Fatal() * engine: TestOrderManager_Modify() and TestStore_modifyOrder() supply t.Error() with proper messages * exchanges/order_manager_test: fix a golangci-lint complaint * engine/order_manager: fix an error comparison bug and simplify * gctcli/commands: check if either price or amount is set, otherwise we would waste an API call
This commit is contained in:
1907
gctrpc/rpc.pb.go
1907
gctrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@@ -2773,6 +2773,42 @@ func local_request_GoCryptoTrader_GetManagedOrders_0(ctx context.Context, marsha
|
||||
|
||||
}
|
||||
|
||||
var (
|
||||
filter_GoCryptoTrader_ModifyOrder_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
|
||||
)
|
||||
|
||||
func request_GoCryptoTrader_ModifyOrder_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ModifyOrderRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_ModifyOrder_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := client.ModifyOrder(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_GoCryptoTrader_ModifyOrder_0(ctx context.Context, marshaler runtime.Marshaler, server GoCryptoTraderServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq ModifyOrderRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
if err := req.ParseForm(); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_GoCryptoTrader_ModifyOrder_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
|
||||
msg, err := server.ModifyOrder(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterGoCryptoTraderHandlerServer registers the http handlers for service GoCryptoTrader to "mux".
|
||||
// UnaryRPC :call GoCryptoTraderServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
@@ -4684,6 +4720,29 @@ func RegisterGoCryptoTraderHandlerServer(ctx context.Context, mux *runtime.Serve
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTrader_ModifyOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
var stream runtime.ServerTransportStream
|
||||
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/gctrpc.GoCryptoTrader/ModifyOrder", runtime.WithHTTPPathPattern("/v1/modifyorder"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := local_request_GoCryptoTrader_ModifyOrder_0(rctx, inboundMarshaler, server, req, pathParams)
|
||||
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTrader_ModifyOrder_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6465,6 +6524,26 @@ func RegisterGoCryptoTraderHandlerClient(ctx context.Context, mux *runtime.Serve
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_GoCryptoTrader_ModifyOrder_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||
ctx, cancel := context.WithCancel(req.Context())
|
||||
defer cancel()
|
||||
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/gctrpc.GoCryptoTrader/ModifyOrder", runtime.WithHTTPPathPattern("/v1/modifyorder"))
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
resp, md, err := request_GoCryptoTrader_ModifyOrder_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||
if err != nil {
|
||||
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||
return
|
||||
}
|
||||
|
||||
forward_GoCryptoTrader_ModifyOrder_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6642,6 +6721,8 @@ var (
|
||||
pattern_GoCryptoTrader_UpdateDataHistoryJobPrerequisite_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "updatedatahistoryjobprerequisite"}, ""))
|
||||
|
||||
pattern_GoCryptoTrader_GetManagedOrders_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getmanagedorders"}, ""))
|
||||
|
||||
pattern_GoCryptoTrader_ModifyOrder_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "modifyorder"}, ""))
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -6818,4 +6899,6 @@ var (
|
||||
forward_GoCryptoTrader_UpdateDataHistoryJobPrerequisite_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_GoCryptoTrader_GetManagedOrders_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_GoCryptoTrader_ModifyOrder_0 = runtime.ForwardResponseMessage
|
||||
)
|
||||
|
||||
@@ -947,6 +947,18 @@ message UpdateDataHistoryJobPrerequisiteRequest {
|
||||
string prerequisite_job_nickname = 2;
|
||||
}
|
||||
|
||||
message ModifyOrderRequest {
|
||||
string exchange = 1;
|
||||
string order_id = 2;
|
||||
CurrencyPair pair = 3;
|
||||
string asset = 4;
|
||||
double amount = 5;
|
||||
double price = 6;
|
||||
}
|
||||
|
||||
message ModifyOrderResponse {
|
||||
string modified_order_id = 1;
|
||||
}
|
||||
|
||||
service GoCryptoTrader {
|
||||
rpc GetInfo (GetInfoRequest) returns (GetInfoResponse) {
|
||||
@@ -1500,4 +1512,9 @@ service GoCryptoTrader {
|
||||
body: "*"
|
||||
};
|
||||
}
|
||||
}
|
||||
rpc ModifyOrder (ModifyOrderRequest) returns (ModifyOrderResponse) {
|
||||
option (google.api.http) = {
|
||||
get: "/v1/modifyorder"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2114,6 +2114,80 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/modifyorder": {
|
||||
"get": {
|
||||
"operationId": "GoCryptoTrader_ModifyOrder",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/gctrpcModifyOrderResponse"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "An unexpected error response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/rpcStatus"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "exchange",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "orderId",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.delimiter",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.base",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "pair.quote",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "asset",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "amount",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
},
|
||||
{
|
||||
"name": "price",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "number",
|
||||
"format": "double"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"GoCryptoTrader"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/v1/removeevent": {
|
||||
"post": {
|
||||
"operationId": "GoCryptoTrader_RemoveEvent",
|
||||
@@ -4033,6 +4107,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"gctrpcModifyOrderResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"modifiedOrderId": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"gctrpcOfflineCoinSummary": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -105,6 +105,7 @@ type GoCryptoTraderClient interface {
|
||||
SetDataHistoryJobStatus(ctx context.Context, in *SetDataHistoryJobStatusRequest, opts ...grpc.CallOption) (*GenericResponse, error)
|
||||
UpdateDataHistoryJobPrerequisite(ctx context.Context, in *UpdateDataHistoryJobPrerequisiteRequest, opts ...grpc.CallOption) (*GenericResponse, error)
|
||||
GetManagedOrders(ctx context.Context, in *GetOrdersRequest, opts ...grpc.CallOption) (*GetOrdersResponse, error)
|
||||
ModifyOrder(ctx context.Context, in *ModifyOrderRequest, opts ...grpc.CallOption) (*ModifyOrderResponse, error)
|
||||
}
|
||||
|
||||
type goCryptoTraderClient struct {
|
||||
@@ -1036,6 +1037,15 @@ func (c *goCryptoTraderClient) GetManagedOrders(ctx context.Context, in *GetOrde
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *goCryptoTraderClient) ModifyOrder(ctx context.Context, in *ModifyOrderRequest, opts ...grpc.CallOption) (*ModifyOrderResponse, error) {
|
||||
out := new(ModifyOrderResponse)
|
||||
err := c.cc.Invoke(ctx, "/gctrpc.GoCryptoTrader/ModifyOrder", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GoCryptoTraderServer is the server API for GoCryptoTrader service.
|
||||
// All implementations must embed UnimplementedGoCryptoTraderServer
|
||||
// for forward compatibility
|
||||
@@ -1127,6 +1137,7 @@ type GoCryptoTraderServer interface {
|
||||
SetDataHistoryJobStatus(context.Context, *SetDataHistoryJobStatusRequest) (*GenericResponse, error)
|
||||
UpdateDataHistoryJobPrerequisite(context.Context, *UpdateDataHistoryJobPrerequisiteRequest) (*GenericResponse, error)
|
||||
GetManagedOrders(context.Context, *GetOrdersRequest) (*GetOrdersResponse, error)
|
||||
ModifyOrder(context.Context, *ModifyOrderRequest) (*ModifyOrderResponse, error)
|
||||
mustEmbedUnimplementedGoCryptoTraderServer()
|
||||
}
|
||||
|
||||
@@ -1395,6 +1406,9 @@ func (UnimplementedGoCryptoTraderServer) UpdateDataHistoryJobPrerequisite(contex
|
||||
func (UnimplementedGoCryptoTraderServer) GetManagedOrders(context.Context, *GetOrdersRequest) (*GetOrdersResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetManagedOrders not implemented")
|
||||
}
|
||||
func (UnimplementedGoCryptoTraderServer) ModifyOrder(context.Context, *ModifyOrderRequest) (*ModifyOrderResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ModifyOrder not implemented")
|
||||
}
|
||||
func (UnimplementedGoCryptoTraderServer) mustEmbedUnimplementedGoCryptoTraderServer() {}
|
||||
|
||||
// UnsafeGoCryptoTraderServer may be embedded to opt out of forward compatibility for this service.
|
||||
@@ -2992,6 +3006,24 @@ func _GoCryptoTrader_GetManagedOrders_Handler(srv interface{}, ctx context.Conte
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _GoCryptoTrader_ModifyOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ModifyOrderRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(GoCryptoTraderServer).ModifyOrder(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/gctrpc.GoCryptoTrader/ModifyOrder",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(GoCryptoTraderServer).ModifyOrder(ctx, req.(*ModifyOrderRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// GoCryptoTrader_ServiceDesc is the grpc.ServiceDesc for GoCryptoTrader service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
@@ -3323,6 +3355,10 @@ var GoCryptoTrader_ServiceDesc = grpc.ServiceDesc{
|
||||
MethodName: "GetManagedOrders",
|
||||
Handler: _GoCryptoTrader_GetManagedOrders_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ModifyOrder",
|
||||
Handler: _GoCryptoTrader_ModifyOrder_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user