Download Kpp.py from Pezh/Cctx: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/Pezh/Cctx/resolve/main/Kpp.py
- Command line
-
hf download hf://spaces/Pezh/Cctx/Kpp.py
-
curl -L -o Kpp.py https://huggingface.co/spaces/Pezh/Cctx/resolve/main/Kpp.py
1.88 kB
| import streamlit as st | |
| import ccxt | |
| import pandas as pd | |
| import datetime | |
| # Create the exchange object | |
| exchange = ccxt.bitfinex() | |
| # Define the time interval | |
| timeframe = '4h' | |
| def get_data(symbol): | |
| # Get the current time | |
| now = datetime.datetime.utcnow() | |
| # Calculate the start time (4 hours ago) | |
| start = now - datetime.timedelta(hours=4) | |
| # Fetch OHLCV data | |
| ohlcv = exchange.fetch_ohlcv(symbol, timeframe) | |
| # Convert the data to a pandas DataFrame | |
| df = pd.DataFrame(ohlcv, 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) | |
| # Filter the data to only include the last 4 hours | |
| data = df.loc[start:] | |
| return data | |
| #now = datetime.datetime.utcnow() | |
| # Calculate the start time (4 hours ago) | |
| #start = now - datetime.timedelta(hours=4) | |
| # Fetch OHLCV data | |
| #ohlcv = exchange.fetch_ohlcv(symbol, timeframe, since=start.timestamp()) | |
| # Convert the data to a pandas DataFrame | |
| #df = pd.DataFrame(ohlcv, 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.') | |