In finance, volume-weighted average price (VWAP) is the ratio of the value traded to total volume traded over a particular time horizon (usually one day). It is a measure of the average price at which a stock is traded over the trading horizon (Wikipedia).
This project aims to calculate the VWAP given one or more trading pairs pulling the data from Coinbase through its Websocket service.
The algorithm runs on-demand, meaning that the VWAP is recalculated after every trading data received, limiting to N tradings. When the limit is reached, the oldest trading will fall off.
The application architecture follows the principles of the Clean Architecture, originally described by Robert C. Martin. The foundation of this kind of architecture is the dependency injection, producing systems that are independent of external agents, testable and easier to maintain. You can read more about Clean Architecture here.
To start the on-demand VWAP calculation, it is required to inform the tradings provider and the structure to stream the VWAP result.
For test purposes, it's only available Coinbase as a provider and the notification is printing the result in stdout. But, it's easy to add more providers implementing its interface and propagating the Trading to the proper channel, as well is easy to implement a real notification structure using some real stream data technology, then injecting both dependencies in the VWAP calculation use case.
With docker you can start the application running make docker-run
or use make run
.
To run all tests you can run make docker-tests
or make tests
.
- Avoiding perform math counts with float64. Instead, would be better to use integer numbers and avoid floating point issues.
-
Improving the VWAP algorithm to avoid go over the full slice every time to execute the calculation.