rbtc_arbitrage 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -1
  3. data/bitstamp/.gitignore +21 -0
  4. data/bitstamp/.rspec +2 -0
  5. data/bitstamp/.ruby-gemset +1 -0
  6. data/bitstamp/.ruby-version +1 -0
  7. data/bitstamp/Gemfile +24 -0
  8. data/bitstamp/Gemfile.lock +64 -0
  9. data/bitstamp/LICENSE.txt +20 -0
  10. data/bitstamp/README.md +96 -0
  11. data/bitstamp/Rakefile +49 -0
  12. data/bitstamp/VERSION +1 -0
  13. data/bitstamp/bitstamp.gemspec +94 -0
  14. data/bitstamp/lib/bitstamp/collection.rb +30 -0
  15. data/bitstamp/lib/bitstamp/helper.rb +19 -0
  16. data/bitstamp/lib/bitstamp/model.rb +33 -0
  17. data/bitstamp/lib/bitstamp/net.rb +49 -0
  18. data/bitstamp/lib/bitstamp/orders.rb +41 -0
  19. data/bitstamp/lib/bitstamp/ticker.rb +16 -0
  20. data/bitstamp/lib/bitstamp/transactions.rb +37 -0
  21. data/bitstamp/lib/bitstamp.rb +77 -0
  22. data/bitstamp/spec/bitstamp_spec.rb +57 -0
  23. data/bitstamp/spec/collection_spec.rb +12 -0
  24. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/balance.yml +63 -0
  25. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/order_book.yml +1910 -0
  26. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/orders/all.yml +62 -0
  27. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/orders/buy.yml +62 -0
  28. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/orders/sell/failure.yml +60 -0
  29. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/ticker.yml +63 -0
  30. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/transactions.yml +244 -0
  31. data/bitstamp/spec/fixtures/vcr_cassettes/bitstamp/user_transactions/all.yml +223 -0
  32. data/bitstamp/spec/orders_spec.rb +40 -0
  33. data/bitstamp/spec/spec_helper.rb +26 -0
  34. data/bitstamp/spec/support/bitstamp_setup.rb +19 -0
  35. data/bitstamp/spec/support/vcr.rb +21 -0
  36. data/bitstamp/spec/transactions_spec.rb +32 -0
  37. data/lib/rbtc_arbitrage/trader/logger.rb +18 -7
  38. data/lib/rbtc_arbitrage/version.rb +1 -1
  39. data/lib/rbtc_arbitrage.rb +5 -1
  40. data/rbtc_arbitrage.gemspec +21 -0
  41. metadata +50 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 343e03101953463b1fe628965585c402baf85ec0
4
- data.tar.gz: bd1db8a57c03e20a6e7a3c8f8750883159e0625b
3
+ metadata.gz: 7b3aa1910e283d61747e74a88374ff6a5dae054f
4
+ data.tar.gz: 18fadeb0fef8552c33d2dc4f94997a8008007849
5
5
  SHA512:
6
- metadata.gz: f94c8549b48deab8e7d56ef63f0a992358fd948e6a78218f7325c56c3c3f9716950a66c4392dcfb328acbf0a4b07c1216ca512f120a05a90813796a6524708a1
7
- data.tar.gz: bb2e4ebc741ecf66bae436ad59e98ddea561106a9219b0f6c18f74f6fcfd12fc5b2f88b7e15311c228da60bcb6a2ba595c7837ca8d5527b367e935a27f07ae7d
6
+ metadata.gz: f7ae364993024663629bbd494745d9f8be45ba6f2dd596a75bc6674447b72a8f7244847ed723d2968197aa8eca04f02eca6d1989471f648888dd0588197fc21e
7
+ data.tar.gz: 903201f2c7f0d117e0b0cfcffae163af22e2da758a3dfe44c93c4378847f4cf9327be35838020b2b5cc8926625d9cf1b4c492ededca2189eb0cad738cdbf6090
data/Gemfile.lock CHANGED
@@ -1,13 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbtc_arbitrage (2.0.2)
4
+ rbtc_arbitrage (2.1.0)
5
5
  activemodel (>= 3.1)
6
6
  activesupport (>= 3.1)
7
7
  btce (= 0.2.4)
8
8
  coinbase (= 1.2.6)
9
9
  faraday (= 0.8.8)
10
10
  pony
11
+ tco (= 0.1.0)
11
12
  thor
12
13
 
13
14
  PATH
@@ -136,6 +137,7 @@ GEM
136
137
  rack-protection (~> 1.4)
137
138
  tilt (~> 1.3, >= 1.3.4)
138
139
  slop (3.4.7)
140
+ tco (0.1.0)
139
141
  term-ansicolor (1.2.2)
140
142
  tins (~> 0.8)
141
143
  thor (0.18.1)
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ bit_stamp_details.yml
6
+ coverage
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
20
+ */**/*un~
21
+ .*un~
data/bitstamp/.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/bitstamp/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
+
data/bitstamp/Rakefile ADDED
@@ -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/bitstamp/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.4.0
@@ -0,0 +1,94 @@
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"
9
+ s.version = "0.4.0"
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.email = "stygeo@gmail.com"
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".rspec",
22
+ ".ruby-gemset",
23
+ ".ruby-version",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.md",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bitstamp.gemspec",
31
+ "lib/bitstamp.rb",
32
+ "lib/bitstamp/collection.rb",
33
+ "lib/bitstamp/helper.rb",
34
+ "lib/bitstamp/model.rb",
35
+ "lib/bitstamp/net.rb",
36
+ "lib/bitstamp/orders.rb",
37
+ "lib/bitstamp/ticker.rb",
38
+ "lib/bitstamp/transactions.rb",
39
+ "spec/bitstamp_spec.rb",
40
+ "spec/collection_spec.rb",
41
+ "spec/fixtures/vcr_cassettes/bitstamp/balance.yml",
42
+ "spec/fixtures/vcr_cassettes/bitstamp/order_book.yml",
43
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/all.yml",
44
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/buy.yml",
45
+ "spec/fixtures/vcr_cassettes/bitstamp/orders/sell/failure.yml",
46
+ "spec/fixtures/vcr_cassettes/bitstamp/ticker.yml",
47
+ "spec/fixtures/vcr_cassettes/bitstamp/transactions.yml",
48
+ "spec/fixtures/vcr_cassettes/bitstamp/user_transactions/all.yml",
49
+ "spec/orders_spec.rb",
50
+ "spec/spec_helper.rb",
51
+ "spec/support/bitstamp_setup.rb",
52
+ "spec/support/vcr.rb",
53
+ "spec/transactions_spec.rb"
54
+ ]
55
+ s.homepage = "http://github.com/kojnapp/bitstamp"
56
+ s.licenses = ["MIT"]
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = "2.1.11"
59
+ s.summary = "Bitstamp Ruby API"
60
+
61
+ if s.respond_to? :specification_version then
62
+ s.specification_version = 4
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<activemodel>, [">= 3.1"])
66
+ s.add_runtime_dependency(%q<activesupport>, [">= 3.1"])
67
+ s.add_runtime_dependency(%q<curb>, ["> 0.8.1"])
68
+ s.add_runtime_dependency(%q<ruby-hmac>, ["= 0.4.0"])
69
+ s.add_development_dependency(%q<rspec>, [">= 0"])
70
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
71
+ s.add_development_dependency(%q<bundler>, ["~> 1.3.5"])
72
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
73
+ else
74
+ s.add_dependency(%q<activemodel>, [">= 3.1"])
75
+ s.add_dependency(%q<activesupport>, [">= 3.1"])
76
+ s.add_dependency(%q<curb>, ["> 0.8.1"])
77
+ s.add_dependency(%q<ruby-hmac>, ["= 0.4.0"])
78
+ s.add_dependency(%q<rspec>, [">= 0"])
79
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
80
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
81
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
82
+ end
83
+ else
84
+ s.add_dependency(%q<activemodel>, [">= 3.1"])
85
+ s.add_dependency(%q<activesupport>, [">= 3.1"])
86
+ s.add_dependency(%q<curb>, ["> 0.8.1"])
87
+ s.add_dependency(%q<ruby-hmac>, ["= 0.4.0"])
88
+ s.add_dependency(%q<rspec>, [">= 0"])
89
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
90
+ s.add_dependency(%q<bundler>, ["~> 1.3.5"])
91
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
92
+ end
93
+ end
94
+
@@ -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
@@ -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,49 @@
1
+ module Bitstamp
2
+ module Net
3
+ def self.to_uri(path)
4
+ return "https://www.bitstamp.net/api#{path}/"
5
+ end
6
+
7
+ def self.curl(verb, path, options={})
8
+ verb = verb.upcase.to_sym
9
+
10
+ c = Curl::Easy.new(self.to_uri(path))
11
+
12
+ if Bitstamp.configured?
13
+ options[:key] = Bitstamp.key
14
+ options[:nonce] = (Time.now.to_f*10000).to_i.to_s
15
+ options[:signature] = HMAC::SHA256.hexdigest(Bitstamp.secret, options[:nonce]+Bitstamp.client_id.to_s+options[:key]).upcase
16
+ end
17
+
18
+ c.post_body = options.to_query
19
+
20
+ c.http(verb)
21
+
22
+ return c
23
+ end
24
+
25
+ def self.get(path, options={})
26
+ request = self.curl(:GET, path, options)
27
+
28
+ return request
29
+ end
30
+
31
+ def self.post(path, options={})
32
+ request = self.curl(:POST, path, options)
33
+
34
+ return request
35
+ end
36
+
37
+ def self.patch(path, options={})
38
+ request = self.curl(:PATCH, path, options)
39
+
40
+ return request
41
+ end
42
+
43
+ def self.delete(path, options={})
44
+ request = self.curl(:DELETE, path, options)
45
+
46
+ return request
47
+ end
48
+ end
49
+ 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_str, 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_str, 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_str
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
4
+
5
+ def self.from_api
6
+ Bitstamp::Helper.parse_object!(Bitstamp::Net.get('/ticker').body_str, 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,37 @@
1
+ module Bitstamp
2
+ class UserTransactions < Bitstamp::Collection
3
+ def all(options = {})
4
+ # Default time delta to an hour
5
+ options[:timedelta] = "3600" unless options[:timedelta]
6
+
7
+ Bitstamp::Helper.parse_objects! Bitstamp::Net::post("/user_transactions", options).body_str, self.model
8
+ end
9
+
10
+ def find(order_id)
11
+ all = self.all
12
+ index = all.index {|order| order.id.to_i == order_id}
13
+
14
+ return all[index] if index
15
+ end
16
+
17
+ def create(options = {})
18
+ end
19
+
20
+ def update(options={})
21
+ end
22
+ end
23
+
24
+ class UserTransaction < Bitstamp::Model
25
+ attr_accessor :datetime, :id, :type, :usd, :btc, :fee, :order_id, :btc_usd, :nonce
26
+ end
27
+
28
+ # adding in methods to pull the last public trades list
29
+ class Transactions < Bitstamp::Model
30
+ attr_accessor :date, :price, :tid, :amount
31
+
32
+ def self.from_api
33
+ Bitstamp::Helper.parse_objects! Bitstamp::Net::get("/transactions").body_str, self
34
+ end
35
+
36
+ end
37
+ end