PyTrading is a sandbox stock market project written in Python 3.
This project has an educational purpose to learn how financial markets work.
| GNU/Linux | Windows | Static analysis | Code coverage |
|---|---|---|---|
Download protoc (e.g. protoc v28.3 for Windows 64 bits)
To generate Protobuf "_pb2.py" files:
cd pytrading\protobuf
protoc --python_out=. *.proto
- An order is composed of a price, a quantity, a way (buy or sell) and the instrument you want to trade (e.g. Apple stock)
- A deal is generated when there is a match between two orders on same price and same instrument (order book's last price is updated)
- An order book hosts every incoming orders waiting to be executed (most interesting price comes first)
TradingServeris composed of two servers: a matching engine and a feeder.MatchingEngineaccepts orders from clients and try to match them.Feederstreams continuously order books content (full snapshot).
TradingClientconnects two client sockets: an ordersender and a feedhandler.OrderSendersends order according to algorithm implemented inmain_loop_hookFeedHandlerreceives order book updates (e.g. price modified, executed order etc..)
TradingServer and TradingClient communicates via TCP/IP serialized messages.
Two serializations are available: plain text (pipe separated) and Protobuf.
TradingSandbox module gives a good example to start in local, take a look in main_loop_hook implementation.
- MongoDB
- Protobuf