Code Monkey home page Code Monkey logo

coinbase-ruby's Introduction

Coinbase Wallet Gem

Gem Version Build Status

This is the official client library for the Coinbase Wallet API v2. We provide an intuitive, stable interface to integrate Coinbase Wallet into your Ruby project.

Important: As this library is targeted for newer API v2, it requires v2 permissions (i.e. wallet:accounts:read). If you're still using v1, please use older version of this library.

Installation

Add this line to your application's Gemfile:

gem 'coinbase'

Then execute:

bundle install

Or install it yourself as:

gem install coinbase

Authentication

API Key (HMAC Client)

We provide a synchronous client based on Net::HTTP as well as a asynchronous client based on the EM-HTTP-Request gem. For most users, the synchronous client will suffice.

require 'coinbase/wallet'
client = Coinbase::Wallet::Client.new(api_key: <api key>, api_secret: <api secret>)

The primary intention of the asynchronous client is to integrate nicely with the Coinbase Exchange Gem. If your project interfaces with our Exchange as well, please consider using this. To use this interface, you must include em-http-request gem on your own.

require 'coinbase/wallet'
require 'em-http'

client = Coinbase::Wallet::AsyncClient.new(api_key: <api_key>, api_secret: <api secret>)

OAuth2 Client

We provide an OAuth client if you need access to user accounts other than your own. Currently, the gem does not handle the handshake process, and assumes you have an access token when it's initialized. The OAuth client is synchronous. Please reach out if you would like us to add an asynchronous OAuth client as well.

require 'coinbase/wallet'

# Initializing OAuthClient with both access and refresh token
client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>, refresh_token: <refresh_token>)

# Initializing OAuthClient with only access token
client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>)

The OAuth client provides a few extra methods to refresh and revoke the access token.

client.refresh!
client.revoke!

Protip:tm:: You can test OAuth2 authentication easily with Developer Access Tokens which can be created under your OAuth2 application settings. These are short lived tokens which authenticate but don't require full OAuth2 handshake to obtain.

Two factor authentication

Send money endpoint requires 2FA token in certain situations (read more here). Specific exception is thrown when this is required:

account = client.primary_account
begin
  account.send(to: '[email protected]', amount: '1', currency: "BTC")
rescue Coinbase::Client::TwoFactorRequiredError
  # Show 2FA dialog to user and collect 2FA token

  # Re-try call with `two_factor_token` param
  account.send(to: '[email protected]', amount: '1', currency: "BTC", two_factor_token: "123456")
end

Requests

We provide one method per API endpoint. Several methods require one or more identifiers to be passed as arguments. Additionally, all parameters can be appended as keyword arguements. If a required parameter is not supplied, the client will raise an error. For instance, the following call will send 100 bitcoin to the account registered with [email protected].

account = client.primary_account
account.send(to: '[email protected]', amount: 100, currency: "USD", description: 'Sending 100 bitcoin')

Pagination

Several endpoints are paginated. By default, the gem will only fetch the first page of data for a given request. You can implement your own pagination scheme, such as pipelining, by setting the starting_after parameter in your response.

client.transactions(account_id) do |data, resp|
  transactions = data
end

more_pages = true
while more_pages
  client.transactions(account_id, starting_after: transactions.last['id']) do |data, resp|
    more_pages = resp.has_more?
    transactions << data
    transactions.flatten!
  end
end

If you want to automatically download the entire dataset, you may pass fetch_all=true as a parameter.

client.transactions(account_id, fetch_all: true) do |data, resp|
  ...
end

Responses

We provide several ways to access return data. Methods will return the data field of the response in hash format.

txs = account.transactions(account_id)
txs.each do |tx|
  p tx['id']
end

You can also handle data inside a block you pass to the method. You must access data this way if you're using the asynchronous client.

account.transactions(account_id) do |txs|
  txs.each { |tx| p tx['id'] }
end

If you need to access the response metadata (headers, pagination info, etc.) you can access the entire response as the second block paramenter.

