btct 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dba68360a478675efb346edbc2d861d2a43905e0
4
+ data.tar.gz: f47f8cd9bfbe1f144e207f47dd8d981cf16e5fc6
5
+ SHA512:
6
+ metadata.gz: 5a95efb95809146a3f60a4dad3be9e08d3d64590c20e39a66e22dda414e3f2f33338adea712835be8ee92a677b7c94da3548fa22696930ebbd519bc18a3c7acb
7
+ data.tar.gz: dc822708571a9185037aa23bc7738f8700b7c7438e7748ad1e6aeffcd6ade2b381685b9b4eb72e4f13c022a4751d8c4cfadf49905ae934148e83086c7c6f9509
@@ -0,0 +1,37 @@
1
+ # Bitcoin Terminal
2
+
3
+ Bitcoin Terminal is a Ruby application for monitoring real-time Bitcoin quotes
4
+ on various exchanges.
5
+
6
+ ![alt text](https://github.com/penberg/btct/raw/master/htdocs/Bitcoin_Terminal.png "Bitcoin Terminal")
7
+
8
+ ## Features
9
+
10
+ * Real-time quotes:
11
+ * BTC-E
12
+ * Bitstamp
13
+ * CampBX
14
+ * Mt.Gox
15
+ * The Rock
16
+
17
+ ## Prerequisites
18
+
19
+ Install Gem dependencies:
20
+
21
+ ```
22
+ $ bundle install
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Start the Bitcoin terminal:
28
+
29
+ ```
30
+ $ ./bin/btct
31
+ ```
32
+
33
+ ## License
34
+
35
+ Copyright © 2013 Pekka Enberg
36
+
37
+ Distributed under the MIT license.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
4
+
5
+ require "btct/terminal"
6
+
7
+ BTCT::Terminal.new(ARGV).run
@@ -0,0 +1,18 @@
1
+ require 'bitstamp'
2
+
3
+ require 'btct/quote'
4
+
5
+ module BTCT
6
+ class BitstampAPI
7
+ def name
8
+ "Bitstamp"
9
+ end
10
+
11
+ def top
12
+ ob = JSON.parse Bitstamp::Net.get('/order_book/').body_str
13
+ bid = ob["bids"].sort { |x, y| x[0].to_f <=> y [0].to_f }.last
14
+ ask = ob["asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
15
+ return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require 'btct/quote'
2
+
3
+ module BTCT
4
+ class BtceAPI
5
+ def name
6
+ "BTC-E"
7
+ end
8
+
9
+ def top
10
+ ob = JSON.parse open("https://btc-e.com/api/2/btc_usd/depth").read
11
+ bid = ob["bids"].sort { |x, y| x[0].to_f <=> y [0].to_f }.last
12
+ ask = ob["asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
13
+ return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'open-uri'
2
+
3
+ require 'btct/quote'
4
+
5
+ module BTCT
6
+ class CampBxAPI
7
+ def name
8
+ "CampBX"
9
+ end
10
+
11
+ def top
12
+ ob = JSON.parse open("http://campbx.com/api/xdepth.php").read
13
+ bid = ob["Bids"].sort { |x, y| x[0].to_f <=> y [0].to_f }.last
14
+ ask = ob["Asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
15
+ return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'mtgox'
2
+
3
+ require 'btct/quote'
4
+
5
+ module BTCT
6
+ class MtGoxAPI
7
+ def name
8
+ "Mt.Gox"
9
+ end
10
+
11
+ def top
12
+ bid = MtGox.bids.sort { |x, y| x.price <=> y.price }.last
13
+ ask = MtGox.asks.sort { |x, y| x.price <=> y.price }.first
14
+ return Quote.new(bid.price, bid.amount, name), Quote.new(ask.price, ask.amount, name)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module BTCT
2
+ class Quote
3
+ attr_reader :price, :amount, :exchange
4
+
5
+ def initialize(price, amount, exchange)
6
+ @price, @amount, @exchange = price.to_f, amount.to_f, exchange
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,65 @@
1
+ require 'curses'
2
+
3
+ require 'btct/bitstamp'
4
+ require 'btct/therock'
5
+ require 'btct/campbx'
6
+ require 'btct/mtgox'
7
+ require 'btct/btce'
8
+
9
+ module BTCT
10
+ class Terminal
11
+ def initialize(argv)
12
+ end
13
+
14
+ def run
15
+ sources = [
16
+ BitstampAPI.new,
17
+ BtceAPI.new,
18
+ CampBxAPI.new,
19
+ MtGoxAPI.new,
20
+ TheRockAPI.new
21
+ ]
22
+ begin
23
+ def onsig(sig)
24
+ Curses.close_screen
25
+ exit sig
26
+ end
27
+ for i in %w[HUP INT QUIT TERM]
28
+ if trap(i, "SIG_IGN") != 0 then # 0 for SIG_IGN
29
+ trap(i) {|sig| onsig(sig) }
30
+ end
31
+ end
32
+ Curses.init_screen
33
+ Curses.nl
34
+ Curses.noecho
35
+ Curses.setpos(0, 0) ; Curses.addstr "BTC/USD"
36
+ Curses.setpos(0, 21) ; Curses.addstr "Bid"
37
+ Curses.setpos(0, 46) ; Curses.addstr "Ask"
38
+ Curses.setpos(1, 14) ; Curses.addstr "Amount Price"
39
+ Curses.setpos(1, 39) ; Curses.addstr "Price Amount"
40
+ Curses.refresh
41
+ while true
42
+ bids = Array.new
43
+ asks = Array.new
44
+ sources.each do |source|
45
+ bid, ask = source.top
46
+ bids.push(bid)
47
+ asks.push(ask)
48
+ end
49
+ bids.sort! { |x,y| y.price <=> x.price }
50
+ asks.sort! { |x,y| x.price <=> y.price }
51
+ row = 2
52
+ bids.zip(asks).each do |bid, ask|
53
+ text = "%-10s %10.6f %12.6f %-12.6f %-10.6f %-10s" % [bid.exchange, bid.amount, bid.price, ask.price, ask.amount, ask.exchange]
54
+ Curses.setpos(row, 0) ; Curses.addstr text
55
+ row = row + 1
56
+ end
57
+ Curses.refresh
58
+ sleep 5
59
+ end
60
+ ensure
61
+ Curses.close_screen
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,22 @@
1
+ require 'open-uri'
2
+
3
+ require 'btct/quote'
4
+
5
+ module BTCT
6
+ class TheRockAPI
7
+ def name
8
+ "The Rock"
9
+ end
10
+
11
+ def top
12
+ begin
13
+ ob = JSON.parse open("https://www.therocktrading.com/api/orderbook/BTCUSD").read
14
+ bid = ob["bids"].sort { |x, y| x[0].to_f <=> y [0].to_f }.last
15
+ ask = ob["asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
16
+ return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
17
+ rescue
18
+ return Quote.new(0.0, 0.0, name), Quote.new(0.0, 0.0, name)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module BTCT
2
+ VERSION = '0.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: btct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Pekka Enberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bitstamp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: mtgox
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.0
41
+ description: Bitcoin terminal for monitoring real-time Bitcoin quotes on the command
42
+ line.
43
+ email: penberg@iki.fi
44
+ executables:
45
+ - btct
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - README.md
50
+ - bin/btct
51
+ - lib/btct/bitstamp.rb
52
+ - lib/btct/btce.rb
53
+ - lib/btct/campbx.rb
54
+ - lib/btct/mtgox.rb
55
+ - lib/btct/quote.rb
56
+ - lib/btct/terminal.rb
57
+ - lib/btct/therock.rb
58
+ - lib/btct/version.rb
59
+ homepage: https://github.com/penberg/btct
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Bitcoin Terminal
83
+ test_files: []