Pezh commited on
Commit
471ab46
1 Parent(s): e640cc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
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
- df = pd.DataFrame(data['data'])
22
- df['open_time'] = pd.to_datetime(df['open_time'], unit='ms') # Replace 'date' with 'open_time'
23
- df.set_index('open_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
-
31
- df = pd.concat(df_list)
32
- return df
33
-
34
- if st.button("sosis"):
35
- # Retrieve historical data from Coinex API
36
  df = get_data()
37
 
38
- # Save historical data to btcusdt_data.pkl
39
- df.to_pickle('btcusdt_data.pkl')
 
 
 
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")