bitstamp-2 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bitstamp.gemspec +3 -2
- data/lib/bitstamp/orders.rb +50 -3
- data/spec/orders_spec.rb +18 -5
- data/spec/support/bitstamp_setup.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1182acafa8d898c11c64b9e365cc1d6e8a8e1786
|
4
|
+
data.tar.gz: f84bdca5f51de2607c9a357ee5e540a73a26f03c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 049d4f8e52b48bd7153f47915cfc1c472f7f746907a0bd2d3aee0140102d415f8b1d22485fc4ee938a906ae9ba15b1416be0e37c84ce29d1b0dcb6bb672b3abb
|
7
|
+
data.tar.gz: 5a092c8ba4994543f7a80e8cf85a16fd7cfb03add66408bccbba1f785fe53fcfe33a73b5b32173944d4303457975e6fc290b170533b81a20f748ccdb09e61c3e
|
data/Gemfile.lock
CHANGED
data/bitstamp.gemspec
CHANGED
@@ -6,10 +6,10 @@
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bitstamp-2"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.7.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.authors = ["Jeffrey Wilcke"]
|
12
|
+
s.authors = ["Jeffrey Wilcke", "Codelitt Inc."]
|
13
13
|
s.date = "2014-03-09"
|
14
14
|
s.description = "Ruby API for use with bitstamp."
|
15
15
|
s.extra_rdoc_files = [
|
@@ -67,6 +67,7 @@ Gem::Specification.new do |s|
|
|
67
67
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
68
68
|
s.add_development_dependency(%q<bundler>, ["~> 1.11.2"])
|
69
69
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
70
|
+
s.add_development_dependency(%q<pry>)
|
70
71
|
else
|
71
72
|
s.add_dependency(%q<activemodel>, [">= 3.1"])
|
72
73
|
s.add_dependency(%q<activesupport>, [">= 3.1"])
|
data/lib/bitstamp/orders.rb
CHANGED
@@ -5,17 +5,43 @@ module Bitstamp
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def create(options = {})
|
8
|
-
path = (options
|
8
|
+
path = self.order_path(options)
|
9
9
|
Bitstamp::Helper.parse_object! Bitstamp::Net.post(path, options).body, self.model
|
10
10
|
end
|
11
11
|
|
12
12
|
def sell(options = {})
|
13
|
-
options.merge!({
|
13
|
+
options.merge!({
|
14
|
+
type: Bitstamp::Order::SELL,
|
15
|
+
side_execution: Bitstamp::Order::LIMIT_ORDER
|
16
|
+
})
|
17
|
+
|
14
18
|
self.create options
|
15
19
|
end
|
16
20
|
|
17
21
|
def buy(options = {})
|
18
|
-
options.merge!({
|
22
|
+
options.merge!({
|
23
|
+
type: Bitstamp::Order::BUY,
|
24
|
+
side_execution: Bitstamp::Order::LIMIT_ORDER
|
25
|
+
})
|
26
|
+
|
27
|
+
self.create options
|
28
|
+
end
|
29
|
+
|
30
|
+
def market_buy(options = {})
|
31
|
+
options.merge!({
|
32
|
+
type: Bitstamp::Order::BUY,
|
33
|
+
side_execution: Bitstamp::Order::MARKET_ORDER
|
34
|
+
})
|
35
|
+
|
36
|
+
self.create options
|
37
|
+
end
|
38
|
+
|
39
|
+
def market_sell(options = {})
|
40
|
+
options.merge!({
|
41
|
+
type: Bitstamp::Order::SELL,
|
42
|
+
side_execution: Bitstamp::Order::MARKET_ORDER
|
43
|
+
})
|
44
|
+
|
19
45
|
self.create options
|
20
46
|
end
|
21
47
|
|
@@ -30,9 +56,30 @@ module Bitstamp
|
|
30
56
|
options.merge!({id: order_id})
|
31
57
|
Bitstamp::Helper.parse_objects! Bitstamp::Net.post('/order_status', options).body, self.model
|
32
58
|
end
|
59
|
+
|
60
|
+
def order_path(options = {})
|
61
|
+
currency_pair = options[:currency_pair].to_s.empty? ? "btcusd" : options[:currency_pair]
|
62
|
+
type = (options[:type] == Bitstamp::Order::SELL ? "sell" : "buy")
|
63
|
+
if options[:side_execution] == Bitstamp::Order::MARKET_ORDER
|
64
|
+
market_order_path(type, options)
|
65
|
+
else
|
66
|
+
limit_order_path(type, options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def market_order_path(type, options = {})
|
71
|
+
currency_pair = options[:currency_pair].to_s.empty? ? "btcusd" : options[:currency_pair]
|
72
|
+
"/v2/#{type}/market/#{currency_pair}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def limit_order_path(type, options = {})
|
76
|
+
"/#{type}"
|
77
|
+
end
|
33
78
|
end
|
34
79
|
|
35
80
|
class Order < Bitstamp::Model
|
81
|
+
MARKET_ORDER = :market
|
82
|
+
LIMIT_ORDER = :limit_order
|
36
83
|
BUY = 0
|
37
84
|
SELL = 1
|
38
85
|
|
data/spec/orders_spec.rb
CHANGED
@@ -21,11 +21,24 @@ describe Bitstamp::Orders do
|
|
21
21
|
it { should be_kind_of Bitstamp::Order }
|
22
22
|
its(:error) { should == "No permission found" }
|
23
23
|
end
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'market orders' do
|
27
|
+
before do
|
28
|
+
VCR.turn_off!
|
29
|
+
stub_request(:post, "https://www.bitstamp.net/api/v2/buy/market/btcusd/")
|
30
|
+
.to_return(status: 200, body: fixture('successful_order_bitstamp.json'), headers: { 'Content-Type' => 'application/json' })
|
31
|
+
end
|
32
|
+
|
33
|
+
after do
|
34
|
+
VCR.turn_on!
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is successfully executed' do
|
38
|
+
executed_order = Bitstamp.orders.market_buy(:amount => 1, :price => 1000)
|
39
|
+
expect(executed_order).to be_kind_of Bitstamp::Order
|
40
|
+
expect(executed_order.price).to eq "1.25"
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
describe :buy, vcr: {cassette_name: 'bitstamp/orders/buy'} do
|
@@ -15,6 +15,6 @@ def setup_bitstamp
|
|
15
15
|
config.key = ENV['BITSTAMP_KEY']
|
16
16
|
config.secret = ENV['BITSTAMP_SECRET']
|
17
17
|
config.client_id = ENV['BITSTAMP_CLIENT_ID']
|
18
|
-
config.nonce_parameter_generator= lambda { "#{Time.now.to_i}#{(Time.now.nsec / 1_000_000)}".to_i }
|
18
|
+
config.nonce_parameter_generator= lambda { "#{Time.now.to_i}#{(Time.now.nsec / 1_000_000)}".to_i.to_s }
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitstamp-2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeffrey Wilcke
|
8
|
+
- Codelitt Inc.
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
@@ -122,6 +123,20 @@ dependencies:
|
|
122
123
|
- - "~>"
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: 1.8.4
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: pry
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
125
140
|
description: Ruby API for use with bitstamp.
|
126
141
|
email:
|
127
142
|
executables: []
|