bter-ruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35aefbbd778c55cb32b44d98afb9c570a7c7a79c
4
- data.tar.gz: 6590117558cca8af1081bbcd28d12dcd921c128e
3
+ metadata.gz: cb2a672bffe805db795ba178c06548570d9fc613
4
+ data.tar.gz: 2cac1d974fedb22933af263aae4c9132c981136c
5
5
  SHA512:
6
- metadata.gz: f5a9080d6ac0d0d10aba144347e5e7c81a72e8f101dbfff3761b9ddfb900e5c181a193a84a006387acaad8ec7e0ab0a2ee9e7a7811a565b0c29f27e0975db848
7
- data.tar.gz: 2a2f58facc364d190fceef3d379bca7f9ecb6bc27018cae9329cf1399e2682219bda787daa99bad3171e8c33d026d2e65fd3d5b9831c23de161c9b97e62a7a33
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 run
7
+ and then require in your project
8
8
  ```ruby
9
- bundle install
9
+ require 'bter'
10
10
  ```
11
- and finally require in your project
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
- require 'bter'
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
- Check the two examples in the examples folder on how to use it.
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
- Request_logger.new.error_log(request)
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
- Request_logger.new.info_log(response.code, response.total_time, response.headers_hash)
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
 
@@ -1,7 +1,8 @@
1
1
  require 'logger'
2
2
 
3
3
  module Bter
4
- class Request_logger
4
+ module RequestLogger
5
+ extend self
5
6
 
6
7
  def error_log(request)
7
8
  logger = Logger.new('logfile.log')
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
- Request_logger.new.error_log(request)
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
- Request_logger.new.info_log(response.code, response.total_time, response.headers_hash)
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.1
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-12 00:00:00.000000000 Z
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