The tracker has been hosted on my personal website.
Demo URL : https://pnl-tracker.demo.ivorynoise.com/docs
To test the flow manually using swagger:
- Please see the results using
/trades/&/portfolioendpoint. I have added same test data to it as mentioned in pdf :)
The data can be seen here: https://pnl-tracker.demo.ivorynoise.com/api/v1/trades
- Please clear all datastore before hitting any route.
Logic is presented here
pnl-tracker/src/position/models.py
Line 51 in 978053f
I avoided any custom class/conversion as I wanted to focus on clarity and keep the excercise short.
All datastores were mimicked using singleton classes
Test coverage was considered only for positions as it is where the core logic lives
The market price can be mimicked using /api/v1/prices endpoint. Also, I did not optimise for real-time pnl updates. The design and engineering decisions shown here will change for such features.
I did not consider fee while computing pnl
In case the sellQty > buyQty, we allow shorting to showcase the pnl calculation.
-
Build the program using
./build-run.sh. This builds and pushes to registry. It can then be deployed via kubernetes. -
To run locally, we can use the following command:
docker run -p 8000:8000 ivorynoise/pnl-tracker