account.transactions(account_id) do |txs, resp|
  p "STATUS: #{resp.status}"
  p "HEADERS: #{resp.headers}"
  p "BODY: #{resp.body}"
end

Response Object

The default representation of response data is a JSON hash. However, we further abstract the response to allow access to response fields as though they were methods.

account = client.primary_account
p "Account:\t account.name"
p "ID:\t account.id"
p "Balance:\t #{account.balance.amount} #{account.balance.currency}"

All values are returned directly from the API unmodified, except the following exceptions:

  • Money amounts are always converted into BigDecimal objects. You should always use BigDecimal when handing bitcoin amounts for accurate precision.
  • Timestamps are always converted into Time objects.

Most methods require an associated account. Thus, responses for the account endpoints contain methods for accessing all the relevant endpoints. This is convenient, as it doesn't require you to supply the same account id over and over again.

account = client.primary_account
account.send(to: "[email protected]", amount: 100, description: "Sending 100 bitcoin")

Alternatively you can pass the account ID straight to the client:

client.transactions(<account_id>)

Account response objects will automatically update if they detect any changes to the account. The easiest way to refresh an account is to call the refresh! method.

account.refresh!

Warnings

It's prudent to be conscious of warnings. By default, the gem will print all warning to STDERR. If you wish to redirect this stream to somewhere else, such as a log file, then you can simply change the $stderr global variable.

Errors

If the request is not successful, the gem will raise an error. We try to raise a unique error for every possible API response. All errors are subclasses of Coinbase::Wallet::APIError.

Error Status
APIError *
BadRequestError 400
ParamRequiredError 400
InvalidRequestError 400
PersonalDetailsRequiredError 400
AuthenticationError 401
UnverifiedEmailError 401
InvalidTokenError 401
RevokedTokenError 401
ExpiredTokenError 401
TwoFactorRequiredError 402
InvalidScopeError 403
NotFoundError 404
ValidationError 422
RateLimitError 429
InternalServerError 500
ServiceUnavailableError 503

Usage

This is not intended to provide complete documentation of the API. For more detail, please refer to the official documentation.

List supported native currencies

client.currencies

List exchange rates

client.exchange_rates

Buy price

client.buy_price
# or
client.buy_price(currency_pair: 'BTC-USD')

Sell price

client.sell_price
# or
client.sell_price(currency_pair: 'ETH-BTC')

Spot price

client.spot_price
# or
client.spot_price(currency_pair: 'BTC-EUR')

Current server time

client.time

Get authorization info

client.auth_info

Lookup user info

client.user(user_id)

Get current user

client.current_user

Update current user

client.update_current_user(name: "New Name")

List all accounts

client.accounts

List account details

client.account(account_id)

List primary account details

client.primary_account

Set account as primary

account.make_primary!

Create a new bitcoin account

client.create_account(name: "New Account")

Update an account

account.update!(name: "New Account Name")

Delete an account

account.delete!

List receive addresses for account

account.addresses

Get receive address info

account.address(address_id)

List transactiona for address

account.address_transactions(address_id)

Create a new receive address

account.create_address

List transactions

account.transactions

Get transaction info

account.transaction(transaction_id)

Send funds

account.send(to: <bitcoin address>, amount: "5.0", currency: "USD", description: "Your first bitcoin!")

Transfer funds to a new account

account.transfer(to: <account ID>, amount: "1", currency: "BTC", description: "Your first bitcoin!")

Request funds

account.request(to: <email>, amount: "8.0", currency: "USD", description: "Burrito")

Resend request

account.resend_request(request_id)

Cancel request

account.cancel_request(request_id)

Fulfill request

account.complete_request(request_id)

List buys

account.list_buys

Get buy info

account.list_buy(buy_id)

Buy bitcoins

account.buy(amount: "1", currency: "BTC")

Commit a buy

You only need to do this if you pass commit=true when you call the buy method.

buy = account.buy(amount: "1", currency: "BTC", commit: false)
account.commit_buy(buy.id)

List sells

account.list_sells

Get sell info

account.list_sell(sell_id)

Sell bitcoins

account.sell(amount: "1", currency: "BTC")

