Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import json
  2. import urllib.request
  3. import project3
  4.  
  5. class Day:
  6. def __init__(self,date,open,high,low,close,volume):
  7. self.date = date
  8. self.open = open
  9. self.low = low
  10. self.close = close
  11. self.high = high
  12. self.volume = volume
  13.  
  14.  
  15. class Day:
  16. def __init__(self,date,open,high,low,close,volume):
  17. self.date = date
  18. self.open = open
  19. self.low = low
  20. self.close = close
  21. self.high = high
  22. self.volume = volume
  23. self.indicator = 0
  24. self.buy = ''
  25. self.sell = ''
  26.  
  27. def setIndicator(self, ind):
  28. self.indicator = ind
  29.  
  30. daylist = []
  31.  
  32. def len_date_range(list1):
  33. length = len(list1)
  34. return length
  35.  
  36. def process_info(json,start,end):
  37.  
  38. for k in sorted(json["Time Series (Daily)"].keys()):
  39. if k <= end:
  40. if k >= start:
  41. data = json["Time Series (Daily)"][k]
  42. open = data["1. open"]
  43. high = data["2. high"]
  44. low = data["3. low"]
  45. close = data["4. close"]
  46. volume = data["5. volume"]
  47. daylist.append(Day(k,open,high,low,close,volume))
  48.  
  49. return daylist
  50. '''for i in daylist:
  51. print(i.date)
  52. print(i.open)'''
  53.  
  54.  
  55. def build_search_url(api,p_url,symbol,strategy) -> str:
  56. '''
  57. This function takes a search query and the maximum number of results
  58. to display, and builds and returns a URL that can be used to ask the
  59. YouTube Data API for information about videos matching the search
  60. request.
  61. '''
  62.  
  63. query_parameters = [
  64. ('function','TIME_SERIES_DAILY' ), ('outputsize', 'full'), ('symbol', symbol),
  65. ('apikey', api),
  66. ]
  67. print(p_url + '/query?' + urllib.parse.urlencode(query_parameters))
  68.  
  69. return p_url + '/query?' + urllib.parse.urlencode(query_parameters)
  70.  
  71. def get_result(url: object) -> object:
  72.  
  73. '''downloads the data using the url and returns it in json'''
  74. response = None
  75. try:
  76. response = urllib.request.urlopen(url)
  77. json_text = response.read().decode(encoding = 'utf-8')
  78.  
  79. return json.loads(json_text)
  80.  
  81. finally:
  82. response.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement