sferik / mtgox Goto Github PK
View Code? Open in Web Editor NEWRuby wrapper for the Mt. Gox Trade API
Home Page: https://en.bitcoin.it/wiki/MtGox/API
License: MIT License
Ruby wrapper for the Mt. Gox Trade API
Home Page: https://en.bitcoin.it/wiki/MtGox/API
License: MIT License
What are your thoughts on adding an API to allow one to set cookies on the connection?
Here's the use case - we had three people running a bit of code that's a big heavy on the mt. gox api. Mt. Gox uses "I'm Under Attack Mode" with CloudFlare. An undocumented feature of that mode (or at least I couldn't find it, but #mtgox channel mentioned it) was that if CF thinks you're DDoSing they'll flip a bit on your IP and require you to perform a javascript-based unit of work, set a cookie in your browser, and then let you in.
As it stands, from one IP we have to send a given cookie across or our API calls fail. I've got a monkeypatch in place in my project right now to support adding cookies into the header (in both get and post requests), but it seems like it could come up for other users of your API client as well.
MtGox's API method 'getTrades' supports parameter 'since' and so should this library. Following code works fine for me (file lib/mtgox/client.rb
):
def trades since = nil
get('/code/data/getTrades.php', since ? { :since => since } : {}).sort_by{|trade| trade['date']}.map do |trade|
Trade.new(trade)
end
end
I added btc alias to my .bashrc
but when I run btc I get this error:
-e:1:in <main>': undefined method
last' for #MtGox::Ticker:0x8f8057c (NoMethodError)
using latest gem
Hello,
MtGox has support for several currencies other than USD. Would be great if we could extend the mtgox gem to support others as well (in my case, EUR).
I will take a look at the code and see if I could make the changes, in which case I'll add a comment to this Issue.
got this warning, many functions are are useable anymore.
THIS API IS DEPRECATED. Please upgrade to newer API such as https://data.mtgox.com/api/2/BTCUSD/money/ticker
Does this support mtgox v1 or v2 api ?
In connection.rb
Could you please document if all API keys and transactions are taking place over SSL/TLS connection or if they are in plaintext.
Thanks.
mtgox/spec/mtgox/client_spec.rb
Line 332 in 5aa0515
If you change the body: body
bit to foo: body
, this test still passes for me. This means that the test LOOKS like we're verifying what was posted, but it's not actually verifying it. Can you confirm whether the same happens for you?
I noticed it when trying to add tonce support just now and a test passed that shouldn't have passed yet.
Hi there,
Sorry for being such a noob. But I keep getting a 403.
btc in bash shell works, but somehow the ticker in ruby doesn't. I've tried with the fork from issue #26, but that had the same result.
Could someone tell me if there's something extra to the example on the homepage?
Simply this, right?
require 'rubygems'
require 'mtgox'
# Fetch the latest price for 1 BTC in USD
puts MtGox.ticker.sell
Gives 403.. Any advice would be much appreciated!
@sferik, wanted to get your feedback on this.
https://github.com/sferik/mtgox/blob/master/lib/mtgox/client.rb#L270
That bubbles up a Faraday error. My plan was to define a custom CancelOrderFailedError rather than bubbling up the Faraday error. That way dependencies up the chain don't have to know implementation details.
Thoughts? Didn't want to do it if you don't want it :)
There is probably a simple explanation behind this, but I can't call history method.
[5] pry(main)> mtgox.history
NoMethodError: undefined method `history' for #<MtGox::Client:0x00000002749238>
As you can see, I have the latest commit.
I checked the source for the method, and it is there.
bundle show mtgox
${USER}/.rvm/gems/ruby-1.9.3-p448/bundler/gems/mtgox-ddde4cd932bc
Funnily enough though, history isn't one of the client methods...
mtgox = MtGox.new
mtgox.methods.select {|m| m.to_s == 'history'}
[]
When trying to obtain current ticker data from MtGox, the client always returns the same decimal number.
In the terminal:
0.576E3
In irb:
puts MtGox.ticker.sell
=> #<BigDecimal:239ed40,'0.574995E3',18(36)>
Same problem arises when using any of the the other methods, e.g. MtGox.ticker.asks
ruby --version
returns ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
So at present, MtGox
is essentially a singleton. I have a need to support multiple different logged in gox users in a single process. I plan to modify this gem to support it, but I wanted to open up a discussion to see if that would be the sort of thing you would care to have submitted. Otherwise I'll just fork, but I hate to diverge.
It seems that the gem could maintain its current API if MtGox.new
just memoized a new instance of MtGox::Client
, and everything else on MtGox proxied through to a new instance.
Does this sound like the sort of PR you'd be interested in?
So far, I see the following moderately substantial changes that would result from this:
MtGox::Configuration
in MtGox::Client
...aaaaand I think that's it. MtGox.key
and MtGox.secret
aren't used anywhere else.
EOFError: end of file reached
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/openssl/buffering.rb:145:in sysread_nonblock' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/openssl/buffering.rb:145:in
read_nonblock'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/protocol.rb:135:in rbuf_fill' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/protocol.rb:86:in
read'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:2448:in ensure in read_chunked' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:2448:in
read_chunked'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:2419:in read_body_0' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:2379:in
read_body'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:905:in block in get' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1194:in
block in transport_request'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:2342:in reading_body' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1193:in
transport_request'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1177:in request' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1170:in
block in request'
from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:627:in start' from ~/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/net/http.rb:1168:in
request'
... 1 levels...
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/adapter/net_http.rb:49:in call' from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/response.rb:8:in
call'
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/response.rb:8:in call' from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/response.rb:8:in
call'
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/request/url_encoded.rb:14:in call' from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/request.rb:88:in
run'
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/request.rb:28:in run' from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/connection.rb:170:in
run_request'
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/faraday-0.6.1/lib/faraday/connection.rb:64:in get' from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/mtgox-0.0.1/lib/mtgox/request.rb:10:in
request'
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/mtgox-0.0.1/lib/mtgox/request.rb:4:in get' from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/mtgox-0.0.1/lib/mtgox/client.rb:42:in
trades'
from ~/.rvm/gems/ruby-1.9.2-p180@global/gems/mtgox-0.0.1/lib/mtgox.rb:14:in method_missing' from bc.rb:157:in
trade_graphs'
from (irb):571
from ~/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `
Can you add a "status" attribute to the Order class to expose the status of the order? According to the documentation I've seen, these are the possible status values: pending, executing, post-pending, open, stop, and invalid.
nitrous commented that "even though version 1 of the API is available and well-documented, it seems that it will soon be redundant, just as version 0 is, with the advent of version 2." (https://bitbucket.org/nitrous/mtgox-api/overview)
I'm not entirely sure what benefits v2 provides apart from better name spacing. However, if v1 is to become deprecated, it would make sense to migrate to v2 soon.
Hi. On Ubuntu with Ruby 1.9.3 just running the simple example
ruby -r rubygems -r mtgox -e "puts MtGox.ticker.sell"
I get this:
/opt/ruby19/lib/ruby/1.9.1/net/http.rb:799:in `connect': SSL_connect
returned=1 errno=0 state=SSLv3 read server certificate B:
certificate verify failed (Faraday::Error::ConnectionFailed)
Any idea how to fix this, or any further information I could provide to help troubleshoot it?
Hey guys,
Title is self explanatory. My guess is that it has something to do with: 503d88e
Anyway, the problem is that I get some weird output after MtGox.balance. It does give me the balance, but like this:
> MtGox.balance
=> [#<MtGox::Balance:0x000000021b2e50
@amount=#<BigDecimal:21b2ba8,'0.1356836241 2E3',18(27)>,
@currency="BTC">,
#<MtGox::Balance:0x000000021b23d8
@amount=#<BigDecimal:21b2270,'0.44609E0',9(18)>,
@currency="USD">]
and MtGox.balance[0].to_f doesn't work... should it?
order_result is mentioned in client.rb, but such method isn't present anywhere in the codebase. Is something amiss?
$ git grep order_result
lib/mtgox/client.rb: # @return [String] order ID for the buy, can be inspected using order_result
lib/mtgox/client.rb: # @return [String] order ID for the sell, can be inspected using order_result
lib/mtgox/client.rb: # @return [String] order ID for the order, can be inspected using order_result
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.