btct 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dba68360a478675efb346edbc2d861d2a43905e0
4
- data.tar.gz: f47f8cd9bfbe1f144e207f47dd8d981cf16e5fc6
3
+ metadata.gz: 125d5152ab71aef7a02b222e64103a169f086d9c
4
+ data.tar.gz: 99a6bbc2aa760f9d95dc131dda3ec960a3835b50
5
5
  SHA512:
6
- metadata.gz: 5a95efb95809146a3f60a4dad3be9e08d3d64590c20e39a66e22dda414e3f2f33338adea712835be8ee92a677b7c94da3548fa22696930ebbd519bc18a3c7acb
7
- data.tar.gz: dc822708571a9185037aa23bc7738f8700b7c7438e7748ad1e6aeffcd6ade2b381685b9b4eb72e4f13c022a4751d8c4cfadf49905ae934148e83086c7c6f9509
6
+ metadata.gz: bf11fdc6bbc42a189a10c702546801d8f4a2e08e155457086c555964f08da9d2720a5d4d205b384182843ed363f88bcb94f0f4474e01f3367bf9657e6add67a9
7
+ data.tar.gz: 71df35eb38e5e459b5be3d88d3a6975a4714e74ebb37d444eaf7d30ffd2051521396d3696e7e594003e2063e397952e63bf92b4652b48f205657fbabeda8463a
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Bitcoin Terminal
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/btct.png)](http://badge.fury.io/rb/btct)
4
+
3
5
  Bitcoin Terminal is a Ruby application for monitoring real-time Bitcoin quotes
4
6
  on various exchanges.
5
7
 
@@ -11,15 +13,15 @@ on various exchanges.
11
13
  * BTC-E
12
14
  * Bitstamp
13
15
  * CampBX
14
- * Mt.Gox
16
+ * Coinbase
15
17
  * The Rock
16
18
 
17
- ## Prerequisites
19
+ ## Installation
18
20
 
19
- Install Gem dependencies:
21
+ Install the gem:
20
22
 
21
23
  ```
22
- $ bundle install
24
+ $ gem install btct
23
25
  ```
24
26
 
25
27
  ## Usage
@@ -27,7 +29,7 @@ $ bundle install
27
29
  Start the Bitcoin terminal:
28
30
 
29
31
  ```
30
- $ ./bin/btct
32
+ $ btct
31
33
  ```
32
34
 
33
35
  ## License
@@ -1,6 +1,8 @@
1
- require 'bitstamp'
2
-
1
+ require 'btct/ticker'
3
2
  require 'btct/quote'
3
+ require 'open-uri'
4
+ require 'date'
5
+ require 'json'
4
6
 
5
7
  module BTCT
6
8
  class BitstampAPI
@@ -9,10 +11,22 @@ module BTCT
9
11
  end
10
12
 
11
13
  def top
12
- ob = JSON.parse Bitstamp::Net.get('/order_book/').body_str
14
+ ob = JSON.parse open("https://www.bitstamp.net/api/order_book/").read
13
15
  bid = ob["bids"].sort { |x, y| x[0].to_f <=> y [0].to_f }.last
14
16
  ask = ob["asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
15
17
  return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
16
18
  end
19
+
20
+ def ticker
21
+ ticker = JSON.parse open("https://www.bitstamp.net/api/ticker/").read
22
+ Ticker.new(
23
+ :last => ticker["last" ].to_f,
24
+ :volume => ticker["volume"].to_f,
25
+ :high => ticker["high" ].to_f,
26
+ :low => ticker["low" ].to_f,
27
+ :time => DateTime.strptime(ticker["timestamp"], '%s'),
28
+ :exchange => name
29
+ )
30
+ end
17
31
  end
18
- end
32
+ end
@@ -1,4 +1,7 @@
1
+ require 'btct/ticker'
1
2
  require 'btct/quote'
3
+ require 'open-uri'
4
+ require 'json'
2
5
 
3
6
  module BTCT
4
7
  class BtceAPI
@@ -12,5 +15,18 @@ module BTCT
12
15
  ask = ob["asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
13
16
  return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
14
17
  end
18
+
19
+ def ticker
20
+ ticker = JSON.parse open("https://btc-e.com/api/2/btc_usd/ticker/").read
21
+ ticker = ticker["ticker"]
22
+ Ticker.new(
23
+ :last => ticker["last" ].to_f,
24
+ :volume => ticker["vol_cur"].to_f,
25
+ :high => ticker["high" ].to_f,
26
+ :low => ticker["low" ].to_f,
27
+ :time => DateTime.strptime(ticker["updated"].to_s, '%s'),
28
+ :exchange => name
29
+ )
30
+ end
15
31
  end
16
32
  end
@@ -9,10 +9,22 @@ module BTCT
9
9
  end
10
10
 
11
11
  def top
12
- ob = JSON.parse open("http://campbx.com/api/xdepth.php").read
12
+ ob = JSON.parse open("https://campbx.com/api/xdepth.php").read
13
13
  bid = ob["Bids"].sort { |x, y| x[0].to_f <=> y [0].to_f }.last
14
14
  ask = ob["Asks"].sort { |x, y| x[0].to_f <=> y [0].to_f }.first
15
15
  return Quote.new(bid[0], bid[1], name), Quote.new(ask[0], ask[1], name)
16
16
  end
17
+
18
+ def ticker
19
+ ticker = JSON.parse open("https://campbx.com/api/xticker.php").read
20
+ Ticker.new(
21
+ :last => ticker["Last Trade"].to_f,
22
+ :volume => 0.0,
23
+ :high => 0.0,
24
+ :low => 0.0,
25
+ :time => DateTime.now.new_offset(0),
26
+ :exchange => name
27
+ )
28
+ end
17
29
  end
18
- end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'open-uri'
2
+
3
+ require 'btct/quote'
4
+
5
+ module BTCT
6
+ class CoinbaseAPI
7
+ def name
8
+ "Coinbase"
9
+ end
10
+
11
+ def top
12
+ top = JSON.parse open("https://api.exchange.coinbase.com/products/BTC-USD/book").read
13
+ bid = top["bids"][0]
14
+ ask = top["asks"][0]
15
+ return Quote.new(bid[0].to_f, bid[1].to_f, name), Quote.new(ask[0].to_f, ask[1].to_f, name)
16
+ end
17
+
18
+ def ticker
19
+ ticker = JSON.parse open("https://api.exchange.coinbase.com/products/BTC-USD/ticker").read
20
+ Ticker.new(
21
+ :last => ticker["price"].to_f,
22
+ :volume => ticker["volume"].to_f,
23
+ :high => 0.0,
24
+ :low => 0.0,
25
+ :time => DateTime.now.new_offset(0),
26
+ :exchange => name
27
+ )
28
+ end
29
+ end
30
+ end
@@ -1,9 +1,9 @@
1
1
  require 'curses'
2
2
 
3
3
  require 'btct/bitstamp'
4
+ require 'btct/coinbase'
4
5
  require 'btct/therock'
5
6
  require 'btct/campbx'
6
- require 'btct/mtgox'
7
7
  require 'btct/btce'
8
8
 
9
9
  module BTCT
@@ -16,7 +16,7 @@ module BTCT
16
16
  BitstampAPI.new,
17
17
  BtceAPI.new,
18
18
  CampBxAPI.new,
19
- MtGoxAPI.new,
19
+ CoinbaseAPI.new,
20
20
  TheRockAPI.new
21
21
  ]
22
22
  begin
@@ -32,6 +32,7 @@ module BTCT
32
32
  Curses.init_screen
33
33
  Curses.nl
34
34
  Curses.noecho
35
+ Curses.curs_set(0)
35
36
  Curses.setpos(0, 0) ; Curses.addstr "BTC/USD"
36
37
  Curses.setpos(0, 21) ; Curses.addstr "Bid"
37
38
  Curses.setpos(0, 46) ; Curses.addstr "Ask"
@@ -54,6 +55,17 @@ module BTCT
54
55
  Curses.setpos(row, 0) ; Curses.addstr text
55
56
  row = row + 1
56
57
  end
58
+ row = 11
59
+ text = "%-10s %-12s %-12s %-12s %-12s %s" % [ "", "Last", "Volume", "High", "Low", "Time" ]
60
+ Curses.setpos(row, 0) ; Curses.addstr text
61
+ row = row + 1
62
+ tickers = sources.map { |source| source.ticker }
63
+ tickers.sort! { |x, y| y.time <=> x.time }
64
+ tickers.each do |ticker|
65
+ text = "%-10s %-12.6f %-12.6f %-12.6f %-12.6f %s" % [ ticker.exchange, ticker.last, ticker.volume, ticker.high, ticker.low, ticker.time.strftime("%H:%M:%S") ]
66
+ Curses.setpos(row, 0) ; Curses.addstr text
67
+ row = row + 1
68
+ end
57
69
  Curses.refresh
58
70
  sleep 5
59
71
  end
@@ -9,14 +9,23 @@ module BTCT
9
9
  end
10
10
 
11
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
12
+ ob = JSON.parse open("https://www.therocktrading.com/api/orderbook/BTCUSD").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
+
18
+ def ticker
19
+ ticker = JSON.parse open("https://www.therocktrading.com/api/ticker/BTCUSD").read
20
+ ticker = ticker["result"][0]
21
+ Ticker.new(
22
+ :last => ticker["last"].to_f,
23
+ :volume => 0.0,
24
+ :high => 0.0,
25
+ :low => 0.0,
26
+ :time => DateTime.now.new_offset(0),
27
+ :exchange => name
28
+ )
20
29
  end
21
30
  end
22
- end
31
+ end
@@ -0,0 +1,9 @@
1
+ module BTCT
2
+ class Ticker
3
+ attr_reader :last, :volume, :high, :low, :time, :exchange
4
+
5
+ def initialize(args)
6
+ args.each { |k, v| instance_variable_set("@#{k}", v) unless v.nil? }
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module BTCT
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: btct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pekka Enberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-23 00:00:00.000000000 Z
11
+ date: 2016-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bitstamp
14
+ name: curses
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.8
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
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
26
+ version: '1.0'
41
27
  description: Bitcoin terminal for monitoring real-time Bitcoin quotes on the command
42
28
  line.
43
29
  email: penberg@iki.fi
@@ -51,10 +37,11 @@ files:
51
37
  - lib/btct/bitstamp.rb
52
38
  - lib/btct/btce.rb
53
39
  - lib/btct/campbx.rb
54
- - lib/btct/mtgox.rb
40
+ - lib/btct/coinbase.rb
55
41
  - lib/btct/quote.rb
56
42
  - lib/btct/terminal.rb
57
43
  - lib/btct/therock.rb
44
+ - lib/btct/ticker.rb
58
45
  - lib/btct/version.rb
59
46
  homepage: https://github.com/penberg/btct
60
47
  licenses:
@@ -66,17 +53,17 @@ require_paths:
66
53
  - lib
67
54
  required_ruby_version: !ruby/object:Gem::Requirement
68
55
  requirements:
69
- - - '>='
56
+ - - ">="
70
57
  - !ruby/object:Gem::Version
71
58
  version: '0'
72
59
  required_rubygems_version: !ruby/object:Gem::Requirement
73
60
  requirements:
74
- - - '>='
61
+ - - ">="
75
62
  - !ruby/object:Gem::Version
76
63
  version: '0'
77
64
  requirements: []
78
65
  rubyforge_project:
79
- rubygems_version: 2.0.3
66
+ rubygems_version: 2.4.5
80
67
  signing_key:
81
68
  specification_version: 4
82
69
  summary: Bitcoin Terminal
@@ -1,17 +0,0 @@
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