GetPositionBookRequest

Struct GetPositionBookRequest 

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

Get Position Book Fetch a position book for an instrument.

Implementations§

Source§

impl GetPositionBookRequest

Source

pub fn new() -> GetPositionBookRequest

Examples found in repository?
examples/endpoints.rs (lines 33-34)
6async fn main() {
7    let api_key = env::var("OANDA_KEY").expect("expected OANDA_KEY environment variable to be set");
8    let api_host = env
9        ::var("OANDA_HOST")
10        .expect("expected OANDA_HOST environment variable to be set");
11
12    // only run example program against demo account!!
13    assert_eq!(api_host, "api-fxpractice.oanda.com");
14
15    let client = fxoanda::Client {
16        host: String::from(api_host),
17        reqwest: reqwest::Client::new(),
18        authentication: String::from(api_key),
19    };
20
21    match
22        fxoanda::GetInstrumentCandlesRequest
23            ::new()
24            .with_instrument("EUR_USD".to_string())
25            .with_granularity(CandlestickGranularity::H4)
26            .remote(&client).await
27    {
28        Ok(x) => println!("OK: {:#?}", x),
29        Err(e) => eprintln!("ERR: {:#?}", e),
30    }
31
32    match
33        fxoanda::GetPositionBookRequest
34            ::new()
35            .with_instrument("EUR_USD".to_string())
36            .remote(&client).await
37    {
38        Ok(x) => println!("OK: {:#?}", x),
39        Err(e) => println!("ERR: {:#?}", e),
40    }
41
42    match
43        fxoanda::GetOrderBookRequest
44            ::new()
45            .with_instrument("EUR_USD".to_string())
46            .remote(&client).await
47    {
48        Ok(x) => println!("OK: {:#?}", x),
49        Err(e) => println!("ERR: {:#?}", e),
50    }
51
52    match fxoanda::ListAccountsRequest::new().remote(&client).await {
53        Ok(x) => println!("OK: {:#?}", x),
54        Err(e) => println!("ERR: {:#?}", e),
55    }
56
57    let response = fxoanda::ListAccountsRequest::new().remote(&client).await.unwrap();
58    let accounts = response.accounts.expect("Did not find 'accounts' field in response");
59    let account = accounts.get(0).expect("Did not find an 'account' in the 'accounts' field");
60    let account_id = account.id
61        .as_ref()
62        .expect("Did not find an 'id' field in the 'account'")
63        .to_string();
64
65    match
66        fxoanda::GetAccountSummaryRequest
67            ::new()
68            .with_account_id(account_id.to_owned())
69            .remote(&client).await
70    {
71        Ok(x) => println!("OK: {:#?}", x),
72        Err(e) => println!("ERR: {:#?}", e),
73    }
74
75    match
76        fxoanda::GetAccountRequest
77            ::new()
78            .with_account_id(account_id.to_owned())
79            .remote(&client).await
80    {
81        Ok(x) => println!("OK: {:#?}", x),
82        Err(e) => println!("ERR: {:#?}", e),
83    }
84
85    match
86        fxoanda::GetAccountInstrumentsRequest
87            ::new()
88            .with_account_id(account_id.to_owned())
89            .remote(&client).await
90    {
91        Ok(x) => println!("OK: {:#?}", x),
92        Err(e) => println!("ERR: {:#?}", e),
93    }
94
95    match
96        fxoanda::ListOrdersRequest
97            ::new()
98            .with_account_id(account_id.to_owned())
99            .remote(&client).await
100    {
101        Ok(x) => println!("OK: {:#?}", x),
102        Err(e) => println!("ERR: {:#?}", e),
103    }
104
105    match
106        fxoanda::ListPendingOrdersRequest
107            ::new()
108            .with_account_id(account_id.to_owned())
109            .remote(&client).await
110    {
111        Ok(x) => println!("OK: {:#?}", x),
112        Err(e) => println!("ERR: {:#?}", e),
113    }
114
115    match
116        fxoanda::ListTradesRequest
117            ::new()
118            .with_account_id(account_id.to_owned())
119            .remote(&client).await
120    {
121        Ok(x) => println!("OK: {:#?}", x),
122        Err(e) => println!("ERR: {:#?}", e),
123    }
124
125    match
126        fxoanda::ListOpenTradesRequest
127            ::new()
128            .with_account_id(account_id.to_owned())
129            .remote(&client).await
130    {
131        Ok(x) => println!("OK: {:#?}", x),
132        Err(e) => println!("ERR: {:#?}", e),
133    }
134
135    match
136        fxoanda::ListPositionsRequest
137            ::new()
138            .with_account_id(account_id.to_owned())
139            .remote(&client).await
140    {
141        Ok(x) => println!("OK: {:#?}", x),
142        Err(e) => println!("ERR: {:#?}", e),
143    }
144
145    match
146        fxoanda::ListOpenPositionsRequest
147            ::new()
148            .with_account_id(account_id.to_owned())
149            .remote(&client).await
150    {
151        Ok(x) => println!("OK: {:#?}", x),
152        Err(e) => println!("ERR: {:#?}", e),
153    }
154
155    match
156        fxoanda::ListTransactionsRequest
157            ::new()
158            .with_account_id(account_id.to_owned())
159            .remote(&client).await
160    {
161        Ok(x) => println!("OK: {:#?}", x),
162        Err(e) => println!("ERR: {:#?}", e),
163    }
164}
Source

pub fn with_uri(self, x: String) -> Self

Source

pub fn with_instrument(self, x: String) -> Self

Name of the Instrument format: A string containing the base currency and quote currency delimited by a “_”.

  • param String
  • return GetPositionBookRequest
Examples found in repository?
examples/endpoints.rs (line 35)
6async fn main() {
7    let api_key = env::var("OANDA_KEY").expect("expected OANDA_KEY environment variable to be set");
8    let api_host = env
9        ::var("OANDA_HOST")
10        .expect("expected OANDA_HOST environment variable to be set");
11
12    // only run example program against demo account!!
13    assert_eq!(api_host, "api-fxpractice.oanda.com");
14
15    let client = fxoanda::Client {
16        host: String::from(api_host),
17        reqwest: reqwest::Client::new(),
18        authentication: String::from(api_key),
19    };
20
21    match
22        fxoanda::GetInstrumentCandlesRequest
23            ::new()
24            .with_instrument("EUR_USD".to_string())
25            .with_granularity(CandlestickGranularity::H4)
26            .remote(&client).await
27    {
28        Ok(x) => println!("OK: {:#?}", x),
29        Err(e) => eprintln!("ERR: {:#?}", e),
30    }
31
32    match
33        fxoanda::GetPositionBookRequest
34            ::new()
35            .with_instrument("EUR_USD".to_string())
36            .remote(&client).await
37    {
38        Ok(x) => println!("OK: {:#?}", x),
39        Err(e) => println!("ERR: {:#?}", e),
40    }
41
42    match
43        fxoanda::GetOrderBookRequest
44            ::new()
45            .with_instrument("EUR_USD".to_string())
46            .remote(&client).await
47    {
48        Ok(x) => println!("OK: {:#?}", x),
49        Err(e) => println!("ERR: {:#?}", e),
50    }
51
52    match fxoanda::ListAccountsRequest::new().remote(&client).await {
53        Ok(x) => println!("OK: {:#?}", x),
54        Err(e) => println!("ERR: {:#?}", e),
55    }
56
57    let response = fxoanda::ListAccountsRequest::new().remote(&client).await.unwrap();
58    let accounts = response.accounts.expect("Did not find 'accounts' field in response");
59    let account = accounts.get(0).expect("Did not find an 'account' in the 'accounts' field");
60    let account_id = account.id
61        .as_ref()
62        .expect("Did not find an 'id' field in the 'account'")
63        .to_string();
64
65    match
66        fxoanda::GetAccountSummaryRequest
67            ::new()
68            .with_account_id(account_id.to_owned())
69            .remote(&client).await
70    {
71        Ok(x) => println!("OK: {:#?}", x),
72        Err(e) => println!("ERR: {:#?}", e),
73    }
74
75    match
76        fxoanda::GetAccountRequest
77            ::new()
78            .with_account_id(account_id.to_owned())
79            .remote(&client).await
80    {
81        Ok(x) => println!("OK: {:#?}", x),
82        Err(e) => println!("ERR: {:#?}", e),
83    }
84
85    match
86        fxoanda::GetAccountInstrumentsRequest
87            ::new()
88            .with_account_id(account_id.to_owned())
89            .remote(&client).await
90    {
91        Ok(x) => println!("OK: {:#?}", x),
92        Err(e) => println!("ERR: {:#?}", e),
93    }
94
95    match
96        fxoanda::ListOrdersRequest
97            ::new()
98            .with_account_id(account_id.to_owned())
99            .remote(&client).await
100    {
101        Ok(x) => println!("OK: {:#?}", x),
102        Err(e) => println!("ERR: {:#?}", e),
103    }
104
105    match
106        fxoanda::ListPendingOrdersRequest
107            ::new()
108            .with_account_id(account_id.to_owned())
109            .remote(&client).await
110    {
111        Ok(x) => println!("OK: {:#?}", x),
112        Err(e) => println!("ERR: {:#?}", e),
113    }
114
115    match
116        fxoanda::ListTradesRequest
117            ::new()
118            .with_account_id(account_id.to_owned())
119            .remote(&client).await
120    {
121        Ok(x) => println!("OK: {:#?}", x),
122        Err(e) => println!("ERR: {:#?}", e),
123    }
124
125    match
126        fxoanda::ListOpenTradesRequest
127            ::new()
128            .with_account_id(account_id.to_owned())
129            .remote(&client).await
130    {
131        Ok(x) => println!("OK: {:#?}", x),
132        Err(e) => println!("ERR: {:#?}", e),
133    }
134
135    match
136        fxoanda::ListPositionsRequest
137            ::new()
138            .with_account_id(account_id.to_owned())
139            .remote(&client).await
140    {
141        Ok(x) => println!("OK: {:#?}", x),
142        Err(e) => println!("ERR: {:#?}", e),
143    }
144
145    match
146        fxoanda::ListOpenPositionsRequest
147            ::new()
148            .with_account_id(account_id.to_owned())
149            .remote(&client).await
150    {
151        Ok(x) => println!("OK: {:#?}", x),
152        Err(e) => println!("ERR: {:#?}", e),
153    }
154
155    match
156        fxoanda::ListTransactionsRequest
157            ::new()
158            .with_account_id(account_id.to_owned())
159            .remote(&client).await
160    {
161        Ok(x) => println!("OK: {:#?}", x),
162        Err(e) => println!("ERR: {:#?}", e),
163    }
164}
Source

pub fn with_authorization(self, x: String) -> Self

The authorization bearer token previously obtained by the client format: The string ’Bearer ’ followed by the token.

  • param String
  • return GetPositionBookRequest
Source

pub fn with_accept_datetime_format(self, x: String) -> Self

Format of DateTime fields in the request and response.

  • param String
  • return GetPositionBookRequest
Source

pub fn with_time(self, x: DateTime<Utc>) -> Self

The time of the snapshot to fetch. If not specified, then the most recent snapshot is fetched. format: The RFC 3339 representation is a string conforming to https://tools.ietf.org/rfc/rfc3339.txt. The Unix representation is a string representing the number of seconds since the Unix Epoch (January 1st, 1970 at UTC). The value is a fractional number, where the fractional part represents a fraction of a second (up to nine decimal places).

  • param DateTime
  • return GetPositionBookRequest
Source

pub async fn remote( self, client: &Client, ) -> Result<GetPositionBookResponse, Box<dyn Error>>

Examples found in repository?
examples/endpoints.rs (line 36)
6async fn main() {
7    let api_key = env::var("OANDA_KEY").expect("expected OANDA_KEY environment variable to be set");
8    let api_host = env
9        ::var("OANDA_HOST")
10        .expect("expected OANDA_HOST environment variable to be set");
11
12    // only run example program against demo account!!
13    assert_eq!(api_host, "api-fxpractice.oanda.com");
14
15    let client = fxoanda::Client {
16        host: String::from(api_host),
17        reqwest: reqwest::Client::new(),
18        authentication: String::from(api_key),
19    };
20
21    match
22        fxoanda::GetInstrumentCandlesRequest
23            ::new()
24            .with_instrument("EUR_USD".to_string())
25            .with_granularity(CandlestickGranularity::H4)
26            .remote(&client).await
27    {
28        Ok(x) => println!("OK: {:#?}", x),
29        Err(e) => eprintln!("ERR: {:#?}", e),
30    }
31
32    match
33        fxoanda::GetPositionBookRequest
34            ::new()
35            .with_instrument("EUR_USD".to_string())
36            .remote(&client).await
37    {
38        Ok(x) => println!("OK: {:#?}", x),
39        Err(e) => println!("ERR: {:#?}", e),
40    }
41
42    match
43        fxoanda::GetOrderBookRequest
44            ::new()
45            .with_instrument("EUR_USD".to_string())
46            .remote(&client).await
47    {
48        Ok(x) => println!("OK: {:#?}", x),
49        Err(e) => println!("ERR: {:#?}", e),
50    }
51
52    match fxoanda::ListAccountsRequest::new().remote(&client).await {
53        Ok(x) => println!("OK: {:#?}", x),
54        Err(e) => println!("ERR: {:#?}", e),
55    }
56
57    let response = fxoanda::ListAccountsRequest::new().remote(&client).await.unwrap();
58    let accounts = response.accounts.expect("Did not find 'accounts' field in response");
59    let account = accounts.get(0).expect("Did not find an 'account' in the 'accounts' field");
60    let account_id = account.id
61        .as_ref()
62        .expect("Did not find an 'id' field in the 'account'")
63        .to_string();
64
65    match
66        fxoanda::GetAccountSummaryRequest
67            ::new()
68            .with_account_id(account_id.to_owned())
69            .remote(&client).await
70    {
71        Ok(x) => println!("OK: {:#?}", x),
72        Err(e) => println!("ERR: {:#?}", e),
73    }
74
75    match
76        fxoanda::GetAccountRequest
77            ::new()
78            .with_account_id(account_id.to_owned())
79            .remote(&client).await
80    {
81        Ok(x) => println!("OK: {:#?}", x),
82        Err(e) => println!("ERR: {:#?}", e),
83    }
84
85    match
86        fxoanda::GetAccountInstrumentsRequest
87            ::new()
88            .with_account_id(account_id.to_owned())
89            .remote(&client).await
90    {
91        Ok(x) => println!("OK: {:#?}", x),
92        Err(e) => println!("ERR: {:#?}", e),
93    }
94
95    match
96        fxoanda::ListOrdersRequest
97            ::new()
98            .with_account_id(account_id.to_owned())
99            .remote(&client).await
100    {
101        Ok(x) => println!("OK: {:#?}", x),
102        Err(e) => println!("ERR: {:#?}", e),
103    }
104
105    match
106        fxoanda::ListPendingOrdersRequest
107            ::new()
108            .with_account_id(account_id.to_owned())
109            .remote(&client).await
110    {
111        Ok(x) => println!("OK: {:#?}", x),
112        Err(e) => println!("ERR: {:#?}", e),
113    }
114
115    match
116        fxoanda::ListTradesRequest
117            ::new()
118            .with_account_id(account_id.to_owned())
119            .remote(&client).await
120    {
121        Ok(x) => println!("OK: {:#?}", x),
122        Err(e) => println!("ERR: {:#?}", e),
123    }
124
125    match
126        fxoanda::ListOpenTradesRequest
127            ::new()
128            .with_account_id(account_id.to_owned())
129            .remote(&client).await
130    {
131        Ok(x) => println!("OK: {:#?}", x),
132        Err(e) => println!("ERR: {:#?}", e),
133    }
134
135    match
136        fxoanda::ListPositionsRequest
137            ::new()
138            .with_account_id(account_id.to_owned())
139            .remote(&client).await
140    {
141        Ok(x) => println!("OK: {:#?}", x),
142        Err(e) => println!("ERR: {:#?}", e),
143    }
144
145    match
146        fxoanda::ListOpenPositionsRequest
147            ::new()
148            .with_account_id(account_id.to_owned())
149            .remote(&client).await
150    {
151        Ok(x) => println!("OK: {:#?}", x),
152        Err(e) => println!("ERR: {:#?}", e),
153    }
154
155    match
156        fxoanda::ListTransactionsRequest
157            ::new()
158            .with_account_id(account_id.to_owned())
159            .remote(&client).await
160    {
161        Ok(x) => println!("OK: {:#?}", x),
162        Err(e) => println!("ERR: {:#?}", e),
163    }
164}

Trait Implementations§

Source§

impl Debug for GetPositionBookRequest

Source§

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

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

impl<'de> Deserialize<'de> for GetPositionBookRequest

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for GetPositionBookRequest

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,