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 |
---|---|---|---|
To generate Protobuf "_pb2.py" files:
$ 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)
TradingServer
is composed of two servers: a matching engine and a feeder.MatchingEngine
accepts orders from clients and try to match them.Feeder
streams continuously order books content (full snapshot).
TradingClient
connects two client sockets: an ordersender and a feedhandler.OrderSender
sends order according to algorithm implemented inmain_loop_hook
FeedHandler
receives 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