-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worldtradedata took a dump, back to alphavantage
- Loading branch information
1 parent
f08e050
commit e77bedd
Showing
4 changed files
with
244 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class AlphaVantageQuote | ||
attr_reader :open, :high, :low, :price, :volume, :trading_day, :prev_close, :change, :change_percent, :exchange, :error, :name, :message, :is_index | ||
attr_accessor :symbol | ||
|
||
def initialize(symbol, apikey) | ||
# Lita.logger.debug "parsing: #{json_blob}" | ||
# hash = JSON.parse(json_blob) | ||
@symbol = symbol | ||
@apikey = apikey | ||
@is_index = false | ||
|
||
response = call_api | ||
hash = JSON.parse response | ||
|
||
quote = hash["Global Quote"] | ||
|
||
quote.keys.each do |key| | ||
case key | ||
when "01. symbol" | ||
@symbol = quote[key] | ||
when "02. open" | ||
@open = self.fix_number quote[key] | ||
when "03. high" | ||
@high = self.fix_number quote[key] | ||
when "04. low" | ||
@low = self.fix_number quote[key] | ||
when "05. price" | ||
@price = self.fix_number quote[key] | ||
when "06. volume" | ||
@volume = quote[key] | ||
when "07. latest trading day" | ||
@trading_day = quote[key] | ||
when "08. previous close" | ||
@prev_close = self.fix_number quote[key] | ||
when "09. change" | ||
@change = self.fix_number quote[key] | ||
when "10. change percent" | ||
@change_percent = self.fix_number quote[key] | ||
end | ||
end | ||
end | ||
|
||
def fix_number(price_str) | ||
price_str.to_f.round(2) | ||
end | ||
|
||
def is_index? | ||
@is_index | ||
end | ||
|
||
def call_api | ||
url = "https://www.alphavantage.co/query" | ||
params = {function: 'GLOBAL_QUOTE', symbol: @symbol, apikey: @apikey} | ||
Lita.logger.debug "#{url} #{params.inspect}" | ||
response = RestClient.get url, {params: params} | ||
|
||
# if @exchange | ||
# params[:stock_exchange] = @exchange | ||
# end | ||
|
||
Lita.logger.debug "response: #{response}" | ||
response | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module IrcColors | ||
prefix = "\x03" | ||
@white = "#{prefix}00" | ||
@black = "#{prefix}01" | ||
@blue = "#{prefix}02" | ||
@green = "#{prefix}03" | ||
@red = "#{prefix}04" | ||
@brown = "#{prefix}05" | ||
@purple = "#{prefix}06" | ||
@orange = "#{prefix}07" | ||
@yellow = "#{prefix}08" | ||
@lime = "#{prefix}09" | ||
@teal = "#{prefix}10" | ||
@aqua = "#{prefix}11" | ||
@royal = "#{prefix}12" | ||
@pink = "#{prefix}13" | ||
@grey = "#{prefix}14" | ||
@silver = "#{prefix}15" | ||
@reset = prefix | ||
|
||
class << self | ||
attr_reader :white, | ||
:black, | ||
:blue, | ||
:green, | ||
:red, | ||
:brown, | ||
:purple, | ||
:orange, | ||
:yellow, | ||
:lime, | ||
:teal, | ||
:aqua, | ||
:royal, | ||
:pink, | ||
:grey, | ||
:silver, | ||
:reset | ||
end | ||
|
||
def initialize | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.