-
Notifications
You must be signed in to change notification settings - Fork 0
/
funding_rate.py
32 lines (25 loc) · 1.02 KB
/
funding_rate.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
from functions import *
import sys
if len(sys.argv) == 2 and (sys.argv[1] == 'minute' or sys.argv[1] =='hour'):
CSV_FILE = f'/home/gustavo/btc_futures_data/{sys.argv[1]}_funding_rate.csv'
else:
sys.exit("Program argument must be 'minute' or 'hour', aborting...")
api_key = get_api_key()
while True:
try:
df_usdt = get_df_from_url('fr_usdt', api_key, round_5min=False)
df_token = get_df_from_url('fr_token', api_key, round_5min=False)
df_oi = get_df_from_url('oi', api_key, round_5min=False)
except Exception as e:
continue
if df_usdt.empty or df_token.empty or df_oi.empty:
print('One of the DFs is empty! Retrying...')
continue
else:
df_usdt = get_weighted_mean_funding_rate(df_usdt, df_oi)
df_token = get_weighted_mean_funding_rate(df_token, df_oi)
df_usdt['type'] = 'USDT'
df_token['type'] = 'TOKEN'
df = pd.concat([df_usdt.tail(1), df_token.tail(1)])
df.to_csv(CSV_FILE, mode='a', index=True, header=False)
break