Commit a sell

You only need to do this if you pass commit=true when you call the sell method.

sell = account.sell(amount: "1", currency: "BTC", commit: false)
account.commit_sell(sell.id)

List deposits

account.list_deposits

Get deposit info

account.list_deposit(deposit_id)

Deposit funds

account.deposit(amount: "10", currency: "USD")

Commit a deposit

You only need to do this if you pass commit=true when you call the deposit method.

deposit = account.deposit(amount: "1", currency: "BTC", commit: false)
account.commit_deposit(deposit.id)

List withdrawals

account.list_withdrawals

Get withdrawal

account.list_withdrawal(withdrawal_id)

Withdraw funds

account.withdraw(amount: "10", currency: "USD")

Commit a withdrawal

You only need to do this if you pass commit=true when you call the withdrawal method.

withdraw = account.withdraw(amount: "1", currency: "BTC", commit: false)
account.commit_withdrawal(withdrawal.id)

List payment methods

client.payment_methods

Get payment method

client.payment_method(payment_method_id)

Get merchant

client.merchant(merchant_id)

Verify a merchant callback

client.verify_callback(request.raw_post, request.headers['CB-SIGNATURE']) # true/false

List orders

client.orders

Get order

client.order(order_id)

Create order

client.create_order(amount: "1", currency: "BTC", name: "Order #1234")

Refund order

order = client.orders.first
order.refund!

Checkouts

List checkouts

client.checkouts

Get checkout

client.checkout(checkout_id)

Get checkout's orders

checkout = client.checkout(checkout_id)
checkout.orders

Create order for checkout

checkout = client.checkout(checkout_id)
checkout.create_order

Contributing and testing

Any and all contributions are welcome! The process is simple: fork this repo, make your changes, add tests, run the test suite, and submit a pull request. Tests are run via rspec. To run the tests, clone the repository and then:

# Install the requirements
gem install coinbase

# Run tests
rspec spec

coinbase-ruby's People

Contributors

aianus avatar alyssais avatar barmstrong avatar dblock avatar elfassy avatar gabeisman avatar herenow avatar hfwang avatar iamjohnford avatar ilyakatz avatar jasonhazel avatar jjduhamel avatar jkrup avatar jobv avatar jorilallo avatar krobertson avatar kyledrake avatar lian avatar maksim-s avatar momer avatar naps62 avatar nishils avatar pissedcapslock avatar prudhvi avatar romainbutteaud avatar saizai avatar sds avatar swizec avatar tmlee avatar williamcoates avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coinbase-ruby's Issues

Coinbase::Wallet::APIError - [410]

It was working fine but in recent getting the following error.
Coinbase::Wallet::APIError - [410] {"errors"=>[{"id"=>"gone", "message"=>"Merchant Services have been deprecated"}]}

Question: How to make calls that require OAuth access token

I have an app that uses the OAuth API to get a user's receive address from coinbase, but I couldn't figure out how to pass the access token into the ruby api you have provided.

Is there a way to make API calls with this library that require an oauth access token? If not, should I submit my implementation of the Oauth API call as a pull request?

Thanks for your help!

Addresses method going not working

