cgore-bitstamp 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1 @@
1
+ bitstamp
@@ -0,0 +1 @@
1
+ ruby-1.9.3
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ ruby '1.9.3'
2
+
3
+ source "http://rubygems.org"
4
+ # Add dependencies required to use your gem here.
5
+ # Example:
6
+ # gem "activesupport", ">= 2.3.5"
7
+ gem "activemodel", ">= 3.1"
8
+ gem "activesupport", ">= 3.1"
9
+ gem 'curb', '> 0.8.1'
10
+ gem "ruby-hmac", "0.4.0"
11
+
12
+ # Add dependencies to develop your gem here.
13
+ # Include everything needed to run rake, tests, features, etc.
14
+ group :development do
15
+ gem "rspec", ">= 0"
16
+ gem "rdoc", "~> 3.12"
17
+ gem "bundler", "~> 1.3.5"
18
+ gem "jeweler", "~> 1.8.4"
19
+ end
20
+
21
+ group :test do
22
+ gem "vcr", "2.6.0"
23
+ gem "webmock", "1.13.0"
24
+ end
@@ -0,0 +1,64 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (4.0.0.beta1)
5
+ activesupport (= 4.0.0.beta1)
6
+ builder (~> 3.1.0)
7
+ activesupport (4.0.0.beta1)
8
+ i18n (~> 0.6.2)
9
+ minitest (~> 4.2)
10
+ multi_json (~> 1.3)
11
+ thread_safe (~> 0.1)
12
+ tzinfo (~> 0.3.33)
13
+ addressable (2.3.5)
14
+ atomic (1.1.7)
15
+ builder (3.1.4)
16
+ crack (0.4.1)
17
+ safe_yaml (~> 0.9.0)
18
+ curb (0.8.3)
19
+ diff-lcs (1.2.4)
20
+ git (1.2.5)
21
+ i18n (0.6.4)
22
+ jeweler (1.8.4)
23
+ bundler (~> 1.0)
24
+ git (>= 1.2.5)
25
+ rake
26
+ rdoc
27
+ json (1.7.7)
28
+ minitest (4.7.1)
29
+ multi_json (1.7.2)
30
+ rake (10.0.4)
31
+ rdoc (3.12.2)
32
+ json (~> 1.4)
33
+ rspec (2.13.0)
34
+ rspec-core (~> 2.13.0)
35
+ rspec-expectations (~> 2.13.0)
36
+ rspec-mocks (~> 2.13.0)
37
+ rspec-core (2.13.1)
38
+ rspec-expectations (2.13.0)
39
+ diff-lcs (>= 1.1.3, < 2.0)
40
+ rspec-mocks (2.13.1)
41
+ ruby-hmac (0.4.0)
42
+ safe_yaml (0.9.7)
43
+ thread_safe (0.1.0)
44
+ atomic
45
+ tzinfo (0.3.37)
46
+ vcr (2.6.0)
47
+ webmock (1.13.0)
48
+ addressable (>= 2.2.7)
49
+ crack (>= 0.3.2)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ activemodel (>= 3.1)
56
+ activesupport (>= 3.1)
57
+ bundler (~> 1.3.5)
58
+ curb (> 0.8.1)
59
+ jeweler (~> 1.8.4)
60
+ rdoc (~> 3.12)
61
+ rspec
62
+ ruby-hmac (= 0.4.0)
63
+ vcr (= 2.6.0)
64
+ webmock (= 1.13.0)
@@ -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.
@@ -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
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "bitstamp"
18
+ gem.homepage = "http://github.com/kojnapp/bitstamp"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Bitstamp Ruby API}
21
+ gem.description = %Q{Ruby API for use with bitstamp.}
22
+ gem.email = "stygeo@gmail.com"
23
+ gem.authors = ["Jeffrey Wilcke"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "bitstamp #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
@@ -0,0 +1,93 @@
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
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{cgore-bitstamp}
8
+ s.version = "0.3.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Jeffrey Wilcke}]
12
+ s.date = %q{2013-11-19}
13
+ s.description = %q{Ruby API for use with bitstamp.}
14
+ s.email = %q{stygeo@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".rspec",
21
+ ".ruby-gemset",
22
+ ".ruby-version",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bitstamp.gemspec",
30
+ "lib/bitstamp.rb",
31
+ "lib/bitstamp/collection.rb",
32
+ "lib/bitstamp/helper.rb",
33
+ "lib/bitstamp/model.rb",
34
+ "lib/bitstamp/net.rb",
35
+ "lib/bitstamp/orders.rb",
36
+ "lib/bitstamp/ticker.rb",
37
+ "lib/bitstamp/transactions.rb",
38
+ "spec/bitstamp_spec.rb",
39
+ "spec/collection_spec.rb",
40
+ "spec/fixtures/vcr_cassettes/bitstamp/balance.yml",
41
+ "spec/fixtures/vcr_cassettes/bitstamp/order_book.yml",
42
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/all.yml",
43
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/buy.yml",
44
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/sell/failure.yml",
45
+ "spec/fixtures/vcr_cassettes/bitstamp/ticker.yml",
46
+ "spec/fixtures/vcr_cassettes/bitstamp/transactions.yml",
47
+ "spec/fixtures/vcr_cassettes/bitstamp/user_transactions/all.yml",
48
+ "spec/orders_spec.rb",
49
+ "spec/spec_helper.rb",
50
+ "spec/support/bitstamp_setup.rb",
51
+ "spec/support/vcr.rb",
52
+ "spec/transactions_spec.rb"
53
+ ]
54
+ s.homepage = %q{http://github.com/kojnapp/bitstamp}
55
+ s.licenses = [%q{MIT}]
56
+ s.require_paths = [%q{lib}]
57
+ s.rubygems_version = %q{1.8.0}
58
+ s.summary = %q{Bitstamp Ruby API}
59
+
60
+ if s.respond_to? :specification_version then
61
+ s.specification_version = 3
62
+
63
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
64
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.1"])
65
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.1"])
66
+ s.add_runtime_dependency(%q<curb>, ["> 0.8.1"])
67
+ s.add_runtime_dependency(%q<ruby-hmac>, ["= 0.4.0"])
68
+ s.add_development_dependency(%q<rspec>, [">= 0"])
69
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
70
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.5"])
71
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
72
+ else
73
+ s.add_dependency(%q<activemodel>, [">= 3.1"])
74
+ s.add_dependency(%q<activesupport>, [">= 3.1"])
75
+ s.add_dependency(%q<curb>, ["> 0.8.1"])
76
+ s.add_dependency(%q<ruby-hmac>, ["= 0.4.0"])
77
+ s.add_dependency(%q<rspec>, [">= 0"])
78
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
79
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
80
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<activemodel>, [">= 3.1"])
84
+ s.add_dependency(%q<activesupport>, [">= 3.1"])
85
+ s.add_dependency(%q<curb>, ["> 0.8.1"])
86
+ s.add_dependency(%q<ruby-hmac>, ["= 0.4.0"])
87
+ s.add_dependency(%q<rspec>, [">= 0"])
88
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
89
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
90
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
91
+ end
92
+ end
93
+
@@ -0,0 +1,77 @@
1
+ require 'active_support/core_ext'
2
+ require 'active_support/inflector'
3
+ require 'active_model'
4
+ require 'curb'
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
+ # API Key
20
+ mattr_accessor :key
21
+
22
+ # Bitstamp secret
23
+ mattr_accessor :secret
24
+
25
+ # Bitstamp client ID
26
+ mattr_accessor :client_id
27
+
28
+ # Currency
29
+ mattr_accessor :currency
30
+ @@currency = :usd
31
+
32
+ def self.orders
33
+ self.sanity_check!
34
+
35
+ @@orders ||= Bitstamp::Orders.new
36
+ end
37
+
38
+ def self.user_transactions
39
+ self.sanity_check!
40
+
41
+ @@transactions ||= Bitstamp::UserTransactions.new
42
+ end
43
+
44
+ def self.transactions
45
+ return Bitstamp::Transactions.from_api
46
+ end
47
+
48
+ def self.balance
49
+ self.sanity_check!
50
+
51
+ JSON.parse Bitstamp::Net.post('/balance').body_str
52
+ end
53
+
54
+ def self.ticker
55
+ return Bitstamp::Ticker.from_api
56
+ end
57
+
58
+ def self.order_book
59
+ return JSON.parse Bitstamp::Net.get('/order_book/').body_str
60
+ end
61
+
62
+ def self.setup
63
+ yield self
64
+ end
65
+
66
+ def self.configured?
67
+ self.key && self.secret && self.client_id
68
+ end
69
+
70
+ def self.sanity_check!
71
+ unless configured?
72
+ raise MissingConfigExeception.new("Bitstamp Gem not properly configured")
73
+ end
74
+ end
75
+
76
+ class MissingConfigExeception<Exception;end;
77
+ 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_str, self.model
16
+ end
17
+
18
+ def create(options = {})
19
+ Bitstamp::Helper.parse_object! Bitstamp::Net::post(self.path, options).body_str, self.model
20
+ end
21
+
22
+ def find(id, options = {})
23
+ Bitstamp::Helper.parse_object! Bitstamp::Net::get("#{self.path}/#{id}").body_str, self.model
24
+ end
25
+
26
+ def update(id, options = {})
27
+ Bitstamp::Helper.parse_object! Bitstamp::Net::patch("#{self.path}/#{id}", options).body_str, self.model
28
+ end
29
+ end
30
+ end