-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
46 lines (37 loc) · 1.49 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pandas as pd
import streamlit as st
import cryptocompare
# Function to fetch market cap data from Binance
def get_market_caps():
# Assuming we have a dictionary with market caps for the sake of this example
market_caps = {
'BTC': 1000000000,
'ETH': 200000000,
'BNB': 50000000,
'ADA': 30000000,
'SOL': 25000000,
'XRP': 23000000,
'DOT': 22000000,
'DOGE':20000000,
'UNI': 19000000,
'LTC': 18000000
}
sorted_symbols = sorted(market_caps, key=market_caps.get, reverse=True)[:10]
return sorted_symbols
# Function to fetch historical data from Binance
def get_historical_data(symbol, end_date):
cryptocompare.cryptocompare._set_api_key_parameter("8fcc98eb2d8de315ea41c547c2565e23773f9ec70d79d89546680c8820203821")
data = cryptocompare.get_historical_price_day(symbol, currency='USD', toTs=end_date, limit=365)
df = pd.DataFrame(data)
if 'time' in df.columns:
df['time'] = pd.to_datetime(df['time'], unit='s')
df.set_index('time', inplace=True)
return df
def get_trend_val(_data):
_data['SMA_Trend'] = 0
for i in range(2, len(_data)):
if _data['SMA_25'].iloc[i] > _data['SMA_25'].iloc[i-1] > _data['SMA_25'].iloc[i-2]:
_data.loc[_data.index[i], 'SMA_Trend'] = 1
elif _data['SMA_25'].iloc[i] < _data['SMA_25'].iloc[i-1] < _data['SMA_25'].iloc[i-2]:
_data.loc[_data.index[i], 'SMA_Trend'] = -1
return _data['SMA_Trend']