Class: Coinbase::FundQuote
- Inherits:
-
Object
- Object
- Coinbase::FundQuote
- 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
-
.create(wallet_id:, address_id:, amount:, asset_id:, network:) ⇒ FundQuote
Creates a new Fund Operation Quote object.
Instance Method Summary collapse
-
#address_id ⇒ String
Returns the Address ID that the fund quote was created for.
-
#amount ⇒ Coinbase::CryptoAmount
Returns the amount that the wallet will receive in crypto.
-
#asset ⇒ Coinbase::Asset
Returns the Asset of the FundOperation.
-
#buy_fee ⇒ Coinbase::FiatAmount
Returns the fee that the wallet’s owner will pay in fiat.
-
#execute! ⇒ Coinbase::FundOperation
Executes a fund operation using the quote.
-
#fiat_amount ⇒ Coinbase::FiatAmount
Returns the amount that the wallet’s owner will pay in fiat.
-
#id ⇒ String
Returns the ID of the Fund Quote.
-
#initialize(model) ⇒ FundQuote
constructor
Returns a new Fund Quote object.
-
#inspect ⇒ String
Same as to_s.
-
#network ⇒ Coinbase::Network
Returns the Network the fund quote was created on.
-
#to_s ⇒ String
Returns a String representation of the Fund Operation.
-
#transfer_fee ⇒ Coinbase::CryptoAmount
Returns the fee that the wallet’s owner will pay in crypto.
-
#wallet_id ⇒ String
Returns the Wallet ID that the fund quote was created for.
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.
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.
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_id ⇒ String
Returns the Address ID that the fund quote was created for.
88 89 90 |
# File 'lib/coinbase/fund_quote.rb', line 88 def address_id @model.address_id end |
#amount ⇒ Coinbase::CryptoAmount
Returns the amount that the wallet will receive in crypto.
100 101 102 |
# File 'lib/coinbase/fund_quote.rb', line 100 def amount @amount ||= CryptoAmount.from_model(@model.crypto_amount) end |
#asset ⇒ Coinbase::Asset
Returns the Asset of the FundOperation.
94 95 96 |
# File 'lib/coinbase/fund_quote.rb', line 94 def asset amount.asset end |
#buy_fee ⇒ Coinbase::FiatAmount
Returns the fee that the wallet’s owner will pay in fiat.
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.
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_amount ⇒ Coinbase::FiatAmount
Returns the amount that the wallet’s owner will pay in fiat.
106 107 108 |
# File 'lib/coinbase/fund_quote.rb', line 106 def fiat_amount @fiat_amount ||= FiatAmount.from_model(@model.fiat_amount) end |
#id ⇒ String
Returns the ID of the Fund Quote.
56 57 58 |
# File 'lib/coinbase/fund_quote.rb', line 56 def id @model.fund_quote_id end |
#inspect ⇒ String
Same as to_s.
139 140 141 |
# File 'lib/coinbase/fund_quote.rb', line 139 def inspect to_s end |
#network ⇒ Coinbase::Network
Returns the Network the fund quote was created on.
76 77 78 |
# File 'lib/coinbase/fund_quote.rb', line 76 def network @network ||= Coinbase::Network.from_id(@model.network_id) end |
#to_s ⇒ String
Returns 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_fee ⇒ Coinbase::CryptoAmount
Returns the fee that the wallet’s owner will pay in crypto.
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_id ⇒ String
Returns the Wallet ID that the fund quote was created for.
82 83 84 |
# File 'lib/coinbase/fund_quote.rb', line 82 def wallet_id @model.wallet_id end |