coinbase 0.0.1 → 4.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +7 -0
- data/CONTRIBUTING.md +53 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +621 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/coinbase.gemspec +26 -0
- data/lib/coinbase/util.rb +16 -0
- data/lib/coinbase/wallet/adapters/em_http.rb +78 -0
- data/lib/coinbase/wallet/adapters/net_http.rb +68 -0
- data/lib/coinbase/wallet/api_client.rb +755 -0
- data/lib/coinbase/wallet/api_errors.rb +120 -0
- data/lib/coinbase/wallet/api_response.rb +41 -0
- data/lib/coinbase/wallet/ca-coinbase.crt +101 -0
- data/lib/coinbase/wallet/client.rb +101 -0
- data/lib/coinbase/wallet/coinbase-callback.pub +14 -0
- data/lib/coinbase/wallet/models/account.rb +193 -0
- data/lib/coinbase/wallet/models/address.rb +12 -0
- data/lib/coinbase/wallet/models/api_object.rb +46 -0
- data/lib/coinbase/wallet/models/checkout.rb +19 -0
- data/lib/coinbase/wallet/models/order.rb +12 -0
- data/lib/coinbase/wallet/models/transaction.rb +21 -0
- data/lib/coinbase/wallet/models/transfer.rb +13 -0
- data/lib/coinbase/wallet/models/user.rb +15 -0
- data/lib/coinbase/wallet/version.rb +5 -0
- data/lib/coinbase/wallet.rb +24 -156
- data/spec/account_spec.rb +199 -0
- data/spec/callback_signature_verification_spec.rb +16 -0
- data/spec/clients/client_spec.rb +34 -0
- data/spec/clients/oauth_client_spec.rb +56 -0
- data/spec/endpoints_spec.rb +352 -0
- data/spec/error_spec.rb +137 -0
- data/spec/models/address_spec.rb +26 -0
- data/spec/models/api_object_spec.rb +70 -0
- data/spec/models/checkout_spec.rb +52 -0
- data/spec/models/current_user_spec.rb +29 -0
- data/spec/models/order_spec.rb +52 -0
- data/spec/models/request_spec.rb +47 -0
- data/spec/models/transfer_spec.rb +64 -0
- data/spec/models/user_spec.rb +24 -0
- data/spec/spec_helper.rb +13 -0
- metadata +67 -112
- data/lib/coinbase/address.rb +0 -127
- data/lib/coinbase/asset.rb +0 -20
- data/lib/coinbase/balance_map.rb +0 -48
- data/lib/coinbase/constants.rb +0 -38
- data/lib/coinbase/network.rb +0 -55
- data/lib/coinbase/transfer.rb +0 -153
- data/lib/coinbase.rb +0 -18
data/README.md
ADDED
@@ -0,0 +1,621 @@
|
|
1
|
+
# Coinbase Wallet Gem
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/coinbase.svg)](https://badge.fury.io/rb/coinbase)
|
4
|
+
[![Build Status](https://travis-ci.org/coinbase/coinbase-ruby.svg?branch=master)](https://travis-ci.org/coinbase/coinbase-ruby)
|
5
|
+
|
6
|
+
This is the official client library for the [Coinbase Wallet API v2](https://developers.coinbase.com/api/v2). We provide an intuitive, stable interface to integrate Coinbase Wallet into your Ruby project.
|
7
|
+
|
8
|
+
_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](https://github.com/coinbase/coinbase-ruby/releases/tag/v2.1.1) of this library.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'coinbase'
|
16
|
+
```
|
17
|
+
|
18
|
+
Then execute:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
bundle install
|
22
|
+
```
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
```sh
|
27
|
+
gem install coinbase
|
28
|
+
```
|
29
|
+
|
30
|
+
## Authentication
|
31
|
+
|
32
|
+
### API Key (HMAC Client)
|
33
|
+
|
34
|
+
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.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'coinbase/wallet'
|
38
|
+
client = Coinbase::Wallet::Client.new(api_key: <api key>, api_secret: <api secret>)
|
39
|
+
```
|
40
|
+
|
41
|
+
The primary intention of the asynchronous client is to integrate nicely with the [Coinbase Exchange Gem](https://github.com/coinbase/coinbase-exchange-ruby). 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.*
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'coinbase/wallet'
|
45
|
+
require 'em-http'
|
46
|
+
|
47
|
+
client = Coinbase::Wallet::AsyncClient.new(api_key: <api_key>, api_secret: <api secret>)
|
48
|
+
```
|
49
|
+
|
50
|
+
### OAuth2 Client
|
51
|
+
|
52
|
+
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.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
require 'coinbase/wallet'
|
56
|
+
|
57
|
+
# Initializing OAuthClient with both access and refresh token
|
58
|
+
client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>, refresh_token: <refresh_token>)
|
59
|
+
|
60
|
+
# Initializing OAuthClient with only access token
|
61
|
+
client = Coinbase::Wallet::OAuthClient.new(access_token: <access token>)
|
62
|
+
```
|
63
|
+
|
64
|
+
The OAuth client provides a few extra methods to refresh and revoke the access token.
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
client.refresh!
|
68
|
+
```
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
client.revoke!
|
72
|
+
```
|
73
|
+
|
74
|
+
_Protip:tm::_ You can test OAuth2 authentication easily with Developer Access Tokens which can be created under your [OAuth2 application settings](https://www.coinbase.com/settings/api). These are short lived tokens which authenticate but don't require full OAuth2 handshake to obtain.
|
75
|
+
|
76
|
+
#### Two factor authentication
|
77
|
+
|
78
|
+
Send money endpoint requires 2FA token in certain situations (read more [here](https://developers.coinbase.com/docs/wallet/coinbase-connect#two-factor-authentication)). Specific exception is thrown when this is required:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
account = client.primary_account
|
82
|
+
begin
|
83
|
+
account.send(to: 'test@test.com', amount: '1', currency: "BTC")
|
84
|
+
rescue Coinbase::Client::TwoFactorRequiredError
|
85
|
+
# Show 2FA dialog to user and collect 2FA token
|
86
|
+
|
87
|
+
# Re-try call with `two_factor_token` param
|
88
|
+
account.send(to: 'test@test.com', amount: '1', currency: "BTC", two_factor_token: "123456")
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
## Requests
|
93
|
+
|
94
|
+
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](https://robots.thoughtbot.com/ruby-2-keyword-arguments). 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 example@coinbase.com.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
account = client.primary_account
|
98
|
+
account.send(to: 'example@coinbase.com', amount: 100, currency: "USD", description: 'Sending 100 bitcoin')
|
99
|
+
```
|
100
|
+
|
101
|
+
### Pagination
|
102
|
+
|
103
|
+
Several endpoints are [paginated](https://developers.coinbase.com/api/v2#pagination). 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](https://en.wikipedia.org/wiki/HTTP_pipelining), by setting the starting_after parameter in your response.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
client.transactions(account_id) do |data, resp|
|
107
|
+
transactions = data
|
108
|
+
end
|
109
|
+
|
110
|
+
more_pages = true
|
111
|
+
while more_pages
|
112
|
+
client.transactions(account_id, starting_after: transactions.last['id']) do |data, resp|
|
113
|
+
more_pages = resp.has_more?
|
114
|
+
transactions << data
|
115
|
+
transactions.flatten!
|
116
|
+
end
|
117
|
+
end
|
118
|
+
```
|
119
|
+
|
120
|
+
If you want to automatically download the entire dataset, you may pass `fetch_all=true` as a parameter.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
client.transactions(account_id, fetch_all: true) do |data, resp|
|
124
|
+
...
|
125
|
+
end
|
126
|
+
```
|
127
|
+
|
128
|
+
## Responses
|
129
|
+
|
130
|
+
We provide several ways to access return data. Methods will return the data field of the response in hash format.
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
txs = account.transactions(account_id)
|
134
|
+
txs.each do |tx|
|
135
|
+
p tx['id']
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
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.**
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
account.transactions(account_id) do |txs|
|
143
|
+
txs.each { |tx| p tx['id'] }
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
If you need to access the response metadata (headers, pagination info, etc.) you can access the entire response as the second block paramenter.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
account.transactions(account_id) do |txs, resp|
|
151
|
+
p "STATUS: #{resp.status}"
|
152
|
+
p "HEADERS: #{resp.headers}"
|
153
|
+
p "BODY: #{resp.body}"
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
**Response Object**
|
158
|
+
|
159
|
+
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.
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
account = client.primary_account
|
163
|
+
p "Account:\t account.name"
|
164
|
+
p "ID:\t account.id"
|
165
|
+
p "Balance:\t #{account.balance.amount} #{account.balance.currency}"
|
166
|
+
```
|
167
|
+
|
168
|
+
All values are returned directly from the API unmodified, except the following exceptions:
|
169
|
+
|
170
|
+
- [Money amounts](https://developers.coinbase.com/api/v2#money-hash) are always converted into [BigDecimal](http://ruby-doc.org/stdlib-2.1.1/libdoc/bigdecimal/rdoc/BigDecimal.html) objects. You should always use BigDecimal when handing bitcoin amounts for accurate precision.
|
171
|
+
- [Timestamps](https://developers.coinbase.com/api/v2#timestamps) are always converted into [Time](http://ruby-doc.org/stdlib-2.1.1/libdoc/time/rdoc/Time.html) objects.
|
172
|
+
|
173
|
+
Most methods require an associated account. Thus, responses for the [account endpoints](https://developers.coinbase.com/api/v2#accounts) 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.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
account = client.primary_account
|
177
|
+
account.send(to: "example@coinbase.com", amount: 100, description: "Sending 100 bitcoin")
|
178
|
+
```
|
179
|
+
|
180
|
+
Alternatively you can pass the account ID straight to the client:
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
client.transactions(<account_id>)
|
184
|
+
```
|
185
|
+
|
186
|
+
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.
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
account.refresh!
|
190
|
+
```
|
191
|
+
|
192
|
+
### Warnings
|
193
|
+
|
194
|
+
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](http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby).
|
195
|
+
|
196
|
+
### Errors
|
197
|
+
|
198
|
+
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`.
|
199
|
+
|
200
|
+
|Error|Status|
|
201
|
+
|---|---|
|
202
|
+
|APIError|*|
|
203
|
+
|BadRequestError|400|
|
204
|
+
|ParamRequiredError|400|
|
205
|
+
|InvalidRequestError|400|
|
206
|
+
|PersonalDetailsRequiredError|400|
|
207
|
+
|AuthenticationError|401|
|
208
|
+
|UnverifiedEmailError|401|
|
209
|
+
|InvalidTokenError|401|
|
210
|
+
|RevokedTokenError|401|
|
211
|
+
|ExpiredTokenError|401|
|
212
|
+
|TwoFactorRequiredError|402|
|
213
|
+
|InvalidScopeError|403|
|
214
|
+
|NotFoundError|404|
|
215
|
+
|ValidationError|422|
|
216
|
+
|RateLimitError|429|
|
217
|
+
|InternalServerError|500|
|
218
|
+
|ServiceUnavailableError|503|
|
219
|
+
|
220
|
+
## Usage
|
221
|
+
|
222
|
+
This is not intended to provide complete documentation of the API. For more detail, please refer to the [official documentation](https://developers.coinbase.com/api/v2).
|
223
|
+
|
224
|
+
### [Market Data](https://developers.coinbase.com/api/v2#data-api)
|
225
|
+
|
226
|
+
**List supported native currencies**
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
client.currencies
|
230
|
+
```
|
231
|
+
|
232
|
+
**List exchange rates**
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
client.exchange_rates
|
236
|
+
```
|
237
|
+
|
238
|
+
**Buy price**
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
client.buy_price
|
242
|
+
# or
|
243
|
+
client.buy_price(currency_pair: 'BTC-USD')
|
244
|
+
```
|
245
|
+
|
246
|
+
**Sell price**
|
247
|
+
|
248
|
+
```ruby
|
249
|
+
client.sell_price
|
250
|
+
# or
|
251
|
+
client.sell_price(currency_pair: 'ETH-BTC')
|
252
|
+
```
|
253
|
+
|
254
|
+
**Spot price**
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
client.spot_price
|
258
|
+
# or
|
259
|
+
client.spot_price(currency_pair: 'BTC-EUR')
|
260
|
+
```
|
261
|
+
|
262
|
+
**Current server time**
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
client.time
|
266
|
+
```
|
267
|
+
|
268
|
+
### [Users](https://developers.coinbase.com/api/v2#users)
|
269
|
+
|
270
|
+
**Get authorization info**
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
client.auth_info
|
274
|
+
```
|
275
|
+
|
276
|
+
**Lookup user info**
|
277
|
+
|
278
|
+
```ruby
|
279
|
+
client.user(user_id)
|
280
|
+
```
|
281
|
+
|
282
|
+
**Get current user**
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
client.current_user
|
286
|
+
```
|
287
|
+
|
288
|
+
**Update current user**
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
client.update_current_user(name: "New Name")
|
292
|
+
```
|
293
|
+
|
294
|
+
### [Accounts](https://developers.coinbase.com/api/v2#accounts)
|
295
|
+
|
296
|
+
**List all accounts**
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
client.accounts
|
300
|
+
```
|
301
|
+
|
302
|
+
**List account details**
|
303
|
+
|
304
|
+
```ruby
|
305
|
+
client.account(account_id)
|
306
|
+
```
|
307
|
+
|
308
|
+
**List primary account details**
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
client.primary_account
|
312
|
+
```
|
313
|
+
|
314
|
+
**Set account as primary**
|
315
|
+
|
316
|
+
```ruby
|
317
|
+
account.make_primary!
|
318
|
+
```
|
319
|
+
|
320
|
+
**Create a new bitcoin account**
|
321
|
+
|
322
|
+
```ruby
|
323
|
+
client.create_account(name: "New Account")
|
324
|
+
```
|
325
|
+
|
326
|
+
**Update an account**
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
account.update!(name: "New Account Name")
|
330
|
+
```
|
331
|
+
|
332
|
+
**Delete an account**
|
333
|
+
|
334
|
+
```ruby
|
335
|
+
account.delete!
|
336
|
+
```
|
337
|
+
|
338
|
+
### [Addresses](https://developers.coinbase.com/api/v2#addresses)
|
339
|
+
|
340
|
+
**List receive addresses for account**
|
341
|
+
|
342
|
+
```ruby
|
343
|
+
account.addresses
|
344
|
+
```
|
345
|
+
|
346
|
+
**Get receive address info**
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
account.address(address_id)
|
350
|
+
```
|
351
|
+
|
352
|
+
**List transactiona for address**
|
353
|
+
|
354
|
+
```ruby
|
355
|
+
account.address_transactions(address_id)
|
356
|
+
```
|
357
|
+
|
358
|
+
**Create a new receive address**
|
359
|
+
|
360
|
+
```ruby
|
361
|
+
account.create_address
|
362
|
+
```
|
363
|
+
|
364
|
+
### [Transactions](https://developers.coinbase.com/api/v2#transactions)
|
365
|
+
|
366
|
+
**List transactions**
|
367
|
+
|
368
|
+
```ruby
|
369
|
+
account.transactions
|
370
|
+
```
|
371
|
+
|
372
|
+
**Get transaction info**
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
account.transaction(transaction_id)
|
376
|
+
```
|
377
|
+
|
378
|
+
**Send funds**
|
379
|
+
|
380
|
+
```ruby
|
381
|
+
account.send(to: <bitcoin address>, amount: "5.0", currency: "USD", description: "Your first bitcoin!")
|
382
|
+
```
|
383
|
+
|
384
|
+
**Transfer funds to a new account**
|
385
|
+
|
386
|
+
```ruby
|
387
|
+
account.transfer(to: <account ID>, amount: "1", currency: "BTC", description: "Your first bitcoin!")
|
388
|
+
```
|
389
|
+
|
390
|
+
**Request funds**
|
391
|
+
|
392
|
+
```ruby
|
393
|
+
account.request(to: <email>, amount: "8.0", currency: "USD", description: "Burrito")
|
394
|
+
```
|
395
|
+
|
396
|
+
**Resend request**
|
397
|
+
|
398
|
+
```ruby
|
399
|
+
account.resend_request(request_id)
|
400
|
+
```
|
401
|
+
|
402
|
+
**Cancel request**
|
403
|
+
|
404
|
+
```ruby
|
405
|
+
account.cancel_request(request_id)
|
406
|
+
```
|
407
|
+
|
408
|
+
**Fulfill request**
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
account.complete_request(request_id)
|
412
|
+
```
|
413
|
+
|
414
|
+
### [Buys](https://developers.coinbase.com/api/v2#buys)
|
415
|
+
|
416
|
+
**List buys**
|
417
|
+
|
418
|
+
```ruby
|
419
|
+
account.list_buys
|
420
|
+
```
|
421
|
+
|
422
|
+
**Get buy info**
|
423
|
+
|
424
|
+
```ruby
|
425
|
+
account.list_buy(buy_id)
|
426
|
+
```
|
427
|
+
|
428
|
+
**Buy bitcoins**
|
429
|
+
|
430
|
+
```ruby
|
431
|
+
account.buy(amount: "1", currency: "BTC")
|
432
|
+
```
|
433
|
+
|
434
|
+
**Commit a buy**
|
435
|
+
|
436
|
+
You only need to do this if you pass `commit=true` when you call the buy method.
|
437
|
+
|
438
|
+
```ruby
|
439
|
+
buy = account.buy(amount: "1", currency: "BTC", commit: false)
|
440
|
+
account.commit_buy(buy.id)
|
441
|
+
```
|
442
|
+
|
443
|
+
### [Sells](https://developers.coinbase.com/api/v2#sells)
|
444
|
+
|
445
|
+
**List sells**
|
446
|
+
|
447
|
+
```ruby
|
448
|
+
account.list_sells
|
449
|
+
```
|
450
|
+
|
451
|
+
**Get sell info**
|
452
|
+
|
453
|
+
```ruby
|
454
|
+
account.list_sell(sell_id)
|
455
|
+
```
|
456
|
+
|
457
|
+
**Sell bitcoins**
|
458
|
+
|
459
|
+
```ruby
|
460
|
+
account.sell(amount: "1", currency: "BTC")
|
461
|
+
```
|
462
|
+
|
463
|
+
**Commit a sell**
|
464
|
+
|
465
|
+
You only need to do this if you pass `commit=true` when you call the sell method.
|
466
|
+
|
467
|
+
```ruby
|
468
|
+
sell = account.sell(amount: "1", currency: "BTC", commit: false)
|
469
|
+
account.commit_sell(sell.id)
|
470
|
+
```
|
471
|
+
|
472
|
+
### [Deposit](https://developers.coinbase.com/api/v2#deposits)
|
473
|
+
|
474
|
+
**List deposits**
|
475
|
+
|
476
|
+
```ruby
|
477
|
+
account.list_deposits
|
478
|
+
```
|
479
|
+
|
480
|
+
**Get deposit info**
|
481
|
+
|
482
|
+
```ruby
|
483
|
+
account.list_deposit(deposit_id)
|
484
|
+
```
|
485
|
+
|
486
|
+
**Deposit funds**
|
487
|
+
|
488
|
+
```ruby
|
489
|
+
account.deposit(amount: "10", currency: "USD")
|
490
|
+
```
|
491
|
+
|
492
|
+
**Commit a deposit**
|
493
|
+
|
494
|
+
You only need to do this if you pass `commit=true` when you call the deposit method.
|
495
|
+
|
496
|
+
```ruby
|
497
|
+
deposit = account.deposit(amount: "1", currency: "BTC", commit: false)
|
498
|
+
account.commit_deposit(deposit.id)
|
499
|
+
```
|
500
|
+
|
501
|
+
### [Withdrawals](https://developers.coinbase.com/api/v2#withdrawals)
|
502
|
+
|
503
|
+
**List withdrawals**
|
504
|
+
|
505
|
+
```ruby
|
506
|
+
account.list_withdrawals
|
507
|
+
```
|
508
|
+
|
509
|
+
**Get withdrawal**
|
510
|
+
|
511
|
+
```ruby
|
512
|
+
account.list_withdrawal(withdrawal_id)
|
513
|
+
```
|
514
|
+
|
515
|
+
**Withdraw funds**
|
516
|
+
|
517
|
+
```ruby
|
518
|
+
account.withdraw(amount: "10", currency: "USD")
|
519
|
+
```
|
520
|
+
|
521
|
+
**Commit a withdrawal**
|
522
|
+
|
523
|
+
You only need to do this if you pass `commit=true` when you call the withdrawal method.
|
524
|
+
|
525
|
+
```ruby
|
526
|
+
withdraw = account.withdraw(amount: "1", currency: "BTC", commit: false)
|
527
|
+
account.commit_withdrawal(withdrawal.id)
|
528
|
+
```
|
529
|
+
|
530
|
+
### [Payment Methods](https://developers.coinbase.com/api/v2#payment-methods)
|
531
|
+
|
532
|
+
**List payment methods**
|
533
|
+
|
534
|
+
```ruby
|
535
|
+
client.payment_methods
|
536
|
+
```
|
537
|
+
|
538
|
+
**Get payment method**
|
539
|
+
|
540
|
+
```ruby
|
541
|
+
client.payment_method(payment_method_id)
|
542
|
+
```
|
543
|
+
|
544
|
+
### [Merchants](https://developers.coinbase.com/api/v2#merchants)
|
545
|
+
|
546
|
+
#### Get merchant
|
547
|
+
|
548
|
+
```ruby
|
549
|
+
client.merchant(merchant_id)
|
550
|
+
```
|
551
|
+
|
552
|
+
#### Verify a merchant callback
|
553
|
+
|
554
|
+
```ruby
|
555
|
+
client.verify_callback(request.raw_post, request.headers['CB-SIGNATURE']) # true/false
|
556
|
+
```
|
557
|
+
|
558
|
+
### [Orders](https://developers.coinbase.com/api/v2#orders)
|
559
|
+
|
560
|
+
#### List orders
|
561
|
+
|
562
|
+
```ruby
|
563
|
+
client.orders
|
564
|
+
```
|
565
|
+
|
566
|
+
#### Get order
|
567
|
+
|
568
|
+
```ruby
|
569
|
+
client.order(order_id)
|
570
|
+
```
|
571
|
+
|
572
|
+
#### Create order
|
573
|
+
|
574
|
+
```ruby
|
575
|
+
client.create_order(amount: "1", currency: "BTC", name: "Order #1234")
|
576
|
+
```
|
577
|
+
|
578
|
+
#### Refund order
|
579
|
+
|
580
|
+
```ruby
|
581
|
+
order = client.orders.first
|
582
|
+
order.refund!
|
583
|
+
```
|
584
|
+
|
585
|
+
### Checkouts
|
586
|
+
|
587
|
+
#### List checkouts
|
588
|
+
|
589
|
+
```ruby
|
590
|
+
client.checkouts
|
591
|
+
```
|
592
|
+
|
593
|
+
#### Get checkout
|
594
|
+
|
595
|
+
```ruby
|
596
|
+
client.checkout(checkout_id)
|
597
|
+
```
|
598
|
+
|
599
|
+
#### Get checkout's orders
|
600
|
+
|
601
|
+
```ruby
|
602
|
+
checkout = client.checkout(checkout_id)
|
603
|
+
checkout.orders
|
604
|
+
```
|
605
|
+
|
606
|
+
#### Create order for checkout
|
607
|
+
|
608
|
+
```ruby
|
609
|
+
checkout = client.checkout(checkout_id)
|
610
|
+
checkout.create_order
|
611
|
+
```
|
612
|
+
|
613
|
+
## Contributing and testing
|
614
|
+
|
615
|
+
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:
|
616
|
+
|
617
|
+
# Install the requirements
|
618
|
+
gem install coinbase
|
619
|
+
|
620
|
+
# Run tests
|
621
|
+
rspec spec
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "coinbase/wallet"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/coinbase.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'coinbase/wallet/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "coinbase"
|
8
|
+
gem.version = Coinbase::Wallet::VERSION
|
9
|
+
gem.license = 'Apache-2.0'
|
10
|
+
gem.authors = ["John Duhamel", "Jori Lallo"]
|
11
|
+
gem.email = ["api@coinbase.com"]
|
12
|
+
gem.description = "Client library for Coinbase Wallet API v2"
|
13
|
+
gem.summary = "Client library for Coinbase Wallet API v2"
|
14
|
+
gem.homepage = "https://developers.coinbase.com/api/v2"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_development_dependency "webmock"
|
24
|
+
gem.add_development_dependency "timecop"
|
25
|
+
gem.add_development_dependency "pry-byebug"
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Coinbase::Util
|
2
|
+
class CurrencyPairError < StandardError; end
|
3
|
+
|
4
|
+
# An adaptar that allow converts a currency into
|
5
|
+
# a currency pair to coenciede with multiple crypto currenices
|
6
|
+
#
|
7
|
+
# @param currency [String] the currency option inputed by the developer
|
8
|
+
# @return [String] The properly formatted currency pair
|
9
|
+
def self.determine_currency_pair(params)
|
10
|
+
return 'BTC-USD' if (!params[:currency] && !params[:currency_pair])
|
11
|
+
return 'BTC-' + params[:currency] if params[:currency]
|
12
|
+
return params[:currency_pair] if params[:currency_pair]
|
13
|
+
|
14
|
+
raise CurrencyPairError, "invalid currency param"
|
15
|
+
end
|
16
|
+
end
|