[19] pry(main)> client.addresses(client.current_user['id'])
Coinbase::Wallet::NotFoundError: Not found
from /usr/local/lib/ruby/gems/2.3/gems/coinbase-4.1.0/lib/coinbase/wallet/api_errors.rb:44:in `check_response_status'

L44 says it's a 404.

'Required parameter missing: currency' error

It's related issue with the former one.
When I try 'account.sell(amount: "1", currency: "BTC", quote: true)' to get the price instead of client.sell_price, it returns 'Required parameter missing: currency' error.

504 Gateway timeout from coinbase gem

We are occasionally seeing a 504 gateway timeout when we try to load the coinbase button on our site.

Output from NewRelic:

ActionView::Template::Error: 757: unexpected token at '<!DOCTYPE html><!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]--><!--[if IE 7]> <html class="no-js ie7 oldie" lang="en-US"> <![endif]--><!--[if IE 8]> <html class="no-js ie8 oldie" lang="en-US"> <![endif]--><!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]--><head><meta http-equiv="refresh" content="0"><meta http-equiv="set-cookie" content="cf_use_ob=https; expires=Sat, 07-Dec-13 14:30:31 GMT; path=/"><meta http-equiv="set-cookie" content="cf_ob_info=504:d91e9285245086e:IAD; expires=Sat, 07-Dec-13 14:30:31 GMT; path=/"><title>coinbase.com | 504: Gateway time-out</title><meta charset="UTF-8" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" /><meta name="robots" content="noindex, nofollow" /><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" /><link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" type="text/css" media="screen,projection" /><!--[if lt IE 9]><link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" type="text/css" media="screen,projection" /><![endif]--><style type="text/css">body{margin:0;padding:0}</style><!--[if lt IE 9]><script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><![endif]--><!--[if gte IE 9]><!--><script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"></script><!--<![endif]--><script type="text/javascript" src="/cdn-cgi/scripts/cf.common.js"></script></head><body><div id="cf-wrapper"> <div id="cf-error-details" class="cf-error-details-wrapper"> <div class="cf-wrapper cf-error-overview"> <h1> <span class="cf-error-type" data-translate="error">Error</span> <span class="cf-error-code">504</span> <small style="font-size:15px;white-space:nowrap">Ray ID: d91e9285245086e</small> </h1> <h2 class="cf-subheadline" data-translate="error_desc">Gateway time-out</h2> </div><!-- /.error-overview --> <div class="cf-section cf-highlight cf-status-display"> <div class="cf-wrapper"> <div class="cf-columns cols-3"> <div id="cf-browser-status" class="cf-column cf-status-item cf-browser-status "> <div class="cf-icon-error-container"> <i class="cf-icon cf-icon-browser"></i> <i class="cf-icon-status cf-icon-ok"></i> </div> <span class="cf-status-desc" data-translate="browser_desc">You</span> <h3 class="cf-status-name" data-translate="browser_label">Browser</h3> <span class="cf-status-label" data-translate="browser_status_label">Working</span></div><div id="cf-cloudflare-status" class="cf-column cf-status-item cf-cloudflare-status "> <div class="cf-icon-error-container"> <i class="cf-icon cf-icon-cloud"></i> <i class="cf-icon-status cf-icon-ok"></i> </div> <span class="cf-status-desc" data-translate="cloud_desc">Ashburn</span> <h3 class="cf-status-name" data-translate="cloud_label">CloudFlare</h3> <span class="cf-status-label" data-translate="cloud_status_label">Working</span></div><div id="cf-host-status" class="cf-column cf-status-item cf-host-status cf-error-source"> <div class="cf-icon-error-container"> <i class="cf-icon cf-icon-server"></i> <i class="cf-icon-status cf-icon-error"></i> </div> <span class="cf-status-desc" data-translate="server_desc">coinbase.com</span> <h3 class="cf-status-name" data-translate="server_label">Host</h3> <span class="cf-status-label" data-translate="server_status_label">Error</span></div> </div> </div> </div><!-- /.status-display --> <div class="cf-section cf-wrapper"> <div class="cf-columns two"> <div class="cf-column"> <h2 data-translate="what_happened">What happened?</h2> <p>The web server report

How to supply the API version.

Each time I execute a method, the following warning is now returned:

WARNING: Please supply API version (YYYY-MM-DD) as CB-VERSION header (https://developers.coinbase.com/api#versioning)

How do I supply the API version through the gem?

Send BTC w/ Fee

I'm getting an error when I try to send bitcoin and include a fee. I think the error might be from the Coinbase API...

$coinbase.send_money("XXX", '0.0001', {transaction: {user_fee: '0.0002'}})

Coinbase::Client::Error: This transaction requires a 0.0002 fee to be accepted by the bitcoin network. Do you want to add it? (This fee does not go to Coinbase.) from /Users/marcbeaupre/.rvm/gems/ruby-1.9.3-p392/gems/coinbase-1.3.0/lib/coinbase/client.rb:204:inhttp_verb'`

