1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Futures contract quote handle.
//!
//! Created via [`Providers::futures`](crate::Providers::futures).
use crate::constants::{Interval, TimeRange};
use crate::error::Result;
use crate::models::chart::Chart;
domain_handle! {
/// A futures contract backed by configured data providers.
///
/// Created via [`Providers::futures`](crate::Providers::futures).
pub struct FuturesContract { symbol, symbol }
cache: crate::models::futures::FuturesQuote, chart,
extra: {
#[cfg(feature = "cftc")]
cot_cache: crate::models::futures::cot::CommitmentsOfTraders,
}
}
impl FuturesContract {
/// Fetch the current quote for this futures contract.
pub async fn quote(&self) -> Result<crate::models::futures::FuturesQuote> {
fetch_via!(
self,
symbol,
FUTURES,
as_futures,
FuturesQuote,
fetch_futures_quote,
crate::models::futures::FuturesQuote
)
}
/// Fetch historical OHLCV candles for this futures contract.
///
/// The symbol is passed to the `CHART` route as-is (e.g. Yahoo futures
/// symbols like `NQ=F`).
pub async fn chart(&self, interval: Interval, range: TimeRange) -> Result<Chart> {
fetch_chart_via!(self, self.symbol.to_string(), interval, range)
}
/// Fetch historical candles over `range` at a sensible default interval
/// ([`TimeRange::default_interval`]).
pub async fn history(&self, range: TimeRange) -> Result<Chart> {
self.chart(range.default_interval(), range).await
}
/// Fetch weekly CFTC Commitments of Traders positioning for this futures
/// contract — long/short/spread broken down by trader category
/// (commercial hedgers, swap dealers, managed money, other reportables,
/// small traders).
///
/// Routed through `Capability::FUTURES`; only [`Provider::Cftc`](crate::Provider::Cftc)
/// serves it, so route `FUTURES` to include it. CFTC covers physical
/// commodities only (agriculture, energy, metals) via the disaggregated
/// futures-only report — the symbol is either a recognised Yahoo-style
/// continuous futures root (`"GC=F"`, `"CL=F"`, …) or a raw CFTC
/// `cftc_contract_market_code` passed straight through.
#[cfg(feature = "cftc")]
pub async fn commitments_of_traders(
&self,
) -> Result<crate::models::futures::cot::CommitmentsOfTraders> {
fetch_via!(
cache: cot_cache,
self,
symbol,
FUTURES,
as_futures,
CommitmentsOfTraders,
fetch_commitments_of_traders,
crate::models::futures::cot::CommitmentsOfTraders
)
}
}
impl_chartable_analytics!(FuturesContract, crate::risk::TradingCalendar::Exchange);