Add OHLC retrieval func (GetHistoricCandles) to all exchanges and expose it as a wrapper func (#414)

* initial wiring to providegethistoricalcandles

* initial wiring to providegethistoricalcandles

* initial wiring to providegethistoricalcandles

* gethistriccandles work from cli using hard coded inputs

* gethistoriccandles RPC service and CLI working fine for coinbasepro

* fixed unit test

* input check on grpc for gethistoriccandles

* updated deps

* fixed the return value when a method is not yet implemented

* code review: fixed CLI input check and int32->int64

* code review: handling wrong exchange name

* added check on granularity and allowing start and end being empty

* code review: removed currency2

* code review: dependency reverted

* improved func comment

* typo in func comment

* get historic values tests

* unit tests for get historical rates on coinbasepro

* using time format time.RFC3339

* names to camel case and improved comments

* test cleanup

* changed to camel case

* added InArray tests

* dropped not needed string time

* enforced use of int64

* fixed make check

* cleaned up code organisation to be consistent

* fixed Travis remarks

* more Travis remarks

* added comments

* regenerated proto files after merge

* linter fix
This commit is contained in:
Christian Achilli
2020-01-24 05:10:33 +00:00
committed by Adrian Gallagher
parent e5b64a5580
commit 5ac5ec8fc1
42 changed files with 1230 additions and 357 deletions

View File

@@ -1,4 +1,5 @@
echo "GoCryptoTrader: Generating gRPC, proxy and swagger files."
export GOPATH=$(go env GOPATH)
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --swagger_out=logtostderr=true:. rpc.proto

File diff suppressed because it is too large Load Diff

View File

@@ -1711,6 +1711,39 @@ func local_request_GoCryptoTrader_GCTScriptAutoLoadToggle_0(ctx context.Context,
}
var (
filter_GoCryptoTrader_GetHistoricCandles_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_GoCryptoTrader_GetHistoricCandles_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetHistoricCandlesRequest
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_GetHistoricCandles_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetHistoricCandles(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_GoCryptoTrader_GetHistoricCandles_0(ctx context.Context, marshaler runtime.Marshaler, server GoCryptoTraderServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetHistoricCandlesRequest
var metadata runtime.ServerMetadata
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_GoCryptoTrader_GetHistoricCandles_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetHistoricCandles(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.
@@ -2804,6 +2837,26 @@ func RegisterGoCryptoTraderHandlerServer(ctx context.Context, mux *runtime.Serve
})
mux.Handle("GET", pattern_GoCryptoTrader_GetHistoricCandles_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.AnnotateIncomingContext(ctx, mux, req)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_GoCryptoTrader_GetHistoricCandles_0(rctx, inboundMarshaler, server, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_GoCryptoTrader_GetHistoricCandles_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -3985,6 +4038,26 @@ func RegisterGoCryptoTraderHandlerClient(ctx context.Context, mux *runtime.Serve
})
mux.Handle("GET", pattern_GoCryptoTrader_GetHistoricCandles_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)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_GoCryptoTrader_GetHistoricCandles_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_GetHistoricCandles_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -4102,6 +4175,8 @@ var (
pattern_GoCryptoTrader_GCTScriptListAll_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "gctscript", "stop"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_GoCryptoTrader_GCTScriptAutoLoadToggle_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "gctscript", "autoload"}, "", runtime.AssumeColonVerbOpt(true)))
pattern_GoCryptoTrader_GetHistoricCandles_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "gethistoriccandles"}, "", runtime.AssumeColonVerbOpt(true)))
)
var (
@@ -4218,4 +4293,6 @@ var (
forward_GoCryptoTrader_GCTScriptListAll_0 = runtime.ForwardResponseMessage
forward_GoCryptoTrader_GCTScriptAutoLoadToggle_0 = runtime.ForwardResponseMessage
forward_GoCryptoTrader_GetHistoricCandles_0 = runtime.ForwardResponseMessage
)

View File

@@ -521,6 +521,26 @@ message GetAuditEventResponse {
repeated AuditEvent events = 1;
}
message GetHistoricCandlesRequest {
string exchange = 1;
CurrencyPair pair = 2;
int64 rangesize = 3;
int64 granularity = 4;
}
message GetHistoricCandlesResponse {
repeated Candle candle =1;
}
message Candle {
int64 time = 1;
double low = 2;
double high = 3;
double open = 4;
double close = 5;
double volume = 6;
}
message AuditEvent {
string type = 1 ;
string identifier = 2;
@@ -956,5 +976,9 @@ service GoCryptoTrader {
};
}
rpc GetHistoricCandles(GetHistoricCandlesRequest) returns (GetHistoricCandlesResponse) {
option (google.api.http) = {
get: "/v1/gethistoriccandles"
};
}
}

View File

@@ -840,6 +840,62 @@
]
}
},
"/v1/gethistoriccandles": {
"get": {
"operationId": "GetHistoricCandles",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetHistoricCandlesResponse"
}
}
},
"parameters": [
{
"name": "exchange",
"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": "rangesize",
"in": "query",
"required": false,
"type": "string",
"format": "int64"
},
{
"name": "granularity",
"in": "query",
"required": false,
"type": "string",
"format": "int64"
}
],
"tags": [
"GoCryptoTrader"
]
}
},
"/v1/getinfo": {
"get": {
"operationId": "GetInfo",
@@ -1548,6 +1604,35 @@
"gctrpcCancelOrderResponse": {
"type": "object"
},
"gctrpcCandle": {
"type": "object",
"properties": {
"time": {
"type": "string",
"format": "int64"
},
"low": {
"type": "number",
"format": "double"
},
"high": {
"type": "number",
"format": "double"
},
"open": {
"type": "number",
"format": "double"
},
"close": {
"type": "number",
"format": "double"
},
"volume": {
"type": "number",
"format": "double"
}
}
},
"gctrpcCoin": {
"type": "object",
"properties": {
@@ -2032,6 +2117,17 @@
}
}
},
"gctrpcGetHistoricCandlesResponse": {
"type": "object",
"properties": {
"candle": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcCandle"
}
}
}
},
"gctrpcGetInfoResponse": {
"type": "object",
"properties": {