bter-ruby 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/README.md +44 -5
- data/lib/bter/public.rb +16 -2
- data/lib/bter/request_logger.rb +2 -1
- data/lib/bter/trading.rb +17 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb2a672bffe805db795ba178c06548570d9fc613
|
4
|
+
data.tar.gz: 2cac1d974fedb22933af263aae4c9132c981136c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632f28a52c5257d08f33ecf2fef3bb3df5c0d9d04b88b6c3972b713c7bd39c2a7cedb8d88afd1b4a9959c84cad640f931d71c04e3f237e72c6ddd81fe4719ec8
|
7
|
+
data.tar.gz: 77a5f346ccd637e9bf2829b06f277200bb22324cbdcc77a465a93ed780e2be4651eb46e76ffb7948e041739b6974c110e8a374c7fab1b9b12adab4c876c52530
|
data/README.md
CHANGED
@@ -4,13 +4,52 @@ Install with
|
|
4
4
|
```ruby
|
5
5
|
gem install bter-ruby
|
6
6
|
```
|
7
|
-
then
|
7
|
+
and then require in your project
|
8
8
|
```ruby
|
9
|
-
|
9
|
+
require 'bter'
|
10
10
|
```
|
11
|
-
and
|
11
|
+
The library has two parts , one for the public api and one for the trading one.
|
12
|
+
|
13
|
+
The public api has 3 methods which return the ticker , market depth
|
14
|
+
and current trades for a given pair(check bter for the available pairs)
|
15
|
+
|
12
16
|
```ruby
|
13
|
-
|
17
|
+
bt = Bter::Public.new
|
18
|
+
|
19
|
+
puts bt.ticker("btc_cny")
|
20
|
+
puts bt.depth("btc_cny")
|
21
|
+
puts bt.trades("btc_cny")
|
22
|
+
```
|
23
|
+
To use the trading api , you need to supply your key and secret
|
24
|
+
```ruby
|
25
|
+
bt = Bter::Trade.new
|
26
|
+
|
27
|
+
bt.key = "my key"
|
28
|
+
bt.secret = "my secret"
|
29
|
+
```
|
30
|
+
Then you can use the available methods:
|
31
|
+
```ruby
|
32
|
+
bt.get_info
|
33
|
+
bt.active_orders
|
34
|
+
bt.order_status(order_id)
|
35
|
+
bt.cancel_order(order_id)
|
36
|
+
bt.buy(pair, amount)
|
37
|
+
bt.sell(pair, amount)
|
38
|
+
```
|
39
|
+
|
40
|
+
You can enable the logger for public and trading requests.
|
41
|
+
It logs successful or failed requests and response info.(off by default)
|
42
|
+
```ruby
|
43
|
+
bt = Bter::Public.new
|
44
|
+
bt.logging :on
|
45
|
+
|
46
|
+
bt2 = Bter::Trade.new
|
47
|
+
bt2.logging :on
|
14
48
|
```
|
15
49
|
|
16
|
-
|
50
|
+
|
51
|
+
Also check the two examples in the examples folder.
|
52
|
+
|
53
|
+
Licensed under MIT.
|
54
|
+
|
55
|
+
|
data/lib/bter/public.rb
CHANGED
@@ -2,14 +2,28 @@
|
|
2
2
|
module Bter
|
3
3
|
class Public
|
4
4
|
|
5
|
+
def initialize
|
6
|
+
@logging = false
|
7
|
+
end
|
8
|
+
|
9
|
+
def logging(p)
|
10
|
+
if p == :on
|
11
|
+
@logging = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
def public_request(method, pair)
|
6
16
|
request = Typhoeus::Request.new("https://bter.com/api/1/#{method}/#{pair}")
|
7
|
-
|
17
|
+
if @logging
|
18
|
+
RequestLogger.error_log(request)
|
19
|
+
end
|
8
20
|
hydra = Typhoeus::Hydra.hydra
|
9
21
|
hydra.queue(request)
|
10
22
|
hydra.run
|
11
23
|
response = request.response
|
12
|
-
|
24
|
+
if @logging
|
25
|
+
RequestLogger.info_log(response.code, response.total_time, response.headers_hash)
|
26
|
+
end
|
13
27
|
response.body
|
14
28
|
end
|
15
29
|
|
data/lib/bter/request_logger.rb
CHANGED
data/lib/bter/trading.rb
CHANGED
@@ -3,6 +3,16 @@ module Bter
|
|
3
3
|
class Trade
|
4
4
|
|
5
5
|
attr_accessor :key, :secret
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@logging = false
|
9
|
+
end
|
10
|
+
|
11
|
+
def logging(p)
|
12
|
+
if p == :on
|
13
|
+
@logging = true
|
14
|
+
end
|
15
|
+
end
|
6
16
|
|
7
17
|
def trade_request(method, params=nil)
|
8
18
|
if params.nil?
|
@@ -19,12 +29,16 @@ module Bter
|
|
19
29
|
body: @params,
|
20
30
|
headers: { Key: @key, Sign: sign }
|
21
31
|
)
|
22
|
-
|
32
|
+
if @logging
|
33
|
+
RequestLogger.error_log(request)
|
34
|
+
end
|
23
35
|
hydra = Typhoeus::Hydra.hydra
|
24
36
|
hydra.queue(request)
|
25
37
|
hydra.run
|
26
38
|
response = request.response
|
27
|
-
|
39
|
+
if @logging
|
40
|
+
RequestLogger.info_log(response.code, response.total_time, response.headers_hash)
|
41
|
+
end
|
28
42
|
response.body
|
29
43
|
end
|
30
44
|
|
@@ -71,7 +85,7 @@ module Bter
|
|
71
85
|
end
|
72
86
|
|
73
87
|
def get_rate(pair)
|
74
|
-
ticker(pair).values_at(:last).flatten
|
88
|
+
Public.new.ticker(pair).values_at(:last).flatten
|
75
89
|
end
|
76
90
|
|
77
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bter-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zisis Maras
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby api for the bter.com cryptocurrency exchange
|
14
14
|
email: zisismaras@gmail.com
|