bitstamp 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +21 -1
- data/VERSION +1 -1
- data/bitstamp.gemspec +3 -1
- data/lib/bitstamp.rb +6 -0
- data/lib/bitstamp/collection.rb +4 -18
- data/lib/bitstamp/helper.rb +16 -0
- data/lib/bitstamp/orders.rb +2 -2
- data/lib/bitstamp/ticker.rb +16 -0
- data/spec/bitstamp_spec.rb +4 -0
- data/spec/orders_spec.rb +2 -2
- metadata +4 -2
data/README.md
CHANGED
@@ -20,6 +20,14 @@ end
|
|
20
20
|
If you fail to set your `key` or `secret` a `MissingConfigExecption`
|
21
21
|
will be raised.
|
22
22
|
|
23
|
+
## Bitstamp ticker
|
24
|
+
|
25
|
+
The bitstamp ticker. Returns `last`, `high`, `low`, `volume`, `bid` and `ask`
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Bitstamp.ticker
|
29
|
+
```
|
30
|
+
|
23
31
|
## Fetch your open order
|
24
32
|
|
25
33
|
Returns an array with your open orders.
|
@@ -44,7 +52,19 @@ Returns an `Order` object.
|
|
44
52
|
Bitstamp.orders.buy(amount: 1.0, price: 111)
|
45
53
|
```
|
46
54
|
|
47
|
-
To be continued
|
55
|
+
*To be continued!**
|
56
|
+
|
57
|
+
# Tests
|
58
|
+
|
59
|
+
If you'd like to run the tests you need to create a yaml file in the
|
60
|
+
root of the gem `bit_stamp_details.yml` which holds your authentication
|
61
|
+
details for Bitstamp.
|
62
|
+
|
63
|
+
```yaml
|
64
|
+
bitstamp:
|
65
|
+
id: 'bitstamp id'
|
66
|
+
password: 'bitstamp password'
|
67
|
+
```
|
48
68
|
|
49
69
|
## Contributing
|
50
70
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bitstamp.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "bitstamp"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jeffrey Wilcke"]
|
@@ -27,9 +27,11 @@ Gem::Specification.new do |s|
|
|
27
27
|
"bitstamp.gemspec",
|
28
28
|
"lib/bitstamp.rb",
|
29
29
|
"lib/bitstamp/collection.rb",
|
30
|
+
"lib/bitstamp/helper.rb",
|
30
31
|
"lib/bitstamp/model.rb",
|
31
32
|
"lib/bitstamp/net.rb",
|
32
33
|
"lib/bitstamp/orders.rb",
|
34
|
+
"lib/bitstamp/ticker.rb",
|
33
35
|
"spec/bitstamp_spec.rb",
|
34
36
|
"spec/collection_spec.rb",
|
35
37
|
"spec/orders_spec.rb",
|
data/lib/bitstamp.rb
CHANGED
@@ -4,10 +4,12 @@ require 'active_model'
|
|
4
4
|
require 'curb'
|
5
5
|
|
6
6
|
require 'bitstamp/net'
|
7
|
+
require 'bitstamp/helper'
|
7
8
|
require 'bitstamp/collection'
|
8
9
|
require 'bitstamp/model'
|
9
10
|
|
10
11
|
require 'bitstamp/orders'
|
12
|
+
require 'bitstamp/ticker'
|
11
13
|
|
12
14
|
String.send(:include, ActiveSupport::Inflector)
|
13
15
|
|
@@ -34,6 +36,10 @@ module Bitstamp
|
|
34
36
|
JSON.parse Bitstamp::Net.get('/balance').body_str
|
35
37
|
end
|
36
38
|
|
39
|
+
def self.ticker
|
40
|
+
return Bitstamp::Ticker.from_api
|
41
|
+
end
|
42
|
+
|
37
43
|
def self.setup
|
38
44
|
yield self
|
39
45
|
end
|
data/lib/bitstamp/collection.rb
CHANGED
@@ -12,33 +12,19 @@ module Bitstamp
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def all(options = {})
|
15
|
-
parse_objects! Bitstamp::Net::get(self.path).body_str, self.model
|
15
|
+
Bitstamp::Helper.parse_objects! Bitstamp::Net::get(self.path).body_str, self.model
|
16
16
|
end
|
17
17
|
|
18
18
|
def create(options = {})
|
19
|
-
parse_object! Bitstamp::Net::post(self.path, options).body_str, self.model
|
19
|
+
Bitstamp::Helper.parse_object! Bitstamp::Net::post(self.path, options).body_str, self.model
|
20
20
|
end
|
21
21
|
|
22
22
|
def find(id, options = {})
|
23
|
-
parse_object! Bistamp::Net::get("#{self.path}/#{id}").body_str, self.model
|
23
|
+
Bitstamp::Helper.parse_object! Bistamp::Net::get("#{self.path}/#{id}").body_str, self.model
|
24
24
|
end
|
25
25
|
|
26
26
|
def update(id, options = {})
|
27
|
-
parse_object! Bitstamp::Net::patch("#{self.path}/#{id}", options).body_str, self.model
|
28
|
-
end
|
29
|
-
|
30
|
-
protected
|
31
|
-
def parse_objects!(string, klass)
|
32
|
-
objects = JSON.parse(string)
|
33
|
-
objects.collect do |t_json|
|
34
|
-
parse_object!(t_json, klass)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def parse_object!(object, klass)
|
39
|
-
object = JSON.parse(object) if object.is_a? String
|
40
|
-
|
41
|
-
klass.new(object)
|
27
|
+
Bitstamp::Helper.parse_object! Bitstamp::Net::patch("#{self.path}/#{id}", options).body_str, self.model
|
42
28
|
end
|
43
29
|
end
|
44
30
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bitstamp
|
2
|
+
module Helper
|
3
|
+
def self.parse_objects!(string, klass)
|
4
|
+
objects = JSON.parse(string)
|
5
|
+
objects.collect do |t_json|
|
6
|
+
parse_object!(t_json, klass)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.parse_object!(object, klass)
|
11
|
+
object = JSON.parse(object) if object.is_a? String
|
12
|
+
|
13
|
+
klass.new(object)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/bitstamp/orders.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Bitstamp
|
2
2
|
class Orders < Bitstamp::Collection
|
3
3
|
def all(options = {})
|
4
|
-
parse_objects! Bitstamp::Net::post('/open_orders').body_str, self.model
|
4
|
+
Bitstamp::Helper.parse_objects! Bitstamp::Net::post('/open_orders').body_str, self.model
|
5
5
|
end
|
6
6
|
|
7
7
|
def create(options = {})
|
8
8
|
path = (options[:type] == Bitstamp::Order::SELL ? "/sell" : "/buy")
|
9
|
-
parse_object! Bitstamp::Net::post(path, options).body_str, self.model
|
9
|
+
Bitstamp::Helper.parse_object! Bitstamp::Net::post(path, options).body_str, self.model
|
10
10
|
end
|
11
11
|
|
12
12
|
def sell(options = {})
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Bitstamp
|
2
|
+
class Ticker < Bitstamp::Model
|
3
|
+
attr_accessor :last, :high, :low, :volume, :bid, :ask
|
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 if ticker.respond_to? :method
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/bitstamp_spec.rb
CHANGED
@@ -19,6 +19,10 @@ describe Bitstamp do
|
|
19
19
|
Bitstamp.should respond_to :orders
|
20
20
|
end
|
21
21
|
|
22
|
+
it 'should have a ticker helper method' do
|
23
|
+
Bitstamp.ticker.should be_kind_of Bitstamp::Ticker
|
24
|
+
end
|
25
|
+
|
22
26
|
it 'should list information about your balance' do
|
23
27
|
read_bitstamp_yaml
|
24
28
|
|
data/spec/orders_spec.rb
CHANGED
@@ -10,10 +10,10 @@ describe Bitstamp::Orders do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should sell bitcoins" do
|
13
|
-
|
13
|
+
Bitstamp.orders.sell(:amount => 1, :price => 1000)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should buy bitcoins" do
|
17
|
-
|
17
|
+
Bitstamp.orders.buy(:amount => 1, :price => 1.01)
|
18
18
|
end
|
19
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitstamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -141,9 +141,11 @@ files:
|
|
141
141
|
- bitstamp.gemspec
|
142
142
|
- lib/bitstamp.rb
|
143
143
|
- lib/bitstamp/collection.rb
|
144
|
+
- lib/bitstamp/helper.rb
|
144
145
|
- lib/bitstamp/model.rb
|
145
146
|
- lib/bitstamp/net.rb
|
146
147
|
- lib/bitstamp/orders.rb
|
148
|
+
- lib/bitstamp/ticker.rb
|
147
149
|
- spec/bitstamp_spec.rb
|
148
150
|
- spec/collection_spec.rb
|
149
151
|
- spec/orders_spec.rb
|
@@ -163,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
165
|
version: '0'
|
164
166
|
segments:
|
165
167
|
- 0
|
166
|
-
hash:
|
168
|
+
hash: 2421895036503918576
|
167
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
170
|
none: false
|
169
171
|
requirements:
|