forked from johndpope/CryptoCurrencyTrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
non_price_data.py
41 lines (27 loc) · 1.25 KB
/
non_price_data.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
import time
import json
import numpy as np
from pytrends.request import TrendReq
from blockchain import util
from API_settings import google_username, google_password
def initialise_google_session():
return TrendReq(google_username, google_password, custom_useragent='My Pytrends Script')
def google_trends_interest_over_time(pytrend_local, search_terms):
pytrend_local.build_payload(kw_list=search_terms)
interest_time_df = pytrend_local.interest_over_time()
unix_times = convert_timestamp_to_unix_time(interest_time_df[search_terms[0]])
return unix_times, interest_time_df[search_terms[0]].tolist()
def hash_rate():
response = util.call_api('charts/hash-rate?format=json', base_url='https://api.blockchain.info/')
hash_json = json.loads(response)
times = np.zeros(len(hash_json['values']))
hash_rates = np.zeros(len(hash_json['values']))
for i in range(len(hash_json['values'])):
times[i] = hash_json['values'][i]['x']
hash_rates[i] = hash_json['values'][i]['y']
return times, hash_rates
def convert_timestamp_to_unix_time(timestamps):
unix_times = []
for i in range(len(timestamps.index)):
unix_times.append(time.mktime(list(timestamps.index)[i].timetuple()))
return unix_times