bitcoinde 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cdf70fd08fe725e109cbd4d05cebbaab98ba87a7
4
+ data.tar.gz: a3627b9e2c58241418ade7099d68141d187ce0bf
5
+ SHA512:
6
+ metadata.gz: cb21b40117d2cb5208a977fbd147889c19694017de4e338422cdee2b7f45d6f5391095ca24c8174f0d90244d0b639b40025a572bf81af778ca69536852722cbf
7
+ data.tar.gz: 10851eb0f2479c06312c90c059e40d23637781b91d9a95b91e450f8ef595e89bf17254f4f802f242f4348cd33efddb143dee7bec8acac3cc7f8755c4a5c02fcd
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ key.yml
2
+ .idea
3
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bitcoinde.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitcoinde (0.1.2)
5
+ addressable
6
+ hashie
7
+ httparty
8
+ nokogiri
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.3.6)
14
+ diff-lcs (1.2.5)
15
+ hashie (2.1.1)
16
+ httparty (0.13.1)
17
+ json (~> 1.8)
18
+ multi_xml (>= 0.5.2)
19
+ json (1.8.1)
20
+ mini_portile (0.5.3)
21
+ multi_xml (0.5.5)
22
+ nokogiri (1.6.1)
23
+ mini_portile (~> 0.5.0)
24
+ rake (10.3.1)
25
+ rspec (2.14.1)
26
+ rspec-core (~> 2.14.0)
27
+ rspec-expectations (~> 2.14.0)
28
+ rspec-mocks (~> 2.14.0)
29
+ rspec-core (2.14.8)
30
+ rspec-expectations (2.14.5)
31
+ diff-lcs (>= 1.1.3, < 2.0)
32
+ rspec-mocks (2.14.6)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ bitcoinde!
39
+ bundler (~> 1.3)
40
+ rake
41
+ rspec
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ ## Summary
2
+
3
+ This gem only provides method to get depth, ticker and orderbook from bitcoin.de
4
+ It uses nokogiri to parse the data so sometimes api calls are a bit long
5
+
6
+ Don't hesitate to contribute.
7
+ If you liked it:
8
+ BTC: 1PizgAWLJbwEsNWG9Cf27skcbgbgZGgeyK
9
+ LTC: LQtM1t6BRd64scsdSBk8nnCLJuc8Qfhm53
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'bitcoinde'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install bitcoinde
24
+
25
+ ## Usage
26
+
27
+ Create a bitcoinde client:
28
+
29
+ ```ruby
30
+
31
+ bitcoinde = Bitcoinde::Client.new
32
+
33
+ ```
34
+
35
+ ### Ticker
36
+ ```ruby
37
+ ticker = bitcoinde.ticker
38
+
39
+ ```
40
+ returns ticker price
41
+ ### Depth
42
+
43
+ ```ruby
44
+ depth = bitcoinde.depth
45
+
46
+ ```
47
+
48
+ returns asks and bids in orderbook
49
+
50
+ ### Trades
51
+
52
+ ```ruby
53
+ trades = bitcoinde.trades
54
+ ```
55
+ returns last trades
data/bitcoinde.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bitcoinde/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bitcoinde"
8
+ spec.version = BitcoindeRuby::VERSION
9
+ spec.authors = ["Julien Hobeika"]
10
+ spec.email = ["julien.hobeika@gmail.com"]
11
+ spec.description = %q{"Public data of bitcoin.de Exchange"}
12
+ spec.summary = %q{"Public data of bitcoin.de Exchange"}
13
+ spec.homepage = "https://github.com/jhk753/bitcoinde"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+
24
+ spec.add_dependency "hashie"
25
+ spec.add_dependency "addressable"
26
+ spec.add_dependency "nokogiri"
27
+ spec.add_dependency "httparty"
28
+ end
data/lib/bitcoinde.rb ADDED
@@ -0,0 +1,2 @@
1
+ require "bitcoinde/version"
2
+ require "bitcoinde/client"
@@ -0,0 +1,78 @@
1
+ require 'hashie'
2
+ require 'base64'
3
+ require 'addressable/uri'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+ require 'yaml'
7
+ require 'httparty'
8
+
9
+
10
+ module Bitcoinde
11
+ class Client
12
+ include HTTParty
13
+
14
+ def initialize(options={})
15
+ @base_uri = options[:base_uri] ||= 'www.bitcoin.de/en/'
16
+ @google ||= self.class.get("https://maps.googleapis.com/maps/api/timezone/json?location=52.5075419,13.4261419&timestamp=#{Time.now.to_i}&sensor=false").parsed_response
17
+ @offset ||= (@google["dstOffset"] + @google["rawOffset"])/3600
18
+ end
19
+
20
+ ###########################
21
+ ###### Public Data ########
22
+ ###########################
23
+
24
+
25
+ def ticker
26
+ page = get_public("market")
27
+ page.css("div.fs12.wp100 div.fright strong").text[0..-3].gsub(",", ".").to_f
28
+ end
29
+
30
+ def depth
31
+ page = get_public("market")
32
+ asks_table = page.css("article.fleft tbody#box_buy_sell_offer tr[data-trade-type='offer']")
33
+ bids_table = page.css("article.fright tbody#box_buy_sell_order tr[data-trade-type='order']")
34
+ asks = []
35
+ bids = []
36
+ bids_table.each do |b|
37
+ bids << {price: b["data-critical-price"].to_f, amount: b["data-critical-amount"].to_f}
38
+ end
39
+ asks_table.each do |a|
40
+ asks << {price: a["data-critical-price"].to_f, amount: a["data-critical-amount"].to_f}
41
+ end
42
+
43
+ Hashie::Mash.new({asks: asks, bids: bids})
44
+ end
45
+
46
+ def trades
47
+ page = get_public("market")
48
+ trades_list = []
49
+ page.css("section.brd2t table.list.aright tr").each do |tr|
50
+ tds = tr.css("td")
51
+ unless tds.empty?
52
+ str = tds[0].text.match("([0-9][0-9](.| |:)){5}")[0]+"+#{@offset}"
53
+ datetime = Time.strptime(str, "%d.%m.%y %H:%M %z")
54
+ trades_list << {time: datetime, price: tds[1].text.gsub(",", ".").to_f, btc_volume: tds[2].text.gsub(",", ".").to_f, eur_volume: tds[3].text.gsub(",", ".").to_f}
55
+ end
56
+ end
57
+ Hashie::Mash.new({trades: trades_list})
58
+
59
+ end
60
+
61
+ def get_public(method, opts={})
62
+ url = 'https://'+ @base_uri + method
63
+ page = Nokogiri(open(url))
64
+ page.css('div#wrap')
65
+ end
66
+
67
+ end
68
+ end
69
+
70
+ class Hashie::Mash
71
+ def try key
72
+ if self.key?(key.to_s)
73
+ self[key]
74
+ else
75
+ self
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module BitcoindeRuby
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitcoinde
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Julien Hobeika
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hashie
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: '"Public data of bitcoin.de Exchange"'
112
+ email:
113
+ - julien.hobeika@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - Gemfile.lock
121
+ - README.md
122
+ - bitcoinde.gemspec
123
+ - lib/bitcoinde.rb
124
+ - lib/bitcoinde/client.rb
125
+ - lib/bitcoinde/version.rb
126
+ homepage: https://github.com/jhk753/bitcoinde
127
+ licenses: []
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.2.2
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: '"Public data of bitcoin.de Exchange"'
149
+ test_files: []