# parambhatia2004/tradingbot architecture

> Architecture diagram of the GitHub repository parambhatia2004/tradingbot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/parambhatia2004/tradingbot
- Repository: https://github.com/parambhatia2004/tradingbot

## Overview

TradingBot is a single-file automated 130/30 long-short equity bot using Alpaca’s paper-trading API. Its workflow waits for market open, periodically ranks a fixed stock universe by recent price change, derives long/short quantities from account equity and prices, then reconciles positions and submits market orders; near close it liquidates positions. The internal strategy, ranking, and order helpers are all implemented in tradingBot.py. The README additionally documents minute-based rebalancing; source excerpts show the loop and timing. There are no separate source modules.

Main entry points: [`tradingBot.py`](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py) (Bot runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_control["Strategy control"]
  node_runtime["Bot runtime<br/>[tradingBot.py]"]
  node_session["Market session<br/>[tradingBot.py]"]
  node_strategy["Strategy state<br/>[tradingBot.py]"]
end

subgraph group_selection["Portfolio selection"]
  node_ranking["Universe ranking<br/>[tradingBot.py]"]
  node_marketdata["Market data<br/>[tradingBot.py]"]
  node_sizing["Position sizing<br/>[tradingBot.py]"]
end

subgraph group_execution["Trading execution"]
  node_reconcile["Position reconciliation<br/>[tradingBot.py]"]
  node_orderhelper["Order helper<br/>[tradingBot.py]"]
end

node_alpaca["Alpaca API"]

node_runtime -->|"waits for open"| node_session
node_runtime -->|"rebalances"| node_reconcile
node_runtime -->|"checks session, cancels orders"| node_alpaca
node_runtime -->|"liquidates near close"| node_orderhelper
node_session -->|"checks market clock"| node_alpaca
node_reconcile -->|"ranks portfolio"| node_ranking
node_ranking -->|"gets price changes"| node_marketdata
node_marketdata -->|"requests minute bars"| node_alpaca
node_ranking -->|"sets target quantities"| node_sizing
node_sizing -->|"reads account and latest bars"| node_alpaca
node_reconcile -->|"reads positions, cancels orders"| node_alpaca
node_reconcile -->|"submits adjustments"| node_orderhelper
node_orderhelper -->|"submits market orders"| node_alpaca

click node_runtime "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_session "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_strategy "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_ranking "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_marketdata "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_sizing "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_reconcile "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"
click node_orderhelper "https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_runtime,node_session,node_strategy toneBlue
class node_ranking,node_marketdata,node_sizing toneAmber
class node_reconcile,node_orderhelper,node_alpaca toneMint
```

## Components

### Strategy control

- [Bot runtime](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`
- [Market session](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`
- [Strategy state](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`

### Portfolio selection

- [Universe ranking](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`
- [Market data](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`
- [Position sizing](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`

### Trading execution

- [Position reconciliation](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`
- [Order helper](https://github.com/parambhatia2004/tradingbot/blob/main/tradingBot.py): `tradingBot.py`

### Other components

- **Alpaca API**

## Connections

- Bot runtime → Market session: waits for open (evidence: `tradingBot.py`)
- Bot runtime → Position reconciliation: rebalances (evidence: `tradingBot.py`)
- Bot runtime → Alpaca API: checks session, cancels orders (evidence: `tradingBot.py`)
- Bot runtime → Order helper: liquidates near close (evidence: `tradingBot.py`)
- Market session → Alpaca API: checks market clock (evidence: `tradingBot.py`)
- Position reconciliation → Universe ranking: ranks portfolio (evidence: `tradingBot.py`)
- Universe ranking → Market data: gets price changes (evidence: `tradingBot.py`)
- Market data → Alpaca API: requests minute bars (evidence: `tradingBot.py`)
- Universe ranking → Position sizing: sets target quantities (evidence: `tradingBot.py`)
- Position sizing → Alpaca API: reads account and latest bars (evidence: `tradingBot.py`)
- Position reconciliation → Alpaca API: reads positions, cancels orders (evidence: `tradingBot.py`)
- Position reconciliation → Order helper: submits adjustments (evidence: `tradingBot.py`)
- Order helper → Alpaca API: submits market orders (evidence: `tradingBot.py`)
