forked from GammaStrategies/uniswap-v3-performance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
250 lines (176 loc) · 6.74 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import logging
from flask import Flask, request, Response
from flask_caching import Cache
from flask_cors import CORS
from v3data import IndexNodeClient
from v3data.pools import pools_from_symbol
from v3data.bollingerbands import BollingerBand
from v3data.charts import BaseLimit, Benchmark, DailyChart
from v3data.hypervisor import HypervisorData
from v3data.visr import VisrInfo, VisrYield, VisrDistribution
from v3data.eth import EthDistribution
from v3data.users import UserInfo
from v3data.visor import VisorVaultInfo
from v3data.toplevel import TopLevelData
from v3data.dashboard import Dashboard
from v3data.config import DEFAULT_TIMEZONE, CHARTS_CACHE_TIMEOUT
from v3data.utils import parse_date
logging.basicConfig(
format='[%(asctime)s:%(levelname)s]:%(message)s',
datefmt='%Y/%m/%d %I:%M:%S',
level=logging.INFO
)
app = Flask(__name__)
app.config.from_mapping({'CACHE_TYPE': 'SimpleCache'})
cache = Cache(app)
CORS(app)
@app.route('/')
def main():
return "Visor Data"
@app.route('/status/subgraph')
def subgraph_status():
client = IndexNodeClient()
return client.status()
@app.route('/charts/bollingerbands/<string:poolAddress>')
@app.route('/bollingerBandsChartData/<string:poolAddress>')
@cache.cached(timeout=CHARTS_CACHE_TIMEOUT)
def bollingerbands_chart(poolAddress):
periodHours = int(request.args.get("periodHours", 24))
bband = BollingerBand(poolAddress, periodHours)
return {'data': bband.chart_data()}
@app.route('/bollingerBandsLatest/<string:poolAddress>')
def bollingerbands_latest(poolAddress):
periodHours = int(request.args.get("periodHours", 24))
bband = BollingerBand(poolAddress, periodHours)
return bband.latest_bands()
@app.route('/charts/dailyTvl')
@cache.cached(timeout=CHARTS_CACHE_TIMEOUT)
def daily_tvl_chart_data():
days = int(request.args.get("days", 20))
daily = DailyChart(days)
return {'data': daily.tvl()}
@app.route('/charts/dailyFlows')
def daily_flows_chart_data():
days = int(request.args.get("days", 20))
daily = DailyChart(days)
return {'data': daily.asset_flows()}
@app.route('/charts/dailyHypervisorFlows/<string:hypervisor_address>')
def daily_hypervisor_flows_chart_data(hypervisor_address):
days = int(request.args.get("days", 20))
daily = DailyChart(days)
return {'data': daily.asset_flows(hypervisor_address)}
@app.route('/charts/baseRange/<string:hypervisor_address>')
@cache.cached(timeout=CHARTS_CACHE_TIMEOUT)
def base_range_chart(hypervisor_address):
hours = int(request.args.get("days", 20)) * 24
hypervisor_address = hypervisor_address.lower()
baseLimitData = BaseLimit(hours=hours, chart=True)
chart_data = baseLimitData.rebalance_ranges(hypervisor_address)
if chart_data:
return {hypervisor_address: chart_data}
else:
return {}
@app.route('/charts/baseRange/all')
@cache.cached(timeout=CHARTS_CACHE_TIMEOUT)
def base_range_chart_all():
hours = int(request.args.get("days", 20)) * 24
baseLimitData = BaseLimit(hours=hours, chart=True)
chart_data = baseLimitData.all_rebalance_ranges()
return chart_data
@app.route('/charts/benchmark/<string:hypervisor_address>')
# @cache.cached(timeout=CHARTS_CACHE_TIMEOUT)
def benchmark_chart(hypervisor_address):
start_date = parse_date(request.args.get("startDate"))
end_date = parse_date(request.args.get("endDate"))
hypervisor_address = hypervisor_address.lower()
benchmark = Benchmark(hypervisor_address, start_date, end_date)
chart_data = benchmark.chart()
if chart_data:
return {hypervisor_address: chart_data}
else:
return {}
@app.route('/user/<string:address>')
def user_data(address):
user_info = UserInfo(address)
return user_info.output(get_data=True)
@app.route('/vault/<string:address>')
def visor_data(address):
visor_vault_info = VisorVaultInfo(address)
return visor_vault_info.output()
@app.route('/pools/<string:token>')
def uniswap_pools(token):
return {"pools": pools_from_symbol(token)}
@app.route('/visr/basicStats')
def visr_basic_stats():
visr_info = VisrInfo(days=30)
return visr_info.output()
@app.route('/visr/yield')
def visr_yield():
visr_yield = VisrYield(days=30)
return visr_yield.output()
@app.route('/visr/dailyDistribution')
def visr_distributions():
days = int(request.args.get("days", 6))
timezone = request.args.get("timezone", DEFAULT_TIMEZONE).upper()
if timezone not in ['UTC', 'UTC-5']:
return Response("Only UTC and UTC-5 timezones supported", status=400)
visr_distributions = VisrDistribution(days=days, timezone=timezone)
return visr_distributions.output()
@app.route('/eth/dailyDistribution')
def eth_distributions():
days = int(request.args.get("days", 6))
timezone = request.args.get("timezone", DEFAULT_TIMEZONE).upper()
if timezone not in ['UTC', 'UTC-5']:
return Response("Only UTC and UTC-5 timezones supported", status=400)
eth_distributions = EthDistribution(days=days, timezone=timezone)
return eth_distributions.output()
@app.route('/hypervisor/<string:hypervisor_address>/basicStats')
def hypervisor_basic_stats(hypervisor_address):
hypervisor = HypervisorData()
basic_stats = hypervisor.basic_stats(hypervisor_address)
if basic_stats:
return basic_stats
else:
return Response("Invalid hypervisor address or not enough data", status=400)
@app.route('/hypervisor/<string:hypervisor_address>/returns')
def hypervisor_apy(hypervisor_address):
hypervisor = HypervisorData()
returns = hypervisor.calculate_returns(hypervisor_address)
if returns:
return {
"hypervisor": hypervisor_address,
"returns": returns
}
else:
return Response("Invalid hypervisor address or not enough data", status=400)
@app.route('/hypervisors/aggregateStats')
def aggregate_stats():
top_level = TopLevelData()
top_level_data = top_level.all_stats()
return {
'totalValueLockedUSD': top_level_data['tvl'],
'pairCount': top_level_data['pool_count'],
'totalFeesClaimedUSD': top_level_data['fees_claimed']
}
@app.route('/hypervisors/recentFees')
def recent_fees():
hours = int(request.args.get("hours", 24))
top_level = TopLevelData()
recent_fees = top_level.recent_fees(hours)
return {
"periodHours": hours,
"fees": recent_fees
}
@app.route('/hypervisors/returns')
def hypervisors_return():
hypervisor = HypervisorData()
return hypervisor.all_returns()
@app.route('/hypervisors/allData')
def hypervisors_all():
hypervisor = HypervisorData()
return hypervisor.all_data()
@app.route('/dashboard')
def dashboard():
period = request.args.get("period", "monthly").lower()
dashboard = Dashboard(period)
return dashboard.info('UTC')