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

Full Node Endpoints #261

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
"type": "separator"
},

"api_integration-clients": "Client Documentation",
"api_integration-indexer": "Indexer Documentation",
"api_integration-full-node-streaming": "Full Node Streaming API",
"api_integration-clients": "Clients",
"api_integration-indexer": "Indexer",
"api_integration-full-nodes": "Full Nodes",
"api_integration-repositories": "Repositories",
"api_integration-trading": "Trading",
"api_integration-deposits_and_withdrawals": "Deposits and Withdrawals",
Expand Down
5 changes: 5 additions & 0 deletions pages/api_integration-full-nodes/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{
"full_node_endpoints": "Full Node Endpoints",
"full_node_streaming": "Full Node gRPC Streaming"
}
116 changes: 116 additions & 0 deletions pages/api_integration-full-nodes/full_node_endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Full Node Endpoints
Full nodes provide two APIs:

- [Full Node API](#full-node-api) for native full node features
- [CometBFT API](#cometbft-api) for CometBFT state

Use these APIs to read the latest network data, to place orders quickly and efficiently, and to build upon with your own custom software.

## Getting Started

The Full Node and CometBFT APIs offer different sets of functionality. They accept different query frameworks. Choose the query method and tool for your use case.

### Choose Query Method

The Full Node API accepts gRPC or REST. The CometBFT API accepts only RPC.

|| Full Node API | CometBFT API |
| ---- | --- | ------ |
| gRPC | ✅ | ✖ |
| REST | ✅ | ✖ |
| RPC | ✖ | ✅ |
Comment on lines +20 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth distinguishing between REST and (Comet's) RPC? Both are JSON over HTTP. I think it's technically correct to separate them but might be confusing.


### Install Query Tools

You can use your own query tool, or your can install one or both of the following CLI tools:

- [grpcurl](https://github.com/fullstorydev/grpcurl?tab=readme-ov-file#installation) to send gRPC and RPC requests
- [curl](https://curl.se/download.html) to send RESTful requests

### Find Your Node URL

To query a full node, you need its URL. If you are running and querying your own full node on the same system, that URL is usually `localhost`. If you want to use an infrastructure provider's public full node, use a URL from the **Full Node Endpoints** section of the [resources page](../infrastructure_providers-network/resources#full-node-endpoints). Choose a node for your deployment type and query method.

Then, check your connection to your target node using the command for your use case:

|| Full Node API | CometBFT API |
| ------ | ------------- | ------------ |
| gRPC | `grpcurl --plaintext <url>.dydxprotocol` | ✖ |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right:

❯ grpcurl dydx-ops-grpc.kingnodes.com:443.dydxprotocol
Too few arguments.
Try 'grpcurl -help' for more details.

❯ grpcurl dydx-ops-grpc.kingnodes.com:443 list
cosmos.auth.v1beta1.Query
cosmos.authz.v1beta1.Query
cosmos.autocli.v1.Query
...

# this one just hangs, can't use --plaintext with SSL
❯ grpcurl --plaintext dydx-ops-grpc.kingnodes.com:443 list
^C

| REST | `curl <url>/dydxprotocol/` | ✖ |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the expected response is "Not Implemented"

❯ curl https://dydx-ops-rest.kingnodes.com/dydxprotocol/
{"code":12, "message":"Not Implemented", "details":[]}%

| RPC | ✖ | `grpcurl --plaintext <url>.status` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RPC should be checked through CURL not gRPC


## Full Node API
The Full Node API provides an identical set of
[gRPC endpoints](#grpc) and
[REST endpoints](#rest-grpc-gateway). You can use either framework. Generally, [gRPC](https://grpc.io/) provides a faster connection.

### gRPC Endpoints
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that gRPC and REST endpoints are the same, just with different protocols for access, I'd think it makes more sense to combine the gRPC and REST sections into "Full Node Endpoints", and then show the example requests for both gRPC and REST.

You can interact with the Full Node API using [grpcurl](https://github.com/fullstorydev/grpcurl?tab=readme-ov-file#installation) or your own tool to send gRPC requests. The gRPC server is available on port `9090` by default.

See the [API specification]() for gRPC endpoints.

**Examples**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO examples would be clearer if they used a live node URL from a specific deployment, like https://dydx-ops-rest.kingnodes.com/ directly, so you can link e.g. straight to https://dydx-ops-rest.kingnodes.com/dydxprotocol/vault/params, and have a separate section explaining that you can substitute your node's address for the base URL.


Get your USDC balance:
```bash
grpcurl --plaintext http://examplenode:9090 api.Service/Method
```

Get a list of instruments available to trade on a node's network:
```bash
grpcurl --plaintext http://examplenode:9090 api.Service/Method
```

Convert human-readable trade information into integers and quantums:
```bash
grpcurl --plaintext http://examplenode:9090 api.Service/Method
```

Place and broadcast an order:
```bash
grpcurl --plaintext http://examplenode:9090 api.Service/Method
```

Get a list of your open positions:
```bash
grpcurl --plaintext http://examplenode:9090 api.Service/Method
```

Get your liquidation price:
```bash
grpcurl --plaintext http://examplenode:9090 api.Service/Method
```

### REST Endpoints
You can interact with the Full Node API using `curl` or your own tool to send RESTful requests. Nodes provide support for REST through [gRPC-Gateway](https://grpc-ecosystem.github.io/grpc-gateway/). The gRPC-Gateway server is available on port `1317` by default.

See the [Silk Nodes API specification](https://dydx.api.silknodes.io/swagger/#/) for REST endpoints.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to link the swagger spec, but having it hosted elsewhere could be confusing (what is silknodes?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the same vein, I think it makes sense to link to the gRPC query service definitions underlying the gRPC endpoints. Maybe just have a quick paragraph explaining how to find the source code for a given endpoint. One of the cool things about DC, for an API user, is that you can just "read the code".


**Examples**

Get your USDC balance:
```bash
curl https://examplenode:1317/path/to/resource
```

Get the height of the network:
```bash
curl https://examplenode:1317/path/to/resource
```

## CometBFT API
You can read CometBFT state information using [grpcurl](https://github.com/fullstorydev/grpcurl?tab=readme-ov-file#installation) or your own tool to send RPC requests. The RPC server is available on port `26657` by default.

See the [CometBFT RPC v0.38 API specification](https://docs.cometbft.com/v0.38/rpc) for CometBFT endpoints.

**Examples**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "stream the height of the network" (rather than query) is the most important one


Get your USDC balance:
```bash
grpcurl --plaintext http://examplenode:26657 api.Service/Method
```

Get the height of the network:
```bash
grpcurl --plaintext http://examplenode:26657 api.Service/Method
```
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (c *GrpcClient) ProcessMatchPerpetualLiquidation(

By protocol design, each validator has their own version of the orderbook and optimistically processes orderbook matches. As a result, you may see interleaved sequences of order removals, placements, and state fill amount updates when optimistically processed orderbook matches are removed and later replayed on the local orderbook.

![full node streaming diagram](../artifacts/full_node_streaming_diagram.jpg)
![full node streaming diagram](../../artifacts/full_node_streaming_diagram.jpg)

Note that DeliverTx maps to exec mode `execModeFinalize`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Full Node gRPC Streaming

This page has moved to [API Integration > Full Node Streaming API](../api_integration-full-node-streaming.md).
This page has moved to [API Integration > Full Node Streaming](../api_integration-full-node-streaming.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This page has moved to [API Integration > Full Node Streaming](../api_integration-full-node-streaming.md).
This page has moved to [API Integration > Full Node Streaming](../../api_integration-full-node-streaming.md).

Loading