Skip to content
This repository was archived by the owner on Sep 4, 2025. It is now read-only.
/ tradehub Public archive

This aims to be an adaptor over your preferred broker or just a mock broker server for paper trading. Using Sqlite3, written in Go.

Notifications You must be signed in to change notification settings

porcelaincode/tradehub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

[{ "instrument_token": "11536", "exchange_segment": "nse_cm" }]

POST /orders

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"
}

GET /positions

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"
    }
  ]
}

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

About

This aims to be an adaptor over your preferred broker or just a mock broker server for paper trading. Using Sqlite3, written in Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published