A WebSocket-based stock query service that connects to Tally servers to retrieve real-time inventory information.
This Rust application maintains a persistent WebSocket connection to receive stock queries, performs fuzzy matching against an items database, queries a Tally server via HTTP for stock details, and returns formatted responses.
- WebSocket Integration: Maintains persistent connection with automatic reconnection
- Fuzzy Matching: Uses RapidFuzz for intelligent item name matching
- Health Monitoring: Implements ping/pong heartbeat mechanism
- Configurable: JSON-based configuration for URLs and file paths
- Type-safe Error Handling: Custom error types with proper context
Create a config.json file in the same directory as the executable:
{
"websocket_url": "wss://your-websocket-server.com/ws",
"tally_url": "http://localhost:9000",
"items_file_path": "items.txt"
}websocket_url: WebSocket server endpoint for receiving stock queriestally_url: Tally server HTTP endpoint - usually a local instance of Tally Primeitems_file_path: Path to the items list file (defaults toitems.txt)
- Rust toolchain (1.89 or later)
- Cargo package manager
cargo build --releaseThe compiled binary will be in target/release/tally_client.
- Install the Windows target:
rustup target add x86_64-pc-windows-gnu- Install MinGW-w64 (platform-specific):
On macOS:
brew install mingw-w64On Ubuntu/Debian:
sudo apt install mingw-w64- Build for Windows:
cargo build --release --target x86_64-pc-windows-gnuThe Windows executable will be in target/x86_64-pc-windows-gnu/release/tally_client.exe.
Simply run:
cargo build --releaseThe executable will be in target\release\tally_client.exe.
-
Copy the following files to your deployment directory:
tally_client.exe(from build output)config.json(configured for your environment)items.txt(your items database)
-
Update
config.jsonwith your server URLs -
Run the executable:
tally_client.exeThe items.txt file should contain one item name per line:
Item Name 1
Item Name 2
Item Name 3
The client expects JSON messages via WebSocket:
{
"id": "unique-request-id",
"query": "item search query"
}{
"id": "unique-request-id",
"stock_info": "Formatted stock information",
"error": null
}Or in case of error:
{
"id": "unique-request-id",
"stock_info": "",
"error": "Error description"
}- Ping Interval: 30 seconds
- Reconnect Delay: 5 seconds after disconnect
- HTTP Timeout: 10 seconds for Tally requests
These values are defined as constants in the code
tally_client/
├── src/
│ ├── main.rs # Application entry point
│ ├── lib.rs # Config and error types
│ ├── tally_client.rs # Core client logic
│ ├── matcher.rs # Fuzzy matching
│ └── parser.rs # XML response parsing
├── templates/
│ └── stock_query.xml # Tally XML query template
├── config.json # Runtime configuration
├── items.txt # Items database
└── Cargo.toml # Dependencies
MIT