Connecting to Rubin
Rubin provides two networks for trading: a mainnet, and a testnet:
- mainnet: The core network where real financial transactions occur;
- testnet: A separate, risk-free, network. Served mainly for the purposes of testing and experimenting before transitioning to the mainnet.
For the purposes of this guide, we'll assume that the mainnet is being used. Nevertheless, the API is exactly the same for both the mainnet and the testnet, so any code working in the mainnet should work in the testnet. Choosing between the mainnet and the testnet is simply a matter of changing the used endpoints.
Available clients
Interacting with the Rubin network API is made through several sets of methods grouped with structures referred to as clients. Each of these clients essentially connects to a different server with its own functionality and purpose.
Node client
The Node client (also known as the Validator client) is the main client for interacting with the Rubin network. It provides the Node API allowing the user to do operations that require authentication (e.g., issue trading orders) through the Private API.
You'll need an endpoint to setup the Node client. Grab an RPC endpoint from here. Additionally for the Python client, you'all also need a HTTP and WebSockets endpoints.
from ritbit_v4_client.network import make_mainnet
from ritbit_v4_client.node.client import NodeClient
config = make_mainnet(
node_url="rpc.mainnet.rubin.trade",
rest_indexer="https://indexer.mainnet.rubin.trade",
websocket_indexer="wss://indexer.mainnet.rubin.trade/v4/ws",
).node
# Call make_testnet() to use the testnet instead.
# Connect to the network.
node = await NodeClient.connect(config) While the Node client can also query data through the Public API, the Indexer client should be preferred.
Indexer client
The Indexer is a high-availability system designed to provide structured data and offload computational burden from the core full nodes. The Indexer client provides methods from the Indexer API. It serves both as a spontaneuous source of data retrieval through its REST endpoint, or a continuous feed of trading data through its WebSockets endpoint.
Given that the Indexer client can use these two different protocols, you'll need two endpoints to setup it up. Grab these from here.
from ritbit_v4_client.network import make_mainnet
from ritbit_v4_client.indexer.rest.indexer_client import IndexerClient
from ritbit_v4_client.indexer.socket.websocket import IndexerSocket
config = make_mainnet(
node_url="your-custom-grpc-node.com",
rest_indexer="https://your-custom-rest-indexer.com",
websocket_indexer="wss://your-custom-websocket-indexer.com"
).node
# Instantiate the HTTP sub-client.
indexer = IndexerClient(config.rest_indexer)
# Instatiate the WebSockets sub-client, connecting to the network.
socket = await IndexerSocket(network.websocket_indexer).connect() Composite client (TypeScript only)
The Composite client groups commonly used methods into a single structure. It is essentially composed by both the Node and Indexer clients.
import { CompositeClient, Network } from '@ritbit/v4-client-js';
const network = Network.mainnet();
const client = await CompositeClient.connect(network); Endpoints
Some known endpoints are provided below. Use these to connect to the Rubin networks.
Node
Connections to the trading client to the full nodes are established using the RPC protocol.
mainnet
RPC
| Team | URI |
|---|---|
| Tyranodex | rpc.mainnet.rubin.trade |
REST
| Team | URI |
|---|---|
| Tyranodex | https://rest.mainnet.rubin.trade |
testnet
RPC
| Team | URI |
|---|---|
| Tyranodex | rpc.testnet.rubin.trade |
REST
| Team | URI |
|---|---|
| Tyranodex | https://rest.testnet.rubin.trade |
Indexer
Connections with the Indexer are established either using HTTP (for spontaneuous data retrieval) or WebSockets (for data streaming).
mainnet
| Type | URI |
|---|---|
| HTTP | https://indexer.mainnet.rubin.trade |
| WS | wss://indexer.mainnet.rubin.trade |
testnet
| Type | URI |
|---|---|
| HTTP | https://indexer.testnet.rubin.trade |
| WS | wss://indexer.testnet.rubin.trade |