A Python SDK wrapper around a simplified Trading API platform for the Bajaj Broking Campus Hiring Assignment.
- Python 3.8+
- pip
# Clone the repository
git clone <repository-url>
cd TradeCore_SDK
# Install dependencies
pip install -r requirements.txtcd backend
uvicorn main:app --reload --host 0.0.0.0 --port 8000The API server will be available at http://localhost:8000
Interactive Swagger docs: http://localhost:8000/docs
All API endpoints (except /api/v1/auth/info) require API key authentication.
X-API-Key: bajaj-trading-api-key-2026
In Swagger UI:
- Click the "Authorize" button at the top
- Enter the API key:
bajaj-trading-api-key-2026 - Click "Authorize"
In curl:
curl -H "X-API-Key: bajaj-trading-api-key-2026" http://localhost:8000/api/v1/instrumentsIn SDK:
sdk = TradingSDK("http://localhost:8000", api_key="bajaj-trading-api-key-2026")GET /api/v1/auth/infoReturns the API key and user details for demo purposes.
Get all tradable instruments
GET /api/v1/instrumentsResponse:
[
{
"symbol": "TCS",
"exchange": "NSE",
"instrumentType": "EQUITY",
"lastTradedPrice": 3850
}
]Place a New Order
POST /api/v1/orders
Content-Type: application/json
{
"symbol": "TCS",
"side": "BUY",
"orderType": "MARKET",
"quantity": 10,
"price": null
}| Field | Type | Required | Description |
|---|---|---|---|
| symbol | string | Yes | Instrument symbol (e.g., TCS, INFY) |
| side | string | Yes | BUY or SELL |
| orderType | string | Yes | MARKET or LIMIT |
| quantity | int | Yes | Must be > 0 |
| price | float | Conditional | Required for LIMIT orders |
Response:
{
"orderId": "uuid-string",
"symbol": "TCS",
"side": "BUY",
"orderType": "MARKET",
"quantity": 10,
"price": 3850,
"status": "EXECUTED"
}Get Order Status
GET /api/v1/orders/{orderId}Order States: NEW, EXECUTED, CANCELLED
Cancel Order
DELETE /api/v1/orders/{orderId}Get all executed trades
GET /api/v1/tradesResponse:
[
{
"tradeId": "uuid-string",
"symbol": "TCS",
"quantity": 10,
"price": 3850,
"side": "BUY"
}
]Get current holdings
GET /api/v1/portfolioResponse:
{
"TCS": {
"symbol": "TCS",
"quantity": 10,
"averagePrice": 3850.0,
"currentValue": 38500.0
}
}from sdk.trading_sdk import TradingSDK
# Initialize SDK
sdk = TradingSDK("http://localhost:8000")
# Get instruments
instruments = sdk.get_instruments()
print(instruments)
# Place a market order
order = sdk.place_order(
symbol="TCS",
side="BUY",
order_type="MARKET",
quantity=10
)
print(order)
# Get trades
trades = sdk.get_trades()
print(trades)
# Get portfolio
portfolio = sdk.get_portfolio()
print(portfolio)
# Cancel an order
sdk.cancel_order(order["orderId"])cd TradeCore_SDK
python -m examples.demoTradeCore_SDK/
βββ backend/
β βββ main.py # FastAPI endpoints
β βββ models.py # Pydantic models
β βββ services.py # Business logic
β βββ store.py # In-memory storage
βββ sdk/
β βββ __init__.py
β βββ trading_sdk.py # Python SDK wrapper
βββ examples/
β βββ demo.py # Usage demonstration
βββ tests/
β βββ test_api.py # Unit tests
βββ requirements.txt
βββ README.md
- Single User System: No authentication required; all operations are for a single user
- In-Memory Storage: Data resets on server restart (no persistence)
- Market Orders: Execute immediately at the last traded price
- LIMIT Orders: Stored with status
NEW(no order book simulation) - Portfolio: Allows negative quantities (short selling simulation)
- Instruments: Pre-configured with TCS and INFY on NSE
| Feature | Status |
|---|---|
| Instrument listing | β |
| Place BUY/SELL orders | β |
| MARKET/LIMIT order types | β |
| Order status tracking | β |
| Order cancellation | β |
| Trade history | β |
| Portfolio holdings | β |
| Input validation | β |
| Error handling | β |
| Swagger/OpenAPI docs | β |
| Logging | β |
| Unit tests | β |
# Install test dependencies
pip install pytest httpx
# Run tests
cd TradeCore_SDK
pytest tests/ -vThis project was created for the Bajaj Broking Campus Hiring Assignment.