Skip to content

twilight-project/relayer-order-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twilight Relayer Order API v0.1.0

A high-throughput JSON-RPC service for submitting, updating, and managing orders on the Twilight Relayer Core.

This API suite handles:

  • Market and limit order submissions
  • Order cancellation and amendment
  • Lend order submission and settlement
  • Limit order settlement

Built for scale and operational isolation, this service is optimized to handle large volumes of order activity without impacting the performance or reliability of the query layer. Ideal for trading bots, exchanges, and institutions interacting directly with the relayer engine.

Features

  • Order Management: Create, execute, and cancel trader orders
  • Kafka Integration: Asynchronous message processing with Kafka
  • ZK-SNARK Verification: Built-in zero-knowledge proof verification
  • Multi-threading: Configurable RPC server threads for optimal performance
  • Docker Support: Ready-to-deploy Docker containers

Prerequisites

  • Rust 1.87.0 or later
  • Kafka broker (for message queuing)
  • Git (for dependency resolution)

Environment Setup

Environment Variables

Create a .env file in the project root by copying the example:

cp .env.example .env

Configure the following environment variables in your .env file:

Required Variables

# Kafka broker address for message queue operations (REQUIRED)
BROKER=localhost:9092

Optional Variables (with defaults)

# Relayer version identifier (default: 0.1.0)
RelayerVersion=v0.1.0

# Snapshot version for the system (default: 0.1.0)
SnapshotVersion=v0.1.0

# RPC queue mode operation setting (default: DIRECT)
RPC_QUEUE_MODE=DIRECT

# RPC server socket address and port (default: 0.0.0.0:3032)
RPC_SERVER_SOCKETADDR=0.0.0.0:3032

# Number of RPC server threads (default: 5)
RPC_SERVER_THREAD=5

Building and Running

Development Build

# Build the project
cargo build

# Run the application
cargo run

Release Build

# Build optimized release version
cargo build --release

# Run the release binary
./target/release/main

Docker Deployment

Development Container

# Build development image
docker build -f Dockerfile -t relayer-order-api:dev .

# Run development container
docker run -p 3032:3032 relayer-order-api:dev

Production Container

# Build production image
docker build -t relayer-order-api:latest .

# Run production container
docker run -p 3032:3032 relayer-order-api:latest

API Endpoints

The server exposes the following JSON-RPC methods:

  • CreateTraderOrder - Submit a new trader order
  • ExecuteTraderOrder - Execute an existing trader order
  • CancelTraderOrder - Cancel an existing trader order
  • CreateLendOrder - Create a lending order
  • ExecuteLendOrder - Execute a lending order

Example Usage

# Health check - server should respond on configured port
curl -X POST http://localhost:3032 \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "CreateTraderOrder", "params": {...}, "id": 1}'

Configuration

Kafka Topics

The application uses the following Kafka topics:

  • CLIENT-REQUEST - For incoming client requests
  • CLIENT-FAILED-REQUEST - For failed request logging

Server Configuration

  • Default Port: 3032
  • Default Thread Count: 5

Development

Project Structure

src/
├── main.rs              # Application entry point
├── config.rs            # Environment configuration
├── lib.rs               # Library exports
├── kafkalib/            # Kafka integration
│   ├── mod.rs
│   └── kafkacmd.rs
└── relayer/             # Core relayer order API functionality
    ├── mod.rs
    ├── commands.rs
    └── rpc_server/
        ├── mod.rs
        └── server.rs

Dependencies

Key dependencies include:

  • kafka - Kafka client library
  • jsonrpc-* - JSON-RPC server components
  • dotenv - Environment variable management
  • twilight-relayer-sdk - Twilight protocol SDKs

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Support

For issues and questions, please refer to the project repository or contact the development team.

About

Public RPC Server for submitting orders to Twilight Relayer

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •