Get Started — Overview
The Bridge Connector is a lightweight C-based communication layer that exposes two dedicated TCP sockets for client applications. One socket accepts inbound request strings (orders or commands) from clients; the other socket sends outbound responses (acknowledgements, execution reports, errors) back to the client. This interface is designed to be:
- Simple (plain string messages)
- Low-latency (suitable for trading/order flows)
- Language-agnostic (clients can be written in C, C++, Python, Java, Perl, etc.)
- Secure when used with the authentication options described below
High-level Architecture
(sends strings) |
(C executable) |
|
Key points
- Request Socket: Client -> Bridge (orders/commands)
- Response Socket: Bridge -> Client (ack/status/error)
- Two independent TCP connections avoid head-of-line blocking and make it easier for client code to separate write/read logic.
- Messages are plain text (UTF-8 recommended) and terminated by a newline (\n) or null (\0) depending on your preference.
Features
- Low latency socket communication
- Request/response based order handling
- Market data broadcast
- RMS and margin validation
Connection Details
Protocol: TCP
Default ports (example):
- Request socket (client -> bridge): 9090
- Response socket (bridge -> client): 9091
Address: Bind to 0.0.0.0 on the server for production, or 127.0.0.1 for local testing.
Message encoding: UTF-8 (recommended)
Message termination: \n (newline). All messages MUST be terminated by newline to allow proper framing.
Max message length: 4096 bytes (configurable)
- Request code 2000 : New Order Request
- Response code 2222 : Order Trade Confirmation
- Exchange Numbers NSE Stocks & Index Future(NFO) : 2
- Token No Token no which we get from contract master
- Echoback This field is used for identifying response for corresponding request which is given by user, in response we will send same value of echoback which will be received in request
2040 : Order Modify Request
2070 : Order Cancel Request
2073 : New Order Confirmation
2074 : Oder Modification Confirmation
2075 : Order Cancel Confirmation
NSE Stocks & Index Option(NOP) : 5
REQUEST New Order
| Pos | Field | Description |
|---|---|---|
| 1 | 2000 | New Order Request |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 0 | Order Id |
| 11 | 202202241021 | Echo Back Client reference |
| 12 | 1 | Order Type Market / Limit |
| 13 | 25 | Order quantity |
| 14 | 35 | Order price |
| 15 | 2 | Order action 1=Buy, 2=Sell |
| 16 | 0.0 | SL trigger price |
| 17 | 25 | Total order quantity |
| 18 | 0 | Remain quantity |
REQUEST Modify Order
| Pos | Field | Description |
|---|---|---|
| 1 | 2040 | Modify Request |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 404404480000101 | Order Id |
| 11 | 202202241021 | Echo Back Client reference |
| 12 | 1 | Order type Market / Limit |
| 13 | 25 | Order quantity |
| 14 | 35 | Order price |
| 15 | 2 | Order action 1=Buy, 2=Sell |
| 16 | 0.0 | SL trigger price |
| 17 | 25 | Total order quantity |
| 18 | 0 | Remain quantity |
REQUEST Cancel Order
| Pos | Field | Description |
|---|---|---|
| 1 | 2070 | Cancel Request |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 404404480000101 | Order Id |
| 11 | 202202241021 | Echo Back Client reference |
| 12 | 1 | Order type Market / Limit |
| 13 | 25 | Order quantity |
| 14 | 35 | Order price |
| 15 | 2 | Order action 1=Buy, 2=Sell |
| 16 | 0.0 | SL trigger price |
| 17 | 25 | Total order quantity |
| 18 | 0 | Remain quantity |
RESPONSE Order Confirmation
| Pos | Field | Description |
|---|---|---|
| 1 | 2073 | Order Confirmation |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 404404480000101 | Order Id |
| 11 | 0 | Trade No |
| 12 | 0 | Executed quantity |
| 13 | 35.0000 | Execution price |
| 14 | 202202241021 | Echo Back Client reference |
| 15 | 2 | 1=Buy, 2=Sell |
| 16 | 0 | Error Code |
| 17 | 0 | Reason Code |
| 18 | 1330161808 | Exchange timestamp |
| 19 | 1330161808 | Last modification time |
| 21 | 12345 | Participent (client id) |
| 22 | 123456789012345 | Term Ctcl |
| 23 | 25 | Remain quantity |
| 24 | 25 | Total original quantity |
RESPONSE Modify Confirmation
| Pos | Field | Description |
|---|---|---|
| 1 | 2074 | Order Modification Confirmation |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 404404480000101 | Order Id |
| 11 | 0 | Trade No |
| 12 | 0 | Executed quantity |
| 13 | 35.0000 | Execution price |
| 14 | 202202241021 | Echo Back Client reference |
| 15 | 2 | 1=Buy, 2=Sell |
| 16 | 0 | Error Code |
| 17 | 0 | Reason Code |
| 18 | 1330161808 | Exchange timestamp |
| 19 | 1330161808 | Last modification time |
| 21 | 12345 | Participent (client id) |
| 22 | 123456789012345 | Term Ctcl |
| 23 | 25 | Remain quantity |
| 24 | 25 | Total Original quantity |
RESPONSE Cancel Confirmation
| Pos | Field | Description |
|---|---|---|
| 1 | 2075 | Order Cancel Confirmation |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 404404480000101 | Order Id |
| 11 | 0 | Trade No |
| 12 | 0 | Executed quantity |
| 13 | 35.0000 | Execution price |
| 14 | 202202241021 | Echo Back Client reference |
| 15 | 2 | 1=Buy, 2=Sell |
| 16 | 0 | Error Code |
| 17 | 0 | Reason Code |
| 18 | 1330161808 | Exchange timestamp |
| 19 | 1330161808 | Last modification time |
| 20 | 12345 | Participent (client id) |
| 21 | 123456789012345 | Term Ctcl |
| 22 | 25 | Remain quantity |
| 23 | 25 | Total Original quantity |
TRADE Trade Confirmation
| Pos | Field | Description |
|---|---|---|
| 1 | 2222 | Trade Confirmation |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | 404404480000101 | Order Id |
| 11 | 20046 | Trade No |
| 12 | 25 | Executed quantity |
| 13 | 35.0000 | Execution price |
| 14 | 202202241021 | Echo Back Client reference |
| 15 | 2 | 1=Buy, 2=Sell |
| 16 | 0 | Error Code |
| 17 | 0 | Reason Code |
| 18 | 1330161808 | Exchange timestamp |
| 19 | 1330161808 | Last modification time |
| 20 | 12345 | Participent (client id) |
| 21 | 123456789012345 | Term Ctcl |
| 22 | 0 | Remain quantity |
| 23 | 25 | Total Original quantity |
REJECT Rejection
| Pos | Field | Description |
|---|---|---|
| 1 | -9999 | Rejection |
| 2 | 5 | Exchange identifier |
| 3 | 52166 | Instrument token |
| 4 | BANKNIFTY | Trading symbol |
| 5 | 02/24/2022 | Contract expiry |
| 6 | OPTIDX | Instrument type |
| 7 | 36200.00 | Option strike price |
| 8 | CE | Option Type |
| 9 | PRO | Trading client |
| 10 | Rejected | Order Id |
| 11 | 0 | Trade No |
| 12 | 0 | Executed quantity |
| 13 | 35 | Execution price |
| 14 | 202202241021 | Echo Back Client reference |
| 15 | 2 | 1=Buy, 2=Sell |
| 16 | -1106 | Error Code |
| 17 | 0 | Reason Code |
| 18 | 0 | Exchange timestamp |
| 19 | 0 | Last modification time |
| 20 | 12345 | Participent (client id) |
| 21 | 123456789012345 | Term Ctcl |
| 22 | 0 | Remain quantity |
| 23 | 25 | Total Original quantity |
| 23 | Dealer TotalBuyValue M:50000.00 N:49300.50 | Error Message |
Broadcast Format
| Pos | Field | Description |
|---|---|---|
| 1 | 57439 | Token |
| 2 | NIFTY | Scrip |
| 3 | 5 | Exchange |
| 4 | 03/03/2022 | Expiry_date |
| 5 | OPTIDX | Instrument |
| 6 | CE | Option Type |
| 7 | 17000.00 | Strike price |
| 8 | 50 | Last trade quantity |
| 9 | 9165 | Last traded price |
| 10 | 9150 | Bid price1 |
| 11 | 900 | Bid quantity1 |
| 12 | 9145 | Bid price2 |
| 13 | 500 | Bid quantity2 |
| 14 | 9170 | Ask price1 |
| 15 | 400 | Ask quantity1 |
| 16 | 9175 | Ask price2 |
| 17 | 900 | Ask quantity2 |
| 18 | 53087000 | Total traded quantity |
| 19 | 0 | Open interest |
Socket Authentication
You MUST protect production sockets. Below are recommended options from simple to most secure.
Shared Secret (Simple)
- Client sends a secret key as the first message after connecting.
- Server validates the secret; if invalid, server closes the connection.
Pros: Easy to implement.
Cons: Secret can be intercepted unless used with TLS.
Handshake example:
1. Server sends AUTH_REQUIRED\n
2. Client sends AUTH|<secret-key>\n
3. Server replies AUTH_OK\n or AUTH_FAIL\n
Heartbeat / Keepalive
- Implement periodic heartbeat messages such as PING\n / PONG\n to detect dead sockets and network issues.
- OS-level TCP keepalive should also be enabled.
Python Sample
Python Simple authenticated client connection
import socket HOST = "127.0.0.1" PORT = 5000 SECRET_KEY = "mysecret123" client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) client.connect((HOST, PORT)) # Receive AUTH request msg = client.recv(1024).decode() if msg == "AUTH:": client.send(SECRET_KEY.encode()) reply = client.recv(1024).decode() if reply != "AUTH_OK": print("Authentication failed") client.close() else: print("Authenticated!") # Continue sending/receiving client.send(b"Hello server") print(client.recv(1024).decode()) client.close()Server Connections
import socket HOST = "0.0.0.0" PORT = 5000 SECRET_KEY = "mysecret123" # shared key server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server.bind((HOST, PORT)) server.listen() print("Server running...") conn, addr = server.accept() print("Connected:", addr) # Step 1: Ask for authentication conn.send(b"AUTH:") # Step 2: Receive client key client_key = conn.recv(1024).decode().strip() if client_key != SECRET_KEY: conn.send(b"AUTH_FAILED") conn.close() else: conn.send(b"AUTH_OK") print("Client authenticated successfully!") # Continue your normal string-based message exchange while True: data = conn.recv(1024).decode() if not data: break print("Received:", data) conn.send(b"Response from server. Thank you I received data.") conn.close()Broadcast receiver (Sample Code)
import socket HOST = "127.0.0.1" # Server IP (change as needed) PORT = 10124 # Port to read from (use your response socket port) try: # Create TCP socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) print(f"Connected to {HOST}:{PORT}") while True: data = s.recv(1024) # Receive up to 1024 bytes if not data: break # Connection closed print("Received:", data.decode().strip()) except Exception as e: print("Error:", e) finally: s.close()Server-side (Bridge) Behavior
- Accept connections on both ports.
- Authenticate incoming request connections before reading order messages.
- Push responses / events on response socket (client should be listening).
- Handle partial reads/writes and message framing robustly.
- Implement logging for audit (timestamps, clientid, raw messages).
- Implement rate limiting and input validation to protect the backend.
Error Handling & Response Codes
Use consistent error responses. Example values:
- REJECTED: Order rejected due to validation
- ERROR: Internal processing error
- TIMEOUT: Processing timed out
- AUTH_FAIL: Authentication failed
- INVALID: Invalid message format
Example error reply:
1004|REJECTED|Requested order string is not as per requirement.\n
Performance & Best Practices
- Keep sockets long-lived avoid connect/disconnect per-order.
- Use non-blocking IO or separate threads for read/write to prevent head-of-line blocking.
- Implement buffering and incremental parsing for large messages.
- Avoid heavy logging on hot paths; use sampling or async logging.
- Measure latency (end-to-end) and set SLAs(Service Level Agreements)
For example:
- 99% of orders will be responded within 50 ms
- Maximum allowed latency: 100 ms
- System uptime: 99.9%
These give customers confidence that your system is reliable
RMS
Risk Management System is a control layer that ensures all trades follow predefined risk limits and regulatory rules before orders are sent to the exchange.
RMS ensures that only valid and permitted orders are placed in the market. It protects traders, brokers, and exchanges from financial, operational, and compliance risks.
Orders are validated against predefined RMS rules.
- Index band check
- Market Price Protection (Yesterday Close check)
- Exposure limit checks (Bot Limit)
- Security Filter & No of instance limit
- Blacklisting (BAN/FII/MWPL) of scrip
- Single Order Value and Quantity checks
- Total Order value and Quantity checks
- Total Turnover checks
- Cash In Hand check
- Cumulative Open Order Value (COOV) check
- Security wise quantity checks
- Net Quantity check
- DPR Check
- LTP Check
Note: The RMS checks listed above are standard validations. Users can add various other custom RMS checks as per their specific requirements. Our system is flexible and can accommodate additional risk management rules beyond those mentioned here.
Margin
Margin checks are applied post order acceptance.
- SPAN Margin (Initial Margin)
- Exposure Margin
We show Total Margin.
API has facility to restrict order on margin breach.
Real-Time Trade Monitor
The Bridge API provides comprehensive real-time monitoring capabilities to track all your trading activities. Our monitoring interface gives you complete visibility into your trades, positions, and order execution status.
Live Trade View
Monitor all executed trades in real-time with detailed information including instance number, execution time, symbol, quantity, and price. The live trade view helps you track your trading activity as it happens, providing instant feedback on order executions.
Live Trade Monitor - Real-time view of all executed trades
Detailed Net Position View
Get comprehensive position tracking with our detailed net position monitor. This view provides in-depth analysis including quantity exposure, rupee exposure, threshold quantities, buy/sell values, profit/loss calculations, and real-time margin requirements. The square-off thresholds help you manage risk effectively.
Detailed Net Position Monitor - Comprehensive position tracking with P&L analysis
Key Features
- Real-Time Updates: All trade data and positions are updated in real-time as orders are executed
- Comprehensive Metrics: Track quantity, price, exposure, margins, and profit/loss for all positions
- Risk Management: Built-in square-off thresholds
- Export Capabilities: Generate CSV reports for detailed analysis and record-keeping