https://github.com/porcelaincode/tradehub
This aims to be an adaptor over your preferred broker or just a mock broker server for paper trading. Using Sqlite3, written in Go.
https://github.com/porcelaincode/tradehub
golang trading
Last synced: 5 months ago
JSON representation
This aims to be an adaptor over your preferred broker or just a mock broker server for paper trading. Using Sqlite3, written in Go.
- Host: GitHub
- URL: https://github.com/porcelaincode/tradehub
- Owner: porcelaincode
- Created: 2024-06-25T17:52:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-27T18:56:50.000Z (over 1 year ago)
- Last Synced: 2025-01-29T15:17:07.938Z (about 1 year ago)
- Topics: golang, trading
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# TradeHub: Mock Broker Server
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.
## Features
- 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.
## Endpoints
### POST /subscribe
Subscribe to an array of instrument tokens to receive simulated market data.
Request body:
```json
[{ "instrument_token": "11536", "exchange_segment": "nse_cm" }]
```
### POST /orders
Place an order with the specified parameters.
Request body:
```json
{
"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"
}
```
### GET /positions
Retrieve the current positions.
Response:
```json
{
"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"
}
]
}
```
## TODO
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