Class: Airwallex::Quote

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::Retrieve
Defined in:
lib/airwallex/resources/quote.rb

Overview

Quote resource for locked exchange rates

Create quotes to lock exchange rates for a short period (typically 30-60 seconds). Use quotes to guarantee the rate when executing conversions.

Examples:

Create a quote

quote = Airwallex::Quote.create(
  buy_currency: 'EUR',
  sell_currency: 'USD',
  sell_amount: 1000.00
)
puts "Locked rate: #{quote.client_rate}, expires: #{quote.expires_at}"

Use quote for conversion

conversion = Airwallex::Conversion.create(quote_id: quote.id)

Instance Attribute Summary

Attributes inherited from APIResource

#attributes, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::Retrieve

retrieve

Methods inherited from APIResource

#changed_attributes, #dirty?, #initialize, #inspect, #method_missing, #refresh, #refresh_from, resource_name, #respond_to_missing?, #to_hash, #to_json, #to_s

Constructor Details

This class inherits a constructor from Airwallex::APIResource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Airwallex::APIResource

Class Method Details

.resource_pathObject



24
25
26
# File 'lib/airwallex/resources/quote.rb', line 24

def self.resource_path
  "/api/v1/fx/quotes"
end

Instance Method Details

#expired?Boolean

Check if quote has expired

Returns:

  • (Boolean)

    true if quote is expired



31
32
33
34
35
36
37
# File 'lib/airwallex/resources/quote.rb', line 31

def expired?
  return false unless respond_to?(:expires_at) && expires_at

  Time.parse(expires_at) < Time.now
rescue ArgumentError
  true
end

#seconds_until_expirationInteger?

Get seconds until expiration

Returns:

  • (Integer, nil)

    seconds remaining, 0 if expired, nil if no expiration



42
43
44
45
46
47
48
49
# File 'lib/airwallex/resources/quote.rb', line 42

def seconds_until_expiration
  return nil unless respond_to?(:expires_at) && expires_at

  remaining = Time.parse(expires_at) - Time.now
  [remaining.to_i, 0].max
rescue ArgumentError
  0
end