cryptsy-api 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: 268fec4131a7482cd01d07213f1f7a1e6b8c9825
4
+ data.tar.gz: 19adae70a7331633a45fe306a8d6e2fbe5b7cada
5
+ SHA512:
6
+ metadata.gz: 0c232ee71806f3a54a74066972a5ef71458e05d63d9fbb8616df618aebb0e810617a0ea8b87342dbb761529b3054cec1d3c527506fddd1bd47b561989cd9f8f7
7
+ data.tar.gz: 88712fbcf849e56e594c4783d489b9ba8115e47645ba635f9e6fe2dd99ddb9f474fa80b3486f35ca05ecc9b97e07a9971084cc9398cf0cb959f32afaeeb20139
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 cryptsy-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Nic Barthelemy
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,39 @@
1
+ # Cryptsy::Ruby
2
+
3
+ A first stab at a Ruby implementation of the Cryptsy API.
4
+
5
+ NOTE: Tests have credentials removed to protect the innocent, and thus private API tests will fail out of the box.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'cryptsy-api'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install cryptsy-api
20
+
21
+ ## Usage
22
+
23
+ require 'cryptsy/api'
24
+
25
+ cryptsy = Cryptsy::API::Client.new(key, secret)
26
+
27
+ e.g. cryptsy.getinfo
28
+
29
+ NOTE: Public APIs don't require a key or secret
30
+
31
+ All apis have been implemented except the deprecated v1 marketdata
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.test_files = FileList['spec/**/*_spec.rb']
7
+ t.libs.push 'spec'
8
+ t.verbose = true
9
+ end
@@ -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 'cryptsy/api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cryptsy-api"
8
+ spec.version = Cryptsy::API::VERSION
9
+ spec.authors = ["Nic Barthelemy"]
10
+ spec.email = ["nbarthel@axomi.com"]
11
+ spec.description = %q{A ruby implementation of the Cryptsy API}
12
+ spec.summary = %q{Covers all API calls at http://www.cryptsy.com/pages/api}
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 'json'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "mini_shoulda"
28
+
29
+ spec.required_ruby_version = '>=1.9'
30
+ end
@@ -0,0 +1,157 @@
1
+ require "cryptsy/api/version"
2
+ require "httparty"
3
+ require "uri"
4
+ require "openssl"
5
+ require "json"
6
+
7
+ module Cryptsy
8
+ module API
9
+ class PublicMethod
10
+ include HTTParty
11
+ base_uri "http://pubapi.cryptsy.com"
12
+
13
+ def execute_method(all_markets, single_market, marketid)
14
+ api_method = marketid.nil? ? all_markets : single_market
15
+ query = {method: api_method}
16
+ query["marketid"] = marketid if marketid
17
+
18
+ response = self.class.get("/api.php", query: query)
19
+ JSON.parse(response.body)
20
+ end
21
+ end
22
+
23
+ class PrivateMethod
24
+ include HTTParty
25
+ base_uri "https://www.cryptsy.com"
26
+ debug_output $stderr
27
+
28
+ def initialize(key=nil, secret=nil)
29
+ @key = key
30
+ @secret = secret
31
+ end
32
+
33
+ def execute_method(method_name, params)
34
+ post_data = {method: method_name, nonce: nonce}.merge(params)
35
+ post_body = URI.encode_www_form(post_data)
36
+
37
+ response = self.class.post("/api",
38
+ headers: { "User-Agent" => "Mozilla/4.0 (compatible; Cryptsy API ruby client)",
39
+ "Sign" => signed_message(post_body),
40
+ "Key" => @key,
41
+ },
42
+ body: post_data)
43
+ JSON.parse(response.body)
44
+ end
45
+
46
+ private
47
+
48
+ def nonce
49
+ Time.now.to_i
50
+ end
51
+
52
+ def signed_message(msg)
53
+ OpenSSL::HMAC.hexdigest('sha512', @secret, msg)
54
+ end
55
+
56
+ end
57
+
58
+ class Client
59
+ def initialize(key=nil, secret=nil)
60
+ @key = key
61
+ @secret = secret
62
+ end
63
+
64
+ # Public APIs
65
+
66
+ # We don't bother to support deprecated v1 api
67
+ def marketdata(marketid=nil)
68
+ call_public_api("marketdata", "singlemarketdata", marketid)
69
+ end
70
+
71
+ def orderdata(marketid=nil)
72
+ call_public_api("orderdata", "singleorderdata", marketid)
73
+ end
74
+
75
+ # Private APIs
76
+
77
+ def getinfo
78
+ call_private_api("getinfo", {})
79
+ end
80
+
81
+ def getmarkets
82
+ call_private_api("getmarkets", {})
83
+ end
84
+
85
+ def mytransactions
86
+ call_private_api("mytransactions", {})
87
+ end
88
+
89
+ def markettrades(marketid)
90
+ call_private_api("markettrades", {marketid: marketid})
91
+ end
92
+
93
+ def marketorders(marketid)
94
+ call_private_api("marketorders", {marketid: marketid})
95
+ end
96
+
97
+ def mytrades(marketid, limit)
98
+ params = {marketid: marketid}
99
+ params.merge({limit: limit}) if limit
100
+ call_private_api("mytrades", params)
101
+ end
102
+
103
+ def allmytrades
104
+ call_private_api("allmytrades", {})
105
+ end
106
+
107
+ def myorders(marketid)
108
+ call_private_api("myorders", {marketid: marketid})
109
+ end
110
+
111
+ def allmyorders
112
+ call_private_api("allmyorders", {})
113
+ end
114
+
115
+ def createorder(marketid, ordertype, quantity, price)
116
+ call_private_api("createorder",
117
+ {marketid: marketid,
118
+ ordertype: ordertype,
119
+ quantity: quantity,
120
+ price: price})
121
+ end
122
+
123
+ def cancelorder(orderid)
124
+ call_private_api("cancelorder", {orderid: orderid})
125
+ end
126
+
127
+ def cancelmarketorders(marketid)
128
+ call_private_api("cancelmarketorders", {marketid: marketid})
129
+ end
130
+
131
+ def cancelallorders
132
+ call_private_api("cancelallorders", {})
133
+ end
134
+
135
+ def calculatefees(ordertype, quantity, price)
136
+ call_private_api("calculatefees",
137
+ {ordertype: ordertype,
138
+ quantity: quantity,
139
+ price: price})
140
+ end
141
+
142
+ def generatenewaddress(currencyid, currencycode)
143
+ call_private_api("generatenewaddress", {currencyid: currencyid,
144
+ currencycode: currencycode})
145
+ end
146
+
147
+ private
148
+ def call_public_api(all_markets, single_market, marketid=nil)
149
+ Cryptsy::API::PublicMethod.new.execute_method(all_markets, single_market, marketid)
150
+ end
151
+
152
+ def call_private_api(method_name, params={})
153
+ Cryptsy::API::PrivateMethod.new(@key,@secret).execute_method(method_name, params)
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,5 @@
1
+ module Cryptsy
2
+ module API
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+ require "cryptsy/api"
3
+
4
+ describe Cryptsy::API::Client do
5
+ before do
6
+ @client = Cryptsy::API::Client.new("XXX","XXX")
7
+ end
8
+
9
+ it "should return getinfo" do
10
+ result = @client.getinfo
11
+ result.wont_be_nil && result["success"].must_equal(1)
12
+ end
13
+
14
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+ require "cryptsy/api"
3
+
4
+ describe Cryptsy::API::Client do
5
+ before do
6
+ @client = Cryptsy::API::Client.new
7
+ end
8
+
9
+ it "should return general market data" do
10
+ result = @client.marketdata
11
+ result.wont_be_nil && result["success"].must_equal(1)
12
+ end
13
+
14
+ it "should return single market data" do
15
+ result = @client.marketdata(94)
16
+ result.wont_be_nil && result["success"].must_equal(1)
17
+ end
18
+
19
+ it "should return orderbook data" do
20
+ result = @client.orderdata
21
+ result.wont_be_nil && result["success"].must_equal(1)
22
+ end
23
+
24
+ it "should return single market orderbook data" do
25
+ result = @client.orderdata(94)
26
+ result.wont_be_nil && result["success"].must_equal(1)
27
+ end
28
+
29
+ end
@@ -0,0 +1,3 @@
1
+ gem 'minitest'
2
+ require 'minitest/autorun'
3
+ require 'minitest/spec'
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cryptsy-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nic Barthelemy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-20 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: json
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: minitest
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: mini_shoulda
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: A ruby implementation of the Cryptsy API
98
+ email:
99
+ - nbarthel@axomi.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - cryptsy-api.gemspec
110
+ - lib/cryptsy/api.rb
111
+ - lib/cryptsy/api/version.rb
112
+ - spec/private_methods_spec.rb
113
+ - spec/public_methods_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: '1.9'
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: Covers all API calls at http://www.cryptsy.com/pages/api
139
+ test_files:
140
+ - spec/private_methods_spec.rb
141
+ - spec/public_methods_spec.rb
142
+ - spec/spec_helper.rb