Rename 'send' to non-reserved method nam

This is more of a suggestion than an issue really, sorry if this is in the wrong place.

Is it possible to rename the send method for some of the clients (wallet, etc)?

I know it's possible to use __send__ instead but it's a bit of a hassle and not very Rails/Ruby like to override the "reserved words".

buy_price and sell_price only return BTH-USD

#!/usr/bin/env ruby
require 'coinbase/wallet'
c=Coinbase::Wallet::Client.new
puts c.buy_price(currency_pair: 'ETH-USD')
puts c.sell_price(currency_pair: 'ETH-USD')
{"amount"=>"1217.77", "currency"=>"USD"}
{"amount"=>"1193.58", "currency"=>"USD"}

It seems like the problem is coinbase/wallet/api_client.rb #buy_price and #sell_price do not use the params. I changed the methods to accept a currency_pair argument, and added that to the URL and now I get the results I expect.

Only works without ssl_ca_file?

Hey,

I'm trying to use coinbase from rails and whenever I use this gem I get an error along the lines of SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)

However, when I comment out the ssl_ca_file line in client.rb, everything starts working flawlessly.

Has the ca-coinbase.crt included in the gem gone out of sync with what the website is actually using these days, or is something more sinister going on?

Cheers,
~Swizec

client.sell_price returns wrong price

This is more of problem of api itself than of coinbase-ruby library, I guess.
When I get the selling price with 'client.sell_price', the price returned is the sell price on coinbase website plus 1% commission.
Since the sell price is amount user 'receives' after selling btc, commission should be subtracted instead of added, am I right?

NoMethodError Exception: undefined method `to_money'

I get this when I call coinbase.balance or coinbase.create_button. The error message contains the correct balance, so it seems my login credentials are correct.

Using Rails 4.2.0 and Ruby 2.2.0. I suspect something changed in the money gem recently.

Here's an example project where this fails: Bitcoin Passbook

HMAC Authentication

Hi,
To intergrate the coinbase methods currently am checking them on rails console. The hmac authentication "coinbase = Coinbase::Client.new(ENV['COINBASE_API_KEY'], ENV['COINBASE_API_SECRET']) when run shows TypeError: no implicit conversion of Symbol into Integer error". What has to be done to solve this ?

Amount Conversion doesn't work properly

2.3.1 :022 > client.accounts[1].balance['amount']
 => "4.73257967" # Correct Amount
2.3.1 :023 > client.accounts[1].balance.amount.to_s
 => "0.473257967E1" # Incorrect Amount
###
2.3.1 :026 > client.accounts[4].balance.amount.to_s
 => "0.36772081E0" # Correct Amount
2.3.1 :027 > client.accounts[4].balance['amount']
 => "0.36772081" # Correct Amount

Using version 4.1.0

Can the API support Subscriptions?

Or would one have to write perhaps a custom subclass or override to add some code to handle subscriptions–e.g., checking each month to resend a BTC/Coinbase payment email, etc.

Cannot refresh OAuth tokens

I'm having an issue with trying to refresh an OAuth access token with a refresh token.

access_token = "3a308bb52491..."
refresh_token = "40df8ab0de80..."

c = Coinbase::Wallet::OAuthClient.new(access_token: access_token, refresh_token: refresh_token)
#<Coinbase::Wallet::OAuthClient:0x0000000fb6a990 ...>

c.refresh!
*** Coinbase::Wallet::APIError Exception: The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.

Any ideas?

(Does the OAuthClient require the Client ID and Client Secret at all?)

Use of deprecated resources

According to the API documentation, the following resources are deprecated and shouldn't be used in the Gem.

  • GET /api/v1/account/balance in /lib/coinbase/client.rb
    def balance options={}
      h = get '/account/balance', options
      h['amount'].to_money(h['currency'])
    end
  • GET /api/v1/account/receive_address in /lib/coinbase/client.rb
    def receive_address options={}
      get '/account/receive_address', options
    end
  • POST /api/v1/account/generate_receive_address in /lib/coinbase/client.rb
    def generate_receive_address options={}
      post '/account/generate_receive_address', options
    end

send_money in BTC

What i would like to do is to send money in Bitcoin, like the following
coinbase.send_money '[email protected]', Money.new(1, 'BTC')

Not sure if its just me or its not working. I think that's because we are passing in the amount as a amount_string instead of amount.

Would like to get your thoughts on this. There must be a graceful way to handle this no?

Undefined method to_money

/home/user/.rvm/gems/ruby-1.9.3-p374/gems/coinbase-1.1.0/lib/coinbase/client.rb:25:in balance': undefined methodto_money' for nil:NilClass (NoMethodError)
from coinbase.rb:4:in `

'

Any ideas?

I can use money gem by itself:
user@ubuntu:$ cat test.rb
require 'money'
puts '100 USD'.to_money
user@ubuntu:
$ ruby test.rb
100.00

I did the following to install:
rvm install 1.9.3
rvm use --default 1.9.3
rvm 1.9.3 do gem install coinbase

require 'coinbase/wallet' in Gemfile

I was having a problem with sending money via Coinbase - even though I had installed the coinbase gem and had require 'coinbase/wallet' in the file where I was making the api call, I was getting a LoadError that 'coinbase/wallet' could not be loaded.

Once I required 'coinbase/wallet' in my Gemfile, the error went away and the payments worked.
gem 'coinbase', '~> 4.0.7', require: 'coinbase/wallet'

It would be helpful to add that to the documentation.

Can't send payments that require user transaction fee

<Hashie::Mash success=true transaction=#<Hashie::Mash amount=# created_at="2013-05-19T14:51:34-07:00" hsh=nil id="..." notes=nil recipient_address="1DUq51XA1X3KJpSsh4iB9kCxcswvMS53Fn" request=false sender=#<Hashie::Mash email=".." id=".." name="Doesnt work omg"> status="pending">>

1ScrybeSNcjqgpPeYNgvdxANArqoC6i5u is 0.0004062

Coinbase::Client::Error (This transaction requires a 0.0005 fee to be accepted by the bitcoin network. Do you want to add it? (This fee does not go to Coinbase.), You are sending too fast. Please wait for some transactions to confirm before sending more.):
app/controllers/payout_summaries_controller.rb:63:in block in confirmed' app/controllers/payout_summaries_controller.rb:57:ineach'
app/controllers/payout_summaries_controller.rb:57:in `confirmed'

`Coinbase::OAuthClient.new` renders a NameError

In the docs it references the module OAuthClient which I should hopefully be able to use in my app but running Coinbase::OAuthClient.new gives me NameError: uninitialized constant Coinbase::OAuthClient

I'd like to help with the OAuth documentation to make things clearer since there seems to be a lot of confusion around this on StackOverflow

Any idea why this module isn't working? Everything looks kosher when digging through the code.

Using Rails 4 and Ruby 2 if that makes a difference

transfers pages

How does one get the second page?

irb(main):022:0> coinbase.transfers(2)
TypeError: no implicit conversion of Symbol into Integer
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/bundler/gems/coinbase-ruby-dd9df6fa5a06/lib/coinbase/client.rb:240:in `[]'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/bundler/gems/coinbase-ruby-dd9df6fa5a06/lib/coinbase/client.rb:240:in `http_verb'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/bundler/gems/coinbase-ruby-dd9df6fa5a06/lib/coinbase/client.rb:194:in `get'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/bundler/gems/coinbase-ruby-dd9df6fa5a06/lib/coinbase/client.rb:183:in `transfers'
    from (irb):22
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/console.rb:90:in `start'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /home/melfassy/www/coinamp/shared/bundle/ruby/2.0.0/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>'
    from bin/rails:4:in `require'
    from bin/rails:4:in `<main>'

NameError: undefined local variable or method `r' for #<Coinbase::OAuthClient:0x007ffaf1397648>

I have about 100 errors from the last week and a half in my application, been investigating on my end as well. Figured it was worth submitting a bug. To my knowledge, the user has valid tokens that are current.

