A high-performance C++ gRPC service that parses and executes trading scripts written in FiScript, a domain-specific language for scheduling and reacting to market events.
OrderParserProcessor enables users to submit trading scripts that define automated trading behaviors. The service:
- Accepts FiScript Programs - Receives trading scripts via gRPC API
- Parses & Validates - Uses ANTLR4 to parse FiScript grammar into an Abstract Syntax Tree (AST)
- Executes Trading Logic - Processes
ScheduleandReactOnblocks to coordinate trading actions - Manages Variables - Supports variable declarations, assignments, and expressions
- Responds Asynchronously - Returns execution status via gRPC
FiScript is a custom scripting language designed for algorithmic trading strategies. It supports:
- Schedule Blocks - Execute trading actions at specific times
- ReactOn Blocks - Respond to market data updates or events
- Variables - Store and manipulate numeric and string values
- Expressions - Perform calculations with
+,-,*,/operators - Print Statements - Debug output for development
price = 100.0
quantity = 50
Schedule(09:30:00) {
Print("Market opened")
}
ReactOn(PriceUpdate, AAPL) {
price += 1.5
Print("Price updated")
}
┌─────────────────┐
│ Client (gRPC) │
└────────┬────────┘
│ ScriptSubmitRequest
▼
┌─────────────────────────────┐
│ gRPC Server (port 50051) │
│ ┌──────────────────────┐ │
│ │ ScriptSubmitHandler │ │
│ └──────────┬───────────┘ │
│ ▼ │
│ ┌──────────────────────┐ │
│ │ ScriptSubmitProcessor│ │
│ └──────────┬───────────┘ │
│ ▼ │
│ ┌──────────────────────┐ │
│ │ ANTLR4 Parser │ │
│ │ (FiScript Grammar) │ │
│ └──────────┬───────────┘ │
│ ▼ │
│ ┌──────────────────────┐ │
│ │ Visitor Pattern │ │
│ │ (AST Traversal) │ │
│ └──────────────────────┘ │
└─────────────────────────────┘
- C++17 - Core programming language
- gRPC - High-performance RPC framework
- Protocol Buffers - Service and message definitions
- ANTLR4 - Parser generator for FiScript grammar
- CMake - Build system
# Set required environment variables
export ORDER_PARSER_PROCESSOR_ROOT="/path/to/OrderParserProcessor"
export ANTLR_VERSION="antlr-4.13.0"# Build the project
cmake -B build
cmake --build build
# Run the server
./build/backend/order_parser_processorThe gRPC server will start on 0.0.0.0:50051.
Use any gRPC client to submit a FiScript program:
service ApiToCore {
rpc ScriptSubmit (ScriptSubmitRequest) returns (SynchronousReply);
}
message ScriptSubmitRequest {
string content = 1; // FiScript program text
string title = 2; // Script title
string summary = 3; // Optional description
string user = 4; // User identifier
Timestamp creation_time = 5;
}OrderParserProcessor/
├── backend/ # C++ gRPC service
│ ├── src/ # Implementation files
│ ├── includes/ # Header files
│ └── main.cc # Server entry point
├── proto/ # Protocol buffer definitions
│ ├── services/ # gRPC service definitions
│ └── messages/ # Message schemas
├── rules/parser/ # ANTLR grammar
│ └── FiScript.g4 # FiScript language definition
├── generated/ # Auto-generated code
│ ├── cpp/ # C++ protobuf & ANTLR output
│ └── python/ # Python protobuf output
└── connectivity/ # Network connectivity module
cmake -B build -DBUILD_TESTS=ON
cmake --build build
ctest --test-dir buildThe FiScript grammar is defined in rules/parser/FiScript.g4. CMake automatically regenerates the parser when the grammar changes.
For interactive grammar development:
# Generate parser manually
antlr4 -Dlanguage=Cpp -visitor rules/parser/FiScript.g4
# Visualize AST from input
grun FiScript script -gui < test_input.txtAfter modifying .proto files, regenerate code:
# C++ generation
protoc -I$ORDER_PARSER_PROCESSOR_ROOT/proto \
--cpp_out=$ORDER_PARSER_PROCESSOR_ROOT/generated/cpp/messages/ \
--grpc_out=$ORDER_PARSER_PROCESSOR_ROOT/generated/cpp/ \
--plugin=protoc-gen-grpc=`which grpc_cpp_plugin` \
$(find $ORDER_PARSER_PROCESSOR_ROOT/proto/services/ -iname "*.proto")
# Python generation
python3 -m grpc_tools.protoc \
--proto_path=$ORDER_PARSER_PROCESSOR_ROOT/proto \
--python_out=$ORDER_PARSER_PROCESSOR_ROOT/generated/python/ \
--grpc_python_out=$ORDER_PARSER_PROCESSOR_ROOT/generated/python/ \
$(find $ORDER_PARSER_PROCESSOR_ROOT/proto/services/ -iname "*.proto")Schedule(args...) { ... }- Execute block at scheduled timeReactOn(args...) { ... }- Execute block when event occursPrint(expression)- Output value for debuggingvariable = expression- Declare and initialize variablevariable += expression- Compound assignment (+=,-=,*=,/=)
- Numeric literals:
42,3.14 - String literals:
"AAPL","Hello" - Variables:
price,quantity - Arithmetic:
price * quantity,(total + 10) / 2
See rules/parser/FiScript.g4 for complete grammar specification.
- Server Port:
50051(configurable in backend/main.cc) - Credentials: InsecureServerCredentials (development only)
- C++ Standard: C++17 (required)
When contributing code:
- Follow C++17 standards
- Use smart pointers for memory management
- Add comments only for non-obvious design decisions
- Run tests before submitting:
ctest --test-dir build - Update
.protofiles when changing API contracts
See LICENSE file for details.
For detailed development instructions, see .claude/CLAUDE.md.