Skip to content

Commit

Permalink
Merge pull request #14 from intrinio/ELH/updates-and-fixes
Browse files Browse the repository at this point in the history
updates and fixes
  • Loading branch information
evanlhyde authored Apr 21, 2022
2 parents 44bcc88 + 1bf443e commit f4d0654
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 2.3.6
ruby 2.7.5
2 changes: 1 addition & 1 deletion intrinio-realtime.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "intrinio-realtime"
spec.version = "3.1.2"
spec.version = "3.2"
spec.authors = ["Intrinio"]
spec.email = ["[email protected]"]
spec.description = %q{Intrinio Ruby SDK for Real-Time Stock Prices}
Expand Down
14 changes: 9 additions & 5 deletions lib/intrinio-realtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,13 @@ def parse_uint32(data)
data.map { |i| [sprintf('%02x',i)].pack('H2') }.join.unpack('V').first
end

def parse_float32(data)
data.map { |i| [sprintf('%02x',i)].pack('H2') }.join.unpack('e').first
end

def parse_trade(data, start_index, symbol_length)
symbol = data[start_index + 2, symbol_length].map!{|c| c.chr}.join
price = parse_int32(data[start_index + 2 + symbol_length, 4]).to_f / 10000.0
price = parse_float32(data[start_index + 2 + symbol_length, 4])
size = parse_uint32(data[start_index + 6 + symbol_length, 4])
timestamp = parse_uint64(data[start_index + 10 + symbol_length, 8])
total_volume = parse_uint32(data[start_index + 18 + symbol_length, 4])
Expand All @@ -263,7 +267,7 @@ def parse_trade(data, start_index, symbol_length)
def parse_quote(data, start_index, symbol_length, msg_type)
type = case when msg_type == 1 then ASK when msg_type == 2 then BID end
symbol = data[start_index + 2, symbol_length].map!{|c| c.chr}.join
price = parse_int32(data[start_index + 2 + symbol_length, 4]).to_f / 10000.0
price = parse_float32(data[start_index + 2 + symbol_length, 4])
size = parse_uint32(data[start_index + 6 + symbol_length, 4])
timestamp = parse_uint64(data[start_index + 10 + symbol_length, 8])
return Quote.new(type, symbol, price, size, timestamp)
Expand Down Expand Up @@ -326,7 +330,7 @@ def refresh_token
http.use_ssl = true if (auth_url.include?("https"))
http.start
request = Net::HTTP::Get.new(uri.request_uri)
request.add_field("Client-Information", "IntrinioRealtimeRubySDKv3.1")
request.add_field("Client-Information", "IntrinioRealtimeRubySDKv3.2")

unless @api_key
request.basic_auth(@username, @password)
Expand Down Expand Up @@ -366,8 +370,8 @@ def api_auth_url(url)

def socket_url
case @provider
when REALTIME then URI.escape("wss://realtime-mx.intrinio.com/socket/websocket?vsn=1.0.0&token=#{@token}")
when MANUAL then URI.escape("ws://" + @ip_address + "/socket/websocket?vsn=1.0.0&token=#{@token}")
when REALTIME then "wss://realtime-mx.intrinio.com/socket/websocket?vsn=1.0.0&token=#{@token}"
when MANUAL then "ws://" + @ip_address + "/socket/websocket?vsn=1.0.0&token=#{@token}"
end
end

Expand Down

0 comments on commit f4d0654

Please sign in to comment.