Ticker

Struct Ticker 

Source
pub struct Ticker { /* private fields */ }
Expand description

A forex ticker for fetching exchange rate data.

§Example

use dukascopy_fx::Ticker;

let ticker = Ticker::new("EUR", "USD");

// Get recent rate
let rate = ticker.rate().await?;
println!("EUR/USD: {}", rate.rate);

// Get historical data
let history = ticker.history("1w").await?;

Implementations§

Source§

impl Ticker

Source

pub fn new(from: &str, to: &str) -> Self

Creates a new ticker for a currency pair.

Source

pub fn parse(pair: &str) -> Result<Self, DukascopyError>

Creates a ticker from a pair string like “EUR/USD” or “EURUSD”.

Source

pub fn interval(self, interval: Duration) -> Self

Sets the data interval for historical queries.

Source

pub fn pair(&self) -> &CurrencyPair

Returns the currency pair.

Source

pub fn symbol(&self) -> String

Returns the ticker symbol (e.g., “EURUSD”).

Source

pub async fn rate_at( &self, timestamp: DateTime<Utc>, ) -> Result<CurrencyExchange, DukascopyError>

Fetches the exchange rate at a specific timestamp.

Source

pub async fn rate(&self) -> Result<CurrencyExchange, DukascopyError>

Fetches the most recent available exchange rate.

Source

pub async fn history( &self, period: &str, ) -> Result<Vec<CurrencyExchange>, DukascopyError>

Fetches historical data for a time period.

§Period Strings
  • "1d" - 1 day
  • "5d" - 5 days
  • "1w" - 1 week
  • "1mo" - 1 month (30 days)
  • "3mo" - 3 months
  • "1y" - 1 year
Source

pub async fn history_range( &self, start: DateTime<Utc>, end: DateTime<Utc>, ) -> Result<Vec<CurrencyExchange>, DukascopyError>

Fetches historical data between two dates.

Source

pub fn eur_usd() -> Self

Source

pub fn gbp_usd() -> Self

Source

pub fn usd_jpy() -> Self

Source

pub fn usd_chf() -> Self

Source

pub fn aud_usd() -> Self

Source

pub fn usd_cad() -> Self

Source

pub fn xau_usd() -> Self

Source

pub fn xag_usd() -> Self

Trait Implementations§

Source§

impl Clone for Ticker

Source§

fn clone(&self) -> Ticker

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ticker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for Ticker

Source§

type Err = DukascopyError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

§

impl Freeze for Ticker

§

impl RefUnwindSafe for Ticker

§

impl Send for Ticker

§

impl Sync for Ticker

§

impl Unpin for Ticker

§

impl UnwindSafe for Ticker

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more