Mimir is a high-performance, AI-driven trading terminal built for the Indian stock market. Powered by advanced predictive models and the Upstox API, it provides real-time market scanning, deep historical context analysis, automated trading signals, and paper trading capabilities—all wrapped in a premium, lightning-fast UI.
See the codeA Production-Ready Algorithmic Trading Engine for the Indian Stock Market.
Key Features • System Architecture • Getting Started • Security Standards • Contributing
Mimir is an advanced algorithmic trading terminal and market intelligence scanner built for the NSE/BSE markets. It ingests real-time market ticks, performs technical and machine-learning-based analysis, and executes algorithmic paper/live trades while broadcasting opportunities to the frontend via WebSockets.
Key service capabilities include:
worker_threads for non-blocking analysis, coupled with PostgreSQL + Redis state persistence.Mimir is a decoupled, event-driven system: a Node/TypeScript backend that owns the market-data feed and trading engines, a Python FastAPI microservice for model inference, PostgreSQL + Redis for persistence and hot state, and a React dashboard fed over binary WebSockets.
node:events, worker_threads, Redis, PostgreSQL (Drizzle ORM).graph TD
subgraph Data Ingestion
A[Upstox WebSocket] -->|Raw Ticks| B(Tick Distribution Server)
B -->|UI Batch Stream| C(WebSocket Broadcaster)
B -->|processedTick| D(Tick Engine)
end
subgraph Orchestration & Event Bus
D -->|marketTick / candleClosed| E{Intelligence Bus}
E --> F[Scanner Orchestrator]
end
subgraph Signal Generation Pipeline
F -->|Evaluate| G[Signal Generator]
G -->|Assemble| H[Feature Engine]
G <-->|Offload| I[Worker Pools]
end
subgraph Intelligence/ML Layer (FastAPI)
H --> J[Chronos-Bolt-Small]
H --> K[FinBERT Sentiment]
H --> L[LightGBM Learned Ranker]
H --> O[Technical Pattern Engine]
L -. optional .-> P[Regime Confluence]
L -. optional .-> Q[PPO RL Endpoint]
end
subgraph Execution
G -->|suggestionTriggered| M[Paper / Live Engine]
M --> N[(PostgreSQL)]
end
The entry point for all real-time market data is the Tick Distribution Server (tick_distribution.ts) and the Tick Engine (tick_engine.ts).
tick_distribution.ts):
processedTick events to the Intelligence Bus asynchronously without blocking the event loop.tick_engine.ts):
processedTick.marketTick and candleClosed events to trigger downstream analysis.Mimir relies on a central EventEmitter-based bus (intelligenceBus in event_bus.ts) to loosely couple its subsystems.
orchestrator.ts): The brain of the application. It listens to marketTick events and orchestrates the analytical pipeline.
EventEmitter bus does not natively handle backpressure. To prevent CPU lockup, heavy technical analysis and AI batch preparation are delegated to Thread Worker Pools (worker_pool.ts). These pools have strict queue limits (e.g., 2000). If the limit is breached, new tasks are immediately rejected (Dynamic Backpressure), ensuring the main Node thread remains responsive.The signal_generator.ts is the central hub where technical setups meet AI ranking.
feature_engine.ts): For each candidate, a FeatureVector is computed. This includes:
rankerIncomplete flag. This intentionally aborts signal generation to prevent the AI from generating predictions based on garbage or default data.The Python AI service (FastAPI) provides the predictive edge:
| Model | Role |
|---|---|
Chronos-Bolt-Small (amazon/chronos-bolt-small) | A lightweight time-series forecasting model predicting probabilistic price trajectory based on closing price sequences. |
FinBERT Sentiment (ProsusAI/finbert) | Evaluates news headlines and macroeconomic keywords to produce a sentiment score (-1.0 to 1.0) under a _pipeline_call_lock. |
| Learned Ranker | A machine-learning model trained on historical setups. Consumes the FeatureVector to predict target hit probability before stop-loss. |
| Rule-Based Regime Detection | Determines the overarching market environment (e.g., Bullish, Volatile, Bearish) using technical breadth and stochastic heuristics. |
When a signal exceeds the required AI confidence thresholds, a suggestionTriggered event is fired and intercepted by paper_engine.ts.
stateStore. It applies a missed fill guard: if the market price has slipped >0.5% away from the original theoretical entry, the trade is rejected.FOR UPDATE) prevents race conditions when multiple signals attempt to allocate margin simultaneously.broker_orders.ts).marketIntelligenceUpdate payload containing live PnL, active suggestions, and market breadth to the React frontend.| Port | Service |
|---|---|
| 3000 | Frontend (React / Vite preview) |
| 5000 | Backend API + trading engine + WebSockets |
| 5433 | PostgreSQL (portable install; Docker uses 5432) |
| 6379 | Redis |
| 8001 | AI microservice (localhost-bound) |
UPSTOXBOT_ADMIN_TOKEN.AI_CORS_ORIGINS.Mimir is designed to execute locally. If deployment requires exposure to the public internet (e.g., via Cloudflare Tunnels), rigorous authentication protocols must be configured to secure data and Upstox API credentials.
UPSTOXBOT_ADMIN_TOKEN environment variable in the .env file as a cryptographically secure string.localStorage.setItem('mimir_admin_token', 'your_secure_token').bot.bat launcher does not initiate the Cloudflare tunnel by default. To start the tunnel, explicitly execute bot.bat tunnel <port>.HF_HUB_OFFLINE=1), making it perfectly fine for standard laptops.If you are on Windows, you do not need to install Node.js, Python, PostgreSQL, or Redis manually! You can use our zero-dependency portable installer:
setup.bat file in the root folder..portable folder), initialize the database, and install npm packages.bot.bat start to boot the entire system!Clone the repository and duplicate the environment template:
git clone https://github.com/Scifi-ally/Mimir.git
cd Mimir
cp .env.example .env
Configure your PostgreSQL database connection string and Upstox API credentials in .env.
Note:
.envis read by both the Node backend and the Python AI service. The AI service loads.env.localthen.env(real environment variables always take precedence) and does so before any model or service starts, so settings likeSYSTEM1_ENGINE,TYPESAFE_API_KEY, andRANKER_MODEL_PATHare all honoured. SetMIMIR_SKIP_DOTENV=1to disable that loading (the test suite does this so results never depend on your local.env).If you are on Windows: set
git config core.autocrlf falsebefore cloning, or keep the committed.gitattributesin place. LightGBM's model parser rejects CRLF and aborts the process, so a line-ending conversion ofranker_model.txtwill stop the AI service from starting.
Install dependencies across all system components:
# Install root and backend dependencies
npm install
npm --prefix backend install --legacy-peer-deps
# Install Python AI service dependencies
pip install -r backend/ai_service/requirements.txt
Run automated database schema migrations and table setup:
npm run setup:db
Launch the application services in development mode:
# Terminal 1: Start the Express Backend API
npm run dev:backend
# Terminal 2: Start the Python Intelligence Service
uvicorn main:app --app-dir backend/ai_service --host 127.0.0.1 --port 8001
# Terminal 3: Start the React Frontend Dashboard
npm --prefix frontend run dev
http://localhost:3000 (or 5173)http://localhost:5000http://localhost:8001bot.bat)For Windows environments, Mimir includes an automated launcher that manages background process spawning and port verification:
bot.bat
To start the application and automatically open an opt-in Cloudflare tunnel:
bot.bat tunnel 3000
To terminate all running services and tunnels cleanly:
bot.bat stop
To initialize the entire stack (Frontend, Backend, AI Engine, PostgreSQL, and Redis) within isolated containerized environments:
docker compose up --build -d
Execute the automated test suites and static type validation prior to deployment:
npm run typecheck
npm test
npm run build
Contributions are encouraged from developers, quantitative analysts, and open-source enthusiasts.
This project is open-source and licensed under the terms of the MIT License.
While this platform offers robust retail-level monitoring and analysis, it is necessary to acknowledge its architectural limits. This system is a retail-level setup masquerading as an institutional platform. True High-Frequency Trading (HFT) and institutional operations require infrastructure that Mimir fundamentally lacks:
Mimir is a high-performance, AI-driven trading terminal built for the Indian stock market. Powered by advanced predictive models and the Upstox API, it provides real-time market scanning, deep historical context analysis, automated trading signals, and paper trading capabilities—all wrapped in a premium, lightning-fast UI.
See the codeA Production-Ready Algorithmic Trading Engine for the Indian Stock Market.
Key Features • System Architecture • Getting Started • Security Standards • Contributing
Mimir is an advanced algorithmic trading terminal and market intelligence scanner built for the NSE/BSE markets. It ingests real-time market ticks, performs technical and machine-learning-based analysis, and executes algorithmic paper/live trades while broadcasting opportunities to the frontend via WebSockets.
Key service capabilities include:
worker_threads for non-blocking analysis, coupled with PostgreSQL + Redis state persistence.Mimir is a decoupled, event-driven system: a Node/TypeScript backend that owns the market-data feed and trading engines, a Python FastAPI microservice for model inference, PostgreSQL + Redis for persistence and hot state, and a React dashboard fed over binary WebSockets.
node:events, worker_threads, Redis, PostgreSQL (Drizzle ORM).graph TD
subgraph Data Ingestion
A[Upstox WebSocket] -->|Raw Ticks| B(Tick Distribution Server)
B -->|UI Batch Stream| C(WebSocket Broadcaster)
B -->|processedTick| D(Tick Engine)
end
subgraph Orchestration & Event Bus
D -->|marketTick / candleClosed| E{Intelligence Bus}
E --> F[Scanner Orchestrator]
end
subgraph Signal Generation Pipeline
F -->|Evaluate| G[Signal Generator]
G -->|Assemble| H[Feature Engine]
G <-->|Offload| I[Worker Pools]
end
subgraph Intelligence/ML Layer (FastAPI)
H --> J[Chronos-Bolt-Small]
H --> K[FinBERT Sentiment]
H --> L[LightGBM Learned Ranker]
H --> O[Technical Pattern Engine]
L -. optional .-> P[Regime Confluence]
L -. optional .-> Q[PPO RL Endpoint]
end
subgraph Execution
G -->|suggestionTriggered| M[Paper / Live Engine]
M --> N[(PostgreSQL)]
end
The entry point for all real-time market data is the Tick Distribution Server (tick_distribution.ts) and the Tick Engine (tick_engine.ts).
tick_distribution.ts):
processedTick events to the Intelligence Bus asynchronously without blocking the event loop.tick_engine.ts):
processedTick.marketTick and candleClosed events to trigger downstream analysis.Mimir relies on a central EventEmitter-based bus (intelligenceBus in event_bus.ts) to loosely couple its subsystems.
orchestrator.ts): The brain of the application. It listens to marketTick events and orchestrates the analytical pipeline.
EventEmitter bus does not natively handle backpressure. To prevent CPU lockup, heavy technical analysis and AI batch preparation are delegated to Thread Worker Pools (worker_pool.ts). These pools have strict queue limits (e.g., 2000). If the limit is breached, new tasks are immediately rejected (Dynamic Backpressure), ensuring the main Node thread remains responsive.The signal_generator.ts is the central hub where technical setups meet AI ranking.
feature_engine.ts): For each candidate, a FeatureVector is computed. This includes:
rankerIncomplete flag. This intentionally aborts signal generation to prevent the AI from generating predictions based on garbage or default data.The Python AI service (FastAPI) provides the predictive edge:
| Model | Role |
|---|---|
Chronos-Bolt-Small (amazon/chronos-bolt-small) | A lightweight time-series forecasting model predicting probabilistic price trajectory based on closing price sequences. |
FinBERT Sentiment (ProsusAI/finbert) | Evaluates news headlines and macroeconomic keywords to produce a sentiment score (-1.0 to 1.0) under a _pipeline_call_lock. |
| Learned Ranker | A machine-learning model trained on historical setups. Consumes the FeatureVector to predict target hit probability before stop-loss. |
| Rule-Based Regime Detection | Determines the overarching market environment (e.g., Bullish, Volatile, Bearish) using technical breadth and stochastic heuristics. |
When a signal exceeds the required AI confidence thresholds, a suggestionTriggered event is fired and intercepted by paper_engine.ts.
stateStore. It applies a missed fill guard: if the market price has slipped >0.5% away from the original theoretical entry, the trade is rejected.FOR UPDATE) prevents race conditions when multiple signals attempt to allocate margin simultaneously.broker_orders.ts).marketIntelligenceUpdate payload containing live PnL, active suggestions, and market breadth to the React frontend.| Port | Service |
|---|---|
| 3000 | Frontend (React / Vite preview) |
| 5000 | Backend API + trading engine + WebSockets |
| 5433 | PostgreSQL (portable install; Docker uses 5432) |
| 6379 | Redis |
| 8001 | AI microservice (localhost-bound) |
UPSTOXBOT_ADMIN_TOKEN.AI_CORS_ORIGINS.Mimir is designed to execute locally. If deployment requires exposure to the public internet (e.g., via Cloudflare Tunnels), rigorous authentication protocols must be configured to secure data and Upstox API credentials.
UPSTOXBOT_ADMIN_TOKEN environment variable in the .env file as a cryptographically secure string.localStorage.setItem('mimir_admin_token', 'your_secure_token').bot.bat launcher does not initiate the Cloudflare tunnel by default. To start the tunnel, explicitly execute bot.bat tunnel <port>.HF_HUB_OFFLINE=1), making it perfectly fine for standard laptops.If you are on Windows, you do not need to install Node.js, Python, PostgreSQL, or Redis manually! You can use our zero-dependency portable installer:
setup.bat file in the root folder..portable folder), initialize the database, and install npm packages.bot.bat start to boot the entire system!Clone the repository and duplicate the environment template:
git clone https://github.com/Scifi-ally/Mimir.git
cd Mimir
cp .env.example .env
Configure your PostgreSQL database connection string and Upstox API credentials in .env.
Note:
.envis read by both the Node backend and the Python AI service. The AI service loads.env.localthen.env(real environment variables always take precedence) and does so before any model or service starts, so settings likeSYSTEM1_ENGINE,TYPESAFE_API_KEY, andRANKER_MODEL_PATHare all honoured. SetMIMIR_SKIP_DOTENV=1to disable that loading (the test suite does this so results never depend on your local.env).If you are on Windows: set
git config core.autocrlf falsebefore cloning, or keep the committed.gitattributesin place. LightGBM's model parser rejects CRLF and aborts the process, so a line-ending conversion ofranker_model.txtwill stop the AI service from starting.
Install dependencies across all system components:
# Install root and backend dependencies
npm install
npm --prefix backend install --legacy-peer-deps
# Install Python AI service dependencies
pip install -r backend/ai_service/requirements.txt
Run automated database schema migrations and table setup:
npm run setup:db
Launch the application services in development mode:
# Terminal 1: Start the Express Backend API
npm run dev:backend
# Terminal 2: Start the Python Intelligence Service
uvicorn main:app --app-dir backend/ai_service --host 127.0.0.1 --port 8001
# Terminal 3: Start the React Frontend Dashboard
npm --prefix frontend run dev
http://localhost:3000 (or 5173)http://localhost:5000http://localhost:8001bot.bat)For Windows environments, Mimir includes an automated launcher that manages background process spawning and port verification:
bot.bat
To start the application and automatically open an opt-in Cloudflare tunnel:
bot.bat tunnel 3000
To terminate all running services and tunnels cleanly:
bot.bat stop
To initialize the entire stack (Frontend, Backend, AI Engine, PostgreSQL, and Redis) within isolated containerized environments:
docker compose up --build -d
Execute the automated test suites and static type validation prior to deployment:
npm run typecheck
npm test
npm run build
Contributions are encouraged from developers, quantitative analysts, and open-source enthusiasts.
This project is open-source and licensed under the terms of the MIT License.
While this platform offers robust retail-level monitoring and analysis, it is necessary to acknowledge its architectural limits. This system is a retail-level setup masquerading as an institutional platform. True High-Frequency Trading (HFT) and institutional operations require infrastructure that Mimir fundamentally lacks: