specapoorv/trading_execution_environment
Execution Desk Assistant Environment
This repository contains an OpenEnv-compatible execution-desk simulator exposed through a FastAPI API and a Gradio UI. It is designed to work as a Hugging Face Docker Space and as a local OpenEnv environment.
The environment models a realistic three-stage execution workflow:
- Data validation
- System readiness
- Order execution
What You Get
- A mounted UI at
/ui/for interactive inspection and manual stepping - OpenEnv HTTP endpoints for programmatic interaction
- A root
inference.pyentrypoint for submission and evaluation workflows - A root
demo.pyentrypoint for a simple scripted run - Pluggable tool calls inside the simulator, so the mocked desk tools can later be replaced with real integrations
Running Locally
Install dependencies:
uv syncStart the server:
uvicorn server.app:app --host 0.0.0.0 --port 7860Local URLs:
- API root:
http://127.0.0.1:7860 - Gradio UI:
http://127.0.0.1:7860/ui/ - FastAPI docs:
http://127.0.0.1:7860/docs
HTTP Endpoints
The environment exposes the standard OpenEnv-style routes:
GET /healthGET /docsPOST /resetPOST /stepGET /stateGET /schemaWS /ws
Example health check:
curl -s http://127.0.0.1:7860/healthExample reset:
curl -X POST http://127.0.0.1:7860/resetExample step:
curl -X POST http://127.0.0.1:7860/step \
-H 'Content-Type: application/json' \
-d '{"action":{"action_type":"CALL_TOOL","tool_name":"market_status_check"}}'Using The UI
The Gradio UI is mounted at /ui/.
It is intended for fast inspection of a live episode without writing client code.
The UI shows:
- Current task metadata
- Latest observation payload
- Latest info payload
- The last submitted action
- Episode reward and termination status
- A step-by-step history table
- A file-upload tab for replaying saved episode logs
In the live tab, you can:
- Reset the environment
- Paste an action as JSON
- Step the simulator manually
The default action example in the UI is:
{"action_type":"CALL_TOOL","tool_name":"market_status_check"}Action Space
Action model: ExecutionDeskAction
Fields:
action_typerequiredtool_nameoptionalparamsoptionaldeclare_flagoptionalsizeoptionalsideoptionalbrokeroptionalurgencyoptionalorder_idoptionalmax_clipoptional
Supported action_type values:
CALL_TOOLDECLARERESTART_STRATEGYESCALATESUBMIT_ORDERSPLIT_ORDERCANCEL_ORDERCHANGE_BROKER
Supported declare_flag values:
data_readysystems_readyexecution_complete
Broker values:
broker_alphabroker_betabroker_delta
Urgency values:
lownormalhigh
Desk Tools
The simulator includes task-specific desk tools such as:
bloomberg_pulloms_position_checkrisk_system_checkcompliance_verifyinternal_report_fetchmarket_status_checkping_oms_connectionstrategy_health_checkcompliance_rechecksubmit_ordersplit_ordercancel_orderchange_brokerget_current_position
These are currently implemented as environment-side tool handlers, but the design is intentionally pluggable. The same action schema can be wired to real internal services, APIs, or broker adapters later without changing the outer API contract.
Observation Shape
Observation model: ExecutionDeskObservation
Top-level fields:
observationinforewarddonemetadata
Important observation sections include:
task_stageknown_datasystem_statuscompliance_flagsposition_stateorder_statetimestamps
The /state endpoint returns OpenEnv session state, including:
episode_idstep_count
Inference And Demo
Submission-oriented inference entrypoint:
python inference.pyDemo entrypoint:
python demo.pyinference.py:
- uses the OpenAI Python client
- requires
HF_TOKENorAPI_KEY - has defaults for
API_BASE_URLandMODEL_NAME - emits logs in the required
[START],[STEP],[END]format
Environment Variables
Common variables used by inference:
HF_TOKENAPI_KEYAPI_BASE_URLMODEL_NAMESEEDMAX_STEPSTEMPERATUREMAX_TOKENS
Validation
Local OpenEnv validation:
openenv validateSubmission pre-check script:
./validate-submission.sh https://specapoorv-trading-execution-environment.hf.spaceDocker Build
docker build -t trading_env-env:latest -f Dockerfile .Project Layout
OpenEnv-Trading-env/
├── README.md
├── Dockerfile
├── openenv.yaml
├── requirements.txt
├── pyproject.toml
├── inference.py
├── demo.py
├── client.py
├── models.py
├── server/
│ ├── app.py
│ ├── env_adapter.py
│ └── core/
│ ├── env/
│ ├── tasks/
│ ├── tools/
│ ├── graders/
│ └── utils/
└── validate-submission.sh