Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/orderbook api update #92

Merged
merged 3 commits into from Dec 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions client/exchange/exchange.go
Expand Up @@ -25,7 +25,8 @@ type ExchangeClient interface {
GetDerivativeMarket(ctx context.Context, marketId string) (derivativeExchangePB.MarketResponse, error)
GetDerivativeOrderbook(ctx context.Context, marketId string) (derivativeExchangePB.OrderbookResponse, error)
GetDerivativeOrderbooks(ctx context.Context, marketIds []string) (derivativeExchangePB.OrderbooksResponse, error)
StreamDerivativeOrderbookSnapshot(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookSnapshotClient, error)
// StreamDerivativeOrderbook deprecated API
StreamDerivativeOrderbook(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookClient, error)
StreamDerivativeOrderbookUpdate(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookUpdateClient, error)
StreamDerivativeMarket(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamMarketClient, error)
GetDerivativeOrders(ctx context.Context, req derivativeExchangePB.OrdersRequest) (derivativeExchangePB.OrdersResponse, error)
Expand Down Expand Up @@ -57,7 +58,8 @@ type ExchangeClient interface {
GetSpotOrders(ctx context.Context, req spotExchangePB.OrdersRequest) (spotExchangePB.OrdersResponse, error)
GetSpotOrderbook(ctx context.Context, marketId string) (spotExchangePB.OrderbookResponse, error)
GetSpotOrderbooks(ctx context.Context, marketIds []string) (spotExchangePB.OrderbooksResponse, error)
StreamSpotOrderbookSnapshot(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookSnapshotClient, error)
// StreamSpotOrderbook deprecated API
StreamSpotOrderbook(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookClient, error)
StreamSpotOrderbookUpdate(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookUpdateClient, error)
GetSpotMarkets(ctx context.Context, req spotExchangePB.MarketsRequest) (spotExchangePB.MarketsResponse, error)
GetSpotMarket(ctx context.Context, marketId string) (spotExchangePB.MarketResponse, error)
Expand Down Expand Up @@ -230,13 +232,13 @@ func (c *exchangeClient) GetDerivativeOrderbooks(ctx context.Context, marketIds
return *res, nil
}

func (c *exchangeClient) StreamDerivativeOrderbookSnapshot(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookSnapshotClient, error) {
req := derivativeExchangePB.StreamOrderbookSnapshotRequest{
func (c *exchangeClient) StreamDerivativeOrderbook(ctx context.Context, marketIds []string) (derivativeExchangePB.InjectiveDerivativeExchangeRPC_StreamOrderbookClient, error) {
req := derivativeExchangePB.StreamOrderbookRequest{
MarketIds: marketIds,
}

ctx = c.getCookie(ctx)
stream, err := c.derivativeExchangeClient.StreamOrderbookSnapshot(ctx, &req)
stream, err := c.derivativeExchangeClient.StreamOrderbook(ctx, &req)
if err != nil {
fmt.Println(err)
return nil, err
Expand Down Expand Up @@ -765,13 +767,13 @@ func (c *exchangeClient) StreamSpotOrderbookUpdate(ctx context.Context, marketId
return stream, nil
}

func (c *exchangeClient) StreamSpotOrderbookSnapshot(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookSnapshotClient, error) {
req := spotExchangePB.StreamOrderbookSnapshotRequest{
func (c *exchangeClient) StreamSpotOrderbook(ctx context.Context, marketIds []string) (spotExchangePB.InjectiveSpotExchangeRPC_StreamOrderbookClient, error) {
req := spotExchangePB.StreamOrderbookRequest{
MarketIds: marketIds,
}

ctx = c.getCookie(ctx)
stream, err := c.spotExchangeClient.StreamOrderbookSnapshot(ctx, &req)
stream, err := c.spotExchangeClient.StreamOrderbook(ctx, &req)
if err != nil {
fmt.Println(err)
return nil, err
Expand Down
Expand Up @@ -17,7 +17,7 @@ func main() {

ctx := context.Background()
marketIds := []string{"0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce"}
stream, err := exchangeClient.StreamDerivativeOrderbookSnapshot(ctx, marketIds)
stream, err := exchangeClient.StreamDerivativeOrderbook(ctx, marketIds)
if err != nil {
fmt.Println(err)
}
Expand Down
Expand Up @@ -148,9 +148,9 @@ func main() {
if len(sells) > 0 && len(buys) > 0 {
// assert orderbook
topBuyPrice := decimal.RequireFromString(buys[0].Price)
topSellPrice := decimal.RequireFromString(sells[0].Price)
if topBuyPrice.GreaterThanOrEqual(topSellPrice) {
panic(fmt.Errorf("crossed orderbook, must restart: buy %s >= %s buy", topBuyPrice, topSellPrice))
lowestSellPrice := decimal.RequireFromString(sells[0].Price)
if topBuyPrice.GreaterThanOrEqual(lowestSellPrice) {
panic(fmt.Errorf("crossed orderbook, must restart: buy %s >= %s sell", topBuyPrice, lowestSellPrice))
}
}

Expand Down
Expand Up @@ -17,7 +17,7 @@ func main() {

ctx := context.Background()
marketIds := []string{"0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0"}
stream, err := exchangeClient.StreamSpotOrderbookSnapshot(ctx, marketIds)
stream, err := exchangeClient.StreamSpotOrderbook(ctx, marketIds)
if err != nil {
fmt.Println(err)
}
Expand Down
6 changes: 3 additions & 3 deletions examples/exchange/spot/8_StreamOrderbookUpdate/example.go
Expand Up @@ -150,9 +150,9 @@ func main() {
if len(sells) > 0 && len(buys) > 0 {
// assert orderbook
topBuyPrice := decimal.RequireFromString(buys[0].Price)
topSellPrice := decimal.RequireFromString(sells[0].Price)
if topBuyPrice.GreaterThanOrEqual(topSellPrice) {
panic(fmt.Errorf("crossed orderbook, must restart: buy %s >= %s buy", topBuyPrice, topSellPrice))
lowestSellPrice := decimal.RequireFromString(sells[0].Price)
if topBuyPrice.GreaterThanOrEqual(lowestSellPrice) {
panic(fmt.Errorf("crossed orderbook, must restart: buy %s >= %s sell", topBuyPrice, lowestSellPrice))
}
}

Expand Down