guten-mtgox 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.gitignore +41 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/.yardopts +4 -0
- data/Gemfile +24 -0
- data/LICENSE.md +20 -0
- data/README.md +69 -0
- data/Rakefile +21 -0
- data/lib/mtgox.rb +49 -0
- data/lib/mtgox/ask.rb +20 -0
- data/lib/mtgox/base.rb +28 -0
- data/lib/mtgox/client.rb +64 -0
- data/lib/mtgox/configuration.rb +39 -0
- data/lib/mtgox/connection.rb +30 -0
- data/lib/mtgox/depth.rb +13 -0
- data/lib/mtgox/me.rb +30 -0
- data/lib/mtgox/order.rb +25 -0
- data/lib/mtgox/request.rb +46 -0
- data/lib/mtgox/response/raise_mtgox_error.rb +13 -0
- data/lib/mtgox/ticker.rb +49 -0
- data/lib/mtgox/trade.rb +29 -0
- data/lib/mtgox/version.rb +3 -0
- data/mtgox.gemspec +19 -0
- data/mtgox.watchr +22 -0
- data/response/raise_mtgox_error_spec.rb +14 -0
- data/spec/fixtures/add.json +1 -0
- data/spec/fixtures/depth.json +20439 -0
- data/spec/fixtures/id_key.json +1 -0
- data/spec/fixtures/info.json +73 -0
- data/spec/fixtures/orders.json +23 -0
- data/spec/fixtures/ticker.json +1 -0
- data/spec/fixtures/trades.json +34454 -0
- data/spec/mtgox/base_spec.rb +18 -0
- data/spec/mtgox/client_spec.rb +111 -0
- data/spec/mtgox/me_spec.rb +71 -0
- data/spec/mtgox_spec.rb +21 -0
- data/spec/spec_helper.rb +70 -0
- metadata +163 -0
data/.gemtest
ADDED
File without changes
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!.gitignore
|
2
|
+
*.gem
|
3
|
+
*.rbc
|
4
|
+
*.sw[a-p]
|
5
|
+
*.tmproj
|
6
|
+
*.tmproject
|
7
|
+
*.un~
|
8
|
+
*~
|
9
|
+
.DS_Store
|
10
|
+
.Spotlight-V100
|
11
|
+
.Trashes
|
12
|
+
._*
|
13
|
+
.bundle
|
14
|
+
.config
|
15
|
+
.directory
|
16
|
+
.elc
|
17
|
+
.redcar
|
18
|
+
.yardoc
|
19
|
+
/.emacs.desktop
|
20
|
+
/.emacs.desktop.lock
|
21
|
+
Desktop.ini
|
22
|
+
Gemfile.lock
|
23
|
+
Icon?
|
24
|
+
InstalledFiles
|
25
|
+
Session.vim
|
26
|
+
Thumbs.db
|
27
|
+
\#*\#
|
28
|
+
_yardoc
|
29
|
+
auto-save-list
|
30
|
+
coverage
|
31
|
+
doc/
|
32
|
+
lib/bundler/man
|
33
|
+
pkg
|
34
|
+
pkg/*
|
35
|
+
rdoc
|
36
|
+
spec/reports
|
37
|
+
test/tmp
|
38
|
+
test/version_tmp
|
39
|
+
tmp
|
40
|
+
tmtags
|
41
|
+
tramp
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source :rubygems
|
2
|
+
|
3
|
+
gem "pd"
|
4
|
+
gem "tagen"
|
5
|
+
gem "faraday", "~> 0.7"
|
6
|
+
gem "faraday_middleware", "~> 0.8"
|
7
|
+
gem "multi_json", "~> 1.0"
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem "rspec"
|
11
|
+
gem "watchr"
|
12
|
+
gem "webmock"
|
13
|
+
gem 'json'
|
14
|
+
gem 'maruku'
|
15
|
+
gem 'rake'
|
16
|
+
gem 'simplecov'
|
17
|
+
gem 'yard'
|
18
|
+
end
|
19
|
+
|
20
|
+
platforms :jruby do
|
21
|
+
gem 'jruby-openssl', '~> 0.7'
|
22
|
+
end
|
23
|
+
|
24
|
+
#gemspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Erik Michaels-Ober
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
mtgox, An Improved version of mtgox-gem with HTTP API v1
|
2
|
+
========================
|
3
|
+
|
4
|
+
| Homepage: | https://github.com/GutenYe/mtgox |
|
5
|
+
|----------------|------------------------------------------------------ |
|
6
|
+
| Author: | Guten |
|
7
|
+
| License: | MIT-LICENSE |
|
8
|
+
| Documentation: | http://rubydoc.info/gems/guten-mtgox/frames |
|
9
|
+
| Issue Tracker: | https://github.com/GutenYe/mtgox/issues |
|
10
|
+
|
11
|
+
An improved version of original [mtgox](https://github.com/sferik/mtgox).
|
12
|
+
|
13
|
+
API support: HTTP API v1
|
14
|
+
|
15
|
+
Getting started
|
16
|
+
---------------
|
17
|
+
|
18
|
+
require "mtgox"
|
19
|
+
|
20
|
+
puts MtGox.ticker
|
21
|
+
|
22
|
+
# Certain methods require authentication
|
23
|
+
MtGox.configure do |config|
|
24
|
+
config.key = YOUR_MTGOX_KEY
|
25
|
+
config.secret = YOUR_MTGOX_SECRET
|
26
|
+
end
|
27
|
+
|
28
|
+
me = MtGox.me
|
29
|
+
|
30
|
+
# Fetch your info
|
31
|
+
puts me.info
|
32
|
+
|
33
|
+
Install
|
34
|
+
-------
|
35
|
+
|
36
|
+
gem install guten-mtgox
|
37
|
+
|
38
|
+
Note on Patches/Pull Requests
|
39
|
+
-----------------------------
|
40
|
+
|
41
|
+
1. Fork the project.
|
42
|
+
2. Make your feature addition or bug fix.
|
43
|
+
3. Add tests for it. This is important so I don't break it in a future version unintentionally.
|
44
|
+
4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
45
|
+
5. Send me a pull request. Bonus points for topic branches.
|
46
|
+
6. Coding Style Guide: https://gist.github.com/1105334
|
47
|
+
|
48
|
+
Credits
|
49
|
+
-------
|
50
|
+
|
51
|
+
* [Contributors](https://github.com/GutenYe/mtgox/contributors)
|
52
|
+
|
53
|
+
Resources
|
54
|
+
---------
|
55
|
+
|
56
|
+
* [MtGox/API/HTTP/v1](https://en.bitcoin.it/wiki/MtGox/API/HTTP/v1) MtGox HTTP API Specification
|
57
|
+
|
58
|
+
Copyright
|
59
|
+
---------
|
60
|
+
|
61
|
+
(the MIT License)
|
62
|
+
|
63
|
+
Copyright (c) 2011 Guten
|
64
|
+
|
65
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
66
|
+
|
67
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler'
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
8
|
+
|
9
|
+
task :default => :spec
|
10
|
+
task :test => :spec
|
11
|
+
|
12
|
+
require 'yard'
|
13
|
+
namespace :doc do
|
14
|
+
YARD::Rake::YardocTask.new do |task|
|
15
|
+
task.files = ['LICENSE.md', 'lib/**/*.rb']
|
16
|
+
task.options = [
|
17
|
+
'--tag', 'authenticated:Requires Authentication',
|
18
|
+
'--markup', 'markdown',
|
19
|
+
]
|
20
|
+
end
|
21
|
+
end
|
data/lib/mtgox.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
3
|
+
|
4
|
+
require "tagen/core"
|
5
|
+
|
6
|
+
module MtGox
|
7
|
+
autoload :VERSION, "mtgox/version"
|
8
|
+
autoload :Client, "mtgox/client"
|
9
|
+
autoload :Me, "mtgox/me"
|
10
|
+
autoload :Configuration, "mtgox/configuration"
|
11
|
+
autoload :Connection, "mtgox/connection"
|
12
|
+
autoload :Request, "mtgox/request"
|
13
|
+
autoload :Base, "mtgox/base"
|
14
|
+
autoload :Ticker, "mtgox/ticker"
|
15
|
+
autoload :Trade, "mtgox/trade"
|
16
|
+
autoload :Depth, "mtgox/depth"
|
17
|
+
autoload :AskBase, "mtgox/ask"
|
18
|
+
autoload :Ask, "mtgox/ask"
|
19
|
+
autoload :Bid, "mtgox/ask"
|
20
|
+
autoload :Order, "mtgox/order"
|
21
|
+
|
22
|
+
Error = Class.new StandardError
|
23
|
+
MysqlError = Class.new Error
|
24
|
+
|
25
|
+
extend Configuration
|
26
|
+
|
27
|
+
class << self
|
28
|
+
# Alias for MtGox::Client.new
|
29
|
+
#
|
30
|
+
# @return [MtGox::Client]
|
31
|
+
def new
|
32
|
+
Client.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def me
|
36
|
+
@@me ||= Me.new
|
37
|
+
end
|
38
|
+
|
39
|
+
# Delegate to MtGox::Client
|
40
|
+
def method_missing(method, *args, &block)
|
41
|
+
return super unless new.respond_to?(method)
|
42
|
+
new.send(method, *args, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
def respond_to?(method, include_private=false)
|
46
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/mtgox/ask.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module MtGox
|
2
|
+
class AskBase < Base
|
3
|
+
attr_accessor :price, :amount, :price_int, :amount_int, :stamp
|
4
|
+
|
5
|
+
def price_int=(raw)
|
6
|
+
@price_int = raw.to_i
|
7
|
+
end
|
8
|
+
|
9
|
+
def amount_int=(raw)
|
10
|
+
@amount_int = raw.to_i
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Ask < AskBase
|
15
|
+
end
|
16
|
+
|
17
|
+
class Bid < AskBase
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/lib/mtgox/base.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module MtGox
|
2
|
+
class Base
|
3
|
+
attr_reader :attrs
|
4
|
+
|
5
|
+
def initialize(attrs={})
|
6
|
+
@attrs = attrs
|
7
|
+
|
8
|
+
attrs.each {|k, v|
|
9
|
+
send "#{k}=", v rescue NoMethodError
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
# skip @attrs
|
14
|
+
def inspect
|
15
|
+
ret = "#<#{self.class}:0x#{object_id}"
|
16
|
+
|
17
|
+
vars = instance_variables.each.with_object([]) do |n, memo|
|
18
|
+
next if n == :@attrs
|
19
|
+
memo << "#{n}=#{instance_variable_get(n).inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
ret << " #{vars.join(", ")}" unless vars.empty?
|
23
|
+
ret << ">"
|
24
|
+
|
25
|
+
ret
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/mtgox/client.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module MtGox
|
2
|
+
class Client
|
3
|
+
include MtGox::Connection
|
4
|
+
include MtGox::Request
|
5
|
+
|
6
|
+
# Fetch the latest ticker data
|
7
|
+
#
|
8
|
+
# @authenticated false
|
9
|
+
# @return [MtGox::Ticker]
|
10
|
+
# @example
|
11
|
+
# MtGox.ticker
|
12
|
+
def ticker(currency=:usd)
|
13
|
+
currency = currency_name(currency)
|
14
|
+
data = get("/api/1/#{currency}/public/ticker?raw")
|
15
|
+
Ticker.new(data)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Fetch depth
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
#
|
22
|
+
# MtGox.depth
|
23
|
+
# MtGox.depth(:full => true)
|
24
|
+
# MtGox.depth(:usd, :full => true)
|
25
|
+
#
|
26
|
+
# @authenticated false
|
27
|
+
# @overload depth([currency=:usd,] o={})
|
28
|
+
# @param [Hash] o options
|
29
|
+
# @option o [Boolean] :full full depth
|
30
|
+
# @return [Depth] with keys :asks and :asks, which contain arrays as described in {MtGox::Client#asks} and {MtGox::Clients#bids}
|
31
|
+
def depth(*args)
|
32
|
+
(currency,), o = args.extract_options
|
33
|
+
currency ||= :usd
|
34
|
+
currency = currency_name(currency)
|
35
|
+
depth = o[:full] ? "fulldepth" : "depth"
|
36
|
+
data = get("/api/1/#{currency}/public/#{depth}?raw")
|
37
|
+
Depth.new data
|
38
|
+
end
|
39
|
+
|
40
|
+
# Fetch recent trades
|
41
|
+
#
|
42
|
+
# @example
|
43
|
+
# MtGox.trades
|
44
|
+
# MtGox.trades :since => 0
|
45
|
+
# MtGox.trades :usd, :since => 0
|
46
|
+
#
|
47
|
+
# @authenticated false
|
48
|
+
# @return [Array<MtGox::Trade>] an array of trades, sorted in chronological order
|
49
|
+
def trades(*args)
|
50
|
+
(currency,), query = args.extract_options
|
51
|
+
currency ||= :usd
|
52
|
+
currency = currency_name(currency)
|
53
|
+
get("/api/1/#{currency}/public/trades?raw", query).map { |data|
|
54
|
+
Trade.new(data)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
protected
|
59
|
+
# :usd => "BTCUSD
|
60
|
+
def currency_name(symbol)
|
61
|
+
"BTC#{symbol.upcase}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module MtGox
|
2
|
+
module Configuration
|
3
|
+
# An array of valid keys in the options hash when configuring a {MtGox::Client}
|
4
|
+
VALID_OPTIONS_KEYS = [
|
5
|
+
:commission,
|
6
|
+
:key,
|
7
|
+
:secret,
|
8
|
+
]
|
9
|
+
|
10
|
+
DEFAULT_COMMISSION = 0.0065.freeze
|
11
|
+
|
12
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
13
|
+
|
14
|
+
# When this module is extended, set all configuration options to their default values
|
15
|
+
def self.extended(base)
|
16
|
+
base.reset
|
17
|
+
end
|
18
|
+
|
19
|
+
# Convenience method to allow configuration options to be set in a block
|
20
|
+
def configure
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
|
24
|
+
# Create a hash of options and their values
|
25
|
+
def options
|
26
|
+
options = {}
|
27
|
+
VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
|
28
|
+
options
|
29
|
+
end
|
30
|
+
|
31
|
+
# Reset all configuration options to defaults
|
32
|
+
def reset
|
33
|
+
self.commission = DEFAULT_COMMISSION
|
34
|
+
self.key = nil
|
35
|
+
self.secret = nil
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'mtgox/response/raise_mtgox_error'
|
3
|
+
require 'faraday_middleware'
|
4
|
+
require 'faraday_middleware/response/parse_json'
|
5
|
+
|
6
|
+
module MtGox
|
7
|
+
module Connection
|
8
|
+
private
|
9
|
+
|
10
|
+
def connection
|
11
|
+
options = {
|
12
|
+
:headers => {
|
13
|
+
:accept => 'application/json',
|
14
|
+
:user_agent => "mtgox gem #{MtGox::VERSION}",
|
15
|
+
},
|
16
|
+
:ssl => {:verify => false},
|
17
|
+
:url => 'https://mtgox.com',
|
18
|
+
}
|
19
|
+
|
20
|
+
Faraday.new(options) do |c|
|
21
|
+
#c.use Faraday::Response::Logger
|
22
|
+
c.use Faraday::Request::UrlEncoded
|
23
|
+
c.use Faraday::Response::RaiseError
|
24
|
+
c.use FaradayMiddleware::ParseJson
|
25
|
+
c.use MtGox::Response::RaiseMtGoxError
|
26
|
+
c.adapter(Faraday.default_adapter)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|