-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MtGox API not working #3
Comments
I lost interest in the project a good while back, and never committed this change. Want to clean this up and submit a PR on this coinbase version for me? require 'money'
#require 'mtgox'
require 'coinbase'
require 'money/bank/google_currency'
class MtgoxBank < Money::Bank::VariableExchange
CACHE_EXPIRATION = 15.minutes
SUPPORTED_CURRENCIES = %w(USD EUR GBP AUD CAD CHF CNY DKK HKD JPY NZD PLN RUB SEK SGD THB)
# We define this here so that we can run tests on the Exchange rates without
# having to worry about whatever the actual exchange rate might be
cattr_accessor :ticker_rates
# Seemingly, floats are what the VariableExchange wants to have returned
# these are then cast to strings and fed to BigDecimal before being applied
# to exchange translations. (Returning strings or BigDecimals will work too)
def get_rate(from, to)
@mutex.synchronize do
case rate_key_for(from, to)
when /\A(#{SUPPORTED_CURRENCIES.join('|')})_TO_BTC\Z/
( BigDecimal(1) / BigDecimal(ticker($1).to_s) ).to_s
when /\ABTC_TO_(#{SUPPORTED_CURRENCIES.join('|')})\Z/
ticker $1
else
# This means we're converting between the exchange currencies, using
# btc as the intermediary
(ticker(to) / ticker(from)).to_s
end
end
end
# If we're converting to BTC, we want to round our irrational numbers to
# something more reasonable. The definition of 'reasonable' is tied to the
# number of digits in the exchange rate.
def exchange_with(from, to_currency)
ret = super from, to_currency
if to_currency.symbol == 'BTC'
# We need to round based on the strength of the source currency
# But many times our source currency is simply btc. So, let's use USD then:
using_currency = (from.currency.iso_code == 'BTC') ? 'USD' : from.currency.iso_code
# This determines the number of decimal digits in the ticker
ticker_digits = Math.log10(ticker(using_currency)).floor
# When we're totally in the decimal digits, we don't need to round
ticker_digits = -3 if ticker_digits < -3
by_mod = 10 ** (5 - ticker_digits)
return Money.new(ret.cents - (ret.cents % by_mod), 'BTC')
end
ret
end
private
def ticker(for_cur)
for_cur = for_cur.to_s.downcase
(self.class.ticker_rates.try(:[],for_cur)) ?
self.class.ticker_rates[for_cur].to_f :
Rails.cache.fetch('mtgox/ticker/%s' % for_cur, :expires_in => CACHE_EXPIRATION){
Rails.logger.info "MtgoxBank is querying for %s" % for_cur
begin
# TODO: clean this up!
coinbase = Coinbase::Client.new('user', 'pass')
usd_rate = coinbase.buy_price(1).to_f
if for_cur == 'USD'
usd_rate
else
goog_rate = Money::Bank::GoogleCurrency.new.get_rate('USD', for_cur).to_f
goog_rate * usd_rate
end
rescue Errno::ETIMEDOUT, Errno::ECONNRESET, Faraday::Error::TimeoutError
# Note/TODO: MtGox is down
end
}
end
end |
Still trying to make this work. I keep getting the following error after having replaced the original code with the one you pasted:
Of course, I put coinbase API credentials in place. You sure you didn't miss anything apart of that file? and as a side note, why not just upload the whole system coinpost.com is using right now so that I could get a fresh one? I would be willing to eventually review the code to polish and PR it if needed. |
Could you help me getting this initially setup, never done a ruby site/project before. |
@gh0stshell I'll gladly help you with this once I've sorted the issues out with @brighton36 in order to make CoinPost work |
Sounds great! I just dont know how to install a Ruby site, have Ruby installed, just never worked with it, wish I had it installed or I maybe be able to help fix the MtGox code. |
So, I believe line 67 is the line where the Coinbase object is instantiated. Probably you have a newer version of the Coinbase lib than I'm using. Here's what I have: What version are you running? (and is line 67 the line where you intialize Coinbase? Can I see that line, with the credentials replaced by X's) |
Ok - I just posted a bunch of changes from the live production site. Take a look now and see what you think? |
OK, thank you very much, I'll keep you updated |
Way better now. Got it up and running quite easily. Got 3 things to ask you. This comes up during
Should be easy fix. I had to..
..to avoid the app to initialize up mtgox. Are you doing the same on production to avoid it? And last - I'm quite new to Rails itself or maybe I'm just stupid - where'd you go to manage the site? As a side note, since the README is kind of lackluster on the setting up part, I'm taking note of every step I'm doing to set CoinPost so that I can create a wiki page for those in need of. Are you ok with me doing so? |
RE: Bundle install issues RE: config/initializers/mtgox_connection.rb RE: Admin RE: README |
If you feel like trusting me in adding me as mantainer, just know I'm not much of a Ruby developer but I'd be glad to help with adding some documentation and helping out users. :) If in need of, my Skype account name is the same as GitHub's. |
@markkuit - is it ready for you to walk me through the install? I am proficient with linux, BSD and web sites just never installed or setup a ruby site before. If there is info on Google I wont bother you with these noob questions. |
There you go @markkuit - Added. Let's see what you come up with? I'd very much appreciate your help with this project. |
Mt.Gox is dead... long live coinbase! |
MtGox API doesn't seem to be working. (http://data.mtgox.com/api/1/BTCUSD/ticker - error 403).
Is there any fix for it / alternative API? What happened to it?
The text was updated successfully, but these errors were encountered: