mercado_bitcoin 0.1.0 → 0.2.0

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: d58b5492bd7c156af06499208f0f05441a47f201
4
- data.tar.gz: 3aca71d49547a54bec36ba50acfa63d7f7c70a33
3
+ metadata.gz: b46652aaea796cd97202c169416b66c1e1b88297
4
+ data.tar.gz: 80657597161d4dcb1c1f33011d88db076b5d7e14
5
5
  SHA512:
6
- metadata.gz: c2735e4917bb2cf5f9b465e732eaeb98adbca26d237a84c6e3a56374ad6f5969f5ef3137786bcdc8e09377940f6c8c8e33167ccfb6a6c0c334979f9f2816af77
7
- data.tar.gz: fc019bb9f44991e34b5bf0838101640ae93ca70a005d905800a55a01e9172d9032facd8c71f40fc07a48e866a234b759d54e6e84220009e36b77e4eb2cb2f8b6
6
+ metadata.gz: b8bb3dfa97d562692c829206f180cb194a398abb68127954211292bf38310f289becb9b162e1ac04c9b26f4d3aede16355693cfae224c055b9150a09516c45a2
7
+ data.tar.gz: 41581861a1b23806eae562408cd177bd774c646688933bfc74b6f7cb6bc8ddbfb8dac00842079b32b3e0bc0f68a7075c13cad1dd299f69b43b1d0d4f15501858
data/README.md CHANGED
@@ -20,7 +20,9 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: missing documentation.
23
+ TODO:
24
+ - write documentation.
25
+ - make a CI
24
26
 
25
27
  ## Contributing
26
28
 
@@ -7,6 +7,8 @@ require 'json'
7
7
  module MercadoBitcoin
8
8
  require 'mercado_bitcoin/errors'
9
9
  autoload :Api, 'mercado_bitcoin/api'
10
+ autoload :TradeApi, 'mercado_bitcoin/trade_api'
11
+ autoload :QueryStringRefinement, 'mercado_bitcoin/query_string_refinement'
10
12
  autoload :BaseApiCall, 'mercado_bitcoin/base_api_call'
11
13
  autoload :Ticker, 'mercado_bitcoin/ticker'
12
14
  autoload :Trade, 'mercado_bitcoin/trade'
@@ -0,0 +1,7 @@
1
+ module MercadoBitcoin::QueryStringRefinement
2
+ refine Hash do
3
+ def to_query_string
4
+ URI.encode_www_form(self)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,72 @@
1
+ require 'openssl'
2
+
3
+ module MercadoBitcoin
4
+ class TradeApi
5
+ using QueryStringRefinement
6
+
7
+ attr_accessor :key, :code
8
+
9
+ def initialize(key:, code:)
10
+ @key = key
11
+ @code = code
12
+ end
13
+
14
+ def get_info
15
+ params = base_params('getInfo')
16
+ post(params)
17
+ end
18
+
19
+ # type: buy, sell
20
+ def trade(pair: 'btc_brl', type:, volume:, price:)
21
+ params = base_params('Trade')
22
+ params[:pair] = pair
23
+ params[:type] = type
24
+ params[:volume] = volume
25
+ params[:price] = price
26
+ post(params)
27
+ end
28
+
29
+ # status: active, canceled, completed
30
+ # since and end: in Unix timestamp: Time.new.to_i
31
+ def order_list(pair: 'btc_brl', type: nil, status: nil, from_id: nil, end_id: nil, since: nil, _end: nil)
32
+ params = base_params('OrderList')
33
+ params[:pair] = pair
34
+ params[:type] = type if type
35
+ params[:status] = status if status
36
+ params[:from_id] = from_id if from_id
37
+ params[:end_id] = end_id if end_id
38
+ params[:since] = since if since
39
+ params[:end] = _end if _end
40
+ post(params)
41
+ end
42
+
43
+ def post(params)
44
+ RestClient.post(base_url, params.to_query_string, header(sign(params)))
45
+ end
46
+
47
+ def base_url
48
+ @base_url ||= "https://www.mercadobitcoin.net/tapi/".freeze
49
+ end
50
+
51
+ def header(signature)
52
+ {
53
+ 'Content-Type' => 'application/x-www-form-urlencoded',
54
+ 'Key' => key,
55
+ 'Sign' => signature
56
+ }
57
+ end
58
+
59
+ def base_params(method)
60
+ {
61
+ method: method,
62
+ tonce: Time.new.to_i + (ENV['TONCE_CORRECTION'].to_i)
63
+ }
64
+ end
65
+
66
+ def sign(string_or_hash)
67
+ string_or_hash = string_or_hash.to_query_string if string_or_hash.is_a?(Hash)
68
+ hmac = OpenSSL::HMAC.new(code, OpenSSL::Digest.new('sha512'))
69
+ hmac.update(string_or_hash).to_s
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module MercadoBitcoin
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercado_bitcoin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Carvalho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-26 00:00:00.000000000 Z
11
+ date: 2016-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: virtus
@@ -123,8 +123,10 @@ files:
123
123
  - lib/mercado_bitcoin/base_api_call.rb
124
124
  - lib/mercado_bitcoin/errors.rb
125
125
  - lib/mercado_bitcoin/order_book.rb
126
+ - lib/mercado_bitcoin/query_string_refinement.rb
126
127
  - lib/mercado_bitcoin/ticker.rb
127
128
  - lib/mercado_bitcoin/trade.rb
129
+ - lib/mercado_bitcoin/trade_api.rb
128
130
  - lib/mercado_bitcoin/version.rb
129
131
  - lib/virtus/timestamp.rb
130
132
  - mercado_bitcoin.gemspec