-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
# eth_analytics | ||
# Ethereum Analytics | ||
|
||
A repository to track blockchain analytics. This repo is WIP and code should be expected to break. | ||
|
||
## Getting Started | ||
|
||
Using a python3 environment, run the following to install all the libraries used in this repository: | ||
``` | ||
pip install -r requirements.txt | ||
``` | ||
Recommend using virtualenv to sandbox your work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
numpy==1.18.1 | ||
gql==2.0.0 | ||
plotly==4.5.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from gql import gql, Client | ||
from gql.transport.requests import RequestsHTTPTransport | ||
|
||
sample_transport=RequestsHTTPTransport( | ||
url='https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2', | ||
verify=True, | ||
retries=5, | ||
) | ||
client = Client( | ||
transport=sample_transport | ||
) | ||
|
||
liquidity = [] | ||
volume = [] | ||
transactions = [] | ||
x = 11276855 | ||
|
||
while x > 11250000: | ||
query = gql(''' | ||
query { | ||
uniswapFactory(id: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f", block: {number: ''' + str(x) + '''}) { | ||
totalVolumeUSD | ||
totalLiquidityUSD | ||
txCount | ||
} | ||
} | ||
''') | ||
response = client.execute(query) | ||
liquidity_value = response['uniswapFactory']['totalLiquidityUSD'] | ||
volume_value = response['uniswapFactory']['totalVolumeUSD'] | ||
transactions_value = response['uniswapFactory']['txCount'] | ||
liquidity.insert(0, liquidity_value) | ||
volume.append(volume_value) | ||
transactions.append(transactions_value) | ||
x=x-1000 | ||
print(x) | ||
print(liquidity) | ||
|
||
import plotly.graph_objects as go | ||
from plotly.subplots import make_subplots | ||
import numpy as np | ||
|
||
# normalize or standardize data as | ||
''' | ||
liquidity = [float(i) for i in liquidity] | ||
volume = [float(i) for i in volume] | ||
transactions = [float(i) for i in transactions] | ||
liquidity = [float(i)/sum(liquidity) for i in liquidity] | ||
volume = [float(i)/sum(volume) for i in volume] | ||
transactions = [float(i)/sum(transactions) for i in transactions] | ||
#title = 'Uniswap Liquidity Over Time' | ||
labels = ['Liquidity', 'Volume', 'Transactions'] | ||
''' | ||
x = np.arange(len(liquidity)) | ||
|
||
# Create figure with secondary y-axis | ||
fig = make_subplots(specs=[[{"secondary_y": True}]]) | ||
|
||
# Add traces | ||
fig.add_trace( | ||
go.Scatter(x=x, y=liquidity, name="Liquidity"), | ||
secondary_y=False, | ||
) | ||
|
||
fig.add_trace( | ||
go.Scatter(x=x, y=volume, name="Volume"), | ||
secondary_y=True, | ||
) | ||
|
||
''' | ||
fig.add_trace( | ||
go.Scatter(x=x, y=transactions, name="Transactions"), | ||
secondary_y=True, | ||
) | ||
''' | ||
|
||
# Add figure title | ||
fig.update_layout( | ||
title_text="Uniswap Liquidity vs Volume" | ||
) | ||
|
||
# Set x-axis title | ||
fig.update_xaxes(title_text="Blocks") | ||
|
||
# Set y-axes titles | ||
fig.update_yaxes(title_text="Liquidity", secondary_y=False) | ||
fig.update_yaxes(title_text="Volume", secondary_y=True) | ||
|
||
fig.show() |