-
Notifications
You must be signed in to change notification settings - Fork 3
/
flip.py
108 lines (83 loc) · 2.86 KB
/
flip.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
API_KEY = ""
import requests
import json
import time
import streamlit as st
import pandas as pd
import plotly.express as px
SQL_QUERY = """
SELECT
date_trunc('hour',block_timestamp) as hour,
sum(amount) as withdrawals,
from_label
FROM ethereum.udm_events
WHERE
block_timestamp >= getdate() - interval '480 hours'
and from_label_type = 'cex'
and (to_label_type <> 'cex' OR to_label_type IS NULL)
and symbol = 'CEL'
GROUP BY 1,3
order by 1 desc
"""
API_KEY = st.text_input("Enter your API key", API_KEY )
SQL_QUERY = st.text_input("Enter your SQL query", SQL_QUERY)
TTL_MINUTES = 15
def create_query():
r = requests.post(
'https://node-api.flipsidecrypto.com/queries',
data=json.dumps({
"sql": SQL_QUERY,
"ttlMinutes": TTL_MINUTES
}),
headers={"Accept": "application/json", "Content-Type": "application/json", "x-api-key": API_KEY},
)
if r.status_code != 200:
raise Exception("Error creating query, got response: " + r.text + "with status code: " + str(r.status_code))
return json.loads(r.text)
def get_query_results(token):
r = requests.get(
'https://node-api.flipsidecrypto.com/queries/' + token,
headers={"Accept": "application/json", "Content-Type": "application/json", "x-api-key": API_KEY}
)
if r.status_code != 200:
raise Exception("Error getting query results, got response: " + r.text + "with status code: " + str(r.status_code))
data = json.loads(r.text)
if data['status'] == 'running':
time.sleep(10)
return get_query_results(token)
return data
query = create_query()
token = query.get('token')
data = get_query_results(token)
# print(data['columnLabels'])
# for row in data['results']:
# print(row)
# return data
data = pd.DataFrame(data['results'], columns=data['columnLabels'])
st.write(data)
st.plotly_chart(px.bar(data, x="HOUR", y="WITHDRAWALS", color = 'FROM_LABEL'))
# def func():
# st.plotly_chart(px.line(data, x="DAYZ", y="ETH_SPENT_FEES_NATIVE"))
# http://localhost:3000, http://localhost:3001
# SELECT
# date_trunc('day',block_timestamp) as hour,
# sum(amount) as withdrawals,
# from_label
# FROM ethereum.udm_events
# WHERE
# block_timestamp >= getdate() - interval '4800 hours'
# and from_label_type = 'cex'
# and (to_label_type <> 'cex' OR to_label_type IS NULL)
# and symbol = 'CEL'
# GROUP BY 1,3
# SELECT
# date_trunc('day',block_timestamp) as hour,
# sum(amount) as deposits,
# to_label
# FROM ethereum.udm_events
# WHERE
# block_timestamp >= getdate() - interval '4800 hours'
# and to_label_type = 'cex'
# and (from_label_type <> 'cex' OR from_label_type IS NULL)
# and symbol = 'CEL'
# GROUP BY 1,3