Virtufin Examples
Example applications demonstrating how to use Virtufin services with real-world market data APIs from Binance and Alpaca.
What You'll Learn
- How to connect external WebSocket streams (Binance, Alpaca) to Dapr pub/sub via WebSocketManager
- How to process real-time market data with WorkManager workers
- How to publish/subscribe to topics and persist state via API Gateway
- How to handle API authentication, reconnection, and error recovery
Languages
All examples are available in three languages, all using packages from the Gitea registry:
| Language | Package Registry | Key Files |
|---|---|---|
| Python | Gitea PyPI | python/websocketmanager/, python/workmanager/ |
| TypeScript | Gitea npm | typescript/examples/ |
Examples
| Example | Description | Concepts Demonstrated |
|---|---|---|
| Binance CLOB | Stream BTC/USDT order book depth from Binance | WebSocket connection, order book management, state store |
| Alpaca CLOB | Stream BTC/USD order book from Alpaca with API key auth | WebSocket auth, incremental updates, reconnect |
| Order Flow Imbalance | Calculate bid/ask imbalance from Binance depth | WorkManager, state change monitoring, signal calculation |
| WebSocketManager Controller | Control WebSockets via WM worker DLL | DotNet DLL worker, gRPC commands, pub/sub response |
Quick Start
# 1. Configure Gitea registry access
cp .env.example .env
# Edit .env with your VIRTUFIN_PACKAGES_USER, VIRTUFIN_PACKAGES_TOKEN, Alpaca keys, etc.
source .env
# 2. Start Virtufin services
docker compose up -d
# 3. Run an example
# Python
cd python
source ../.env
export UV_INDEX_VIRTUFIN_USERNAME=$VIRTUFIN_PACKAGES_USER
export UV_INDEX_VIRTUFIN_PASSWORD=$VIRTUFIN_PACKAGES_TOKEN
uv sync
uv run python websocketmanager/binance_clob_example.py
# TypeScript
cd typescript && npm install && npm run wsm