https://github.com/letsila/vwap
Real time crypto VWAP calculator
https://github.com/letsila/vwap
Last synced: about 2 months ago
JSON representation
Real time crypto VWAP calculator
- Host: GitHub
- URL: https://github.com/letsila/vwap
- Owner: letsila
- License: mit
- Created: 2021-12-04T15:49:24.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-06T17:12:32.000Z (over 4 years ago)
- Last Synced: 2025-12-03T11:58:17.342Z (7 months ago)
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VWAP calculator
A realtime VWAP calculator of crypto currencies. It uses coinbase as its default provider for real time data over websocket.

## Design
The service in `./internal/service.go` is composed of two main components:
* A websocket client that pulls data off an exchange.
* The default choice is coinbase.
* Any exchange can be used as long as it implements the client interface defined in the websocket package.
* A list of data points defined in the VWAP package.
* The VWAP calculation is performed each time a data point is pushed to the list and saved in a hash map for each trading pairs.
* We don't loop over the datapoints so the VWAP calculation is done in constant time, O(1).
## Configuration
The following flags are available while running the project through CLI using the binary.
* `trading-pairs`: a comma separated strings of crypto currencies pairs, default is set to `BTC-USD,ETH-USD,ETH-BTC`
* `ws-url`: the URL of the websocket server to use, default is coinbase websocket URL.
* `window-size`: the sliding window used for the VWAP calculation, default is set to **200**.
## Decimal
For precision sake we used https://github.com/shopspring/decimal for all calculation.
## Run it
First, make sure that you have go version 0.17 installed on your machine. Then ...
```
make run
```
or
```
make build
```
then ...
```
./vwap -ws-url "" -trading-pairs "" -window-size
```
## Tests
* Runs all the tests.
```
make test
```
* Runs the unit tests.
```
make test-unit
```
* Runs the integration test.
```
make test-intergration
```