Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support for new mtgox authentication #10

Merged
merged 9 commits into from

2 participants

@yrral86

I've updated the gem to use key and secret instead of username and password. As far as I know, the old method no longer works.

@sferik sferik referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@sferik sferik merged commit 4856489 into sferik:master
@sferik
Owner

Thanks for the patch.

@sferik
Owner

I had to revert this change because it caused tests to fail. Please make tests pass and resubmit this pull request.

@yrral86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 README.md
@@ -23,8 +23,8 @@ author, which you can do using the following script:
# Certain methods require authentication
MtGox.configure do |config|
- config.username = YOUR_MTGOX_USERNAME
- config.password = YOUR_MTGOX_PASSWORD
+ config.key = YOUR_MTGOX_KEY
+ config.secret = YOUR_MTGOX_SECRET
end
MtGox.withdraw 1.0, "1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L"
@@ -50,8 +50,8 @@ author, which you can do using the following script:
# Certain methods require authentication
MtGox.configure do |config|
- config.username = YOUR_MTGOX_USERNAME
- config.password = YOUR_MTGOX_PASSWORD
+ config.key = YOUR_MTGOX_KEY
+ config.secret = YOUR_MTGOX_SECRET
end
# Fetch your current balance
@@ -88,6 +88,8 @@ Here are some ways *you* can contribute:
* by reviewing patches
* by financially (please send bitcoin donations to
1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L)
+* donations can go to 171dH9Uum6wWLSwH2g8g2yto6SG7NEGyXG if you appreciate the
+ new authentication support
## <a name="issues">Submitting an Issue</a>
We use the [GitHub issue tracker](https://github.com/sferik/mtgox/issues) to
View
16 lib/mtgox/client.rb
@@ -121,7 +121,7 @@ def trades
# @example
# MtGox.balance
def balance
- parse_balance(post('/api/0/getFunds.php', pass_params))
+ parse_balance(post('/api/0/getFunds.php', {}))
end
# Fetch your open orders, both buys and sells, for network efficiency
@@ -164,7 +164,7 @@ def sells
# # Buy one bitcoin for $0.011
# MtGox.buy! 1.0, 0.011
def buy!(amount, price)
- parse_orders(post('/api/0/buyBTC.php', pass_params.merge({:amount => amount, :price => price}))['orders'])
+ parse_orders(post('/api/0/buyBTC.php', {:amount => amount, :price => price})['orders'])
end
# Place a limit order to sell BTC
@@ -177,7 +177,7 @@ def buy!(amount, price)
# # Sell one bitcoin for $100
# MtGox.sell! 1.0, 100.0
def sell!(amount, price)
- parse_orders(post('/api/0/sellBTC.php', pass_params.merge({:amount => amount, :price => price}))['orders'])
+ parse_orders(post('/api/0/sellBTC.php', {:amount => amount, :price => price})['orders'])
end
# Cancel an open order
@@ -200,13 +200,13 @@ def sell!(amount, price)
def cancel(args)
if args.is_a?(Hash)
order = args.delete_if{|k, v| !['oid', 'type'].include?(k.to_s)}
- parse_orders(post('/api/0/cancelOrder.php', pass_params.merge(order))['orders'])
+ parse_orders(post('/api/0/cancelOrder.php', order)['orders'])
else
orders = post('/api/0/getOrders.php', pass_params)['orders']
order = orders.find{|order| order['oid'] == args.to_s}
if order
order = order.delete_if{|k, v| !['oid', 'type'].include?(k.to_s)}
- parse_orders(post('/api/0/cancelOrder.php', pass_params.merge(order))['orders'])
+ parse_orders(post('/api/0/cancelOrder.php', order)['orders'])
else
raise Faraday::Error::ResourceNotFound, {:status => 404, :headers => {}, :body => 'Order not found.'}
end
@@ -223,7 +223,7 @@ def cancel(args)
# # Withdraw 1 BTC from your account
# MtGox.withdraw! 1.0, '1KxSo9bGBfPVFEtWNLpnUK1bfLNNT4q31L'
def withdraw!(amount, btca)
- parse_balance(post('/api/0/withdraw.php', pass_params.merge({:group1 => 'BTC', :amount => amount, :btca => btca})))
+ parse_balance(post('/api/0/withdraw.php', {:group1 => 'BTC', :amount => amount, :btca => btca}))
end
private
@@ -248,9 +248,5 @@ def parse_orders(orders)
end
{:buys => buys, :sells => sells}
end
-
- def pass_params
- {:name => MtGox.username, :pass => MtGox.password}
- end
end
end
View
8 lib/mtgox/configuration.rb
@@ -5,8 +5,8 @@ module Configuration
# An array of valid keys in the options hash when configuring a {MtGox::Client}
VALID_OPTIONS_KEYS = [
:commission,
- :password,
- :username,
+ :key,
+ :secret,
]
DEFAULT_COMMISSION = 0.0065.freeze
@@ -33,8 +33,8 @@ def options
# Reset all configuration options to defaults
def reset
self.commission = DEFAULT_COMMISSION
- self.password = nil
- self.username = nil
+ self.key = nil
+ self.secret = nil
self
end
end
View
11 lib/mtgox/request.rb
@@ -16,11 +16,20 @@ def request(method, path, options)
when :get
request.url(path, options)
when :post
+ options.merge!({:nonce => (Time.now.to_f*1000000).to_i})
request.path = path
- request.body = options unless options.empty?
+ request.body = options.to_param unless options.empty?
+ request.headers = headers(request.body)
end
end
response.body
end
+
+ def headers(request)
+ signature = Base64.strict_encode64(OpenSSL::HMAC.digest 'sha512',
+ Base64.decode64(MtGox.secret),
+ request)
+ {'Rest-Key' => MtGox.key, 'Rest-Sign' => signature}
+ end
end
end
Something went wrong with that request. Please try again.