Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import urllib.request
- import project3
- class Day:
- def __init__(self,date,open,high,low,close,volume):
- self.date = date
- self.open = open
- self.low = low
- self.close = close
- self.high = high
- self.volume = volume
- class Day:
- def __init__(self,date,open,high,low,close,volume):
- self.date = date
- self.open = open
- self.low = low
- self.close = close
- self.high = high
- self.volume = volume
- self.indicator = 0
- self.buy = ''
- self.sell = ''
- def setIndicator(self, ind):
- self.indicator = ind
- daylist = []
- def len_date_range(list1):
- length = len(list1)
- return length
- def process_info(json,start,end):
- for k in sorted(json["Time Series (Daily)"].keys()):
- if k <= end:
- if k >= start:
- data = json["Time Series (Daily)"][k]
- open = data["1. open"]
- high = data["2. high"]
- low = data["3. low"]
- close = data["4. close"]
- volume = data["5. volume"]
- daylist.append(Day(k,open,high,low,close,volume))
- return daylist
- '''for i in daylist:
- print(i.date)
- print(i.open)'''
- def build_search_url(api,p_url,symbol,strategy) -> str:
- '''
- This function takes a search query and the maximum number of results
- to display, and builds and returns a URL that can be used to ask the
- YouTube Data API for information about videos matching the search
- request.
- '''
- query_parameters = [
- ('function','TIME_SERIES_DAILY' ), ('outputsize', 'full'), ('symbol', symbol),
- ('apikey', api),
- ]
- print(p_url + '/query?' + urllib.parse.urlencode(query_parameters))
- return p_url + '/query?' + urllib.parse.urlencode(query_parameters)
- def get_result(url: object) -> object:
- '''downloads the data using the url and returns it in json'''
- response = None
- try:
- response = urllib.request.urlopen(url)
- json_text = response.read().decode(encoding = 'utf-8')
- return json.loads(json_text)
- finally:
- response.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement