trades 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/trades +0 -1
  2. data/lib/trades.rb +45 -6
  3. metadata +2 -2
data/bin/trades CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'trades'
4
4
 
5
-
6
5
  begin
7
6
  Trades.new ARGV
8
7
  rescue SystemExit, Interrupt
data/lib/trades.rb CHANGED
@@ -4,6 +4,28 @@ require 'json'
4
4
 
5
5
  class Trades
6
6
  def initialize(args = [])
7
+ <<<<<<< HEAD
8
+ begin
9
+ puts "Connecting..."
10
+ @socket = TCPSocket.open("bitcoincharts.com", 27007)
11
+ @exchanges = []
12
+ @last_prices = {}
13
+
14
+ # Convert the exchange names to lowercase
15
+ args.each do |x| @exchanges.push(x.downcase) end
16
+ args.clear
17
+
18
+ # thUSD | 2011-06-27 23:00:55 | USD | 17.05 | 0.5 |
19
+ puts "Exchange | Date and time | Currency | Price | Volume |"
20
+
21
+ self.loop
22
+ rescue
23
+ puts "Error: #{$!}"
24
+ end
25
+ end
26
+
27
+ def loop
28
+ =======
7
29
  @socket = TCPSocket.open("bitcoincharts.com", 27007)
8
30
 
9
31
  # Convert the exchange names to lowercase
@@ -14,21 +36,38 @@ class Trades
14
36
  # thUSD | 2011-06-27 23:00:55 | USD | 17.05 | 0.5 |
15
37
  puts "Exchange | Date and time | Currency | Price | Volume |"
16
38
 
39
+ >>>>>>> parent of b9f8509... Added colors to the output
17
40
  while data = @socket.gets do
18
41
  if data.length > 0
19
- begin
20
- j = JSON.parse(data.strip.tr("\x00", '')) # Delete all \x00
21
- rescue
22
- puts "Error: #{$!}\n #{data}"
23
- end
42
+ j = JSON.parse(data.strip.tr("\x00", '')) # Delete all \x00 weirdness
24
43
 
25
- if args.length == 0 or args.include?(j['symbol'].downcase) then
44
+ if @exchanges.empty? or @exchanges.include?(j['symbol'].downcase) then
26
45
  line = j['symbol'].ljust(15) + "| "
27
46
  line += Time.at(j['timestamp']).strftime("%Y-%m-%d %H:%M:%S").\
28
47
  ljust(20)
29
48
  line += "| " + j['currency'].ljust(9) + "| "
49
+ <<<<<<< HEAD
50
+
51
+ # Coloring: Compare the current price and the last price
52
+ current_price = j['price'].round(2)
53
+ last_price = @last_prices[j['symbol']].to_f # Its 0 on startup
54
+
55
+ if current_price > last_price then
56
+ line += current_price.to_s.ljust(7).green
57
+ elsif current_price < last_price then
58
+ line += current_price.to_s.ljust(7).red
59
+ else
60
+ line += current_price.to_s.ljust(7)
61
+ end
62
+
63
+ @last_prices[j['symbol']] = current_price
64
+
65
+
66
+ line += "| " + j['volume'].round(2).to_s.ljust(7) + "|"
67
+ =======
30
68
  line += j['price'].round(2).to_s.ljust(7) + "| "
31
69
  line += j['volume'].round(2).to_s.ljust(7) + "|"
70
+ >>>>>>> parent of b9f8509... Added colors to the output
32
71
 
33
72
  puts line
34
73
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trades
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Waxjar
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-28 00:00:00 +02:00
13
+ date: 2011-06-29 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency