satoshi_ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a7c421dc1fd01177bf229be317dda7c151bc1dd
4
+ data.tar.gz: c87f382d5dba56d70fc0b838fb0b8a52efc20631
5
+ SHA512:
6
+ metadata.gz: 3f5360ff37cbe6f913ffac258bec609d05b1a94518dedb990d0e1a3b4e7d0baba9a5be69f31e46f42d23a7d53af699ac746b659cd0593c895b124e2dbb662815
7
+ data.tar.gz: 89292283121cbc0125f2b2c4b82dc43269855598cc8989e393da4195779a69a0a392afb6e8592162a9b6ca388a1374956071a2f5ee094184ee595469eeaf22db
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in satoshi_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ahmed Youssef
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,29 @@
1
+ # SatoshiRuby
2
+
3
+ Satoshi API Gem 'under development'
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'satoshi_ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install satoshi_ruby
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,125 @@
1
+ require "satoshi_ruby/version"
2
+ require 'httparty'
3
+ require 'queryparams'
4
+ require 'bigdecimal'
5
+ require 'satoshi_ruby/utilities/currency_utility'
6
+
7
+ module SatoshiRuby
8
+
9
+ class Satoshi
10
+ include HTTParty
11
+
12
+ URL = 'https://api.vaultofsatoshi.com'
13
+
14
+ def initialize api_key, api_sign
15
+ @api_key = api_key
16
+ @api_sign = api_sign
17
+ end
18
+
19
+ def wallet_address cur = ''
20
+ end_point = '/info/wallet_address'
21
+ data = {currency: cur.to_s}
22
+ action end_point, data
23
+ end
24
+
25
+ def currency cur = ''
26
+ end_point = '/info/currency'
27
+ data = {currency: cur.to_s}
28
+ action end_point, data
29
+ end
30
+
31
+ def account
32
+ end_point = '/info/account'
33
+ action end_point, nil
34
+ end
35
+
36
+ def balance cur = ''
37
+ end_point = '/info/balance'
38
+ data = {currency: cur.to_s}
39
+ action end_point, data
40
+ end
41
+
42
+ def wallet_history cur, count = 100, after = ''
43
+ end_point = '/info/wallet_history'
44
+ data = {currency: cur.to_s, count: count, after: after}
45
+ action end_point, data
46
+ end
47
+
48
+ def ticker order_currency, payment_currency
49
+ end_point = '/info/ticker'
50
+ data = {order_currency: order_currency, payment_currency: payment_currency}
51
+ action end_point, data
52
+ end
53
+
54
+ def quote type, order_currency, units, payment_currency, price
55
+ end_point = '/info/quote'
56
+ data = {type: type, order_currency: order_currency, units: units, payment_currency: payment_currency,
57
+ price: price}
58
+ action end_point, data
59
+ end
60
+
61
+ def orderbook order_currency, payment_currency, group_orders, count
62
+ end_point = '/info/orderbook'
63
+ data = {order_currency: order_currency, payment_currency: payment_currency, group_orders: group_orders,
64
+ count: count}
65
+ action end_point, data
66
+ end
67
+
68
+ def orders count = 100, after = '', open_only = ''
69
+ end_point = '/info/orders'
70
+ data = {count: count, after: after}
71
+ data = open_only.empty? ? data : data.merge({open_only: open_only})
72
+ action end_point, data
73
+ end
74
+
75
+ def order_details order_id
76
+ end_point = '/info/order_detail'
77
+ data = {order_id: order_id}
78
+ action end_point, data
79
+ end
80
+
81
+ def place type, order_currency, units, payment_currency, price
82
+ end_point = '/trade/place'
83
+ data = {type: type, order_currency: order_currency, units: units, payment_currency: payment_currency,
84
+ price: price}
85
+ action end_point, data
86
+ end
87
+
88
+ def cancel order_id
89
+ end_point = '/trade/cancel'
90
+ data = {order_id: order_id}
91
+ action end_point, data
92
+ end
93
+
94
+ private
95
+
96
+ def get_nonce
97
+ time = Time.now
98
+ time.to_i.to_s + time.usec.to_s
99
+ end
100
+
101
+ def sign base_string
102
+ hmac = OpenSSL::HMAC.hexdigest('sha512', @api_sign, base_string)
103
+ Base64.encode64(hmac).gsub("\n", '')
104
+ end
105
+
106
+ def path end_point
107
+ URL + end_point
108
+ end
109
+
110
+ def action end_point, data = ''
111
+ nonce = get_nonce
112
+ data = data.nil? ? {nonce: nonce} : data.merge({nonce: nonce})
113
+ signed = sign(end_point + 0.chr + parameterize(data))
114
+ options = {body: data, headers: {'Api-Key' => @api_key, 'Api-Sign' => signed}}
115
+ res = self.class.post(path(end_point), options)
116
+ puts res
117
+ res
118
+ end
119
+
120
+ def parameterize(params)
121
+ URI.escape(QueryParams.encode(params))
122
+ end
123
+
124
+ end
125
+ end
@@ -0,0 +1,23 @@
1
+ class CurrencyUtility
2
+ def self.currency_create_value(value_int, precision)
3
+ data = Hash.new
4
+ data['precision'] = precision
5
+ data['value'] = BigDecimal(BigDecimal(value_int).floor(precision) / (BigDecimal(10 ** precision).floor(precision))).floor(precision);
6
+ data['value_int'] = value_int;
7
+ data
8
+ end
9
+
10
+ def self.currency_create_value_int(value, precision)
11
+ data = Hash.new
12
+ data['precision'] = precision
13
+ data['value'] = value
14
+ data['value_int'] = BigDecimal(BigDecimal(value.to_s).floor(precision) * (BigDecimal(10 ** precision).floor(precision))).floor(precision).to_i;
15
+ data
16
+ end
17
+
18
+ def self.currency_to_string(data)
19
+ precision = data['precision']
20
+ value_int = data['value_int']
21
+ return BigDecimal(value_int / (BigDecimal(10 ** precision))).floor(precision).to_s("F");
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module SatoshiRuby
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'satoshi_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "satoshi_ruby"
8
+ spec.version = SatoshiRuby::VERSION
9
+ spec.authors = ["Ahmed Youssef"]
10
+ spec.email = ["ahmed@overcstudios.com"]
11
+ spec.description = %q{Consuming vaultofsatoshi.com APIs}
12
+ spec.summary = %q{Consuming vaultofsatoshi.com APIs}
13
+ spec.homepage = ""
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_dependency "httparty"
22
+ spec.add_dependency "queryparams"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "simplecov"
28
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper'
2
+ describe 'Satoshi API' do
3
+ before(:all) do
4
+ api_key = ENV['API_KEY']
5
+ api_sign = ENV['API_SIGN']
6
+ @satoshi = SatoshiRuby::Satoshi.new(api_key, api_sign)
7
+ end
8
+
9
+ it 'Satoshi keys should not be empty' do
10
+ ENV['API_KEY'].should_not be_empty
11
+ ENV['API_SIGN'].should_not be_empty
12
+ end
13
+
14
+ describe '-***Positive***-' do
15
+
16
+ it 'Wallet address should return wallet addresses' do
17
+ ret = @satoshi.wallet_address
18
+ ret['status'].should eq 'success'
19
+ end
20
+
21
+ it 'Wallet address should return wallet address for BTC' do
22
+ ret = @satoshi.wallet_address 'BTC'
23
+ ret['status'].should eq 'success'
24
+ end
25
+
26
+ it 'Currency should return array of currencies' do
27
+ ret = @satoshi.currency
28
+ ret['status'].should eq 'success'
29
+ end
30
+
31
+ it 'Currency should return BTC currency' do
32
+ ret = @satoshi.currency 'BTC'
33
+ ret['status'].should eq 'success'
34
+ end
35
+
36
+ it 'Account should return main account' do
37
+ ret = @satoshi.account
38
+ ret['status'].should eq 'success'
39
+ end
40
+
41
+ it 'Balance should return balances list' do
42
+ ret = @satoshi.balance
43
+ ret['status'].should eq 'success'
44
+ end
45
+
46
+ it 'Balance should return BTC balance' do
47
+ ret = @satoshi.balance 'BTC'
48
+ ret['status'].should eq 'success'
49
+ end
50
+
51
+ it 'Ticker should return trading statistics' do
52
+ ret = @satoshi.ticker 'btc', 'usd'
53
+ ret['status'].should eq 'success'
54
+ end
55
+
56
+ it 'Quote should return trade cost' do
57
+ ret = @satoshi.quote 'bid', 'btc', CurrencyUtility.currency_create_value(12, 1), 'usd', CurrencyUtility.currency_create_value_int(0.1, 4)
58
+ ret['status'].should eq 'success'
59
+ CurrencyUtility.currency_to_string(ret['data']['total']).should include('.')
60
+ end
61
+
62
+ it 'Orderbook should return orderbook' do
63
+ ret = @satoshi.orderbook 'btc', 'usd', 1, 20
64
+ ret['status'].should eq 'success'
65
+ end
66
+
67
+ it 'Orders should return my orders' do
68
+ ret = @satoshi.orders 10, '1387972933374496'
69
+ ret['status'].should eq 'success'
70
+ end
71
+
72
+ it 'Order details should return success' do
73
+ ret = @satoshi.order_details 'nil'
74
+ ret['status'].should eq 'success'
75
+ ret['data'].should be_empty
76
+ end
77
+
78
+
79
+ end
80
+
81
+ describe '-***Negative***-' do
82
+
83
+ it 'Order details should return invalid signature' do
84
+ ret = @satoshi.order_details nil
85
+ ret['message'].should eq 'Invalid signature'
86
+ end
87
+
88
+ it 'Place should return invalid order currency' do
89
+ ret = @satoshi.place 'bid', 'usd', CurrencyUtility.currency_create_value(12, 1), 'btc', CurrencyUtility.currency_create_value_int(0.1, 4)
90
+ ret['message'].should eq 'Invalid order currency'
91
+ end
92
+
93
+ it 'Cancel should return invalid signature' do
94
+ ret = @satoshi.cancel nil
95
+ ret['message'].should eq 'Invalid signature'
96
+ end
97
+
98
+ it 'Cancel should return order_id must be a number' do
99
+ ret = @satoshi.cancel 'nil'
100
+ ret['status'].should eq 'error'
101
+ ret['message'].should eq 'order_id must be a number'
102
+ end
103
+
104
+ it 'Cancel should return invalid order id' do
105
+ ret = @satoshi.cancel 10000000000001
106
+ ret['message'].should eq 'Invalid order_id'
107
+ end
108
+
109
+ it 'Wallet history should return error' do
110
+ ret = @satoshi.wallet_history 'btc', nil
111
+ ret['message'].should eq 'Invalid signature'
112
+ end
113
+
114
+ end
115
+
116
+ end
@@ -0,0 +1,10 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ require 'satoshi_ruby'
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: satoshi_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ahmed Youssef
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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
+ - !ruby/object:Gem::Dependency
28
+ name: queryparams
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Consuming vaultofsatoshi.com APIs
98
+ email:
99
+ - ahmed@overcstudios.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/satoshi_ruby.rb
110
+ - lib/satoshi_ruby/utilities/currency_utility.rb
111
+ - lib/satoshi_ruby/version.rb
112
+ - satoshi_ruby.gemspec
113
+ - spec/satoshi_ruby_spec.rb
114
+ - spec/spec_helper.rb
115
+ homepage: ''
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.1.11
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Consuming vaultofsatoshi.com APIs
139
+ test_files:
140
+ - spec/satoshi_ruby_spec.rb
141
+ - spec/spec_helper.rb
142
+ has_rdoc: