Download app.py from Pezh/Cctx: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/Pezh/Cctx/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pezh/Cctx/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pezh/Cctx/resolve/main/app.py
1.72 kB
| import streamlit as st | |
| import ccxt | |
| import pandas as pd | |
| import time | |
| # Create the exchange object | |
| exchange = ccxt.bitfinex() | |
| # Define the time interval | |
| timeframe = '4h' | |
| def get_data(symbol): | |
| # Initialize an empty list to store the data | |
| data = [] | |
| # Set the start time to the earliest possible time | |
| start = 0 | |
| # Set the limit to the maximum number of data points that can be fetched in a single request | |
| limit = 2000 | |
| # Fetch the data in smaller chunks | |
| while True: | |
| # Fetch the data for the current chunk | |
| ohlcv = exchange.fetch_ohlcv(symbol, timeframe, since=start, limit=limit) | |
| # If the data is empty, break the loop | |
| if not ohlcv: | |
| break | |
| # Append the data to the list | |
| data.extend(ohlcv) | |
| # Set the start time for the next chunk to the timestamp of the last data point in the current chunk | |
| start = ohlcv[-1][0] | |
| time.sleep(1) | |
| # Convert the list to a pandas DataFrame | |
| df = pd.DataFrame(data, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume']) | |
| # Convert the timestamp to a datetime object | |
| df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms') | |
| # Set the timestamp as the index | |
| df.set_index('timestamp', inplace=True) | |
| return df | |
| # Add a text input for the cryptocurrency symbol | |
| symbol = st.text_input('Enter the cryptocurrency symbol (e.g. BTC/USD)') | |
| # Add a button to fetch the data | |
| if st.button('Fetch data'): | |
| if symbol: | |
| try: | |
| data = get_data(symbol) | |
| st.write(data) | |
| except Exception as e: | |
| st.error(f'Error fetching data: {e}') | |
| else: | |
| st.warning('Please enter a cryptocurrency symbol.') | |