trades 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/trades.rb +8 -2
- metadata +1 -1
data/lib/trades.rb
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
-
require 'socket'
|
2
1
|
require 'rubygems'
|
2
|
+
require 'socket'
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
class Trades
|
6
6
|
def initialize(args = [])
|
7
7
|
@socket = TCPSocket.open("bitcoincharts.com", 27007)
|
8
8
|
|
9
|
+
# Convert the exchange names to lowercase
|
10
|
+
args.collect do |exchange|
|
11
|
+
exchange.downcase
|
12
|
+
end
|
13
|
+
|
9
14
|
# thUSD | 2011-06-27 23:00:55 | USD | 17.05 | 0.5 |
|
10
15
|
puts "Exchange | Date and time | Currency | Price | Volume |"
|
11
16
|
|
12
17
|
while data = @socket.gets do
|
13
18
|
if data.length > 0
|
14
19
|
begin
|
15
|
-
j = JSON.parse(data.strip)
|
20
|
+
j = JSON.parse(data.strip.tr("\x00", '')) # Delete all \x00
|
16
21
|
rescue
|
22
|
+
puts "Error: #{$!}\n #{data}"
|
17
23
|
end
|
18
24
|
|
19
25
|
if args.length == 0 or args.include?(j['symbol'].downcase) then
|