{"id":17352824,"url":"https://github.com/gavincyi/lightmatchingengine","last_synced_at":"2025-04-04T19:11:00.286Z","repository":{"id":45191684,"uuid":"81263233","full_name":"gavincyi/LightMatchingEngine","owner":"gavincyi","description":"A very light matching engine in Python.","archived":false,"fork":false,"pushed_at":"2022-01-02T10:01:59.000Z","size":63,"stargazers_count":332,"open_issues_count":2,"forks_count":92,"subscribers_count":28,"default_branch":"develop","last_synced_at":"2025-03-28T18:07:18.846Z","etag":null,"topics":["hft-trading","matching-engine","order","orderbook","trading"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gavincyi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-07T22:53:43.000Z","updated_at":"2025-03-23T20:22:38.000Z","dependencies_parsed_at":"2022-08-26T10:31:28.949Z","dependency_job_id":null,"html_url":"https://github.com/gavincyi/LightMatchingEngine","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavincyi%2FLightMatchingEngine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavincyi%2FLightMatchingEngine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavincyi%2FLightMatchingEngine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gavincyi%2FLightMatchingEngine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gavincyi","download_url":"https://codeload.github.com/gavincyi/LightMatchingEngine/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234921,"owners_count":20905854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hft-trading","matching-engine","order","orderbook","trading"],"created_at":"2024-10-15T17:14:46.469Z","updated_at":"2025-04-04T19:11:00.269Z","avatar_url":"https://github.com/gavincyi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LightMatchingEngine\n\nA light matching engine written in Python. \n\nThe engine is a trivial object to support\n\n* Add order - Returns the order and filled trades\n* Cancel order - Returns the original order\n\nThe objective is to provide a easy interface for users on the standard\nprice-time priority matching algorithm among different instruments.\n\n## Installation\n\nThe package can be installed by:\n\n```\npip install lightmatchingengine\n```\n\n## Usage\n\nCreate a matching engine instance. \n\n```\nfrom lightmatchingengine.lightmatchingengine import LightMatchingEngine, Side\n\nlme = LightMatchingEngine()\n```\n\nPlace an order.\n\n```\norder, trades = lme.add_order(\"EUR/USD\", 1.10, 1000, Side.BUY)\n```\n\nCancel an order.\n\n```\ndel_order = lme.cancel_order(order.order_id, order.instmt)\n```\n\nFill an order.\n\n```\nbuy_order, trades = lme.add_order(\"EUR/USD\", 1.10, 1000, Side.BUY)\nprint(\"Number of trades = %d\" % len(trades))                # Number of trades = 0\nprint(\"Buy order quantity = %d\" % buy_order.qty)            # Buy order quantity = 1000\nprint(\"Buy order filled = %d\" % buy_order.cum_qty)          # Buy order filled = 0\nprint(\"Buy order leaves = %d\" % buy_order.leaves_qty)       # Buy order leaves = 1000\n\nsell_order, trades = lme.add_order(\"EUR/USD\", 1.10, 1000, Side.SELL)\nprint(\"Number of trades = %d\" % len(trades))                # Number of trades = 2\nprint(\"Buy order quantity = %d\" % buy_order.qty)            # Buy order quantity = 1000\nprint(\"Buy order filled = %d\" % buy_order.cum_qty)          # Buy order filled = 1000\nprint(\"Buy order leaves = %d\" % buy_order.leaves_qty)       # Buy order leaves = 0\nprint(\"Trade price = %.2f\" % trades[0].trade_price)         # Trade price = 1.10\nprint(\"Trade quantity = %d\" % trades[0].trade_qty)          # Trade quantity = 1000\nprint(\"Trade side = %d\" % trades[0].trade_side)             # Trade side = 2\n\n```\n\nFailing to delete an order returns a None value.\n\n```\ndel_order = lme.cancel_order(9999, order.instmt)\nprint(\"Is order deleted = %d\" % (del_order is not None))    # Is order deleted = 0\n```\n\n## Supported version\n\nPython 2.x and 3.x are both supported.\n\n## Order\n\nThe order object contains the following information:\n\n* Exchange order ID (order_id)\n* Instrument name (instmt)\n* Price (price)\n* Quantity (qty)\n* Side (Buy/Sell) (side)\n* Cumulated filled quantity (cum_qty)\n* Leaves quantity (leaves_qty)\n\n## Trade\n\nThe trade object contains the following information:\n\n* Trade ID (trade_id)\n* Instrument name (instmt)\n* Exchange order ID (order_id)\n* Trade price (trade_price)\n* Trade quantity (trade_qty)\n* Trade side (trade_side)\n\n## Performance\n\nTo run the performance test, run the commands\n\n```\npip install lightmatchingengine[performance]\npython tests/performance/performance_test.py --freq 20\n```\n\nIt returns the latency in nanosecond like below\n\n|       |      add |   cancel |   add (trade \u003e 0) |   add (trade \u003e 2.0) |\n|:------|---------:|---------:|------------------:|--------------------:|\n| count | 100      |  61      |           27      |               6     |\n| mean  | 107.954  |  50.3532 |          164.412  |             205.437 |\n| std   |  58.1438 |  16.3396 |           36.412  |              24.176 |\n| min   |  17.1661 |  11.4441 |           74.1482 |             183.105 |\n| 25%   |  81.3007 |  51.9753 |          141.382  |             188.47  |\n| 50%   |  92.5064 |  58.4126 |          152.349  |             200.748 |\n| 75%   | 140.19   |  59.3662 |          190.496  |             211.239 |\n| max   | 445.604  |  71.0487 |          248.909  |             248.909 |\n\n\n## Contact\n\nFor any inquiries, please feel free to contact me by gavincyi at gmail dot com.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavincyi%2Flightmatchingengine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgavincyi%2Flightmatchingengine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgavincyi%2Flightmatchingengine/lists"}