One additional note: I'm using the v3 branch of the gem because it gives more verbose errors. I know it's not finished but I needed the errors. This might be an improvement for the branch. Happy to contribute if needed.

The top lines from the stacktrace:

/vendor/bundle/ruby/2.1.0/bundler/gems/coinbase-ruby-f894536fe223/lib/coinbase/oauth_client.rb:61 in "http_verb"
/vendor/bundle/ruby/2.1.0/bundler/gems/coinbase-ruby-f894536fe223/lib/coinbase/client.rb:184 in "get"
/vendor/bundle/ruby/2.1.0/bundler/gems/coinbase-ruby-f894536fe223/lib/coinbase/client.rb:31 in "balance"
/lib/tasks/sell.rake:15 in "block (3 levels) in <top (required)>"

sell.rake:15 in my codebase is client_balance = client.balance.to_f

Links to relevant lines:

Any ideas how to resolve this or is it a bug in the gem? If it's not a bug, what's the best way to catch this error?

`account.address_transactions(address_id)` broken

When I call account#address_transactions(address_id) like it says to do in the do the API. I get a

NoMethodError: undefined method `address_transactions' for #<Coinbase::Wallet::Account:0x00000006552188>

either the docs need to be updated to say:
client.address_transactions(client.primary_account['id'], address['id'])
or we need to add support for that method.

.buy! not working? // need more verbose errors please

In my app I have a brand new user with brand new tokens,

Instantiating a client with their credentials, then doing the following. Gives me this error with no reason as to why it fails:

purchase = client.buy!(0.0009)
OAuth2::Error Exception:
nil

Doing a the exact same thing but swapping buy! for sell! works perfectly and the sale goes through.

Side note
This gem seems to throw a lot of errors in it's present state and would benefit from some more description as to why things are failing so we can correct errors in our code quickly and build cool stuff on top of Coinbase

OAuth Token Refresh Issue

When using command Client.refresh! I am getting this error.
The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.

SSL Certificates

I'm actually having a problem with the SSL certs in the Python library. They appear to have changed again. Could you guys check into it? Thanks!

-George

Inquiry about ROI features

I've been working on a project using the coinbase-ruby gem to calculate the ROI for each currency I own. I've ended up creating (or intending to create) functionality which gets data from the API and performs a few simple calculations on it. As I've done so I've wondered if these features would be better suited to the actual gem. I wanted to reach out and see if the maintainers of the project would be interested in merging pull requests implementing some or all of the following interfaces:

  • USD invested
  • USD lost
  • USD gained (or ROI)
  • Current cash-in value (or, ROI taking into account transaction fees)

These features could be useful for people creating bots to watch the market and sell when a certain ROI is reached.

Example:

Something like the following program:

client       = Coinbase::Wallet::Client.new(api_key: API_KEY, api_secret: API_secret)
btc          = client.account(:BTC)
usd_invested = btc.usd_invested ## => {"amount"=>"167.45", "currency"=>"USD"}
usd_gained   = btc.usd_gained   ## => {"amount"=>"10.67", "currency"=>"USD"}
usd_lost     = btc.usd_lost     ## => {"amount"=>"0.00", "currency"=>"USD"}
roi          = btc.usd_roi      ## => {"amount"=>"9.17", "currency"=>"USD"}

If these interfaces sound useful to anyone, let me know. Otherwise, I'll just continue to implement them on my side of things.

''

Ignore this issue.

Coinbase::Wallet::InvalidRequestError: Invalid currency (BTC-USD)

Hello,

I tried to use the examples in the documentation but I got this error:

Coinbase::Wallet::InvalidRequestError: Invalid currency (BTC-USD)
/Users/etagwerker/.rvm/gems/ruby-2.3.3@coinbase/gems/coinbase-4.1.0/lib/coinbase/wallet/api_errors.rb:29:in `check_response_status'
/Users/etagwerker/.rvm/gems/ruby-2.3.3@coinbase/gems/coinbase-4.1.0/lib/coinbase/wallet/adapters/net_http.rb:36:in `http_verb'
/Users/etagwerker/.rvm/gems/ruby-2.3.3@coinbase/gems/coinbase-4.1.0/lib/coinbase/wallet/api_client.rb:649:in `get'
/Users/etagwerker/.rvm/gems/ruby-2.3.3@coinbase/gems/coinbase-4.1.0/lib/coinbase/wallet/api_client.rb:31:in `buy_price'
/Users/etagwerker/Projects/coinbase-alerter/Rakefile:13:in `block in <top (required)>'

The code that I tried to use:

client.buy_price(currency: 'BTC-USD')
client.sell_price(currency: 'ETH-BTC')
client.spot_price(currency: 'BTC-EUR')

Now it works if I change my code to look like this:

client.buy_price(currency_pair: 'BTC-USD')
client.sell_price(currency_pair: 'ETH-BTC')
client.spot_price(currency_pair: 'BTC-EUR')

Maybe the README is out of date?

Please let me know.

Thanks!

OpenSSL Error in Production

Hi,

I've seen the previous OpenSSL errors, but I am getting this only when trying to generate button code in production.

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

I am using SSL myself, but I tried it with my SSL disabled and it still failed.

Thanks

api.sandbox.coinbase.com:443 open=false

Last day I tried using same API using sandbox that worked, but today it is not working and throwing 443 error. below is my sample code. I see below error from sandbox:

irb(main):001:0> require 'coinbase/wallet'
=> true
irb(main):002:0> SANDBOX_URL = 'https://api.sandbox.coinbase.com'
=> "https://api.sandbox.coinbase.com"
irb(main):003:0> client = Coinbase::Wallet::Client.new(api_key: "M8NTtZ1XfvUdgpfx",api_secret: "kdIcDMXYK2SMaGWIM6uupc3myvP6OOyg" , api_url: SANDBOX_URL)
=> #<Coinbase::Wallet::Client:0x87d18a8 @api_key="M8NTtZ1XfvUdgpfx", @api_secret="kdIcDMXYK2SMaGWIM6uupc3myvP6OOyg", @api_uri=#<URI::HTTPS:0x87d14e8 URL:https://api.sandbox.coinbase.com>, @conn=#<Net::HTTP api.sandbox.coinbase.com:443 open=false>>

Any help please ?

Transactions search

Is it possible to search transactions where bitcoin was sent to a particular wallet? If no, where is the best place to ask for a feature request for the api?

Gem errors refreshing access_token and refresh_token

Writing a Rake job that looks like this:

User.all.each do |user|
      user_credentials = {
        access_token: user.access_token,
        refresh_token: user.refresh_token,
        expires_at: Time.now + 1.day
      }

      @coinbase = Coinbase::OAuthClient.new(ENV['COINBASE_CLIENT_ID'], ENV['COINBASE_CLIENT_SECRET'], user_credentials)
      @coinbase.refresh!

.refresh! is giving me the following error, looks as though something is missing from Coinbase-ruby's OAuth refresh functionality? Shouldn't I need to pass in the existing refresh_token in order to get two new tokens?

@coinbase.oauth_token.refresh! spits the same error out

OAuth2::Error: invalid_request: The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed.
{"error":"invalid_request","error_description":"The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed."}
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.4/lib/oauth2/client.rb:113:in `request'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.4/lib/oauth2/client.rb:138:in `get_token'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.4/lib/oauth2/access_token.rb:86:in `refresh!'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/gems/coinbase-2.0.0/lib/coinbase/oauth_client.rb:58:in `refresh!'
/Users/zackshapiro/dev/stopcoin/lib/tasks/short.rake:14:in `block (3 levels) in <top (required)>'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.1.0/lib/active_record/relation/delegation.rb:46:in `each'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/gems/activerecord-4.1.0/lib/active_record/relation/delegation.rb:46:in `each'
/Users/zackshapiro/dev/stopcoin/lib/tasks/short.rake:6:in `block (2 levels) in <top (required)>'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `eval'
/Users/zackshapiro/.rvm/gems/ruby-2.0.0-p451/bin/ruby_executable_hooks:15:in `<main>'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.