Skip to content

Commit

Permalink
Merge pull request #194 from InjectiveLabs/feat/add_new_indexer_posit…
Browse files Browse the repository at this point in the history
…ion_endpoints

Feat/add new indexer position endpoints
  • Loading branch information
aarmoa authored Dec 21, 2023
2 parents 0e33b0e + 75e344f commit 505179d
Show file tree
Hide file tree
Showing 14 changed files with 2,185 additions and 1,157 deletions.
28 changes: 28 additions & 0 deletions client/exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type ExchangeClient interface {
GetDerivativeOrders(ctx context.Context, req derivativeExchangePB.OrdersRequest) (derivativeExchangePB.OrdersResponse, error)
GetDerivativeMarkets(ctx context.Context, req derivativeExchangePB.MarketsRequest) (derivativeExchangePB.MarketsResponse, error)
GetDerivativePositions(ctx context.Context, req derivativeExchangePB.PositionsRequest) (derivativeExchangePB.PositionsResponse, error)
GetDerivativePositionsV2(ctx context.Context, req derivativeExchangePB.PositionsV2Request) (derivativeExchangePB.PositionsV2Response, error)
GetDerivativeLiquidablePositions(ctx context.Context, req derivativeExchangePB.LiquidablePositionsRequest) (derivativeExchangePB.LiquidablePositionsResponse, error)
StreamDerivativePositions(ctx context.Context, req derivativeExchangePB.StreamPositionsRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamPositionsClient, error)
StreamDerivativeOrders(ctx context.Context, req derivativeExchangePB.StreamOrdersRequest) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrdersClient, error)
Expand Down Expand Up @@ -82,6 +83,7 @@ type ExchangeClient interface {
GetRedemptions(ctx context.Context, req insurancePB.RedemptionsRequest) (insurancePB.RedemptionsResponse, error)

GetAccountPortfolio(ctx context.Context, accountAddress string) (portfolioExchangePB.AccountPortfolioResponse, error)
GetAccountPortfolioBalances(ctx context.Context, accountAddress string) (portfolioExchangePB.AccountPortfolioBalancesResponse, error)
StreamAccountPortfolio(ctx context.Context, accountAddress string, subaccountId, balanceType string) (portfolioExchangePB.InjectivePortfolioRPC_StreamAccountPortfolioClient, error)

StreamKeepalive(ctx context.Context) (metaPB.InjectiveMetaRPC_StreamKeepaliveClient, error)
Expand Down Expand Up @@ -195,6 +197,7 @@ func (c *exchangeClient) GetDerivativeOrders(ctx context.Context, req derivative
return *res, nil
}

// Deprecated: Use GetDerivativePositionsV2 instead.
func (c *exchangeClient) GetDerivativePositions(ctx context.Context, req derivativeExchangePB.PositionsRequest) (derivativeExchangePB.PositionsResponse, error) {
ctx = c.getCookie(ctx)
res, err := c.derivativeExchangeClient.Positions(ctx, &req)
Expand All @@ -206,6 +209,17 @@ func (c *exchangeClient) GetDerivativePositions(ctx context.Context, req derivat
return *res, nil
}

func (c *exchangeClient) GetDerivativePositionsV2(ctx context.Context, req derivativeExchangePB.PositionsV2Request) (derivativeExchangePB.PositionsV2Response, error) {
ctx = c.getCookie(ctx)
res, err := c.derivativeExchangeClient.PositionsV2(ctx, &req)
if err != nil {
fmt.Println(err)
return derivativeExchangePB.PositionsV2Response{}, err
}

return *res, nil
}

func (c *exchangeClient) GetDerivativeLiquidablePositions(ctx context.Context, req derivativeExchangePB.LiquidablePositionsRequest) (derivativeExchangePB.LiquidablePositionsResponse, error) {
ctx = c.getCookie(ctx)
res, err := c.derivativeExchangeClient.LiquidablePositions(ctx, &req)
Expand Down Expand Up @@ -944,6 +958,7 @@ func (c *exchangeClient) StreamKeepalive(ctx context.Context) (metaPB.InjectiveM
return stream, nil
}

// Deprecated: Use GetAccountPortfolioBalances instead.
func (c *exchangeClient) GetAccountPortfolio(ctx context.Context, accountAddress string) (portfolioExchangePB.AccountPortfolioResponse, error) {
ctx = c.getCookie(ctx)
res, err := c.portfolioExchangeClient.AccountPortfolio(ctx, &portfolioExchangePB.AccountPortfolioRequest{
Expand All @@ -957,6 +972,19 @@ func (c *exchangeClient) GetAccountPortfolio(ctx context.Context, accountAddress
return *res, nil
}

func (c *exchangeClient) GetAccountPortfolioBalances(ctx context.Context, accountAddress string) (portfolioExchangePB.AccountPortfolioBalancesResponse, error) {
ctx = c.getCookie(ctx)
res, err := c.portfolioExchangeClient.AccountPortfolioBalances(ctx, &portfolioExchangePB.AccountPortfolioBalancesRequest{
AccountAddress: accountAddress,
})
if err != nil {
fmt.Println(err)
return portfolioExchangePB.AccountPortfolioBalancesResponse{}, err
}

return *res, nil
}

func (c *exchangeClient) StreamAccountPortfolio(ctx context.Context, accountAddress string, subaccountId, balanceType string) (portfolioExchangePB.InjectivePortfolioRPC_StreamAccountPortfolioClient, error) {
ctx = c.getCookie(ctx)
stream, err := c.portfolioExchangeClient.StreamAccountPortfolio(ctx, &portfolioExchangePB.StreamAccountPortfolioRequest{
Expand Down
4 changes: 2 additions & 2 deletions examples/exchange/derivatives/4_Orderbook/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func main() {
}

ctx := context.Background()
marketId := "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"
res, err := exchangeClient.GetDerivativeOrderbook(ctx, marketId)
marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
res, err := exchangeClient.GetDerivativeOrderbookV2(ctx, marketId)
if err != nil {
panic(err)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/exchange/derivatives/8_Positions/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ func main() {
}

ctx := context.Background()
marketId := "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"
marketId := "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6"
subaccountId := "0xc6fe5d33615a1c52c08018c47e8bc53646a0e101000000000000000000000000"
skip := uint64(0)
limit := int32(10)

req := derivativeExchangePB.PositionsRequest{
req := derivativeExchangePB.PositionsV2Request{
MarketId: marketId,
SubaccountId: subaccountId,
Skip: skip,
Limit: limit,
}

res, err := exchangeClient.GetDerivativePositions(ctx, req)
res, err := exchangeClient.GetDerivativePositionsV2(ctx, req)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/exchange/portfolio/1_AccountPortfolio/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {

ctx := context.Background()
accountAddress := "inj1clw20s2uxeyxtam6f7m84vgae92s9eh7vygagt"
res, err := exchangeClient.GetAccountPortfolio(ctx, accountAddress)
res, err := exchangeClient.GetAccountPortfolioBalances(ctx, accountAddress)
if err != nil {
fmt.Println(err)
}
Expand Down
Loading

0 comments on commit 505179d

Please sign in to comment.