Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import requests
|
3 |
+
import time
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
def get_data():
|
7 |
+
data_points = 10000
|
8 |
+
interval = '1h'
|
9 |
+
limit = 1500
|
10 |
+
start_time = int(time.time() * 1000) - (data_points * 60 * 60 * 1000)
|
11 |
+
df_list = []
|
12 |
+
|
13 |
+
for i in range(0, data_points, limit):
|
14 |
+
params = {
|
15 |
+
'interval': interval,
|
16 |
+
'limit': limit,
|
17 |
+
'start_time': start_time + (i * 60 * 60 * 1000)
|
18 |
+
}
|
19 |
+
response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
|
20 |
+
data = response.json()
|
21 |
+
df = pd.DataFrame(data['data'])
|
22 |
+
df['time'] = pd.to_datetime(df['time'], unit='ms')
|
23 |
+
df.set_index('time', inplace=True)
|
24 |
+
df.drop(['vol', 'amount'], axis=1, inplace=True)
|
25 |
+
df_list.append(df)
|
26 |
+
|
27 |
+
df = pd.concat(df_list)
|
28 |
+
return df
|
29 |
+
|
30 |
+
if button("sosis"):
|
31 |
+
# Retrieve historical data from Coinex API
|
32 |
+
df = get_data()
|
33 |
+
|
34 |
+
# Save historical data to btcusdt_data.pkl
|
35 |
+
df.to_pickle('btcusdt_data.pkl')
|