Class: Coinbase::FundQuote

Inherits:
Object
  • Object
show all
Defined in:
lib/coinbase/fund_quote.rb

Overview

A representation of a Fund Operation Quote, which is a quote for a fund operation that buys funds from the Coinbase platform and sends then to the developer’s address.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ FundQuote

Returns a new Fund Quote object. Do not use this method directly. Instead, use Wallet#quote_fund or Address#quote_fund.

Parameters:

Raises:

  • (ArgumentError)


48
49
50
51
52
# File 'lib/coinbase/fund_quote.rb', line 48

def initialize(model)
  raise ArgumentError, 'must be a FundQuote' unless model.is_a?(Coinbase::Client::FundQuote)

  @model = model
end

Class Method Details

.create(wallet_id:, address_id:, amount:, asset_id:, network:) ⇒ FundQuote

Creates a new Fund Operation Quote object.

Parameters:

  • address_id (String)

    The Address ID of the sending Address

  • wallet_id (String)

    The Wallet ID of the sending Wallet

  • amount (BigDecimal)

    The amount of the Asset to send

  • network (Coinbase::Network, Symbol)

    The Network or Network ID of the Asset

  • asset_id (Symbol)

    The Asset ID of the Asset to send

Returns:

Raises:

  • (Coinbase::ApiError)

    If the Fund Quote fails



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/coinbase/fund_quote.rb', line 20

def create(wallet_id:, address_id:, amount:, asset_id:, network:)
  network = Coinbase::Network.from_id(network)
  asset = network.get_asset(asset_id)

  model = Coinbase.call_api do
    fund_api.create_fund_quote(
      wallet_id,
      address_id,
      {
        asset_id: asset.primary_denomination.to_s,
        amount: asset.to_atomic_amount(amount).to_i.to_s
      }
    )
  end

  new(model)
end

Instance Method Details

#address_idString

Returns the Address ID that the fund quote was created for.

Returns:

  • (String)

    The Address ID



88
89
90
# File 'lib/coinbase/fund_quote.rb', line 88

def address_id
  @model.address_id
end

#amountCoinbase::CryptoAmount

Returns the amount that the wallet will receive in crypto.

Returns:



100
101
102
# File 'lib/coinbase/fund_quote.rb', line 100

def amount
  @amount ||= CryptoAmount.from_model(@model.crypto_amount)
end

#assetCoinbase::Asset

Returns the Asset of the FundOperation.

Returns:



94
95
96
# File 'lib/coinbase/fund_quote.rb', line 94

def asset
  amount.asset
end

#buy_feeCoinbase::FiatAmount

Returns the fee that the wallet’s owner will pay in fiat.

Returns:



112
113
114
# File 'lib/coinbase/fund_quote.rb', line 112

def buy_fee
  @buy_fee ||= FiatAmount.from_model(@model.fees.buy_fee)
end

#execute!Coinbase::FundOperation

Executes a fund operation using the quote.

Returns:

Raises:

  • (Coinbase::ApiError)

    If the FundOperation fails



63
64
65
66
67
68
69
70
71
72
# File 'lib/coinbase/fund_quote.rb', line 63

def execute!
  FundOperation.create(
    wallet_id: wallet_id,
    address_id: address_id,
    amount: amount.amount,
    asset_id: asset.asset_id,
    network: network.id,
    quote: self
  )
end

#fiat_amountCoinbase::FiatAmount

Returns the amount that the wallet’s owner will pay in fiat.

Returns:



106
107
108
# File 'lib/coinbase/fund_quote.rb', line 106

def fiat_amount
  @fiat_amount ||= FiatAmount.from_model(@model.fiat_amount)
end

#idString

Returns the ID of the Fund Quote.

Returns:

  • (String)

    The Fund Quote ID



56
57
58
# File 'lib/coinbase/fund_quote.rb', line 56

def id
  @model.fund_quote_id
end

#inspectString

Same as to_s.

Returns:

  • (String)

    a String representation of the Transfer



139
140
141
# File 'lib/coinbase/fund_quote.rb', line 139

def inspect
  to_s
end

#networkCoinbase::Network

Returns the Network the fund quote was created on.

Returns:



76
77
78
# File 'lib/coinbase/fund_quote.rb', line 76

def network
  @network ||= Coinbase::Network.from_id(@model.network_id)
end

#to_sString

Returns a String representation of the Fund Operation.

Returns:

  • (String)

    a String representation of the Fund Operation



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/coinbase/fund_quote.rb', line 124

def to_s
  Coinbase.pretty_print_object(
    self.class,
    network_id: network.id,
    wallet_id: wallet_id,
    address_id: address_id,
    crypto_amount: amount,
    fiat_amount: fiat_amount,
    buy_fee: buy_fee,
    transfer_fee: transfer_fee
  )
end

#transfer_feeCoinbase::CryptoAmount

Returns the fee that the wallet’s owner will pay in crypto.

Returns:



118
119
120
# File 'lib/coinbase/fund_quote.rb', line 118

def transfer_fee
  @transfer_fee ||= CryptoAmount.from_model(@model.fees.transfer_fee)
end

#wallet_idString

Returns the Wallet ID that the fund quote was created for.

Returns:

  • (String)

    The Wallet ID



82
83
84
# File 'lib/coinbase/fund_quote.rb', line 82

def wallet_id
  @model.wallet_id
end