FTX: Margin lending/borrow rate history (#981)

* Adds lending rates/borrows to FTX and the command

* Movements, renames, rpc test

* Fleshing out rpc response

* Allows rpcserver to calculate offline (but not gctcli). Expands tests

* rn structs. add exchange_wrapper_issues support

* Adds a nice yearly rate

* Surprise yearly borrow rate!

* Rn+Mv to margin package. Fixes some serious whoopsies

* Adds average lend/borrow rates instead of sum

* rm oopsie whoopsie

* This is what the linter was having an issue with

* re-gen

* lintl

* niteroos
This commit is contained in:
Scott
2022-07-12 14:27:35 +10:00
committed by GitHub
parent e02053a2d6
commit bed9425a08
21 changed files with 3135 additions and 989 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3149,6 +3149,42 @@ func local_request_GoCryptoTraderService_GetTechnicalAnalysis_0(ctx context.Cont
}
var (
filter_GoCryptoTraderService_GetMarginRatesHistory_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_GoCryptoTraderService_GetMarginRatesHistory_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetMarginRatesHistoryRequest
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_GoCryptoTraderService_GetMarginRatesHistory_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetMarginRatesHistory(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_GoCryptoTraderService_GetMarginRatesHistory_0(ctx context.Context, marshaler runtime.Marshaler, server GoCryptoTraderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetMarginRatesHistoryRequest
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_GoCryptoTraderService_GetMarginRatesHistory_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetMarginRatesHistory(ctx, &protoReq)
return msg, metadata, err
}
// RegisterGoCryptoTraderServiceHandlerServer registers the http handlers for service GoCryptoTraderService to "mux".
// UnaryRPC :call GoCryptoTraderServiceServer directly.
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
@@ -5405,6 +5441,30 @@ func RegisterGoCryptoTraderServiceHandlerServer(ctx context.Context, mux *runtim
})
mux.Handle("GET", pattern_GoCryptoTraderService_GetMarginRatesHistory_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)
var err error
ctx, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/gctrpc.GoCryptoTraderService/GetMarginRatesHistory", runtime.WithHTTPPathPattern("/v1/getmarginrateshistory"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_GoCryptoTraderService_GetMarginRatesHistory_0(ctx, 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_GoCryptoTraderService_GetMarginRatesHistory_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -7504,6 +7564,27 @@ func RegisterGoCryptoTraderServiceHandlerClient(ctx context.Context, mux *runtim
})
mux.Handle("GET", pattern_GoCryptoTraderService_GetMarginRatesHistory_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)
var err error
ctx, err = runtime.AnnotateContext(ctx, mux, req, "/gctrpc.GoCryptoTraderService/GetMarginRatesHistory", runtime.WithHTTPPathPattern("/v1/getmarginrateshistory"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_GoCryptoTraderService_GetMarginRatesHistory_0(ctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_GoCryptoTraderService_GetMarginRatesHistory_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -7703,6 +7784,8 @@ var (
pattern_GoCryptoTraderService_Shutdown_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "shutdown"}, ""))
pattern_GoCryptoTraderService_GetTechnicalAnalysis_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "gettechnicalanalysis"}, ""))
pattern_GoCryptoTraderService_GetMarginRatesHistory_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getmarginrateshistory"}, ""))
)
var (
@@ -7901,4 +7984,6 @@ var (
forward_GoCryptoTraderService_Shutdown_0 = runtime.ForwardResponseMessage
forward_GoCryptoTraderService_GetTechnicalAnalysis_0 = runtime.ForwardResponseMessage
forward_GoCryptoTraderService_GetMarginRatesHistory_0 = runtime.ForwardResponseMessage
)

View File

@@ -1146,6 +1146,55 @@ message GetTechnicalAnalysisResponse {
map<string, ListOfSignals> signals = 1;
}
message GetMarginRatesHistoryRequest {
string exchange = 1;
string asset = 2;
string currency = 3;
string start_date = 4;
string end_date = 5;
bool get_predicted_rate = 6;
bool get_lending_payments = 7;
bool get_borrow_rates = 8;
bool get_borrow_costs = 9;
bool include_all_rates = 10;
bool calculate_offline = 11;
string taker_fee_rate = 12;
repeated MarginRate rates = 13;
}
message LendingPayment {
string payment = 1;
string size = 2;
}
message BorrowCost {
string cost = 1;
string size = 2;
}
message MarginRate {
string time = 1;
string market_borrow_size = 2;
string hourly_rate = 3;
string yearly_rate = 4;
string hourly_borrow_rate = 5;
string yearly_borrow_rate = 6;
LendingPayment lending_payment = 7;
BorrowCost borrow_cost = 8;
}
message GetMarginRatesHistoryResponse {
repeated MarginRate rates = 1;
int64 total_rates = 2;
string sum_borrow_costs = 3;
string avg_borrow_size = 4;
string sum_lending_payments = 5;
string avg_lending_size = 6;
MarginRate latest_rate = 7;
MarginRate predicted_rate = 8;
string taker_fee_rate = 9;
}
service GoCryptoTraderService {
rpc GetInfo(GetInfoRequest) returns (GetInfoResponse) {
option (google.api.http) = {
@@ -1754,4 +1803,9 @@ service GoCryptoTraderService {
get: "/v1/gettechnicalanalysis"
};
}
rpc GetMarginRatesHistory(GetMarginRatesHistoryRequest) returns (GetMarginRatesHistoryResponse) {
option (google.api.http) = {
get: "/v1/getmarginrateshistory"
};
}
}

View File

@@ -2176,6 +2176,102 @@
]
}
},
"/v1/getmarginrateshistory": {
"get": {
"operationId": "GoCryptoTraderService_GetMarginRatesHistory",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetMarginRatesHistoryResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "exchange",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "asset",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "currency",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "startDate",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "endDate",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "getPredictedRate",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "getLendingPayments",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "getBorrowRates",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "getBorrowCosts",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "includeAllRates",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "calculateOffline",
"in": "query",
"required": false,
"type": "boolean"
},
{
"name": "takerFeeRate",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getorder": {
"post": {
"operationId": "GoCryptoTraderService_GetOrder",
@@ -3888,6 +3984,17 @@
}
}
},
"gctrpcBorrowCost": {
"type": "object",
"properties": {
"cost": {
"type": "string"
},
"size": {
"type": "string"
}
}
},
"gctrpcCancelAllOrdersRequest": {
"type": "object",
"properties": {
@@ -5001,6 +5108,42 @@
}
}
},
"gctrpcGetMarginRatesHistoryResponse": {
"type": "object",
"properties": {
"rates": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcMarginRate"
}
},
"totalRates": {
"type": "string",
"format": "int64"
},
"sumBorrowCosts": {
"type": "string"
},
"avgBorrowSize": {
"type": "string"
},
"sumLendingPayments": {
"type": "string"
},
"avgLendingSize": {
"type": "string"
},
"latestRate": {
"$ref": "#/definitions/gctrpcMarginRate"
},
"predictedRate": {
"$ref": "#/definitions/gctrpcMarginRate"
},
"takerFeeRate": {
"type": "string"
}
}
},
"gctrpcGetOrderRequest": {
"type": "object",
"properties": {
@@ -5178,6 +5321,17 @@
}
}
},
"gctrpcLendingPayment": {
"type": "object",
"properties": {
"payment": {
"type": "string"
},
"size": {
"type": "string"
}
}
},
"gctrpcListOfSignals": {
"type": "object",
"properties": {
@@ -5190,6 +5344,35 @@
}
}
},
"gctrpcMarginRate": {
"type": "object",
"properties": {
"time": {
"type": "string"
},
"marketBorrowSize": {
"type": "string"
},
"hourlyRate": {
"type": "string"
},
"yearlyRate": {
"type": "string"
},
"hourlyBorrowRate": {
"type": "string"
},
"yearlyBorrowRate": {
"type": "string"
},
"lendingPayment": {
"$ref": "#/definitions/gctrpcLendingPayment"
},
"borrowCost": {
"$ref": "#/definitions/gctrpcBorrowCost"
}
}
},
"gctrpcModifyOrderResponse": {
"type": "object",
"properties": {

View File

@@ -120,6 +120,7 @@ type GoCryptoTraderServiceClient interface {
GetCollateral(ctx context.Context, in *GetCollateralRequest, opts ...grpc.CallOption) (*GetCollateralResponse, error)
Shutdown(ctx context.Context, in *ShutdownRequest, opts ...grpc.CallOption) (*ShutdownResponse, error)
GetTechnicalAnalysis(ctx context.Context, in *GetTechnicalAnalysisRequest, opts ...grpc.CallOption) (*GetTechnicalAnalysisResponse, error)
GetMarginRatesHistory(ctx context.Context, in *GetMarginRatesHistoryRequest, opts ...grpc.CallOption) (*GetMarginRatesHistoryResponse, error)
}
type goCryptoTraderServiceClient struct {
@@ -1150,6 +1151,15 @@ func (c *goCryptoTraderServiceClient) GetTechnicalAnalysis(ctx context.Context,
return out, nil
}
func (c *goCryptoTraderServiceClient) GetMarginRatesHistory(ctx context.Context, in *GetMarginRatesHistoryRequest, opts ...grpc.CallOption) (*GetMarginRatesHistoryResponse, error) {
out := new(GetMarginRatesHistoryResponse)
err := c.cc.Invoke(ctx, "/gctrpc.GoCryptoTraderService/GetMarginRatesHistory", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// GoCryptoTraderServiceServer is the server API for GoCryptoTraderService service.
// All implementations must embed UnimplementedGoCryptoTraderServiceServer
// for forward compatibility
@@ -1252,6 +1262,7 @@ type GoCryptoTraderServiceServer interface {
GetCollateral(context.Context, *GetCollateralRequest) (*GetCollateralResponse, error)
Shutdown(context.Context, *ShutdownRequest) (*ShutdownResponse, error)
GetTechnicalAnalysis(context.Context, *GetTechnicalAnalysisRequest) (*GetTechnicalAnalysisResponse, error)
GetMarginRatesHistory(context.Context, *GetMarginRatesHistoryRequest) (*GetMarginRatesHistoryResponse, error)
mustEmbedUnimplementedGoCryptoTraderServiceServer()
}
@@ -1553,6 +1564,9 @@ func (UnimplementedGoCryptoTraderServiceServer) Shutdown(context.Context, *Shutd
func (UnimplementedGoCryptoTraderServiceServer) GetTechnicalAnalysis(context.Context, *GetTechnicalAnalysisRequest) (*GetTechnicalAnalysisResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetTechnicalAnalysis not implemented")
}
func (UnimplementedGoCryptoTraderServiceServer) GetMarginRatesHistory(context.Context, *GetMarginRatesHistoryRequest) (*GetMarginRatesHistoryResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMarginRatesHistory not implemented")
}
func (UnimplementedGoCryptoTraderServiceServer) mustEmbedUnimplementedGoCryptoTraderServiceServer() {}
// UnsafeGoCryptoTraderServiceServer may be embedded to opt out of forward compatibility for this service.
@@ -3348,6 +3362,24 @@ func _GoCryptoTraderService_GetTechnicalAnalysis_Handler(srv interface{}, ctx co
return interceptor(ctx, in, info, handler)
}
func _GoCryptoTraderService_GetMarginRatesHistory_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetMarginRatesHistoryRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GoCryptoTraderServiceServer).GetMarginRatesHistory(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/gctrpc.GoCryptoTraderService/GetMarginRatesHistory",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GoCryptoTraderServiceServer).GetMarginRatesHistory(ctx, req.(*GetMarginRatesHistoryRequest))
}
return interceptor(ctx, in, info, handler)
}
// GoCryptoTraderService_ServiceDesc is the grpc.ServiceDesc for GoCryptoTraderService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
@@ -3723,6 +3755,10 @@ var GoCryptoTraderService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetTechnicalAnalysis",
Handler: _GoCryptoTraderService_GetTechnicalAnalysis_Handler,
},
{
MethodName: "GetMarginRatesHistory",
Handler: _GoCryptoTraderService_GetMarginRatesHistory_Handler,
},
},
Streams: []grpc.StreamDesc{
{