Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon committed May 8, 2024
1 parent 516b0af commit 130ca6f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# vwap
# VWAP

This repository implements a Volume Weighted Average Price (VWAP) calculator for the gno.land ecosystem. It retrieves trading data from the Gnoswap RPC API, calculates the exchange ratios between tokens, and computes the VWAP for each token pair.

## VWAP Calculation

The VWAP is calculated using the following formula:

$$
VWAP =
\begin{cases}
\frac{\sum_{i=1}^{n}{(Price_i \times Volume_i)}}{\sum_{i=1}^{n}{Volume_i}} & \text{if } \sum_{i=1}^{n}{Volume_i} > 0 \\
LastActivePrice & \text{if } \sum_{i=1}^{n}{Volume_i} = 0
\end{cases}
$$

where:

- $Price_i$ is the price of the $i$-th trade
- $Volume_i$ is the volume of the $i$-th trade
- $n$ is the total number of trades within the specified time window (e.g., last 10 minutes)
- $LastActivePrice$ is the last recorded price if there are no trades within the specified time window

The VWAP is calculated by summing up the product of price and volume for each trade within the specified time frame and dividing it by the total volume.

If there are no trades within the period, the last recorded price is used as the VWAP.

## Features

- Calculates the exchange ratios between tokens
- Computes the VWAP for each token pair based on the trading data from the last 10 minutes

## Pre-requisites

- Go version 1.22 or higher
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ module github.com/gnoswap-labs/vwap

go 1.22.2

require github.com/stretchr/testify v1.9.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/testify v1.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 130ca6f

Please sign in to comment.