A simple stock exchange price simulation service built with Rust that provides real-time stock price feeds via gRPC.
This project implements a gRPC server that simulates stock price movements for a set of predefined tickers (AAPL, TSLA, GOOG, AMZN, MSFT, NFLX, META, NVDA, JPM, V). The service provides both single price requests and streaming price feeds with realistic price fluctuations based on a drift and volatility model.
- gRPC API: Provides a Protocol Buffers-based API for price feeds
- Price Simulation: Realistic price movements with small upward drift and random volatility
- Streaming Support: Real-time price streaming for continuous updates
- Multiple Tickers: Supports 10 popular stock tickers with initial base prices
- Configurable Server: Environment-based configuration for host and port settings
- Rust (latest stable version)
- Protocol Buffers compiler (
protoc)
To install protobuf compiler on Ubuntu/Debian:
sudo apt-get install protobuf-compiler- Clone the repository:
git clone https://github.com/loudsheep/stock-exchange-sim-prices.git
cd stock-exchange-sim-prices- Build the project:
cargo build- Run the server:
cargo runThe server will start listening on 127.0.0.1:50051 by default.
The server can be configured using environment variables:
SERVER_HOST: Server host address (default:127.0.0.1)SERVER_PORT: Server port number (default:50051)
You can create a .env file based on .env.example for local development.
The service provides two gRPC endpoints:
GetPrice(PriceRequest) -> PriceResponse: Get current price for a specific tickerStreamPrices(PriceRequest) -> stream PriceResponse: Stream continuous price updates
- AAPL (Apple Inc.)
- TSLA (Tesla, Inc.)
- GOOG (Alphabet Inc.)
- AMZN (Amazon.com, Inc.)
- MSFT (Microsoft Corporation)
- NFLX (Netflix, Inc.)
- META (Meta Platforms, Inc.)
- NVDA (NVIDIA Corporation)
- JPM (JPMorgan Chase & Co.)
- V (Visa Inc.)
This project is available for educational and demonstration purposes.