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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -19,15 +19,21 @@ def get_data():
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
@@ -39,4 +45,4 @@ if st.button("Fetch historical data"):
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")
 
19
  response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
20
  data = response.json()
21
 
22
+ if 'data' in data:
23
+ keys = data['data'][0].keys()
24
+ st.write(keys) # Print out the keys in the first data point
25
+
26
+ try:
27
+ df = pd.DataFrame(data['data'])
28
+ # Adjust the key based on the actual keys in the data dictionary
29
+ timestamp_key = 'time' if 'time' in keys else 'open_time'
30
+ df[timestamp_key] = pd.to_datetime(df[timestamp_key], unit='ms')
31
+ df.set_index(timestamp_key, inplace=True)
32
+ df.drop(['vol', 'amount'], axis=1, inplace=True)
33
+ df_list.append(df)
34
+ except KeyError as e:
35
+ st.error(f"KeyError: {e}. Please check the keys in the data returned by the API.")
36
+ return None
37
 
38
  df = pd.concat(df_list)
39
  return df
 
45
  if df is not None:
46
  # Save historical data to btcusdt_data.pkl
47
  df.to_pickle('btcusdt_data.pkl')
48
+ st.write("Data fetched successfully and saved to btcusdt_data.pkl")