Pezh commited on
Commit
3416086
1 Parent(s): 58382a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -19,13 +19,10 @@ def get_data():
19
  response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
20
  data = response.json()
21
 
22
- st.write(data) # Print out the entire data dictionary
23
-
24
- if 'data' in data:
25
  try:
26
  df = pd.DataFrame(data['data'])
27
- # Access the data keys based on the actual structure of the data dictionary
28
- timestamp_key = 'time' # Adjust this based on the structure
29
  df[timestamp_key] = pd.to_datetime(df[timestamp_key], unit='ms')
30
  df.set_index(timestamp_key, inplace=True)
31
  df.drop(['vol', 'amount'], axis=1, inplace=True)
@@ -33,6 +30,9 @@ def get_data():
33
  except KeyError as e:
34
  st.error(f"KeyError: {e}. Please check the keys in the data returned by the API.")
35
  return None
 
 
 
36
 
37
  df = pd.concat(df_list)
38
  return df
 
19
  response = requests.get('https://api.coinex.com/v1/market/kline/BTCUSDT', params=params)
20
  data = response.json()
21
 
22
+ if 'data' in data and data['data']: # Check if 'data' is present and not empty
 
 
23
  try:
24
  df = pd.DataFrame(data['data'])
25
+ timestamp_key = 'time' # Adjust this based on the data structure
 
26
  df[timestamp_key] = pd.to_datetime(df[timestamp_key], unit='ms')
27
  df.set_index(timestamp_key, inplace=True)
28
  df.drop(['vol', 'amount'], axis=1, inplace=True)
 
30
  except KeyError as e:
31
  st.error(f"KeyError: {e}. Please check the keys in the data returned by the API.")
32
  return None
33
+ else:
34
+ st.error("Data not found in the API response.")
35
+ return None
36
 
37
  df = pd.concat(df_list)
38
  return df