Update app.py
Browse files
app.py
CHANGED
@@ -18,22 +18,25 @@ def get_data():
|
|
18 |
}
|
19 |
response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
|
20 |
data = response.json()
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
df = pd.concat(df_list)
|
28 |
return df
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
return df
|
33 |
-
|
34 |
-
if st.button("sosis"):
|
35 |
-
# Retrieve historical data from Coinex API
|
36 |
df = get_data()
|
37 |
|
38 |
-
|
39 |
-
|
|
|
|
|
|
18 |
}
|
19 |
response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
|
20 |
data = response.json()
|
21 |
+
|
22 |
+
try:
|
23 |
+
df = pd.DataFrame(data['data'])
|
24 |
+
df['time'] = pd.to_datetime(df['time'], unit='ms') # Assuming the timestamp key is 'time'
|
25 |
+
df.set_index('time', inplace=True)
|
26 |
+
df.drop(['vol', 'amount'], axis=1, inplace=True)
|
27 |
+
df_list.append(df)
|
28 |
+
except KeyError as e:
|
29 |
+
st.error(f"KeyError: {e}. Please check the keys in the data returned by the API.")
|
30 |
+
return None
|
31 |
|
32 |
df = pd.concat(df_list)
|
33 |
return df
|
34 |
|
35 |
+
if st.button("Fetch historical data"):
|
36 |
+
# Retrieve historical data from Coinex API
|
|
|
|
|
|
|
|
|
37 |
df = get_data()
|
38 |
|
39 |
+
if df is not None:
|
40 |
+
# Save historical data to btcusdt_data.pkl
|
41 |
+
df.to_pickle('btcusdt_data.pkl')
|
42 |
+
st.write("Data fetched successfully and saved to btcusdt_data.pkl")
|