peatio_client 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ebced0663c94ea971c0c1e812693fa215141f91e
4
+ data.tar.gz: 86ebc990d3b7302ec103c351ac3b44632a45b0cf
5
+ SHA512:
6
+ metadata.gz: b0a06eedcae95c3ce95178b611e76b9c1345d0626c188197c1019b931f52934c4ee5ec166e5df97084c8f1cca7123aff736ba1a448cedde4bdfe0fb889d53f96
7
+ data.tar.gz: 1bfc45f0a3b52eeac45f7fc500b660ee572bbf420f309f1a824b882e6ecd44e1a3fd99b0586f19a0f2954eab78e92dcfe2075757435ffb74217175177fba83ce
data/README.markdown ADDED
@@ -0,0 +1,54 @@
1
+ Ruby client for Peatio API
2
+ ==========================
3
+
4
+ [![Build Status](https://travis-ci.org/peatio/peatio-client-ruby.png?branch=master)](https://travis-ci.org/peatio/peatio-client-ruby)
5
+
6
+ `peatio-client-ruby` is a client for Peatio API, support all Peatio API functions like submit order, get tickers, etc. It's also a reference client implementation, where you can find how to authenticate private Peatio API.
7
+
8
+ ### Requirements ###
9
+
10
+ * ruby 2.0.0 or higher (if you want to run 'rake test' in this gem you'll need ruby 2.1.0 or higher)
11
+ * openssl
12
+
13
+ ### Install ###
14
+
15
+ gem install peatio_client
16
+
17
+ ### Usage ###
18
+
19
+ #### Command line tool ####
20
+
21
+ TBD
22
+
23
+ #### Library ####
24
+
25
+ Use `#get` or `#post` to access API after you created a `PeatioAPI::Client`:
26
+
27
+ ```ruby
28
+ require 'peatio_client'
29
+
30
+ # initialize client. `endpoint` can be ignored
31
+ client = PeatioAPI::Client.new access_key: 'your_access_key', secret_key: 'your_secret_key', endpoint: 'https://peatio.com'
32
+
33
+ # GET public api /api/v2/markets
34
+ client.get '/api/v2/markets'
35
+
36
+ # GET private api /api/v2/orders with 'market=btccny'
37
+ client.get '/api/v2/orders', market: 'btccny'
38
+
39
+ # POST to create an order
40
+ client.post '/api/v2/orders', market: 'btccny', side: 'sell', volume: '0.11', price: '2955.0'
41
+
42
+ # POST to create multiple orders at once
43
+ client.post '/api/v2/orders/multi', market: 'btccny', orders: [{side: 'buy', volume: '0.15', price: '2955.0'}, {side: 'sell', volume: '0.16', price: '2956'}]
44
+ ```
45
+
46
+ Check [Peatio API v2 Documents](https://peatio.com/documents/api_v2) for details on Peatio API.
47
+
48
+ ### License ###
49
+
50
+ `peatio-client-ruby` is released under MIT license. See [http://peatio.mit-license.org](http://peatio.mit-license.org) for more information.
51
+
52
+ ### How To Contribute ###
53
+
54
+ Just create an issue or open a pull request :)
@@ -0,0 +1,31 @@
1
+ module PeatioAPI
2
+ class Auth
3
+
4
+ def initialize(access_key, secret_key)
5
+ @access_key = access_key
6
+ @secret_key = secret_key
7
+ end
8
+
9
+ def signed_params(verb, path, params={})
10
+ params = format_params params
11
+ signature = sign verb, path, URI.unescape(params.to_query)
12
+ params.merge(signature: signature)
13
+ end
14
+
15
+ def sign(verb, path, params)
16
+ OpenSSL::HMAC.hexdigest 'SHA256', @secret_key, payload(verb, path, params)
17
+ end
18
+
19
+ def payload(verb, path, params)
20
+ "#{verb.upcase}|#{path}|#{params}"
21
+ end
22
+
23
+ def format_params(params)
24
+ params = params.symbolize_keys
25
+ params[:access_key] ||= @access_key
26
+ params[:tonce] ||= (Time.now.to_f*1000).to_i
27
+ params
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require_relative 'client/version'
4
+
5
+ module PeatioAPI
6
+ class Client
7
+
8
+ attr :auth
9
+
10
+ def initialize(options={})
11
+ options.symbolize_keys!
12
+ setup_auth_keys options
13
+ @endpoint = options[:endpoint] || 'https://peatio.com'
14
+ end
15
+
16
+ def get(path, params={})
17
+ uri = URI("#{@endpoint}#{path}")
18
+
19
+ # sign on all requests, even those to public API
20
+ signed_params = @auth.signed_params 'GET', path, params
21
+ uri.query = URI.encode_www_form signed_params
22
+
23
+ parse Net::HTTP.get_response(uri)
24
+ end
25
+
26
+ def post(path, params={})
27
+ uri = URI("#{@endpoint}#{path}")
28
+ Net::HTTP.new(uri.hostname, uri.port).start do |http|
29
+ params = @auth.signed_params 'POST', path, params
30
+ parse http.request_post(path, params.to_query)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def parse(response)
37
+ if response.code =~ /2../
38
+ JSON.parse response.body
39
+ else
40
+ raise "Request failed: #{response.body}"
41
+ end
42
+ end
43
+
44
+ def setup_auth_keys(options)
45
+ if options[:access_key] && options[:secret_key]
46
+ @access_key = options[:access_key]
47
+ @secret_key = options[:secret_key]
48
+ @auth = Auth.new @access_key, @secret_key
49
+ else
50
+ raise ArgumentError, 'Missing access key and/or secret key'
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module PeatioAPI
2
+ class Client
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ module PeatioAPI
2
+ class Config
3
+
4
+ def self.get_peatiorc(path)
5
+ if File.exist? path
6
+ lines = File.readlines path
7
+ [ lines[0].strip, lines[1].strip ]
8
+ end
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ require 'active_support/core_ext'
2
+ require 'active_support/hash_with_indifferent_access'
3
+
4
+ require_relative 'peatio_api/config'
5
+ require_relative 'peatio_api/auth'
6
+ require_relative 'peatio_api/client'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peatio_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peatio Opensource
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: A ruby client which can access all Peatio's API.
28
+ email:
29
+ - community@peatio.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.markdown
35
+ - lib/peatio_api/auth.rb
36
+ - lib/peatio_api/client.rb
37
+ - lib/peatio_api/client/version.rb
38
+ - lib/peatio_api/config.rb
39
+ - lib/peatio_client.rb
40
+ homepage: https://github.com/peatio/peatio-client-ruby
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.2.0
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A ruby client to access Peatio's API.
64
+ test_files: []