exchanges/futures: Implement open interest (#1417)

* adds open interest to exchanges

* ADDS TESTING YEAH

* New endpoints, BTSE, RPCS, cached

* slight design change, begin gateio

You will need to get cached for
each exchange that supports it

* gateio, huobi, rpc

* fix up kraken, cache retrieval

* okx, gateio

* finalising all implementations and tests

* definitely my final ever commit on this

* Well, well, well

* final v2

* quick fix of bug

* test coverage, assert notempty, test helper

Added a new testhelper for currency
management because its very annoying
in a parallel test setting which wastes
so much space otherwise

* minimises REST requests for Open Interest

* types.Number merge misses

* Minimises Kraken REST calls

* len change, value -> pointer receiver

* further fixup

* fixes gateio, batch calculates open interest

* single gateio, lint const fixes

* rejig and more thorough oi for huobi

* formatting expansion

* minor fix for handling expiring contracts

* rm unused Binance strings

* add bybit support, fix bybit issues

* oopsie doopsie, dont look at my whoopsie

* Fix issue, remove feature

* move an irrelevant function for the pr

* mini bybit upgrades

* fixes cli request bug
This commit is contained in:
Scott
2024-01-12 15:27:35 +11:00
committed by GitHub
parent 614042110a
commit b71bf1f3d1
62 changed files with 22660 additions and 10095 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3681,6 +3681,42 @@ func local_request_GoCryptoTraderService_ChangePositionMargin_0(ctx context.Cont
}
var (
filter_GoCryptoTraderService_GetOpenInterest_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_GoCryptoTraderService_GetOpenInterest_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetOpenInterestRequest
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_GetOpenInterest_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetOpenInterest(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_GoCryptoTraderService_GetOpenInterest_0(ctx context.Context, marshaler runtime.Marshaler, server GoCryptoTraderServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetOpenInterestRequest
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_GetOpenInterest_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetOpenInterest(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.
@@ -6404,6 +6440,31 @@ func RegisterGoCryptoTraderServiceHandlerServer(ctx context.Context, mux *runtim
})
mux.Handle("GET", pattern_GoCryptoTraderService_GetOpenInterest_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
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/gctrpc.GoCryptoTraderService/GetOpenInterest", runtime.WithHTTPPathPattern("/v1/getopeninterest"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_GoCryptoTraderService_GetOpenInterest_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_GoCryptoTraderService_GetOpenInterest_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -8931,6 +8992,28 @@ func RegisterGoCryptoTraderServiceHandlerClient(ctx context.Context, mux *runtim
})
mux.Handle("GET", pattern_GoCryptoTraderService_GetOpenInterest_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
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/gctrpc.GoCryptoTraderService/GetOpenInterest", runtime.WithHTTPPathPattern("/v1/getopeninterest"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_GoCryptoTraderService_GetOpenInterest_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_GoCryptoTraderService_GetOpenInterest_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@@ -9160,6 +9243,8 @@ var (
pattern_GoCryptoTraderService_SetLeverage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getleverage"}, ""))
pattern_GoCryptoTraderService_ChangePositionMargin_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "changepositionmargin"}, ""))
pattern_GoCryptoTraderService_GetOpenInterest_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getopeninterest"}, ""))
)
var (
@@ -9388,4 +9473,6 @@ var (
forward_GoCryptoTraderService_SetLeverage_0 = runtime.ForwardResponseMessage
forward_GoCryptoTraderService_ChangePositionMargin_0 = runtime.ForwardResponseMessage
forward_GoCryptoTraderService_GetOpenInterest_0 = runtime.ForwardResponseMessage
)

View File

@@ -1501,6 +1501,27 @@ message GetOrderbookAmountByImpactResponse {
bool full_orderbook_side_consumed = 11;
}
message GetOpenInterestRequest {
string exchange = 1;
repeated OpenInterestDataRequest data = 2;
}
message OpenInterestDataRequest {
string asset = 1;
CurrencyPair pair = 2;
}
message GetOpenInterestResponse {
repeated OpenInterestDataResponse data = 1;
}
message OpenInterestDataResponse {
string exchange = 1;
string asset = 2;
CurrencyPair pair = 3;
double open_interest = 4;
}
service GoCryptoTraderService {
rpc GetInfo(GetInfoRequest) returns (GetInfoResponse) {
option (google.api.http) = {get: "/v1/getinfo"};
@@ -2044,4 +2065,7 @@ service GoCryptoTraderService {
body: "*"
};
}
rpc GetOpenInterest(GetOpenInterestRequest) returns (GetOpenInterestResponse) {
option (google.api.http) = {get: "/v1/getopeninterest"};
}
}

View File

@@ -2869,6 +2869,36 @@
]
}
},
"/v1/getopeninterest": {
"get": {
"operationId": "GoCryptoTraderService_GetOpenInterest",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetOpenInterestResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "exchange",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"GoCryptoTraderService"
]
}
},
"/v1/getorder": {
"post": {
"operationId": "GoCryptoTraderService_GetOrder",
@@ -6291,6 +6321,18 @@
}
}
},
"gctrpcGetOpenInterestResponse": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/gctrpcOpenInterestDataResponse"
}
}
}
},
"gctrpcGetOrderRequest": {
"type": "object",
"properties": {
@@ -6730,6 +6772,35 @@
}
}
},
"gctrpcOpenInterestDataRequest": {
"type": "object",
"properties": {
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
}
}
},
"gctrpcOpenInterestDataResponse": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"asset": {
"type": "string"
},
"pair": {
"$ref": "#/definitions/gctrpcCurrencyPair"
},
"openInterest": {
"type": "number",
"format": "double"
}
}
},
"gctrpcOrderDetails": {
"type": "object",
"properties": {

View File

@@ -132,6 +132,7 @@ const (
GoCryptoTraderService_SetMarginType_FullMethodName = "/gctrpc.GoCryptoTraderService/SetMarginType"
GoCryptoTraderService_SetLeverage_FullMethodName = "/gctrpc.GoCryptoTraderService/SetLeverage"
GoCryptoTraderService_ChangePositionMargin_FullMethodName = "/gctrpc.GoCryptoTraderService/ChangePositionMargin"
GoCryptoTraderService_GetOpenInterest_FullMethodName = "/gctrpc.GoCryptoTraderService/GetOpenInterest"
)
// GoCryptoTraderServiceClient is the client API for GoCryptoTraderService service.
@@ -251,6 +252,7 @@ type GoCryptoTraderServiceClient interface {
SetMarginType(ctx context.Context, in *SetMarginTypeRequest, opts ...grpc.CallOption) (*SetMarginTypeResponse, error)
SetLeverage(ctx context.Context, in *SetLeverageRequest, opts ...grpc.CallOption) (*SetLeverageResponse, error)
ChangePositionMargin(ctx context.Context, in *ChangePositionMarginRequest, opts ...grpc.CallOption) (*ChangePositionMarginResponse, error)
GetOpenInterest(ctx context.Context, in *GetOpenInterestRequest, opts ...grpc.CallOption) (*GetOpenInterestResponse, error)
}
type goCryptoTraderServiceClient struct {
@@ -1416,6 +1418,15 @@ func (c *goCryptoTraderServiceClient) ChangePositionMargin(ctx context.Context,
return out, nil
}
func (c *goCryptoTraderServiceClient) GetOpenInterest(ctx context.Context, in *GetOpenInterestRequest, opts ...grpc.CallOption) (*GetOpenInterestResponse, error) {
out := new(GetOpenInterestResponse)
err := c.cc.Invoke(ctx, GoCryptoTraderService_GetOpenInterest_FullMethodName, 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
@@ -1533,6 +1544,7 @@ type GoCryptoTraderServiceServer interface {
SetMarginType(context.Context, *SetMarginTypeRequest) (*SetMarginTypeResponse, error)
SetLeverage(context.Context, *SetLeverageRequest) (*SetLeverageResponse, error)
ChangePositionMargin(context.Context, *ChangePositionMarginRequest) (*ChangePositionMarginResponse, error)
GetOpenInterest(context.Context, *GetOpenInterestRequest) (*GetOpenInterestResponse, error)
mustEmbedUnimplementedGoCryptoTraderServiceServer()
}
@@ -1879,6 +1891,9 @@ func (UnimplementedGoCryptoTraderServiceServer) SetLeverage(context.Context, *Se
func (UnimplementedGoCryptoTraderServiceServer) ChangePositionMargin(context.Context, *ChangePositionMarginRequest) (*ChangePositionMarginResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ChangePositionMargin not implemented")
}
func (UnimplementedGoCryptoTraderServiceServer) GetOpenInterest(context.Context, *GetOpenInterestRequest) (*GetOpenInterestResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetOpenInterest not implemented")
}
func (UnimplementedGoCryptoTraderServiceServer) mustEmbedUnimplementedGoCryptoTraderServiceServer() {}
// UnsafeGoCryptoTraderServiceServer may be embedded to opt out of forward compatibility for this service.
@@ -3944,6 +3959,24 @@ func _GoCryptoTraderService_ChangePositionMargin_Handler(srv interface{}, ctx co
return interceptor(ctx, in, info, handler)
}
func _GoCryptoTraderService_GetOpenInterest_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetOpenInterestRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GoCryptoTraderServiceServer).GetOpenInterest(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: GoCryptoTraderService_GetOpenInterest_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GoCryptoTraderServiceServer).GetOpenInterest(ctx, req.(*GetOpenInterestRequest))
}
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)
@@ -4379,6 +4412,10 @@ var GoCryptoTraderService_ServiceDesc = grpc.ServiceDesc{
MethodName: "ChangePositionMargin",
Handler: _GoCryptoTraderService_ChangePositionMargin_Handler,
},
{
MethodName: "GetOpenInterest",
Handler: _GoCryptoTraderService_GetOpenInterest_Handler,
},
},
Streams: []grpc.StreamDesc{
{