bitstamp-2 0.4.1

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: 949dae684fbe9d95feeae2af71c119bae3d2ad21
4
+ data.tar.gz: 1dd4a69ab4bb3fc8bb67427a349c3e8dffa54658
5
+ SHA512:
6
+ metadata.gz: cc9df62309343a4cdee4c8f9f71562247fba600d337b608ab6d1bedd6948e1a4990bb14a418dcab9cf6773536ee5df6ad497b248c85d35b01d98e512cac473ee
7
+ data.tar.gz: c9c91e47323f61877c023576326746754c559c3312c88023086e2cf61e60beacf6b2af6b2efacf7949783263d8b78c74c86d67523ca8dbf893fc747e37a122b9
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ group :test do
5
+ gem "vcr", "2.6.0"
6
+ gem "webmock", "1.13.0"
7
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bitstamp (0.4.1)
5
+ activemodel (>= 3.1)
6
+ activesupport (>= 3.1)
7
+ httpi (~> 2.4.1)
8
+ ruby-hmac (= 0.4.0)
9
+
10
+ GEM
11
+ remote: http://rubygems.org/
12
+ specs:
13
+ activemodel (4.2.6)
14
+ activesupport (= 4.2.6)
15
+ builder (~> 3.1)
16
+ activesupport (4.2.6)
17
+ i18n (~> 0.7)
18
+ json (~> 1.7, >= 1.7.7)
19
+ minitest (~> 5.1)
20
+ thread_safe (~> 0.3, >= 0.3.4)
21
+ tzinfo (~> 1.1)
22
+ addressable (2.3.5)
23
+ builder (3.2.2)
24
+ crack (0.4.1)
25
+ safe_yaml (~> 0.9.0)
26
+ diff-lcs (1.2.4)
27
+ git (1.2.5)
28
+ httpi (2.4.1)
29
+ rack
30
+ i18n (0.7.0)
31
+ jeweler (1.8.4)
32
+ bundler (~> 1.0)
33
+ git (>= 1.2.5)
34
+ rake
35
+ rdoc
36
+ json (1.8.3)
37
+ minitest (5.8.4)
38
+ rack (1.6.4)
39
+ rake (10.0.4)
40
+ rdoc (3.12.2)
41
+ json (~> 1.4)
42
+ rspec (2.13.0)
43
+ rspec-core (~> 2.13.0)
44
+ rspec-expectations (~> 2.13.0)
45
+ rspec-mocks (~> 2.13.0)
46
+ rspec-core (2.13.1)
47
+ rspec-expectations (2.13.0)
48
+ diff-lcs (>= 1.1.3, < 2.0)
49
+ rspec-mocks (2.13.1)
50
+ ruby-hmac (0.4.0)
51
+ safe_yaml (0.9.7)
52
+ thread_safe (0.3.5)
53
+ tzinfo (1.2.2)
54
+ thread_safe (~> 0.1)
55
+ vcr (2.6.0)
56
+ webmock (1.13.0)
57
+ addressable (>= 2.2.7)
58
+ crack (>= 0.3.2)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ bitstamp!
65
+ bundler (~> 1.11.2)
66
+ jeweler (~> 1.8.4)
67
+ rdoc (~> 3.12)
68
+ rspec
69
+ vcr (= 2.6.0)
70
+ webmock (= 1.13.0)
71
+
72
+ BUNDLED WITH
73
+ 1.11.2
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Kojn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Bitstamp Ruby API
2
+
3
+ Feel free to fork, modify & redistribute under the MIT license.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bitstamp'
10
+
11
+ ## Create API Key
12
+
13
+ More info at: [https://www.bitstamp.net/article/api-key-implementation/](https://www.bitstamp.net/article/api-key-implementation/)
14
+
15
+ ## Setup
16
+
17
+ ```ruby
18
+ Bitstamp.setup do |config|
19
+ config.key = YOUR_API_KEY
20
+ config.secret = YOUR_API_SECRET
21
+ config.client_id = YOUR_BITSTAMP_USERNAME
22
+ end
23
+ ```
24
+
25
+ If you fail to set your `key` or `secret` or `client_id` a `MissingConfigExeception`
26
+ will be raised.
27
+
28
+ ## Bitstamp ticker
29
+
30
+ The bitstamp ticker. Returns `last`, `high`, `low`, `volume`, `bid` and `ask`
31
+
32
+ ```ruby
33
+ Bitstamp.ticker
34
+ ```
35
+
36
+ It's also possible to query through the `Bitstamp::Ticker` object with
37
+ each individual method.
38
+
39
+ ```ruby
40
+ Bitstamp::Ticker.low # => "109.00"
41
+ ```
42
+
43
+ ## Fetch your open order
44
+
45
+ Returns an array with your open orders.
46
+
47
+ ```ruby
48
+ Bitstamp.orders.all
49
+ ```
50
+
51
+ ## Create a sell order
52
+
53
+ Returns an `Order` object.
54
+
55
+ ```ruby
56
+ Bitstamp.orders.sell(amount: 1.0, price: 111)
57
+ ```
58
+
59
+ ## Create a buy order
60
+
61
+ Returns an `Order` object.
62
+
63
+ ```ruby
64
+ Bitstamp.orders.buy(amount: 1.0, price: 111)
65
+ ```
66
+
67
+ ## Fetch your transactions
68
+
69
+ Returns an `Array` of `UserTransaction`.
70
+
71
+ ```ruby
72
+ Bitstamp.user_transactions.all
73
+ ```
74
+
75
+ *To be continued!**
76
+
77
+ # Tests
78
+
79
+ If you'd like to run the tests you need to set the following environment variables:
80
+
81
+ ```
82
+ export BITSTAMP_KEY=xxx
83
+ export BITSTAMP_SECRET=yyy
84
+ export BITSTAMP_CLIENT_ID=zzz
85
+ ```
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork it
90
+ 2. Create your feature branch (`git checkout -b
91
+ my-new-feature`)
92
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
93
+ 4. Push to the branch (`git push origin my-new-feature`)
94
+ 5. Create new Pull Request
95
+
96
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require "bundler/gem_tasks"
6
+
7
+ begin
8
+ Bundler.setup(:default, :development)
9
+ rescue Bundler::BundlerError => e
10
+ $stderr.puts e.message
11
+ $stderr.puts "Run `bundle install` to install missing gems"
12
+ exit e.status_code
13
+ end
14
+ require 'rake'
15
+
16
+ require 'jeweler'
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+ gem.name = "bitstamp"
20
+ gem.homepage = "http://github.com/kojnapp/bitstamp"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{Bitstamp Ruby API}
23
+ gem.description = %Q{Ruby API for use with bitstamp.}
24
+ gem.email = "stygeo@gmail.com"
25
+ gem.authors = ["Jeffrey Wilcke"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "bitstamp #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
data/bitstamp.gemspec ADDED
@@ -0,0 +1,90 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: bitstamp 0.4.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "bitstamp-2"
9
+ s.version = "0.4.1"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["Jeffrey Wilcke"]
13
+ s.date = "2014-03-09"
14
+ s.description = "Ruby API for use with bitstamp."
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".rspec",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bitstamp.gemspec",
28
+ "lib/bitstamp.rb",
29
+ "lib/bitstamp/collection.rb",
30
+ "lib/bitstamp/helper.rb",
31
+ "lib/bitstamp/model.rb",
32
+ "lib/bitstamp/net.rb",
33
+ "lib/bitstamp/orders.rb",
34
+ "lib/bitstamp/ticker.rb",
35
+ "lib/bitstamp/transactions.rb",
36
+ "spec/bitstamp_spec.rb",
37
+ "spec/collection_spec.rb",
38
+ "spec/fixtures/vcr_cassettes/bitstamp/balance.yml",
39
+ "spec/fixtures/vcr_cassettes/bitstamp/order_book.yml",
40
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/all.yml",
41
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/buy.yml",
42
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/sell/failure.yml",
43
+ "spec/fixtures/vcr_cassettes/bitstamp/ticker.yml",
44
+ "spec/fixtures/vcr_cassettes/bitstamp/transactions.yml",
45
+ "spec/fixtures/vcr_cassettes/bitstamp/user_transactions/all.yml",
46
+ "spec/orders_spec.rb",
47
+ "spec/spec_helper.rb",
48
+ "spec/support/bitstamp_setup.rb",
49
+ "spec/support/vcr.rb",
50
+ "spec/transactions_spec.rb"
51
+ ]
52
+ s.homepage = "https://github.com/diogoribeiro/bitstamp"
53
+ s.licenses = ["MIT"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = "2.1.11"
56
+ s.summary = "Bitstamp Ruby API"
57
+
58
+ if s.respond_to? :specification_version then
59
+ s.specification_version = 4
60
+
61
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
62
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.1"])
63
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.1"])
64
+ s.add_runtime_dependency(%q<httpi>, ["~> 2.4.1"])
65
+ s.add_runtime_dependency(%q<ruby-hmac>, ["= 0.4.0"])
66
+ s.add_development_dependency(%q<rspec>, [">= 0"])
67
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
68
+ s.add_development_dependency(%q<bundler>, ["~> 1.11.2"])
69
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
70
+ else
71
+ s.add_dependency(%q<activemodel>, [">= 3.1"])
72
+ s.add_dependency(%q<activesupport>, [">= 3.1"])
73
+ s.add_dependency(%q<httpi>, ["~> 2.4.1"])
74
+ s.add_dependency(%q<ruby-hmac>, ["= 0.4.0"])
75
+ s.add_dependency(%q<rspec>, [">= 0"])
76
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
77
+ s.add_dependency(%q<bundler>, ["~> 1.11.2"])
78
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
79
+ end
80
+ else
81
+ s.add_dependency(%q<activemodel>, [">= 3.1"])
82
+ s.add_dependency(%q<activesupport>, [">= 3.1"])
83
+ s.add_dependency(%q<httpi>, ["~> 2.4.1"])
84
+ s.add_dependency(%q<ruby-hmac>, ["= 0.4.0"])
85
+ s.add_dependency(%q<rspec>, [">= 0"])
86
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
87
+ s.add_dependency(%q<bundler>, ["~> 1.11.2"])
88
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
89
+ end
90
+ end
@@ -0,0 +1,30 @@
1
+ module Bitstamp
2
+ class Collection
3
+ attr_accessor :access_token, :module, :name, :model, :path
4
+
5
+ def initialize(api_prefix="/api")
6
+ self.access_token = Bitstamp.key
7
+
8
+ self.module = self.class.to_s.singularize.underscore
9
+ self.name = self.module.split('/').last
10
+ self.model = self.module.camelize.constantize
11
+ self.path = "#{api_prefix}/#{self.name.pluralize}"
12
+ end
13
+
14
+ def all(options = {})
15
+ Bitstamp::Helper.parse_objects! Bitstamp::Net.get(self.path).body, self.model
16
+ end
17
+
18
+ def create(options = {})
19
+ Bitstamp::Helper.parse_object! Bitstamp::Net.post(self.path, options).body, self.model
20
+ end
21
+
22
+ def find(id, options = {})
23
+ Bitstamp::Helper.parse_object! Bitstamp::Net.get("#{self.path}/#{id}").body, self.model
24
+ end
25
+
26
+ def update(id, options = {})
27
+ Bitstamp::Helper.parse_object! Bitstamp::Net.patch("#{self.path}/#{id}", options).body, self.model
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ module Bitstamp
2
+ module Helper
3
+ def self.parse_objects!(string, klass)
4
+ # If Bitstamp returned nothing (which it does if the results yield empty) 'cast' it to an array
5
+ string = "[]" if string == ""
6
+
7
+ objects = JSON.parse(string)
8
+ objects.collect do |t_json|
9
+ parse_object!(t_json, klass)
10
+ end
11
+ end
12
+
13
+ def self.parse_object!(object, klass)
14
+ object = JSON.parse(object) if object.is_a? String
15
+
16
+ klass.new(object)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ module Bitstamp
2
+ class Model
3
+ attr_accessor :error, :message
4
+
5
+ if ActiveModel::VERSION::MAJOR <= 3
6
+ include ActiveModel::Validations
7
+ include ActiveModel::Conversion
8
+ extend ActiveModel::Naming
9
+
10
+ def initialize(attributes = {})
11
+ self.attributes = attributes
12
+ end
13
+ else
14
+ include ActiveModel::Model
15
+ end
16
+
17
+ # Set the attributes based on the given hash
18
+ def attributes=(attributes = {})
19
+ attributes.each do |name, value|
20
+ begin
21
+ send("#{name}=", value)
22
+ rescue NoMethodError => e
23
+ puts "Unable to assign #{name}. No such method."
24
+ end
25
+ end
26
+ end
27
+
28
+ # Returns a hash with the current instance variables
29
+ def attributes
30
+ Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,44 @@
1
+ module Bitstamp
2
+ module Net
3
+ HTTPI_ADAPTER = :net_http
4
+
5
+ def self.to_uri(path)
6
+ return "https://www.bitstamp.net/api#{path}/"
7
+ end
8
+
9
+ def self.req(verb, path, options={})
10
+ r = HTTPI::Request.new(self.to_uri(path))
11
+
12
+ if Bitstamp.conn_timeout
13
+ r.open_timeout = Bitstamp.conn_timeout
14
+ r.read_timeout = Bitstamp.conn_timeout
15
+ end
16
+
17
+ if Bitstamp.configured?
18
+ options[:key] = Bitstamp.key
19
+ options[:nonce] = (Time.now.to_f*10000).to_i.to_s
20
+ options[:signature] = HMAC::SHA256.hexdigest(Bitstamp.secret, options[:nonce]+Bitstamp.client_id.to_s+options[:key]).upcase
21
+ end
22
+
23
+ r.body = options
24
+
25
+ HTTPI.request(verb, r, HTTPI_ADAPTER)
26
+ end
27
+
28
+ def self.get(path, options={})
29
+ self.req(:get, path, options)
30
+ end
31
+
32
+ def self.post(path, options={})
33
+ self.req(:post, path, options)
34
+ end
35
+
36
+ def self.patch(path, options={})
37
+ self.req(:patch, path, options)
38
+ end
39
+
40
+ def self.delete(path, options={})
41
+ self.req(:delete, path, options)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ module Bitstamp
2
+ class Orders < Bitstamp::Collection
3
+ def all(options = {})
4
+ Bitstamp::Helper.parse_objects! Bitstamp::Net.post('/open_orders').body, self.model
5
+ end
6
+
7
+ def create(options = {})
8
+ path = (options[:type] == Bitstamp::Order::SELL ? "/sell" : "/buy")
9
+ Bitstamp::Helper.parse_object! Bitstamp::Net.post(path, options).body, self.model
10
+ end
11
+
12
+ def sell(options = {})
13
+ options.merge!({type: Bitstamp::Order::SELL})
14
+ self.create options
15
+ end
16
+
17
+ def buy(options = {})
18
+ options.merge!({type: Bitstamp::Order::BUY})
19
+ self.create options
20
+ end
21
+
22
+ def find(order_id)
23
+ all = self.all
24
+ index = all.index {|order| order.id.to_i == order_id}
25
+
26
+ return all[index] if index
27
+ end
28
+ end
29
+
30
+ class Order < Bitstamp::Model
31
+ BUY = 0
32
+ SELL = 1
33
+
34
+ attr_accessor :type, :amount, :price, :id, :datetime
35
+ attr_accessor :error, :message
36
+
37
+ def cancel!
38
+ Bitstamp::Net.post('/cancel_order', {id: self.id}).body
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ module Bitstamp
2
+ class Ticker < Bitstamp::Model
3
+ attr_accessor :last, :high, :low, :volume, :bid, :ask, :timestamp, :vwap, :open
4
+
5
+ def self.from_api
6
+ Bitstamp::Helper.parse_object!(Bitstamp::Net.get('/ticker').body, self)
7
+ end
8
+
9
+ def self.method_missing method, *args
10
+ ticker = self.from_api
11
+ return ticker.send(method) if ticker.respond_to? method
12
+
13
+ super
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ module Bitstamp
2
+ class UserTransactions < Bitstamp::Collection
3
+ def all(options = {})
4
+ Bitstamp::Helper.parse_objects! Bitstamp::Net.post("/user_transactions", options).body, self.model
5
+ end
6
+
7
+ def find(trans_id)
8
+ all = self.all
9
+ index = all.index {|trans| trans.id.to_i == trans_id}
10
+
11
+ return all[index] if index
12
+ end
13
+
14
+ def create(options = {})
15
+ end
16
+
17
+ def update(options = {})
18
+ end
19
+ end
20
+
21
+ class UserTransaction < Bitstamp::Model
22
+ attr_accessor :datetime, :id, :type, :usd, :btc, :fee, :order_id, :btc_usd, :nonce
23
+ end
24
+
25
+ # adding in methods to pull the last public trades list
26
+ class Transactions < Bitstamp::Model
27
+ attr_accessor :date, :price, :tid, :amount
28
+
29
+ def self.from_api
30
+ Bitstamp::Helper.parse_objects! Bitstamp::Net.get("/transactions").body, self
31
+ end
32
+
33
+ end
34
+
35
+
36
+ end
data/lib/bitstamp.rb ADDED
@@ -0,0 +1,104 @@
1
+ require 'active_support/dependencies'
2
+ require 'active_model'
3
+ require 'httpi'
4
+ require 'json'
5
+ require 'hmac-sha2'
6
+
7
+ require 'bitstamp/net'
8
+ require 'bitstamp/helper'
9
+ require 'bitstamp/collection'
10
+ require 'bitstamp/model'
11
+
12
+ require 'bitstamp/orders'
13
+ require 'bitstamp/transactions'
14
+ require 'bitstamp/ticker'
15
+
16
+ String.send(:include, ActiveSupport::Inflector)
17
+
18
+ module Bitstamp
19
+
20
+ # Connection timeouts
21
+ mattr_accessor :conn_timeout
22
+
23
+ # API Key
24
+ mattr_accessor :key
25
+
26
+ # Bitstamp secret
27
+ mattr_accessor :secret
28
+
29
+ # Bitstamp client ID
30
+ mattr_accessor :client_id
31
+
32
+ # Currency
33
+ mattr_accessor :currency
34
+ @@currency = :usd
35
+
36
+ def self.orders
37
+ self.sanity_check!
38
+
39
+ @@orders ||= Bitstamp::Orders.new
40
+ end
41
+
42
+ def self.user_transactions
43
+ self.sanity_check!
44
+
45
+ @@transactions ||= Bitstamp::UserTransactions.new
46
+ end
47
+
48
+ def self.transactions
49
+ return Bitstamp::Transactions.from_api
50
+ end
51
+
52
+ def self.balance
53
+ self.sanity_check!
54
+
55
+ JSON.parse Bitstamp::Net.post('/balance').body
56
+ end
57
+
58
+ def self.withdraw_bitcoins(options = {})
59
+ self.sanity_check!
60
+ if options[:amount].nil? || options[:address].nil?
61
+ raise MissingConfigExeception.new("Required parameters not supplied, :amount, :address")
62
+ end
63
+ response_body = Bitstamp::Net.post('/bitcoin_withdrawal',options).body
64
+ if response_body != 'true'
65
+ return JSON.parse response_body
66
+ else
67
+ return response_body
68
+ end
69
+ end
70
+ def self.bitcoin_deposit_address
71
+ # returns the deposit address
72
+ self.sanity_check!
73
+ return Bitstamp::Net.post('/bitcoin_deposit_address').body
74
+ end
75
+
76
+ def self.unconfirmed_user_deposits
77
+ self.sanity_check!
78
+ return JSON.parse Bitstamp::Net.post("/unconfirmed_btc").body
79
+ end
80
+
81
+ def self.ticker
82
+ return Bitstamp::Ticker.from_api
83
+ end
84
+
85
+ def self.order_book
86
+ return JSON.parse Bitstamp::Net.get('/order_book/').body
87
+ end
88
+
89
+ def self.setup
90
+ yield self
91
+ end
92
+
93
+ def self.configured?
94
+ self.key && self.secret && self.client_id
95
+ end
96
+
97
+ def self.sanity_check!
98
+ unless configured?
99
+ raise MissingConfigExeception.new("Bitstamp Gem not properly configured")
100
+ end
101
+ end
102
+
103
+ class MissingConfigExeception<Exception;end;
104
+ end