github.com/InjectiveLabs/sdk-go@v1.53.0/client/exchange/exchange_test_support.go (about)

     1  package exchange
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  
     7  	"github.com/InjectiveLabs/sdk-go/client/common"
     8  
     9  	accountPB "github.com/InjectiveLabs/sdk-go/exchange/accounts_rpc/pb"
    10  	auctionPB "github.com/InjectiveLabs/sdk-go/exchange/auction_rpc/pb"
    11  	derivativeExchangePB "github.com/InjectiveLabs/sdk-go/exchange/derivative_exchange_rpc/pb"
    12  	insurancePB "github.com/InjectiveLabs/sdk-go/exchange/insurance_rpc/pb"
    13  	metaPB "github.com/InjectiveLabs/sdk-go/exchange/meta_rpc/pb"
    14  	oraclePB "github.com/InjectiveLabs/sdk-go/exchange/oracle_rpc/pb"
    15  	portfolioExchangePB "github.com/InjectiveLabs/sdk-go/exchange/portfolio_rpc/pb"
    16  	spotExchangePB "github.com/InjectiveLabs/sdk-go/exchange/spot_exchange_rpc/pb"
    17  	"google.golang.org/grpc"
    18  )
    19  
    20  type MockExchangeClient struct {
    21  	Network                    common.Network
    22  	SpotMarketsResponses       []*spotExchangePB.MarketsResponse
    23  	DerivativeMarketsResponses []*derivativeExchangePB.MarketsResponse
    24  }
    25  
    26  func (e *MockExchangeClient) QueryClient() *grpc.ClientConn {
    27  	dummyConnection := grpc.ClientConn{}
    28  	return &dummyConnection
    29  }
    30  
    31  func (e *MockExchangeClient) GetDerivativeMarket(ctx context.Context, marketId string) (*derivativeExchangePB.MarketResponse, error) {
    32  	return &derivativeExchangePB.MarketResponse{}, nil
    33  }
    34  
    35  func (e *MockExchangeClient) GetDerivativeOrderbookV2(ctx context.Context, marketId string) (*derivativeExchangePB.OrderbookV2Response, error) {
    36  	return &derivativeExchangePB.OrderbookV2Response{}, nil
    37  }
    38  
    39  func (e *MockExchangeClient) GetDerivativeOrderbooksV2(ctx context.Context, marketIDs []string) (*derivativeExchangePB.OrderbooksV2Response, error) {
    40  	return &derivativeExchangePB.OrderbooksV2Response{}, nil
    41  }
    42  
    43  func (e *MockExchangeClient) StreamDerivativeOrderbookV2(ctx context.Context, marketIDs []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookV2Client, error) {
    44  	return nil, nil
    45  }
    46  
    47  func (e *MockExchangeClient) StreamDerivativeOrderbookUpdate(ctx context.Context, marketIDs []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookUpdateClient, error) {
    48  	return nil, nil
    49  }
    50  
    51  func (e *MockExchangeClient) StreamDerivativeMarket(ctx context.Context, marketIDs []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamMarketClient, error) {
    52  	return nil, nil
    53  }
    54  
    55  func (e *MockExchangeClient) GetDerivativeOrders(ctx context.Context, req *derivativeExchangePB.OrdersRequest) (*derivativeExchangePB.OrdersResponse, error) {
    56  	return &derivativeExchangePB.OrdersResponse{}, nil
    57  }
    58  
    59  func (e *MockExchangeClient) GetDerivativeMarkets(ctx context.Context, req *derivativeExchangePB.MarketsRequest) (*derivativeExchangePB.MarketsResponse, error) {
    60  	var response *derivativeExchangePB.MarketsResponse
    61  	var localError error
    62  	if len(e.DerivativeMarketsResponses) > 0 {
    63  		response = e.DerivativeMarketsResponses[0]
    64  		e.DerivativeMarketsResponses = e.DerivativeMarketsResponses[1:]
    65  		localError = nil
    66  	} else {
    67  		response = &derivativeExchangePB.MarketsResponse{}
    68  		localError = errors.New("There are no responses configured")
    69  	}
    70  
    71  	return response, localError
    72  }
    73  
    74  func (e *MockExchangeClient) GetDerivativePositions(ctx context.Context, req *derivativeExchangePB.PositionsRequest) (*derivativeExchangePB.PositionsResponse, error) {
    75  	return &derivativeExchangePB.PositionsResponse{}, nil
    76  }
    77  
    78  func (e *MockExchangeClient) GetDerivativePositionsV2(ctx context.Context, req *derivativeExchangePB.PositionsV2Request) (*derivativeExchangePB.PositionsV2Response, error) {
    79  	return &derivativeExchangePB.PositionsV2Response{}, nil
    80  }
    81  
    82  func (e *MockExchangeClient) GetDerivativeLiquidablePositions(ctx context.Context, req *derivativeExchangePB.LiquidablePositionsRequest) (*derivativeExchangePB.LiquidablePositionsResponse, error) {
    83  	return &derivativeExchangePB.LiquidablePositionsResponse{}, nil
    84  }
    85  
    86  func (e *MockExchangeClient) StreamDerivativePositions(ctx context.Context, req *derivativeExchangePB.StreamPositionsRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamPositionsClient, error) {
    87  	return nil, nil
    88  }
    89  
    90  func (e *MockExchangeClient) StreamDerivativeOrders(ctx context.Context, req *derivativeExchangePB.StreamOrdersRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrdersClient, error) {
    91  	return nil, nil
    92  }
    93  
    94  func (e *MockExchangeClient) GetDerivativeTrades(ctx context.Context, req *derivativeExchangePB.TradesRequest) (*derivativeExchangePB.TradesResponse, error) {
    95  	return &derivativeExchangePB.TradesResponse{}, nil
    96  }
    97  
    98  func (e *MockExchangeClient) GetDerivativeTradesV2(ctx context.Context, req *derivativeExchangePB.TradesV2Request) (*derivativeExchangePB.TradesV2Response, error) {
    99  	return &derivativeExchangePB.TradesV2Response{}, nil
   100  }
   101  
   102  func (e *MockExchangeClient) StreamDerivativeTrades(ctx context.Context, req *derivativeExchangePB.StreamTradesRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamTradesClient, error) {
   103  	return nil, nil
   104  }
   105  
   106  func (e *MockExchangeClient) StreamDerivativeV2Trades(ctx context.Context, req *derivativeExchangePB.StreamTradesV2Request) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamTradesV2Client, error) {
   107  	return nil, nil
   108  }
   109  
   110  func (e *MockExchangeClient) GetSubaccountDerivativeOrdersList(ctx context.Context, req *derivativeExchangePB.SubaccountOrdersListRequest) (*derivativeExchangePB.SubaccountOrdersListResponse, error) {
   111  	return &derivativeExchangePB.SubaccountOrdersListResponse{}, nil
   112  }
   113  
   114  func (e *MockExchangeClient) GetSubaccountDerivativeTradesList(ctx context.Context, req *derivativeExchangePB.SubaccountTradesListRequest) (*derivativeExchangePB.SubaccountTradesListResponse, error) {
   115  	return &derivativeExchangePB.SubaccountTradesListResponse{}, nil
   116  }
   117  
   118  func (e *MockExchangeClient) GetHistoricalDerivativeOrders(ctx context.Context, req *derivativeExchangePB.OrdersHistoryRequest) (*derivativeExchangePB.OrdersHistoryResponse, error) {
   119  	return &derivativeExchangePB.OrdersHistoryResponse{}, nil
   120  }
   121  
   122  func (e *MockExchangeClient) StreamHistoricalDerivativeOrders(ctx context.Context, req *derivativeExchangePB.StreamOrdersHistoryRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrdersHistoryClient, error) {
   123  	return nil, nil
   124  }
   125  
   126  func (e *MockExchangeClient) GetDerivativeFundingPayments(ctx context.Context, req *derivativeExchangePB.FundingPaymentsRequest) (*derivativeExchangePB.FundingPaymentsResponse, error) {
   127  	return &derivativeExchangePB.FundingPaymentsResponse{}, nil
   128  }
   129  
   130  func (e *MockExchangeClient) GetDerivativeFundingRates(ctx context.Context, req *derivativeExchangePB.FundingRatesRequest) (*derivativeExchangePB.FundingRatesResponse, error) {
   131  	return &derivativeExchangePB.FundingRatesResponse{}, nil
   132  }
   133  
   134  func (e *MockExchangeClient) GetPrice(ctx context.Context, baseSymbol, quoteSymbol, oracleType string, oracleScaleFactor uint32) (*oraclePB.PriceResponse, error) {
   135  	return &oraclePB.PriceResponse{}, nil
   136  }
   137  
   138  func (e *MockExchangeClient) GetOracleList(ctx context.Context) (*oraclePB.OracleListResponse, error) {
   139  	return &oraclePB.OracleListResponse{}, nil
   140  }
   141  
   142  func (e *MockExchangeClient) StreamPrices(ctx context.Context, baseSymbol, quoteSymbol, oracleType string) (oraclePB.InjectiveOracleRPC_StreamPricesClient, error) {
   143  	return nil, nil
   144  }
   145  
   146  func (e *MockExchangeClient) GetAuction(ctx context.Context, round int64) (*auctionPB.AuctionEndpointResponse, error) {
   147  	return &auctionPB.AuctionEndpointResponse{}, nil
   148  }
   149  
   150  func (e *MockExchangeClient) GetAuctions(ctx context.Context) (*auctionPB.AuctionsResponse, error) {
   151  	return &auctionPB.AuctionsResponse{}, nil
   152  }
   153  
   154  func (e *MockExchangeClient) StreamBids(ctx context.Context) (auctionPB.InjectiveAuctionRPC_StreamBidsClient, error) {
   155  	return nil, nil
   156  }
   157  
   158  func (e *MockExchangeClient) GetSubaccountsList(ctx context.Context, accountAddress string) (*accountPB.SubaccountsListResponse, error) {
   159  	return &accountPB.SubaccountsListResponse{}, nil
   160  }
   161  
   162  func (e *MockExchangeClient) GetSubaccountBalance(ctx context.Context, subaccountId, denom string) (*accountPB.SubaccountBalanceEndpointResponse, error) {
   163  	return &accountPB.SubaccountBalanceEndpointResponse{}, nil
   164  }
   165  
   166  func (e *MockExchangeClient) StreamSubaccountBalance(ctx context.Context, subaccountId string) (accountPB.InjectiveAccountsRPC_StreamSubaccountBalanceClient, error) {
   167  	return nil, nil
   168  }
   169  
   170  func (e *MockExchangeClient) GetSubaccountBalancesList(ctx context.Context, subaccountId string) (*accountPB.SubaccountBalancesListResponse, error) {
   171  	return &accountPB.SubaccountBalancesListResponse{}, nil
   172  }
   173  
   174  func (e *MockExchangeClient) GetSubaccountHistory(ctx context.Context, req *accountPB.SubaccountHistoryRequest) (*accountPB.SubaccountHistoryResponse, error) {
   175  	return &accountPB.SubaccountHistoryResponse{}, nil
   176  }
   177  
   178  func (e *MockExchangeClient) GetSubaccountOrderSummary(ctx context.Context, req *accountPB.SubaccountOrderSummaryRequest) (*accountPB.SubaccountOrderSummaryResponse, error) {
   179  	return &accountPB.SubaccountOrderSummaryResponse{}, nil
   180  }
   181  
   182  func (e *MockExchangeClient) GetOrderStates(ctx context.Context, req *accountPB.OrderStatesRequest) (*accountPB.OrderStatesResponse, error) {
   183  	return &accountPB.OrderStatesResponse{}, nil
   184  }
   185  
   186  func (e *MockExchangeClient) GetPortfolio(ctx context.Context, accountAddress string) (*accountPB.PortfolioResponse, error) {
   187  	return &accountPB.PortfolioResponse{}, nil
   188  }
   189  
   190  func (e *MockExchangeClient) GetRewards(ctx context.Context, req *accountPB.RewardsRequest) (*accountPB.RewardsResponse, error) {
   191  	return &accountPB.RewardsResponse{}, nil
   192  }
   193  
   194  func (e *MockExchangeClient) GetSpotOrders(ctx context.Context, req *spotExchangePB.OrdersRequest) (*spotExchangePB.OrdersResponse, error) {
   195  	return &spotExchangePB.OrdersResponse{}, nil
   196  }
   197  
   198  func (e *MockExchangeClient) GetSpotOrderbookV2(ctx context.Context, marketId string) (*spotExchangePB.OrderbookV2Response, error) {
   199  	return &spotExchangePB.OrderbookV2Response{}, nil
   200  }
   201  
   202  func (e *MockExchangeClient) GetSpotOrderbooksV2(ctx context.Context, marketIDs []string) (*spotExchangePB.OrderbooksV2Response, error) {
   203  	return &spotExchangePB.OrderbooksV2Response{}, nil
   204  }
   205  
   206  func (e *MockExchangeClient) StreamSpotOrderbookV2(ctx context.Context, marketIDs []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookV2Client, error) {
   207  	return nil, nil
   208  }
   209  
   210  func (e *MockExchangeClient) StreamSpotOrderbookUpdate(ctx context.Context, marketIDs []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookUpdateClient, error) {
   211  	return nil, nil
   212  }
   213  
   214  func (e *MockExchangeClient) GetSpotMarkets(ctx context.Context, req *spotExchangePB.MarketsRequest) (*spotExchangePB.MarketsResponse, error) {
   215  	var response *spotExchangePB.MarketsResponse
   216  	var localError error
   217  	if len(e.SpotMarketsResponses) > 0 {
   218  		response = e.SpotMarketsResponses[0]
   219  		e.SpotMarketsResponses = e.SpotMarketsResponses[1:]
   220  		localError = nil
   221  	} else {
   222  		response = &spotExchangePB.MarketsResponse{}
   223  		localError = errors.New("There are no responses configured")
   224  	}
   225  
   226  	return response, localError
   227  }
   228  
   229  func (e *MockExchangeClient) GetSpotMarket(ctx context.Context, marketId string) (*spotExchangePB.MarketResponse, error) {
   230  	return &spotExchangePB.MarketResponse{}, nil
   231  }
   232  
   233  func (e *MockExchangeClient) StreamSpotMarket(ctx context.Context, marketIDs []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamMarketsClient, error) {
   234  	return nil, nil
   235  }
   236  
   237  func (e *MockExchangeClient) StreamSpotOrders(ctx context.Context, req *spotExchangePB.StreamOrdersRequest) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrdersClient, error) {
   238  	return nil, nil
   239  }
   240  
   241  func (e *MockExchangeClient) GetSpotTrades(ctx context.Context, req *spotExchangePB.TradesRequest) (*spotExchangePB.TradesResponse, error) {
   242  	return &spotExchangePB.TradesResponse{}, nil
   243  }
   244  
   245  func (e *MockExchangeClient) GetSpotTradesV2(ctx context.Context, req *spotExchangePB.TradesV2Request) (*spotExchangePB.TradesV2Response, error) {
   246  	return &spotExchangePB.TradesV2Response{}, nil
   247  }
   248  
   249  func (e *MockExchangeClient) StreamSpotTrades(ctx context.Context, req *spotExchangePB.StreamTradesRequest) (spotExchangePB.InjectiveSpotExchangeRPC_StreamTradesClient, error) {
   250  	return nil, nil
   251  }
   252  
   253  func (e *MockExchangeClient) StreamSpotTradesV2(ctx context.Context, req *spotExchangePB.StreamTradesV2Request) (spotExchangePB.InjectiveSpotExchangeRPC_StreamTradesV2Client, error) {
   254  	return nil, nil
   255  }
   256  
   257  func (e *MockExchangeClient) GetSubaccountSpotOrdersList(ctx context.Context, req *spotExchangePB.SubaccountOrdersListRequest) (*spotExchangePB.SubaccountOrdersListResponse, error) {
   258  	return &spotExchangePB.SubaccountOrdersListResponse{}, nil
   259  }
   260  
   261  func (e *MockExchangeClient) GetSubaccountSpotTradesList(ctx context.Context, req *spotExchangePB.SubaccountTradesListRequest) (*spotExchangePB.SubaccountTradesListResponse, error) {
   262  	return &spotExchangePB.SubaccountTradesListResponse{}, nil
   263  }
   264  
   265  func (e *MockExchangeClient) GetHistoricalSpotOrders(ctx context.Context, req *spotExchangePB.OrdersHistoryRequest) (*spotExchangePB.OrdersHistoryResponse, error) {
   266  	return &spotExchangePB.OrdersHistoryResponse{}, nil
   267  }
   268  
   269  func (e *MockExchangeClient) StreamHistoricalSpotOrders(ctx context.Context, req *spotExchangePB.StreamOrdersHistoryRequest) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrdersHistoryClient, error) {
   270  	return nil, nil
   271  }
   272  
   273  func (e *MockExchangeClient) GetInsuranceFunds(ctx context.Context, req *insurancePB.FundsRequest) (*insurancePB.FundsResponse, error) {
   274  	return &insurancePB.FundsResponse{}, nil
   275  }
   276  
   277  func (e *MockExchangeClient) GetRedemptions(ctx context.Context, req *insurancePB.RedemptionsRequest) (*insurancePB.RedemptionsResponse, error) {
   278  	return &insurancePB.RedemptionsResponse{}, nil
   279  }
   280  
   281  func (e *MockExchangeClient) GetAccountPortfolio(ctx context.Context, accountAddress string) (*portfolioExchangePB.AccountPortfolioResponse, error) {
   282  	return &portfolioExchangePB.AccountPortfolioResponse{}, nil
   283  }
   284  
   285  func (e *MockExchangeClient) GetAccountPortfolioBalances(ctx context.Context, accountAddress string) (*portfolioExchangePB.AccountPortfolioBalancesResponse, error) {
   286  	return &portfolioExchangePB.AccountPortfolioBalancesResponse{}, nil
   287  }
   288  
   289  func (e *MockExchangeClient) StreamAccountPortfolio(ctx context.Context, accountAddress, subaccountId, balanceType string) (portfolioExchangePB.InjectivePortfolioRPC_StreamAccountPortfolioClient, error) {
   290  	return nil, nil
   291  }
   292  
   293  func (e *MockExchangeClient) StreamKeepalive(ctx context.Context) (metaPB.InjectiveMetaRPC_StreamKeepaliveClient, error) {
   294  	return nil, nil
   295  }
   296  
   297  func (e *MockExchangeClient) GetInfo(ctx context.Context, req *metaPB.InfoRequest) (*metaPB.InfoResponse, error) {
   298  	return &metaPB.InfoResponse{}, nil
   299  }
   300  
   301  func (e *MockExchangeClient) GetVersion(ctx context.Context, req *metaPB.VersionRequest) (*metaPB.VersionResponse, error) {
   302  	return &metaPB.VersionResponse{}, nil
   303  }
   304  
   305  func (e *MockExchangeClient) Ping(ctx context.Context, req *metaPB.PingRequest) (*metaPB.PingResponse, error) {
   306  	return &metaPB.PingResponse{}, nil
   307  }
   308  
   309  func (e *MockExchangeClient) GetNetwork() common.Network {
   310  	return e.Network
   311  }
   312  
   313  func (e *MockExchangeClient) Close() {
   314  
   315  }