This project is a mock broker server built with FastAPI, allowing you to paper trade using simulated market data. The server handles instruments, orders, positions, and emits relevant events via WebSockets.
- Downloads instruments from an external API and stores them in an SQLite database.
- Provides endpoints for subscribing to instrument tokens and placing orders.
- Simulates live market data and emits events for subscribed instruments.
- Handles orders and updates positions, including GTT and regular orders.
Subscribe to an array of instrument tokens to receive simulated market data.
Request body:
[{ "instrument_token": "11536", "exchange_segment": "nse_cm" }]Place an order with the specified parameters.
Request body:
{
"am": "YES",
"dq": "0",
"es": "nse_cm",
"mp": "0",
"pc": "NRML",
"pf": "N",
"pr": "100.5",
"pt": "L",
"qt": "10",
"rt": "DAY",
"tp": "0",
"ts": "YESBANK-EQ",
"tt": "B",
"ig": "order_tag"
}Retrieve the current positions.
Response:
{
"stat": "Ok",
"stCode": 200,
"data": [
{
"buyAmt": "2625.00",
"cfSellAmt": "0.00",
"prod": "NRML",
"exSeg": "nse_fo",
"sqrFlg": "Y",
"actId": "PRS2206",
"cfBuyQty": "0",
"cfSellQty": "0",
"tok": "53179",
"flBuyQty": "25",
"flSellQty": "25",
"sellAmt": "2625.00",
"posFlg": "true",
"cfBuyAmt": "0.00",
"stkPrc": "0.00",
"trdSym": "BANKNIFTY21JULFUT",
"sym": "BANKNIFTY",
"expDt": "29 Jul, 2021",
"type": "FUTIDX",
"series": "XX",
"brdLtQty": "25",
"exp": "1627569000",
"optTp": "XX",
"genNum": "1",
"genDen": "1",
"prcNum": "1",
"prcDen": "1",
"lotSz": "25",
"multiplier": "1",
"precision": "2",
"hsUpTm": "2021/07/13 18:34:44"
}
]
}Write better random LTP generation logic
Move the database to Aerospike or Redis for better performance
Handle concurrency and transaction Handling such that all database operations are performed within proper transactions to maintain data integrity.
Add detailed error handling and logging to capture and debug issues effectively.
Implement necessary security measures such as authentication and authorization if required.
Optimize database queries and WebSocket handling for better performance under load.
Write the entire thing in Go lang