cexio 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --markup markdown
2
+ --markup-provider redcarpet
3
+ --charset utf-8
4
+ --readme README.md
5
+ -
6
+ README.md
7
+ LICENSE
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cex.io.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 t0pep0
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # Cex.io
2
+
3
+ CEX.IO API integration. Ruby gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'cexio'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install cexio
18
+
19
+ ## Usage
20
+
21
+ ##How to use?
22
+
23
+ ###1. Create your php project
24
+
25
+ ###2. Add "requre_once("cexapi.class.php")
26
+
27
+ ###3. Create class
28
+ ```ruby
29
+ api = CEX::API(username, api_key, api_secret)
30
+ ```
31
+ ```
32
+ username - your username on cex.io
33
+ api_key - your API key
34
+ api_secret - your API secret code
35
+ ```
36
+ ###4. Methods and parameters:
37
+
38
+ ####a) API method parametrs
39
+ ```
40
+ 1. couple = ("GHS\BTC" | "BF1\BTC") currency pair
41
+ 2. since = integer return trades with tid >= since
42
+ 3. order_id = integer
43
+ 4. ptype = ("sell" | "buy") type of order
44
+ 5. amount = float
45
+ 6. price = float
46
+ ```
47
+
48
+ ####b) API methods
49
+ ```
50
+ 1. ticker(couple = 'GHS/BTC') - get ticker
51
+ 2. order_book(couple = 'GHS/BTC') - get order
52
+ 3. trade_history(since = 1, couple = 'GHS/BTC') - get all order
53
+ 4. balance() - get your balance
54
+ 5. current_orders(couple = 'GHS/BTC') - get open order
55
+ 6. cancel_order(order_id) - cancel order №order_id
56
+ 7. place_order(ptype = 'buy', amount = 1, price = 1, couple = 'GHS/BTC') - create order
57
+ ```
58
+
59
+ ####c) Full API documentation: https://cex.io/api
60
+
61
+ ###5. Examples
62
+
63
+ ####Connect and get balance:
64
+ ```ruby
65
+ # -*- encoding : utf-8 -*-
66
+ require 'rubygems'
67
+ require 'cexio'
68
+
69
+ cex = CEX::API.new(username, api_key, api_secret)
70
+ puts cex.balance
71
+
72
+ ```
73
+ ```json
74
+ {'timestamp': '1383379054', 'BTC': {'available': '0.04614310', 'orders': '0.00170000'}, 'GHS': {'available': '0.02000000'}}
75
+ ```
76
+
77
+ ####Get balance:
78
+ ```ruby
79
+ puts cex.balance
80
+ ```
81
+ ```json
82
+ {'timestamp': '1383379054', 'BTC': {'available': '0.04614310', 'orders': '0.00170000'}, 'GHS': {'available': '0.02000000'}}
83
+ ```
84
+
85
+ ####Get API ticker:
86
+ ```ruby
87
+ puts cex.ticker('GHS/BTC')
88
+ ```
89
+ ```json
90
+ {u'volume': '7154.78339022', 'last': '0.1078', 'timestamp': '1383379041', 'bid': '0.10778', 'high': '0.10799999', 'low': '0.10670076', 'ask': '0.10780000000000001'}
91
+ ```
92
+
93
+ ####Get order book:
94
+ ```ruby
95
+ puts cex.order_book('BF1/BTC')
96
+ ```
97
+ ```json
98
+ {'timestamp': '1383378967', 'bids': [['1.7', '0.30100000'], ['1.67', '0.00011000'], ['0.8', '0.02070000'], ['0.1002', '0.27748002'], ['0.1', '0.10000000'], ['0.011', '0.30500000'], ['0.009', '1.00000000'], ['0.00171', '0.00100000'], ['0.0012', '1.00000000'], ['0.00116819', '0.50000000'], ['0.001002', '33.00000000'], ['0.001001', '53.00000000'], ['0.001', '3.00000000'], ['0.00097626', '36.00000000'], ['0.0006', '85.00000000'], ['0.00058409', '0.50000000'], ['0.0004889', '0.06823960'], ['0.0003', '1.00000000'], ['0.00029204', '0.90000000'], ['0.0001', '101.00000000']], 'asks': []}
99
+ ```
100
+
101
+ ####Get your current active orders:
102
+ ```ruby
103
+ puts cex.current_orders('BF1/BTC')
104
+ ```
105
+ ```json
106
+ [{'price': '1.7', 'amount': '0.00100000', 'time': '1383378514737', 'type': 'buy', 'id': '6219104', 'pending': '0.00100000'}]
107
+ ```
108
+
109
+ ####Place new order:
110
+ ```ruby
111
+ puts cex.place_order('buy', 0.001, 1.7, 'BF1/BTC')
112
+ ```
113
+ ```json
114
+ {'price': '1.7', 'amount': '0.00100000', 'time': 1383378987622, 'type': 'buy', 'id': '6219145', 'pending': '0.00100000'}
115
+ ```
116
+
117
+ ####Place another order (GHS/BTC):
118
+ ```ruby
119
+ puts cex.place_order('buy', 0.01, 0.10789, 'GHS/BTC')
120
+ ```
121
+ ```json
122
+ {'price': '0.10789', 'amount': '0.01000000', 'time': 1383379024072, 'type': 'buy', 'id': '6219150', 'pending': '0.00000000'}
123
+ ```
124
+
125
+ ####Cancel order:
126
+ ```ruby
127
+ cex.cancel_order(6219145)
128
+ ```
129
+ ```json
130
+ True
131
+ ```
132
+
133
+ ## Contributing
134
+
135
+ 1. Fork it
136
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
137
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
138
+ 4. Push to the branch (`git push origin my-new-feature`)
139
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require "yard"
data/cexio.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cexio/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cexio"
8
+ spec.version = Cexio::VERSION
9
+ spec.authors = ["t0pep0"]
10
+ spec.email = ["t0pep0.gentoo@gmail.com"]
11
+ spec.description = "Gem for acsess to api cex.io"
12
+ spec.summary = "Cex.io api library"
13
+ spec.homepage = "https://github.com/t0pep0/cex.io-api-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "yard"
24
+ spec.add_development_dependency "redcarpet"
25
+ spec.add_development_dependency "rspec-core"
26
+ spec.add_development_dependency "rspec-expectations"
27
+ spec.add_development_dependency "rr"
28
+
29
+
30
+ end
@@ -0,0 +1,3 @@
1
+ module Cexio
2
+ VERSION = "0.0.1"
3
+ end
data/lib/cexio.rb ADDED
@@ -0,0 +1,80 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "cexio/version"
3
+ require "openssl"
4
+ require "net/http"
5
+ require "net/https"
6
+ require "uri"
7
+ require "json"
8
+ require "addressable/uri"
9
+
10
+ module CEX
11
+
12
+ class API
13
+ attr_accessor :api_key, :api_secret, :username, :nonce_v
14
+
15
+ def initialize(username, api_key, api_secret)
16
+ self.username = username
17
+ self.api_key = api_key
18
+ self.api_secret = api_secret
19
+ end
20
+
21
+ def api_call(method, param = {}, priv = false, couple = '')
22
+ url = 'https://cex.io/api/'+method+'/'
23
+ url = url + couple + '/' if couple != ''
24
+ if priv
25
+ self.nonce
26
+ param.merge!(:key => self.api_key, :signature => self.signature.to_s, :nonce => self.nonce_v)
27
+ end
28
+ answer = self.post(url, param)
29
+ JSON.parse(answer)
30
+ end
31
+
32
+ def ticker(couple = 'GHS/BTC')
33
+ self.api_call('ticker', {}, false, couple)
34
+ end
35
+
36
+ def order_book(couple = 'GHS/BTC')
37
+ self.api_call('order_book', {}, false, couple)
38
+ end
39
+
40
+ def trade_history(since = 1, couple = 'GHS/BTC')
41
+ self.api_call('trade_history', {:since => since.to_s}, false, couple)
42
+ end
43
+
44
+ def balance
45
+ self.api_call('balance', {}, true)
46
+ end
47
+
48
+ def open_orders(couple = 'GHS/BTC')
49
+ self.api_call('open_orders', {}, true, couple)
50
+ end
51
+
52
+ def cancel_order(order_id)
53
+ self.api_call('cancel_order', {:id => order_id.to_s}, true)
54
+ end
55
+
56
+ def place_order(ptype = 'buy', amount = 1, price =1, couple = 'GHS/BTC')
57
+ self.api_call('place_order', {:type => ptype, :amount => amount.to_s, :price => price.to_s}, true, couple)
58
+ end
59
+
60
+
61
+
62
+ def nonce
63
+ self.nonce_v = Time.now.to_i.to_s
64
+ end
65
+
66
+ def signature
67
+ str = self.nonce_v + self.username + self.api_key
68
+ OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha256'), self.api_secret, str)
69
+ end
70
+
71
+ def post(url, param)
72
+ uri = URI.parse(url)
73
+ https = Net::HTTP.new(uri.host, uri.port)
74
+ https.use_ssl = true
75
+ params = Addressable::URI.new
76
+ params.query_values = param
77
+ https.post(uri.path, params.query).body
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,18 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+ config.mock_with :rr
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cexio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - t0pep0
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: redcarpet
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec-core
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec-expectations
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rr
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Gem for acsess to api cex.io
127
+ email:
128
+ - t0pep0.gentoo@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - .rspec
135
+ - .yardopts
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - cexio.gemspec
141
+ - lib/cexio.rb
142
+ - lib/cexio/version.rb
143
+ - spec/spec_helper.rb
144
+ homepage: https://github.com/t0pep0/cex.io-api-ruby
145
+ licenses:
146
+ - MIT
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ none: false
153
+ requirements:
154
+ - - ! '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ none: false
159
+ requirements:
160
+ - - ! '>='
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 1.8.23
166
+ signing_key:
167
+ specification_version: 3
168
+ summary: Cex.io api library
169
+ test_files:
170
+ - spec/spec_helper.rb
171
+ has_rdoc: