coinbase-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 95dc1d24dc32cd17d2781d876dfa1802aa5cd0c061adde263cec928767f4b882
4
+ data.tar.gz: a7ea7a69384f0503f2ff44407bba4a07eb2b46a66f52ddff94ca32946e28e394
5
+ SHA512:
6
+ metadata.gz: f5a578511565c78f1cdb33c5086503e8c27929c493b3180feb8e7753e2e1894edb9b496f1ec7eef004b0c00f85f72e7b8bdc642daf440b60ba0f0559cedba4dd
7
+ data.tar.gz: 226b70ab8f59e845f0014b00120faefbc8616dad767143a703aed349c959acc9e198043c699abdc8869fa59c4e67220b52fb25218a6d08922bfac98b3d8b98d1
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Coinbase Accounts APIs
5
+ class Accounts < Client
6
+ ACCOUNT_BASE = 'accounts'
7
+
8
+ def initialize
9
+ super
10
+ end
11
+
12
+ # Lists current user accounts.
13
+ #
14
+ # @return [Array of Hashes] a list of accounts.
15
+ def list
16
+ format_response(
17
+ get(
18
+ "/#{ACCOUNT_BASE}"
19
+ )
20
+ )
21
+ end
22
+
23
+ # History List account activity of the API key's profile.
24
+ #
25
+ # @param account_id [String] Returns list of ledger entries
26
+ # from this account id.
27
+ # @param before [String]. Parameter requires a positive integer.
28
+ # If set, returns ledger entries before the specified integer.
29
+ # @param after [String]. Parameter requires a positive integer.
30
+ # If set, returns ledger entries after the specified integer.
31
+ # @param start_date [String]. If set, returns ledger entries created after
32
+ # the start_date timestamp, sorted by newest creation date.
33
+ # When combined with end_date, returns ledger entries in the specified
34
+ # time range.
35
+ # @param end_date [String]. If set, returns ledger entries created before
36
+ # the end_date timestamp, sorted by newest creation date.
37
+ # @param limit [Integer]. Number of results per request. Maximum 1000.
38
+ #
39
+ # @return [Array of Hashes] List account activity of the API key's profile.
40
+ def history(account_id, options = {})
41
+ operational_url = "/#{ACCOUNT_BASE}/#{account_id}/ledger"
42
+ query_params = build_query_params(options)
43
+ operational_url += '?' + query_params unless query_params.empty?
44
+ format_response(
45
+ get(
46
+ operational_url
47
+ )
48
+ )
49
+ end
50
+
51
+ # Holds of an account that belong to the same profile as the API key.
52
+ #
53
+ # @param account_id [String]
54
+ # @return [Array of Hashes]
55
+ def holds(account_id)
56
+ format_response(
57
+ get(
58
+ "/#{ACCOUNT_BASE}/#{account_id}/holds"
59
+ )
60
+ )
61
+ end
62
+
63
+ # Show current user account by account_id.
64
+ #
65
+ # @param account_id [String]
66
+ # @return [Hash] a account.
67
+ def fetch(account_id)
68
+ format_response(
69
+ get(
70
+ "/#{ACCOUNT_BASE}/#{account_id}"
71
+ )
72
+ )
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Base class to connect to coinbase
5
+ class Client
6
+ include Util
7
+
8
+ def initialize
9
+ @api_key = Coinbase::Client.configuration[:api_key]
10
+ @api_secret = Coinbase::Client.configuration[:api_secret]
11
+ @passphrase = Coinbase::Client.configuration[:passphrase]
12
+ [@api_key, @api_secret, @passphrase].each do |opt|
13
+ raise 'Missing coinbase credentials' if opt.blank?
14
+ end
15
+ end
16
+
17
+ def signature(method, timestamp, request_path: '', body: nil)
18
+ body = body.to_json if body.is_a?(Hash)
19
+ message = "#{timestamp}#{method}#{request_path}#{body}"
20
+ # create a sha256 hmac with the secret
21
+ secret = Base64.decode64(@api_secret)
22
+ hash = OpenSSL::HMAC.digest('sha256', secret, message)
23
+ Base64.strict_encode64(hash)
24
+ end
25
+
26
+ def headers(method, path, body)
27
+ timestamp = Time.now.to_i.to_s
28
+ sign = signature(method, timestamp, request_path: path, body: body)
29
+ {
30
+ 'Content-Type' => 'application/json',
31
+ 'Accept' => 'application/json',
32
+ 'CB-ACCESS-KEY' => @api_key,
33
+ 'CB-ACCESS-SIGN' => sign,
34
+ 'CB-ACCESS-TIMESTAMP' => timestamp,
35
+ 'CB-ACCESS-PASSPHRASE' => @passphrase,
36
+ 'User-Agent' => 'request'
37
+ }
38
+ end
39
+
40
+ def http_request(method, path, body: nil)
41
+ request_headers = headers(method, path, body)
42
+ request_params = { headers: request_headers }
43
+ request_params.merge!(body: body.to_json) if body.present?
44
+ yield(request_params) if block_given?
45
+ end
46
+
47
+ def get(path)
48
+ http_request(:GET, path) do |request_params|
49
+ HTTParty.get("#{base_uri}#{path}", request_params)
50
+ end
51
+ end
52
+
53
+ def post(path, body: nil)
54
+ http_request(:POST, path, body: body) do |request_params|
55
+ HTTParty.post("#{base_uri}#{path}", request_params)
56
+ end
57
+ end
58
+
59
+ def put(path, body: nil)
60
+ http_request(:PUT, path, body: body) do |request_params|
61
+ HTTParty.put("#{base_uri}#{path}", request_params)
62
+ end
63
+ end
64
+
65
+ def delete(path)
66
+ http_request(:DELETE, path) do |request_params|
67
+ HTTParty.delete("#{base_uri}#{path}", request_params)
68
+ end
69
+ end
70
+
71
+ def self.configuration
72
+ @configuration ||= HashWithIndifferentAccess.new
73
+ end
74
+
75
+ def self.configure
76
+ yield(configuration)
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Coinbase Conversions API's
5
+ class Conversions < Client
6
+ CONVERSION_URL = '/conversions'
7
+
8
+ # Creates the order with the given data.
9
+ #
10
+ # @param params [Hash] with following fields
11
+ # to [String] A valid currency id.
12
+ # from [String] A valid currency id.
13
+ # amount [Float] Amount of from to convert to to,
14
+ # current limit is 10,000,000
15
+ #
16
+ # @return [Hash] a hash with status code and order details.
17
+ def create(params = {})
18
+ format_response(post(CONVERSION_URL, body: params))
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Currency APIs
5
+ class Currency
6
+ include Util
7
+
8
+ # include Coinbase::Util
9
+ # List known currencies.
10
+ #
11
+ # @return [Hash] a list of currencies.
12
+ def list
13
+ send_request('/currencies')
14
+ end
15
+
16
+ # Show specific currency.
17
+ #
18
+ # @params [String] currency ID
19
+ # @return [Hash] a list of currencies.
20
+ def fetch(currency_id)
21
+ send_request("/currencies/#{currency_id}")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Deposite coinbase APIs
5
+ class Deposits < Transfers
6
+ DEFAULT_TYPE = 'deposit'
7
+ # Generate a crypto deposit address.
8
+ #
9
+ # @param coinbase_account_id [String] ID of coinbase account.
10
+ # @return [Hash] a hash with status code and deposit address details.
11
+ def generate_address(coinbase_account_id)
12
+ response = post(
13
+ "/coinbase-accounts/#{coinbase_account_id}/addresses"
14
+ )
15
+ format_response(response)
16
+ end
17
+
18
+ # Deposit funds from a coinbase account.
19
+ #
20
+ # @param deposit_details [Hash] with following fields
21
+ # amount [Float] The amount to deposit.
22
+ # currency [String] The type of currency.
23
+ # coinbase_account_id [String] ID of coinbase account.
24
+ # @return [Hash] a hash with status code and deposit details.
25
+ def by_account(deposit_details)
26
+ response = post(
27
+ '/deposits/coinbase-account', body: deposit_details
28
+ )
29
+ format_response(response)
30
+ end
31
+
32
+ # Deposit funds from a payment method.
33
+ #
34
+ # @param deposit_details [Hash] with following fields
35
+ # amount [Float] The amount to deposit.
36
+ # currency [String] The type of currency.
37
+ # payment_method_id [String] ID of the payment method.
38
+ # @return [Hash] a hash with status code and deposit details.
39
+ def by_method(deposit_details)
40
+ response = post(
41
+ '/deposits/payment-method',
42
+ body: deposit_details
43
+ )
44
+ format_response(response)
45
+ end
46
+
47
+ # Fetch the list of deposits from the profile of the API key,
48
+ # in descending order by created time.
49
+ #
50
+ # @param profile_id [String] Limit list of deposits to this profile_id.
51
+ # By default, it retrieves deposits using default profile (optional).
52
+ # @param type [String] Set to deposit or internal_deposit (optional).
53
+ # By default will fetch deposits.
54
+ # @param paginate_options [Hash] an hash with the following parameters
55
+ # before [String] If before is set, then it returns deposits created after
56
+ # the before timestamp, sorted by oldest creation date (optional).
57
+ # after [String] If after is set, then it returns deposits created before
58
+ # the after timestamp, sorted by newest (optional).
59
+ # limit [Integer] Truncate list to this many deposits, capped at 100.
60
+ # Default is 100. (optional).
61
+ # @return [Hash] a hash with status code and deposit list.
62
+ def list(options = {})
63
+ options[:type] = options[:type].blank? ? DEFAULT_TYPE : options[:type]
64
+ super(options)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Fees
4
+ module Coinbase
5
+ # List Fees
6
+ class Fees < Client
7
+ FEE_API = '/fees'
8
+
9
+ # Get the current fees.
10
+ #
11
+ # @return [Hash] a hash with status code and fees details with current
12
+ # maker & taker rates and trailing volume.
13
+ def list
14
+ format_response(get(FEE_API))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,118 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Coinbase
4
+ module Coinbase
5
+ # Create, Delete, Lists orders
6
+ class Orders < Client
7
+ ORDER_URL = '/orders'
8
+
9
+ # Creates the order with the given data.
10
+ #
11
+ # @param order_details [Hash] with following fields
12
+ # side [String] buy or sell.
13
+ # product_id [String] A valid product id (e.g. "BTC-USD").
14
+ # client_oid [String] Order ID selected by you to identify your order
15
+ # (optional).
16
+ # type [String] limit or market, default is limit (optional).
17
+ # stp [String] Self-trade prevention flag (optional).
18
+ # stop [String] Either loss or entry. Requires stop_price to be defined
19
+ # (optional).
20
+ # stop_price [String] Only if stop is defined. Sets trigger price for stop
21
+ # order (optional).
22
+ # Limit Order Params
23
+ # size [String] Amount of base currency to buy or sell.
24
+ # price [String] Price per bitcoin.
25
+ # time_in_force [String] GTC, GTT, IOC, or FOK, default is GTC (optional).
26
+ # cancel_after [String] min, hour, day but requires time_in_force to be GTT
27
+ # (optional).
28
+ # post_only [Boolean] Post only flag but invalid when time_in_force is IOC
29
+ # or FOK (optional).
30
+ # Market Order Params (One of size or funds is required.)
31
+ # size [String] Amount of base currency to buy or sell (optional).
32
+ # funds [String] Desired amount of quote currency to use (optional).
33
+ # @return [Hash] a hash with status code and order details.
34
+ def create(order_details = {})
35
+ format_response(post(ORDER_URL, body: order_details))
36
+ end
37
+
38
+ # Cancel all open orders from the profile that the API key belongs to.
39
+ #
40
+ # @param product_id [String] The product ID of the order,
41
+ # only cancel orders open for a specific product (optional).
42
+ # @return [Hash] a hash with status code and list of ids of the canceled
43
+ # orders.
44
+ def cancel_all(product_id = nil)
45
+ operational_url = ORDER_URL
46
+ operational_url += "?product_id=#{product_id}" if product_id
47
+ response = delete(operational_url)
48
+ format_response(response)
49
+ end
50
+
51
+ # Cancel a previously placed order.
52
+ # Order must belong to the profile that the API key belongs to.
53
+ #
54
+ # @param options [Hash] an hash with the following parameters
55
+ # product_id [String] The product ID of the order (optional).
56
+ # id [String] The ID of the order (optional).
57
+ # product_id [String] The product ID of the order (optional).
58
+ # client_oid [String] Order ID selected by you to identify your order
59
+ # (optional)
60
+ # One of client_oid or id is required.
61
+ # @return [Hash] a hash with status code and list of ids
62
+ # of the canceled orders.
63
+ def cancel(options = {})
64
+ if options.key?(:id)
65
+ operational_url = "#{ORDER_URL}/#{options[:id]}"
66
+ elsif options.key?(:client_oid)
67
+ operational_url = "#{ORDER_URL}/client:#{options[:client_oid]}"
68
+ else
69
+ return { code: '500', result: 'One of client_oid or id is required.' }
70
+ end
71
+ operational_url += "?product_id=#{product_id}" if options[:product_id]
72
+ response = delete(operational_url)
73
+ format_response(response)
74
+ end
75
+
76
+ # Fetch a single order by order id from the profile that
77
+ # the API key belongs to.
78
+ #
79
+ # @param options [Hash] an hash with the following parameters
80
+ # product_id [String] The product ID of the order (optional).
81
+ # id [String] The ID of the order (optional).
82
+ # client_oid [String] Order ID selected by you to identify your order
83
+ # (optional)
84
+ # One of client_oid or id is required.
85
+ # @return [Hash] a hash with status code and order details.
86
+ def fetch(options = {})
87
+ if options.key?(:id)
88
+ operational_url = "#{ORDER_URL}/#{options[:id]}"
89
+ elsif options.key?(:client_oid)
90
+ operational_url = "#{ORDER_URL}/client:#{options[:client_oid]}"
91
+ else
92
+ return { code: '500', result: 'One of client_oid or id is required.' }
93
+ end
94
+ response = get(operational_url)
95
+ format_response(response)
96
+ end
97
+
98
+ # Fetch the list of current open orders.
99
+ # Only open or un-settled orders are returned.
100
+ #
101
+ # @param product_id [String] The product ID of the order (optional).
102
+ # @param statuses [Array] Limit list of orders to these statuses.
103
+ # Passing all returns orders of all statuses.
104
+ # @param paginate_options [Hash] an hash with the following parameters
105
+ # before [String] Request page before (newer) this pagination id (optional).
106
+ # after [String] Request page after (older) this pagination id (optional).
107
+ # limit [Integer] Number of results per request. Maximum 1000,
108
+ # default is 1000 (optional).
109
+ # @return [Hash] a hash with status code and order details.
110
+ def list(params = {})
111
+ operational_url = ORDER_URL
112
+ query_params = build_query_params(params)
113
+ operational_url += '/?' + query_params unless query_params.empty?
114
+ response = get(operational_url)
115
+ format_response(response)
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Product APIs
5
+ class Products
6
+ include Util
7
+
8
+ # Get a list of available currency pairs for trading.
9
+ #
10
+ # @return [Array of Hashes] a list of currency pair trading.
11
+ def list
12
+ send_request('/products')
13
+ end
14
+
15
+ # Get market data for a specific currency pair
16
+ #
17
+ # @param product_id [String]
18
+ # @return [Hash] specific currency pair trading.
19
+ def fetch(product_id)
20
+ send_request("/products/#{product_id}")
21
+ end
22
+
23
+ # Get a list of open orders for a product
24
+ #
25
+ # @param product_id [String]
26
+ # @param level [Number] Defualt is 1 below is description about same
27
+ # 1 Only the best bid and ask
28
+ # 2 Top 50 bids and asks (aggregated)
29
+ # 3 Full order book (non aggregated)
30
+ # @return [Hash] orders for product.
31
+ def orderbook(product_id, level = 1)
32
+ send_request("/products/#{product_id}/book?level=#{level}")
33
+ end
34
+
35
+ # Get information about the last trade
36
+ #
37
+ # @param product_id [String]
38
+ # @return [Hash] trade info.
39
+ def last_trade(product_id)
40
+ send_request("/products/#{product_id}/ticker")
41
+ end
42
+
43
+ # List the latest trades for a product.
44
+ #
45
+ # @param product_id [String]
46
+ # @param paginate_options [Hash] an hash with the following parameters
47
+ # before [String] Request page before (newer) this pagination id (optional).
48
+ # after [String] Request page after (older) this pagination id (optional).
49
+ # limit [Integer] Number of results per request. Maximum 1000,
50
+ # default is 1000 (optional).
51
+ # @return [Array of Hashes] trades for product.
52
+ def trade_history(product_id, paginate_options = {})
53
+ query_params = build_query_params(paginate_options)
54
+ send_request("/products/#{product_id}/trades?#{query_params}")
55
+ end
56
+
57
+ # Get historic rates for a product.
58
+ #
59
+ # @param product_id [String]
60
+ # @param options [Hash]
61
+ # @return [Array] rates for product.
62
+ def price_history(product_id, options = {})
63
+ query = build_query_params(options) unless options.blank?
64
+
65
+ send_request("/products/#{product_id}/candles?#{query}")
66
+ end
67
+
68
+ # Get 24 hr stats for the product.
69
+ #
70
+ # @param product_id [String]
71
+ # @return [Hash] stats for product.
72
+ def daily_stats(product_id)
73
+ send_request("/products/#{product_id}/stats")
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Coinbase Transactio APIs
5
+ class Transactions < Client
6
+ TRANSACTION_BASE_URL = '/accounts'
7
+
8
+ # Initializes the API client for transaction.
9
+ #
10
+ # @param account_id [String] The ID of the account.
11
+ # @return [Object] transaction API client with generated token.
12
+ def initialize(account_id)
13
+ @account_id = account_id
14
+ super()
15
+ end
16
+
17
+ # Lists account activity. By default it will return recent 25 transactions.
18
+ #
19
+ # @param paginate_options [Hash] an hash with the following parameters
20
+ # before [String] Request page before (newer) this pagination id (optional).
21
+ # after [String] Request page after (older) this pagination id (optional).
22
+ # limit [Integer] Number of results per request.
23
+ # @return [Hash] a list of transactions records.
24
+ def ledger(paginate_options = {})
25
+ operation_url = "#{TRANSACTION_BASE_URL}/#{@account_id}/ledger"
26
+ query_params = build_query_params(paginate_options)
27
+ operation_url += '/?' + query_params if query_params.present?
28
+ response = get(operation_url)
29
+ format_response(response)
30
+ end
31
+
32
+ # List holds of an account.
33
+ #
34
+ # @param paginate_options [Hash] an hash with the following parameters
35
+ # before [String] Request page before (newer) this pagination id (optional).
36
+ # after [String] Request page after (older) this pagination id (optional).
37
+ # limit [Integer] Number of results per request.
38
+ # @return [Hash] a list of transactions records.
39
+ def holds(paginate_options = {})
40
+ operation_url = "#{TRANSACTION_BASE_URL}/#{@account_id}/holds"
41
+ query_params = build_query_params(paginate_options)
42
+ operation_url += '/?' + query_params if query_params.present?
43
+ response = get(operation_url)
44
+ format_response(response)
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Coinbase transfer APIs
5
+ class Transfers < Client
6
+ # List available payment methods.
7
+ # @return [Hash] a hash of payment methods.
8
+ def payment_methods
9
+ operation_url = '/payment-methods'
10
+ response = get(operation_url)
11
+ format_response(response)
12
+ end
13
+
14
+ # Fetch information on a single deposit.
15
+ #
16
+ # @param transfer_id [String] The transfer ID of the deposit.
17
+ #
18
+ # @return [Hash] a hash with status code and deposit information.
19
+ def fetch(transfer_id)
20
+ operation_url = "/transfers/#{transfer_id}"
21
+ response = get(operation_url)
22
+ format_response(response)
23
+ end
24
+
25
+ # Fetch the list of deposits from the profile of the API key,
26
+ # in descending order by created time.
27
+ #
28
+ # @param profile_id [String] Limit list of deposits to this profile_id.
29
+ # By default, it retrieves deposits using default profile (optional).
30
+ # @param type [String] Set to deposit or internal_deposit (optional).
31
+ # @param paginate_options [Hash] an hash with the following parameters
32
+ # before [String] If before is set, then it returns deposits created after
33
+ # the before timestamp, sorted by oldest creation date (optional).
34
+ # after [String] If after is set, then it returns deposits created before
35
+ # the after timestamp, sorted by newest (optional).
36
+ # limit [Integer] Truncate list to this many deposits, capped at 100.
37
+ # Default is 100. (optional).
38
+ # @return [Hash] a hash with status code and deposit list.
39
+ def list(options = {})
40
+ operation_url = '/transfers'
41
+ query_params = build_query_params(options)
42
+
43
+ operation_url += '/?' + query_params if query_params.present?
44
+ response = get(operation_url)
45
+ format_response(response)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Utility file for general methods
5
+ module Util
6
+
7
+ def send_request(path)
8
+ headers = {
9
+ 'Content-Type' => 'application/json',
10
+ 'Accept' => 'application/json',
11
+ 'User-Agent' => 'request'
12
+ }
13
+ response = HTTParty.get("#{base_uri}#{path}", headers: headers)
14
+ format_response(response)
15
+ end
16
+
17
+ def format_response(response)
18
+ {
19
+ status: response.code,
20
+ result: (JSON.parse(response.body) rescue response.body),
21
+ pagination: pagination_params(response.headers)
22
+ }
23
+ end
24
+
25
+ def pagination_params(headers = {})
26
+ return {} if headers['cb-before'].blank? || headers['cb-after'].blank?
27
+
28
+ { before: headers['cb-before'], after: headers['cb-after'] }
29
+ end
30
+
31
+ # Build query params for URL
32
+ def build_query_params(params = nil)
33
+ return params if params.blank?
34
+
35
+ query_array = params.keys.map { |key| [key.to_s, params[key]] }
36
+ URI.encode_www_form(query_array)
37
+ end
38
+
39
+ def base_uri
40
+ Coinbase::Client.configuration[:url]
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coinbase
4
+ # Withdrawl coinbase APIs
5
+ class Withdrawals < Transfers
6
+ WITHDRAWAL_API = '/transfers'
7
+ DEFAULT_TYPE = 'withdraw'
8
+
9
+ # Fetch the network fee estimate when sending to the given address.
10
+ #
11
+ # @param currency [String] The type of currency.
12
+ # @param crypto_address [String] A crypto address of the recipient.
13
+ # @return [Hash] a hash with status code and fee estimate.
14
+ def fee_estimate(params = {})
15
+ operational_url = '/withdrawals/fee-estimate'
16
+ query_params = build_query_params(params)
17
+ operational_url += '/?' + query_params unless query_params.empty?
18
+ response = get(operational_url)
19
+ format_response(response)
20
+ end
21
+
22
+ # Withdraw funds to a crypto address.
23
+ #
24
+ # @param withdraw_details [Hash] with following fields
25
+ # amount [Float] The amount to withdraw.
26
+ # currency [String] The type of currency.
27
+ # crypto_address [String] A crypto address of the recipient.
28
+ # destination_tag [String] A destination tag for currencies
29
+ # that support one.
30
+ # no_destination_tag [Boolean] A boolean flag to opt out of
31
+ # using a destination tag for currencies that support one.
32
+ # This is required when not providing a destination tag.
33
+ # add_network_fee_to_total [Boolean] A boolean flag to add the network fee
34
+ # on top of the amount.
35
+ # @return [Hash] a hash with status code and withdraw details.
36
+ def by_crypto(withdraw_details = {})
37
+ format_response(
38
+ post(
39
+ '/withdrawals/crypto',
40
+ body: withdraw_details
41
+ )
42
+ )
43
+ end
44
+
45
+ # Withdraw funds to a coinbase account.
46
+ #
47
+ # @param withdraw_details [Hash] with following fields
48
+ # amount [Float] The amount to withdraw.
49
+ # currency [String] The type of currency.
50
+ # coinbase_account_id [String] ID of coinbase account.
51
+ # @return [Hash] a hash with status code and withdraw details.
52
+ def by_account(withdraw_details = {})
53
+ format_response(
54
+ post(
55
+ '/withdrawals/coinbase-account',
56
+ body: withdraw_details
57
+ )
58
+ )
59
+ end
60
+
61
+ # Withdraw funds to a payment method.
62
+ #
63
+ # @param withdraw_details [Hash] with following fields
64
+ # amount [Float] The amount to withdraw.
65
+ # currency [String] The type of currency.
66
+ # payment_method_id [String] ID of the payment method.
67
+ # @return [Hash] a hash with status code and withdraw details.
68
+ def by_method(withdraw_details)
69
+ format_response(
70
+ post(
71
+ '/withdrawals/payment-method',
72
+ body: withdraw_details
73
+ )
74
+ )
75
+ end
76
+
77
+ # Fetch the list of Withdrawals from the profile of the API key,
78
+ # in descending order by created time.
79
+ #
80
+ # @param profile_id [String] Limit list of withdrawals to this profile_id.
81
+ # By default, it retrieves withdrawals using default profile(optional).
82
+ # @param type [String] Set to withdraw or internal_withdraw (optional).
83
+ # @param paginate_options [Hash] an hash with the following parameters
84
+ # before [String] If before is set,then it returns withdrawals created after
85
+ # the before timestamp, sorted by oldest creation date(optional).
86
+ # after [String] If after is set, then it returns withdrawals created before
87
+ # the after timestamp, sorted by newest (optional).
88
+ # limit [Integer] Truncate list to this many withdrawals, capped at 100.
89
+ # Default is 100. (optional).
90
+ # @return [Hash] a hash with status code and withdrawal list.
91
+ def list(options = {})
92
+ options[:type] = options[:type].blank? ? DEFAULT_TYPE : options[:type]
93
+ super(options)
94
+ end
95
+ end
96
+ end
data/lib/coinbase.rb ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require 'active_support'
5
+ require 'coinbase/util'
6
+ require 'coinbase/client'
7
+ require 'coinbase/products'
8
+ require 'coinbase/currency'
9
+ require 'coinbase/accounts'
10
+ require 'coinbase/transactions'
11
+ require 'coinbase/orders'
12
+ require 'coinbase/transfers'
13
+ require 'coinbase/withdrawals'
14
+ require 'coinbase/fees'
15
+ require 'coinbase/deposits'
16
+ require 'coinbase/conversions'
17
+
18
+ # Coinbase base module
19
+ module Coinbase
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'rails/generators'
2
+ module Coinbase
3
+ module Generators
4
+ class InitializeGenerator < Rails::Generators::Base
5
+ def create_initializer_file
6
+ yaml_file = {
7
+ development: {
8
+ url: "https://api-public.sandbox.exchange.coinbase.com",
9
+ api_key: "",
10
+ api_secret: "",
11
+ passphrase: ""
12
+ }
13
+ }
14
+
15
+ create_file 'config/coinbase.yml', yaml_file.to_yaml
16
+ create_file 'config/initializers/coinbase.rb',
17
+ "COINBASE_CONFIG = YAML.load_file(Rails.root.join('config', 'coinbase.yml')).with_indifferent_access[Rails.env]"
18
+ end
19
+ end
20
+ end
21
+ end
22
+
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coinbase-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nisha Jadhav
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.20'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.20'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-airbnb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 3.0.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 3.0.2
69
+ description: Ruby coinbase wrapper
70
+ email: nisha.jadhav@forusall.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/coinbase.rb
76
+ - lib/coinbase/accounts.rb
77
+ - lib/coinbase/client.rb
78
+ - lib/coinbase/conversions.rb
79
+ - lib/coinbase/currency.rb
80
+ - lib/coinbase/deposits.rb
81
+ - lib/coinbase/fees.rb
82
+ - lib/coinbase/orders.rb
83
+ - lib/coinbase/products.rb
84
+ - lib/coinbase/transactions.rb
85
+ - lib/coinbase/transfers.rb
86
+ - lib/coinbase/util.rb
87
+ - lib/coinbase/withdrawals.rb
88
+ - lib/generators/coinbase/initialize_generator.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.2.32
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Ruby coinbase wrapper
112
+ test_files: []